Skip to content

Commit

Permalink
[crypto] drop the unnecessary hash_block code
Browse files Browse the repository at this point in the history
this was a leftover from corosync port of the code and it was
a failsafe for buffer allocation apparently. buffer allocation
was completely reworked in corosync to dynamically account for
headers and so on.

this also removes one memcpy and shave some more time in hashing
operations.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Nov 13, 2016
1 parent 81a5017 commit b28ec6b
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions libknet/nsscrypto.c
Expand Up @@ -109,15 +109,6 @@ size_t hash_len[] = {
SHA512_LENGTH /* CRYPTO_HASH_TYPE_SHA512 */
};

size_t hash_block_len[] = {
0, /* CRYPTO_HASH_TYPE_NONE */
MD5_BLOCK_LENGTH, /* CRYPTO_HASH_TYPE_MD5 */
SHA1_BLOCK_LENGTH, /* CRYPTO_HASH_TYPE_SHA1 */
SHA256_BLOCK_LENGTH, /* CRYPTO_HASH_TYPE_SHA256 */
SHA384_BLOCK_LENGTH, /* CRYPTO_HASH_TYPE_SHA384 */
SHA512_BLOCK_LENGTH /* CRYPTO_HASH_TYPE_SHA512 */
};

struct nsscrypto_instance {
PK11SymKey *nss_sym_key;
PK11SymKey *nss_sym_key_sign;
Expand Down Expand Up @@ -400,7 +391,6 @@ static int calculate_nss_hash(
PK11Context* hash_context = NULL;
SECItem hash_param;
unsigned int hash_tmp_outlen = 0;
unsigned char hash_block[hash_block_len[instance->crypto_hash_type]];
int err = -1;

/* Now do the digest */
Expand Down Expand Up @@ -437,16 +427,15 @@ static int calculate_nss_hash(
}

if (PK11_DigestFinal(hash_context,
hash_block,
hash,
&hash_tmp_outlen,
hash_block_len[instance->crypto_hash_type]) != SECSuccess) {
hash_len[instance->crypto_hash_type]) != SECSuccess) {
log_err(knet_h, KNET_SUB_NSSCRYPTO, "PK11_DigestFinale failed (hash) hash_type=%d (err %d)",
(int)hash_to_nss[instance->crypto_hash_type],
PR_GetError());
goto out;
}

memmove(hash, hash_block, hash_len[instance->crypto_hash_type]);
err = 0;

out:
Expand Down

0 comments on commit b28ec6b

Please sign in to comment.