OLD | NEW |
1 /* p12_mutl.c */ | 1 /* p12_mutl.c */ |
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 * project 1999. | 3 * project 1999. |
4 */ | 4 */ |
5 /* ==================================================================== | 5 /* ==================================================================== |
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 #include <openssl/pkcs12.h> | 64 #include <openssl/pkcs12.h> |
65 | 65 |
66 /* Generate a MAC */ | 66 /* Generate a MAC */ |
67 int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, | 67 int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, |
68 unsigned char *mac, unsigned int *maclen) | 68 unsigned char *mac, unsigned int *maclen) |
69 { | 69 { |
70 const EVP_MD *md_type; | 70 const EVP_MD *md_type; |
71 HMAC_CTX hmac; | 71 HMAC_CTX hmac; |
72 unsigned char key[EVP_MAX_MD_SIZE], *salt; | 72 unsigned char key[EVP_MAX_MD_SIZE], *salt; |
73 int saltlen, iter; | 73 int saltlen, iter; |
| 74 int md_size; |
74 | 75 |
75 if (!PKCS7_type_is_data(p12->authsafes)) | 76 if (!PKCS7_type_is_data(p12->authsafes)) |
76 { | 77 { |
77 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_CONTENT_TYPE_NOT_DATA
); | 78 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_CONTENT_TYPE_NOT_DATA
); |
78 return 0; | 79 return 0; |
79 } | 80 } |
80 | 81 |
81 salt = p12->mac->salt->data; | 82 salt = p12->mac->salt->data; |
82 saltlen = p12->mac->salt->length; | 83 saltlen = p12->mac->salt->length; |
83 if (!p12->mac->iter) iter = 1; | 84 if (!p12->mac->iter) iter = 1; |
84 else iter = ASN1_INTEGER_get (p12->mac->iter); | 85 else iter = ASN1_INTEGER_get (p12->mac->iter); |
85 if(!(md_type = | 86 if(!(md_type = |
86 EVP_get_digestbyobj (p12->mac->dinfo->algor->algorithm))) { | 87 EVP_get_digestbyobj (p12->mac->dinfo->algor->algorithm))) { |
87 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_UNKNOWN_DIGEST_ALGORI
THM); | 88 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_UNKNOWN_DIGEST_ALGORI
THM); |
88 return 0; | 89 return 0; |
89 } | 90 } |
| 91 md_size = EVP_MD_size(md_type); |
| 92 if (md_size < 0) |
| 93 return 0; |
90 if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter, | 94 if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter, |
91 » » » » EVP_MD_size(md_type), key, md_type)) { | 95 » » » » md_size, key, md_type)) { |
92 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR); | 96 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR); |
93 return 0; | 97 return 0; |
94 } | 98 } |
95 HMAC_CTX_init(&hmac); | 99 HMAC_CTX_init(&hmac); |
96 » HMAC_Init_ex(&hmac, key, EVP_MD_size(md_type), md_type, NULL); | 100 » HMAC_Init_ex(&hmac, key, md_size, md_type, NULL); |
97 HMAC_Update(&hmac, p12->authsafes->d.data->data, | 101 HMAC_Update(&hmac, p12->authsafes->d.data->data, |
98 p12->authsafes->d.data->length); | 102 p12->authsafes->d.data->length); |
99 HMAC_Final(&hmac, mac, maclen); | 103 HMAC_Final(&hmac, mac, maclen); |
100 HMAC_CTX_cleanup(&hmac); | 104 HMAC_CTX_cleanup(&hmac); |
101 return 1; | 105 return 1; |
102 } | 106 } |
103 | 107 |
104 /* Verify the mac */ | 108 /* Verify the mac */ |
105 int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen) | 109 int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen) |
106 { | 110 { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); | 177 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); |
174 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { | 178 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { |
175 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); | 179 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); |
176 return 0; | 180 return 0; |
177 } | 181 } |
178 p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL; | 182 p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL; |
179 | 183 |
180 return 1; | 184 return 1; |
181 } | 185 } |
182 #endif | 186 #endif |
OLD | NEW |