Source release 18.1.0

This commit is contained in:
John "Juce" Bruce
2023-06-23 15:45:08 -07:00
parent 2baa7c6e2b
commit b2c35151ad
2074 changed files with 196004 additions and 427059 deletions

View File

@@ -207,7 +207,9 @@ OEMCryptoResult OemCertificate::GetPublicCertificate(
return OEMCrypto_ERROR_SHORT_BUFFER;
}
*public_cert_length = cert_data.size();
memcpy(public_cert, cert_data.data(), cert_data.size());
if (public_cert != nullptr) {
memcpy(public_cert, cert_data.data(), cert_data.size());
}
return OEMCrypto_SUCCESS;
}

View File

@@ -92,7 +92,7 @@ bool ParseRsaPrivateKeyInfo(const uint8_t* buffer, size_t length,
}
ScopedBio bio;
// Check allowed scheme type.
if (!memcmp("SIGN", buffer, 4)) {
if (memcmp("SIGN", buffer, 4) == 0) {
uint32_t allowed_schemes_bno;
memcpy(&allowed_schemes_bno, reinterpret_cast<const uint8_t*>(&buffer[4]),
4);
@@ -399,7 +399,8 @@ std::vector<uint8_t> RsaPublicKey::Serialize() const {
OEMCryptoResult RsaPublicKey::VerifySignature(
const uint8_t* message, size_t message_length, const uint8_t* signature,
size_t signature_length, RsaSignatureAlgorithm algorithm) const {
size_t signature_length, RsaSignatureAlgorithm algorithm,
OEMCrypto_SignatureHashAlgorithm hash_algorithm) const {
if (signature == nullptr || signature_length == 0) {
LOGE("Signature is missing");
return OEMCrypto_ERROR_INVALID_CONTEXT;
@@ -411,7 +412,7 @@ OEMCryptoResult RsaPublicKey::VerifySignature(
switch (algorithm) {
case kRsaPssDefault:
return VerifySignaturePss(message, message_length, signature,
signature_length);
signature_length, hash_algorithm);
case kRsaPkcs1Cast:
return VerifySignaturePkcs1Cast(message, message_length, signature,
signature_length);
@@ -422,7 +423,8 @@ OEMCryptoResult RsaPublicKey::VerifySignature(
OEMCryptoResult RsaPublicKey::VerifySignature(
const std::string& message, const std::string& signature,
RsaSignatureAlgorithm algorithm) const {
RsaSignatureAlgorithm algorithm,
OEMCrypto_SignatureHashAlgorithm hash_algorithm) const {
if (signature.empty()) {
LOGE("Signature should not be empty");
return OEMCrypto_ERROR_INVALID_CONTEXT;
@@ -430,18 +432,19 @@ OEMCryptoResult RsaPublicKey::VerifySignature(
return VerifySignature(reinterpret_cast<const uint8_t*>(message.data()),
message.size(),
reinterpret_cast<const uint8_t*>(signature.data()),
signature.size(), algorithm);
signature.size(), algorithm, hash_algorithm);
}
OEMCryptoResult RsaPublicKey::VerifySignature(
const std::vector<uint8_t>& message, const std::vector<uint8_t>& signature,
RsaSignatureAlgorithm algorithm) const {
RsaSignatureAlgorithm algorithm,
OEMCrypto_SignatureHashAlgorithm hash_algorithm) const {
if (signature.empty()) {
LOGE("Signature should not be empty");
return OEMCrypto_ERROR_INVALID_CONTEXT;
}
return VerifySignature(message.data(), message.size(), signature.data(),
signature.size(), algorithm);
signature.size(), algorithm, hash_algorithm);
}
OEMCryptoResult RsaPublicKey::EncryptSessionKey(
@@ -664,7 +667,8 @@ bool RsaPublicKey::InitFromSslHandle(const RSA* rsa_handle,
OEMCryptoResult RsaPublicKey::VerifySignaturePss(
const uint8_t* message, size_t message_length, const uint8_t* signature,
size_t signature_length) const {
size_t signature_length,
OEMCrypto_SignatureHashAlgorithm hash_algorithm) const {
// Step 0: Ensure the signature algorithm is supported by key.
if (!(allowed_schemes_ & kSign_RSASSA_PSS)) {
LOGE("RSA key cannot verify using PSS");
@@ -680,14 +684,34 @@ OEMCryptoResult RsaPublicKey::VerifySignaturePss(
LOGE("Failed to set PKEY RSA key");
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
}
// Step 2a: Setup a EVP MD CTX for PSS Verification.
// Step 2a: Choose the correct digest algorithm.
const EVP_MD* digest = nullptr;
switch (hash_algorithm) {
case OEMCrypto_SHA1:
digest = EVP_sha1();
break;
case OEMCrypto_SHA2_256:
digest = EVP_sha256();
break;
case OEMCrypto_SHA2_384:
digest = EVP_sha384();
break;
case OEMCrypto_SHA2_512:
digest = EVP_sha512();
break;
}
if (digest == nullptr) {
LOGE("Unrecognized hash algorithm %d", hash_algorithm);
return OEMCrypto_ERROR_INVALID_CONTEXT;
}
// Step 2b: Setup an EVP MD CTX for PSS Verification.
ScopedEvpMdCtx md_ctx = EVP_MD_CTX_new();
if (!md_ctx) {
LOGE("Failed to allocate MD CTX");
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
}
EVP_PKEY_CTX* pkey_ctx = nullptr; // Ownership is maintained by |md_ctx|
int res = EVP_DigestVerifyInit(md_ctx.get(), &pkey_ctx, EVP_sha1(), nullptr,
int res = EVP_DigestVerifyInit(md_ctx.get(), &pkey_ctx, digest, nullptr,
pkey.get());
if (res != 1) {
LOGE("Failed to initialize MD CTX for verification");
@@ -697,7 +721,7 @@ OEMCryptoResult RsaPublicKey::VerifySignaturePss(
LOGE("PKEY CTX is unexpectedly null");
return OEMCrypto_ERROR_UNKNOWN_FAILURE;
}
// Step 2b: Configure OEMCrypto RSASSA-PSS options.
// Step 2c: Configure OEMCrypto RSASSA-PSS options.
res = EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING);
if (res != 1) {
LOGE("Failed to set PSS padding");
@@ -787,7 +811,9 @@ OEMCryptoResult RsaPublicKey::EncryptOaep(const uint8_t* message,
return OEMCrypto_ERROR_SHORT_BUFFER;
}
*enc_message_length = enc_size;
memcpy(enc_message, encrypt_buffer.data(), enc_size);
if (enc_message != nullptr) {
memcpy(enc_message, encrypt_buffer.data(), enc_size);
}
return OEMCrypto_SUCCESS;
}