Skip to content

Commit

Permalink
Added sw_crypto signature verify for CRYPTO_RSA_OAEP
Browse files Browse the repository at this point in the history
  • Loading branch information
kjyrinki-unikie committed Jan 13, 2025
1 parent ce97e4c commit 0646d9f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/drivers/sw_crypto/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,57 @@ bool crypto_signature_check(crypto_session_handle_t handle,

break;

case CRYPTO_RSA_OAEP: {
rsa_key key;

initialize_tomcrypt();

if (public_key && rsa_import(public_key, keylen, &key) == CRYPT_OK) {
// Register hash algorithm.
const struct ltc_hash_descriptor *hash_desc = &sha256_desc;
const int hash_idx = register_hash(hash_desc);

if (hash_idx < 0) {
return false;
}

// Hash message.
unsigned char hash[32];
hash_state md;

hash_desc->init(&md);
hash_desc->process(&md, (const unsigned char *) message, (unsigned long) message_size);
hash_desc->done(&md, hash);

// Define padding scheme.
const int padding = LTC_PKCS_1_OAEP;
const unsigned long saltlen = 0;

// Verify signature.
int stat = 0;

if (rsa_verify_hash_ex(signature,
256,
hash,
hash_desc->hashsize,
padding,
hash_idx,
saltlen,
&stat,
&key)
== CRYPT_OK
&& stat) {
ret = true;
}

rsa_free(&key);
}
}
break;

default:
ret = false;
break;
}

return ret;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ libtomcrypt_wrappers.c
libtomcrypt/src/misc/crypt/crypt_ltc_mp_descriptor.c
libtomcrypt/src/misc/crypt/crypt_hash_is_valid.c
libtomcrypt/src/misc/crypt/crypt_prng_is_valid.c
libtomcrypt/src/misc/crypt/crypt_register_hash.c
libtomcrypt/src/misc/mem_neq.c
libtomcrypt/src/misc/zeromem.c
)

Expand Down
2 changes: 1 addition & 1 deletion src/lib/secure_udp

0 comments on commit 0646d9f

Please sign in to comment.