Advertisement
AnthonyCagliano

Untitled

Oct 21st, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. bool hashlib_SSLVerifySignature(const uint8_t *ca_pubkey, size_t keysize, const uint8_t *cert, size_t certlen, uint8_t sig_alg){
  2. if((ca_pubkey == NULL) || (cert == NULL)) return false;
  3. if(certlen <= keysize) return false;
  4. switch(sig_alg){
  5. case RSA_SHA256:
  6. {
  7. uint8_t sig_buf[RSA_MODULUS_MAX];
  8. uint8_t sha256digest[32];
  9. SHA256_CTX ctx;
  10. uint8_t mbuffer[64*4];
  11. memcpy(sig_buf, &cert[certlen-keysize-1], keysize);
  12. hashlib_RSAEncrypt(sig_buf, keysize, ca_pubkey, keysize);
  13. hashlib_Sha256Init(&ctx, mbuffer);
  14. hashlib_Sha256Update(&ctx, cert, certlen-keysize);
  15. hashlib_Sha256Final(&ctx, sha256digest);
  16. return hashlib_RSAVerifyPSS(sha256digest, 32, sig_buf, keysize);
  17. break;
  18. }
  19. default:
  20. return false;
  21. }
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement