Skip to content

Commit

Permalink
[Review OP-TEE#3] Check OID hash algorithm returned
Browse files Browse the repository at this point in the history
Re-work drvcrypt_get_alg_hash_oid() and move it to hash_oid.c

Signed-off-by: Clement Faure <clement.faure@nxp.com>
  • Loading branch information
clementfaure committed Feb 27, 2020
1 parent 8946e05 commit 6fe3ff3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
19 changes: 1 addition & 18 deletions core/drivers/crypto/crypto_api/acipher/rsassa.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,6 @@

#include "local.h"

static struct drvcrypt_oid *rsassa_get_hash_oid_alg(uint32_t algo)
{
uint32_t main_alg = TEE_ALG_GET_MAIN_ALG(algo);

switch (main_alg) {
case TEE_MAIN_ALGO_MD5:
case TEE_MAIN_ALGO_SHA1:
case TEE_MAIN_ALGO_SHA224:
case TEE_MAIN_ALGO_SHA256:
case TEE_MAIN_ALGO_SHA384:
case TEE_MAIN_ALGO_SHA512:
return &drvcrypt_hash_oid[main_alg];
default:
return NULL;
}
}

/*
* PKCS#1 V1.5 - Encode the message in Distinguished Encoding Rules
* (DER) format.
Expand All @@ -54,7 +37,7 @@ static TEE_Result emsa_pkcs1_v1_5_encode(struct drvcrypt_rsa_ssa *ssa_data,
size_t ps_size = 0;
uint8_t *buf = NULL;

hash_oid = rsassa_get_hash_oid_alg(ssa_data->hash_algo);
hash_oid = drvcrypt_get_alg_hash_oid(ssa_data->hash_algo);
if (!hash_oid)
return TEE_ERROR_NOT_SUPPORTED;

Expand Down
7 changes: 7 additions & 0 deletions core/drivers/crypto/crypto_api/include/drvcrypt_asn1_oid.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,11 @@ struct drvcrypt_oid {
*/
extern const struct drvcrypt_oid drvcrypt_hash_oid[];

/*
* Return the Hash OID value registered in the Hash OID table.
*
* @algo Hash algorithm identifier
*/
struct drvcrypt_oid *drvcrypt_get_alg_hash_oid(uint32_t algo);

#endif /* __ASN1_OID_H__ */
10 changes: 10 additions & 0 deletions core/drivers/crypto/crypto_api/oid/hash_oid.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ const struct drvcrypt_oid drvcrypt_hash_oid[] = {
/* SHA512 */
{ DRVCRYPT_OID_ID_SHA512, DRVCRYPT_OID_LEN(DRVCRYPT_OID_ID_SHA512) },
};

struct drvcrypt_oid *drvcrypt_get_alg_hash_oid(uint32_t algo)
{
uint32_t main_alg = TEE_ALG_GET_MAIN_ALG(algo);

if (main_alg < ARRAY_SIZE(drvcrypt_hash_oid))
return &drvcrypt_hash_oid[main_alg];

return NULL;
}

0 comments on commit 6fe3ff3

Please sign in to comment.