From 9782c09a3a64165100f1cd71c3f635d5af9fa225 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sun, 28 Dec 2014 14:00:52 +0100 Subject: [PATCH] use XMEM{CMP, CPY, SET} macros instead of standard versions --- src/encauth/ccm/ccm_init.c | 2 +- src/encauth/ccm/ccm_memory_ex.c | 16 ++++++++-------- src/headers/tomcrypt_hash.h | 2 +- src/misc/pk_get_oid.c | 4 ++-- .../der_decode_subject_public_key_info.c | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/encauth/ccm/ccm_init.c b/src/encauth/ccm/ccm_init.c index 8a6dfbc..7e3bdf8 100644 --- a/src/encauth/ccm/ccm_init.c +++ b/src/encauth/ccm/ccm_init.c @@ -33,7 +33,7 @@ int ccm_init(ccm_state *ccm, int cipher, LTC_ARGCHK(key != NULL); LTC_ARGCHK(taglen != 0); - memset(ccm, 0, sizeof(ccm_state)); + XMEMSET(ccm, 0, sizeof(ccm_state)); /* check cipher input */ if ((err = cipher_is_valid(cipher)) != CRYPT_OK) { diff --git a/src/encauth/ccm/ccm_memory_ex.c b/src/encauth/ccm/ccm_memory_ex.c index af44f2f..f8e0aea 100644 --- a/src/encauth/ccm/ccm_memory_ex.c +++ b/src/encauth/ccm/ccm_memory_ex.c @@ -329,17 +329,17 @@ if (CTR == NULL) { } } -// grab the CTR -memcpy(ctrcopy, ctr, 16); + // grab the CTR + XMEMCPY(ctrcopy, ctr, 16); /* setup CTR for the TAG (zero the count) */ -if (CTR == NULL) { - for (y = 15; y > 15 - L; y--) { - ctr[y] = 0x00; + if (CTR == NULL) { + for (y = 15; y > 15 - L; y--) { + ctr[y] = 0x00; + } + } else { + XMEMCPY(ctr, CTR, 16); } -} else { - XMEMCPY(ctr, CTR, 16); -} if ((err = cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey)) != CRYPT_OK) { goto error; diff --git a/src/headers/tomcrypt_hash.h b/src/headers/tomcrypt_hash.h index 3129958..c5a4d81 100644 --- a/src/headers/tomcrypt_hash.h +++ b/src/headers/tomcrypt_hash.h @@ -386,7 +386,7 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) inlen -= block_size; \ } else { \ n = MIN(inlen, (block_size - md-> state_var .curlen)); \ - memcpy(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \ + XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \ md-> state_var .curlen += n; \ in += n; \ inlen -= n; \ diff --git a/src/misc/pk_get_oid.c b/src/misc/pk_get_oid.c index 807b5fa..c48049e 100644 --- a/src/misc/pk_get_oid.c +++ b/src/misc/pk_get_oid.c @@ -27,10 +27,10 @@ int pk_get_oid(int pk, oid_st *st) { switch (pk) { case PKA_RSA: - memcpy(st, &rsa_oid, sizeof(*st)); + XMEMCPY(st, &rsa_oid, sizeof(*st)); break; case PKA_DSA: - memcpy(st, &dsa_oid, sizeof(*st)); + XMEMCPY(st, &dsa_oid, sizeof(*st)); break; default: return CRYPT_INVALID_ARG; diff --git a/src/pk/asn1/der/sequence/der_decode_subject_public_key_info.c b/src/pk/asn1/der/sequence/der_decode_subject_public_key_info.c index b0f2f94..71009c6 100644 --- a/src/pk/asn1/der/sequence/der_decode_subject_public_key_info.c +++ b/src/pk/asn1/der/sequence/der_decode_subject_public_key_info.c @@ -76,7 +76,7 @@ int der_decode_subject_public_key_info(const unsigned char *in, unsigned long in } if ((alg_id[0].size != oid.OIDlen) || - memcmp(oid.OID, alg_id[0].data, oid.OIDlen * sizeof(oid.OID[0]))) { + XMEMCMP(oid.OID, alg_id[0].data, oid.OIDlen * sizeof(oid.OID[0]))) { /* OID mismatch */ err = CRYPT_PK_INVALID_TYPE; goto LBL_ERR; @@ -84,7 +84,7 @@ int der_decode_subject_public_key_info(const unsigned char *in, unsigned long in len = subject_pubkey[1].size/8; if (*public_key_len > len) { - memcpy(public_key, subject_pubkey[1].data, len); + XMEMCPY(public_key, subject_pubkey[1].data, len); *public_key_len = len; } else { *public_key_len = len;