rsaverify.pp 768 B

123456789101112131415161718192021222324252627282930313233
  1. program rsaverify;
  2. uses classes, libnettle, rsautil, libgmp, ctypes;
  3. Procedure Stop(Msg : string);
  4. begin
  5. Writeln(Msg);
  6. Halt(1);
  7. end;
  8. Var
  9. pubkey : Trsa_public_key;
  10. hash : tsha1_ctx;
  11. s : Tmpz_t;
  12. begin
  13. LoadLibGMP;
  14. InitializeNettle;
  15. if (ParamCount<>3) then
  16. Stop('Usage : rsasign pubkeyfile file signaturefile'+slinebreak+'Signature in base 16');
  17. if not ReadRSAKey(ParamStr(1),pubkey) then
  18. Stop('Failed to read key from '+ParamStr(1));
  19. nettle_sha1_init(@hash);
  20. HashFile(nettle_sha1,@Hash,ParamStr(2));
  21. if not ReadSignature(paramstr(3),s) then
  22. Stop('Failed to read key from '+ParamStr(3));
  23. if (nettle_rsa_sha1_verify(@pubkey, @hash, @s)=0) then
  24. Stop('Failed to verify signature')
  25. else
  26. Stop('Signature verifies OK')
  27. end.