Skip to content

Commit

Permalink
Removed unused ref_count from cipher context.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfigus committed Nov 4, 2014
1 parent 97a80f4 commit c8e9afe
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 98 deletions.
7 changes: 0 additions & 7 deletions crypto/cipher/aes_cbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ aes_cbc_alloc(cipher_t **c, int key_len, int tlen) {
(*c)->type = &aes_cbc;
(*c)->state = pointer + sizeof(cipher_t);

/* increment ref_count */
aes_cbc.ref_count++;

/* set key size */
(*c)->key_len = key_len;

Expand All @@ -101,9 +98,6 @@ aes_cbc_dealloc(cipher_t *c) {
/* free memory */
crypto_free(c);

/* decrement ref_count */
aes_cbc.ref_count--;

return err_status_ok;
}

Expand Down Expand Up @@ -556,7 +550,6 @@ cipher_type_t aes_cbc = {
(cipher_set_iv_func_t) aes_cbc_set_iv,
(cipher_get_tag_func_t) 0,
(char *) aes_cbc_description,
(int) 0, /* instance count */
(cipher_test_case_t *) &aes_cbc_test_case_3,
(debug_module_t *) &mod_aes_cbc,
(cipher_type_id_t) AES_CBC
Expand Down
18 changes: 1 addition & 17 deletions crypto/cipher/aes_gcm_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,17 @@ err_status_t aes_gcm_openssl_alloc (cipher_t **c, int key_len, int tlen)
(*c)->state = allptr + sizeof(cipher_t);
gcm = (aes_gcm_ctx_t *)(*c)->state;

/* increment ref_count */
/* setup cipher attributes */
switch (key_len) {
case AES_128_GCM_KEYSIZE_WSALT:
(*c)->type = &aes_gcm_128_openssl;
(*c)->algorithm = AES_128_GCM;
aes_gcm_128_openssl.ref_count++;
((aes_gcm_ctx_t*)(*c)->state)->key_size = AES_128_KEYSIZE;
((aes_gcm_ctx_t*)(*c)->state)->tag_len = tlen;
break;
case AES_256_GCM_KEYSIZE_WSALT:
(*c)->type = &aes_gcm_256_openssl;
(*c)->algorithm = AES_256_GCM;
aes_gcm_256_openssl.ref_count++;
((aes_gcm_ctx_t*)(*c)->state)->key_size = AES_256_KEYSIZE;
((aes_gcm_ctx_t*)(*c)->state)->tag_len = tlen;
break;
Expand All @@ -152,18 +150,6 @@ err_status_t aes_gcm_openssl_dealloc (cipher_t *c)
ctx = (aes_gcm_ctx_t*)c->state;
if (ctx) {
EVP_CIPHER_CTX_cleanup(&ctx->ctx);
/* decrement ref_count for the appropriate engine */
switch (ctx->key_size) {
case AES_256_KEYSIZE:
aes_gcm_256_openssl.ref_count--;
break;
case AES_128_KEYSIZE:
aes_gcm_128_openssl.ref_count--;
break;
default:
return (err_status_dealloc_fail);
break;
}
}

/* zeroize entire state*/
Expand Down Expand Up @@ -544,7 +530,6 @@ cipher_type_t aes_gcm_128_openssl = {
(cipher_set_iv_func_t) aes_gcm_openssl_set_iv,
(cipher_get_tag_func_t) aes_gcm_openssl_get_tag,
(char*) aes_gcm_128_openssl_description,
(int) 0, /* instance count */
(cipher_test_case_t*) &aes_gcm_test_case_0,
(debug_module_t*) &mod_aes_gcm,
(cipher_type_id_t) AES_128_GCM
Expand All @@ -563,7 +548,6 @@ cipher_type_t aes_gcm_256_openssl = {
(cipher_set_iv_func_t) aes_gcm_openssl_set_iv,
(cipher_get_tag_func_t) aes_gcm_openssl_get_tag,
(char*) aes_gcm_256_openssl_description,
(int) 0, /* instance count */
(cipher_test_case_t*) &aes_gcm_test_case_1,
(debug_module_t*) &mod_aes_gcm,
(cipher_type_id_t) AES_256_GCM
Expand Down
7 changes: 0 additions & 7 deletions crypto/cipher/aes_icm.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ aes_icm_alloc_ismacryp(cipher_t **c, int key_len, int forIsmacryp) {
(*c)->type = &aes_icm;
(*c)->state = pointer + sizeof(cipher_t);

/* increment ref_count */
aes_icm.ref_count++;

/* set key size */
(*c)->key_len = key_len;

Expand All @@ -159,9 +156,6 @@ aes_icm_dealloc(cipher_t *c) {
/* free memory */
crypto_free(c);

/* decrement ref_count */
aes_icm.ref_count--;

return err_status_ok;
}

Expand Down Expand Up @@ -580,7 +574,6 @@ cipher_type_t aes_icm = {
(cipher_set_iv_func_t) aes_icm_set_iv,
(cipher_get_tag_func_t) 0,
(char *) aes_icm_description,
(int) 0, /* instance count */
(cipher_test_case_t *) &aes_icm_test_case_1,
(debug_module_t *) &mod_aes_icm,
(cipher_type_id_t) AES_ICM
Expand Down
23 changes: 1 addition & 22 deletions crypto/cipher/aes_icm_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,21 @@ err_status_t aes_icm_openssl_alloc (cipher_t **c, int key_len, int tlen)
(*c)->state = allptr + sizeof(cipher_t);
icm = (aes_icm_ctx_t*)(*c)->state;

/* increment ref_count */
/* setup cipher parameters */
switch (key_len) {
case AES_128_KEYSIZE_WSALT:
(*c)->algorithm = AES_128_ICM;
(*c)->type = &aes_icm;
aes_icm.ref_count++;
((aes_icm_ctx_t*)(*c)->state)->key_size = AES_128_KEYSIZE;
break;
case AES_192_KEYSIZE_WSALT:
(*c)->algorithm = AES_192_ICM;
(*c)->type = &aes_icm_192;
aes_icm_192.ref_count++;
((aes_icm_ctx_t*)(*c)->state)->key_size = AES_192_KEYSIZE;
break;
case AES_256_KEYSIZE_WSALT:
(*c)->algorithm = AES_256_ICM;
(*c)->type = &aes_icm_256;
aes_icm_256.ref_count++;
((aes_icm_ctx_t*)(*c)->state)->key_size = AES_256_KEYSIZE;
break;
}
Expand Down Expand Up @@ -185,21 +182,6 @@ err_status_t aes_icm_openssl_dealloc (cipher_t *c)
ctx = (aes_icm_ctx_t*)c->state;
if (ctx != NULL) {
EVP_CIPHER_CTX_cleanup(&ctx->ctx);
/* decrement ref_count for the appropriate engine */
switch (ctx->key_size) {
case AES_256_KEYSIZE:
aes_icm_256.ref_count--;
break;
case AES_192_KEYSIZE:
aes_icm_192.ref_count--;
break;
case AES_128_KEYSIZE:
aes_icm.ref_count--;
break;
default:
return err_status_dealloc_fail;
break;
}
}

/* zeroize entire state*/
Expand Down Expand Up @@ -492,7 +474,6 @@ cipher_type_t aes_icm = {
(cipher_set_iv_func_t) aes_icm_openssl_set_iv,
(cipher_get_tag_func_t) 0,
(char*) aes_icm_openssl_description,
(int) 0, /* instance count */
(cipher_test_case_t*) &aes_icm_test_case_0,
(debug_module_t*) &mod_aes_icm,
(cipher_type_id_t) AES_ICM
Expand All @@ -512,7 +493,6 @@ cipher_type_t aes_icm_192 = {
(cipher_set_iv_func_t) aes_icm_openssl_set_iv,
(cipher_get_tag_func_t) 0,
(char*) aes_icm_192_openssl_description,
(int) 0, /* instance count */
(cipher_test_case_t*) &aes_icm_192_test_case_1,
(debug_module_t*) &mod_aes_icm,
(cipher_type_id_t) AES_192_ICM
Expand All @@ -532,7 +512,6 @@ cipher_type_t aes_icm_256 = {
(cipher_set_iv_func_t) aes_icm_openssl_set_iv,
(cipher_get_tag_func_t) 0,
(char*) aes_icm_256_openssl_description,
(int) 0, /* instance count */
(cipher_test_case_t*) &aes_icm_256_test_case_2,
(debug_module_t*) &mod_aes_icm,
(cipher_type_id_t) AES_256_ICM
Expand Down
7 changes: 0 additions & 7 deletions crypto/cipher/null_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ null_cipher_alloc(cipher_t **c, int key_len, int tlen) {
/* set key size */
(*c)->key_len = key_len;

/* increment ref_count */
null_cipher.ref_count++;

return err_status_ok;

}
Expand All @@ -96,9 +93,6 @@ null_cipher_dealloc(cipher_t *c) {
/* free memory of type null_cipher */
crypto_free(c);

/* decrement reference count */
null_cipher.ref_count--;

return err_status_ok;

}
Expand Down Expand Up @@ -155,7 +149,6 @@ cipher_type_t null_cipher = {
(cipher_set_iv_func_t) null_cipher_set_iv,
(cipher_get_tag_func_t) 0,
(char *) null_cipher_description,
(int) 0,
(cipher_test_case_t *) &null_cipher_test_0,
(debug_module_t *) NULL,
(cipher_type_id_t) NULL_CIPHER
Expand Down
5 changes: 0 additions & 5 deletions crypto/hash/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ auth_get_prefix_length(const auth_t *a) {
return a->prefix_len;
}

int
auth_type_get_ref_count(const auth_type_t *at) {
return at->ref_count;
}

/*
* auth_type_test() tests an auth function of type ct against
* test cases provided in a list test_data of values of key, data, and tag
Expand Down
7 changes: 0 additions & 7 deletions crypto/hash/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ hmac_alloc(auth_t **a, int key_len, int out_len) {
(*a)->key_len = key_len;
(*a)->prefix_len = 0;

/* increment global count of all hmac uses */
hmac.ref_count++;

return err_status_ok;
}

Expand All @@ -106,9 +103,6 @@ hmac_dealloc(auth_t *a) {
/* free memory */
crypto_free(a);

/* decrement global count of all hmac uses */
hmac.ref_count--;

return err_status_ok;
}

Expand Down Expand Up @@ -264,7 +258,6 @@ hmac = {
(auth_update_func) hmac_update,
(auth_start_func) hmac_start,
(char *) hmac_description,
(int) 0, /* instance count */
(auth_test_case_t *) &hmac_test_case_0,
(debug_module_t *) &mod_hmac,
(auth_type_id_t) HMAC_SHA1
Expand Down
7 changes: 0 additions & 7 deletions crypto/hash/hmac_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ hmac_alloc (auth_t **a, int key_len, int out_len)
new_hmac_ctx = (hmac_ctx_t*)((*a)->state);
memset(new_hmac_ctx, 0, sizeof(hmac_ctx_t));

/* increment global count of all hmac uses */
hmac.ref_count++;

return err_status_ok;
}

Expand All @@ -126,9 +123,6 @@ hmac_dealloc (auth_t *a)
/* free memory */
crypto_free(a);

/* decrement global count of all hmac uses */
hmac.ref_count--;

return err_status_ok;
}

Expand Down Expand Up @@ -294,7 +288,6 @@ auth_type_t
(auth_update_func) hmac_update,
(auth_start_func) hmac_start,
(char*) hmac_description,
(int) 0, /* instance count */
(auth_test_case_t*) &hmac_test_case_0,
(debug_module_t*) &mod_hmac,
(auth_type_id_t) HMAC_SHA1
Expand Down
7 changes: 0 additions & 7 deletions crypto/hash/null_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ null_auth_alloc(auth_t **a, int key_len, int out_len) {
(*a)->prefix_len = out_len;
(*a)->key_len = key_len;

/* increment global count of all null_auth uses */
null_auth.ref_count++;

return err_status_ok;
}

Expand All @@ -93,9 +90,6 @@ null_auth_dealloc(auth_t *a) {
/* free memory */
crypto_free(a);

/* decrement global count of all null_auth uses */
null_auth.ref_count--;

return err_status_ok;
}

Expand Down Expand Up @@ -157,7 +151,6 @@ null_auth = {
(auth_update_func) null_auth_update,
(auth_start_func) null_auth_start,
(char *) null_auth_description,
(int) 0, /* instance count */
(auth_test_case_t *) &null_auth_test_case_0,
(debug_module_t *) NULL,
(auth_type_id_t) NULL_AUTH
Expand Down
9 changes: 0 additions & 9 deletions crypto/include/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ typedef struct auth_type_t {
auth_update_func update;
auth_start_func start;
char *description;
int ref_count;
auth_test_case_t *test_data;
debug_module_t *debug;
auth_type_id_t id;
Expand Down Expand Up @@ -160,12 +159,4 @@ auth_type_self_test(const auth_type_t *at);
err_status_t
auth_type_test(const auth_type_t *at, const auth_test_case_t *test_data);

/*
* auth_type_get_ref_count(at) returns the reference count (the number
* of instantiations) of the auth_type_t at
*/

int
auth_type_get_ref_count(const auth_type_t *at);

#endif /* AUTH_H */
1 change: 0 additions & 1 deletion crypto/include/cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ typedef struct cipher_type_t {
cipher_set_iv_func_t set_iv;
cipher_get_tag_func_t get_tag;
char *description;
int ref_count;
cipher_test_case_t *test_data;
debug_module_t *debug;
cipher_type_id_t id;
Expand Down
2 changes: 0 additions & 2 deletions crypto/kernel/crypto_kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ crypto_kernel_status() {
/* for each cipher type, describe and test */
while(ctype != NULL) {
printf("cipher: %s\n", ctype->cipher_type->description);
printf(" instance count: %d\n", ctype->cipher_type->ref_count);
printf(" self-test: ");
status = cipher_type_self_test(ctype->cipher_type);
if (status) {
Expand All @@ -228,7 +227,6 @@ crypto_kernel_status() {
/* for each auth type, describe and test */
while(atype != NULL) {
printf("auth func: %s\n", atype->auth_type->description);
printf(" instance count: %d\n", atype->auth_type->ref_count);
printf(" self-test: ");
status = auth_type_self_test(atype->auth_type);
if (status) {
Expand Down

0 comments on commit c8e9afe

Please sign in to comment.