1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48:
| function GetPaddedValue(value: TBigNumber): TBytes; var l: integer; padded: TBytes; begin result := TBytes(value); l := (1024 shr 3); if length(result) >= l then begin exit; end;
padded := copy(result,(l - length(result)),length(result)); result := padded; end;
function RSADecrypt(buffer: PBytes;position: Integer;length:Integer): boolean; var input,output,m1,m2,h: TBigNumber; begin
if (length - position <> 128) then begin result := false; exit; end; SetLength(input,128);
input := TBigNumber(copy(buffer^,position, 128)); m1 := BM_PowerMod(input,otServerDP,otServerP); m2 := BM_PowerMod(input,otServerDQ,otServerQ);
if BM_CompareG(m2,m1) then begin h := BM_Sub(otServerP,BM_MultiplyMod(BM_Sub(m2,m1),otServerInverseQ,otServerP)); output := BM_Add(m2,BM_Multiply(otServerQ,h)); end else begin h := BM_MultiplyMod(BM_Sub(m2,m1),otServerInverseQ,otServerP); output := BM_Add(m2,BM_Multiply(otServerQ,h)); end;
buffer^ := copy(GetPaddedValue(output),position,128); result := true; end; |