Risks for HIV are:
1) having unprotected, penetrative anal or vaginal sex, or
2) sharing intravenous needles.
You did not have one of those two events, so you are at NO risk for HIV. No one has ever been infected by giving a handjob, even with cuts or scrapes. You will not be the first.
No idea what is causing your pain - I only know that it has NOTHING to do with HIV since you had zero risk.