int RSAVerifyBinary_f(const uint8_t* key_blob, const RSAPublicKey* key, const uint8_t* buf, int len, const uint8_t* sig, int algorithm) { RSAPublicKey* verification_key = NULL; uint8_t* digest = NULL; int key_size; int sig_size; int success; if (algorithm >= kNumAlgorithms) return 0; /* Invalid algorithm. */ key_size = RSAProcessedKeySize(algorithm); sig_size = siglen_map[algorithm] * sizeof(uint32_t); if (key_blob && !key) verification_key = RSAPublicKeyFromBuf(key_blob, key_size); else if (!key_blob && key) verification_key = (RSAPublicKey*) key; /* Supress const warning. */ else return 0; /* Both can't be NULL or non-NULL. */ digest = DigestBuf(buf, len, algorithm); success = RSA_verify(verification_key, sig, sig_size, algorithm, digest); Free(digest); if (!key) RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */ return success; }
RSAPublicKey *PublicKeyToRSA(const VbPublicKey *key) { RSAPublicKey *rsa; uint64_t key_size; if (kNumAlgorithms <= key->algorithm) { VBDEBUG(("Invalid algorithm.\n")); return NULL; } if (!RSAProcessedKeySize(key->algorithm, &key_size) || key_size != key->key_size) { VBDEBUG(("Wrong key size for algorithm\n")); return NULL; } rsa = RSAPublicKeyFromBuf(GetPublicKeyDataC(key), key->key_size); if (!rsa) return NULL; rsa->algorithm = (unsigned int)key->algorithm; return rsa; }