diff options
| author | miod <> | 2014-06-21 12:00:01 +0000 |
|---|---|---|
| committer | miod <> | 2014-06-21 12:00:01 +0000 |
| commit | 5d79dc417a7572846cdf18b2b4aeee3cec01f48d (patch) | |
| tree | 4918517133d4c086155d739ea9f19fc7b736b3d9 /src/lib/libcrypto/hmac/hm_ameth.c | |
| parent | 016198f0453915e1b5948f50de71776ac2b5ac9a (diff) | |
| download | openbsd-5d79dc417a7572846cdf18b2b4aeee3cec01f48d.tar.gz openbsd-5d79dc417a7572846cdf18b2b4aeee3cec01f48d.tar.bz2 openbsd-5d79dc417a7572846cdf18b2b4aeee3cec01f48d.zip | |
KNF
Diffstat (limited to 'src/lib/libcrypto/hmac/hm_ameth.c')
| -rw-r--r-- | src/lib/libcrypto/hmac/hm_ameth.c | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/src/lib/libcrypto/hmac/hm_ameth.c b/src/lib/libcrypto/hmac/hm_ameth.c index e3633963fa..ef97918472 100644 --- a/src/lib/libcrypto/hmac/hm_ameth.c +++ b/src/lib/libcrypto/hmac/hm_ameth.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: hm_ameth.c,v 1.4 2014/06/12 15:49:29 deraadt Exp $ */ | 1 | /* $OpenBSD: hm_ameth.c,v 1.5 2014/06/21 12:00:01 miod Exp $ */ |
| 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 2007. | 3 | * project 2007. |
| 4 | */ | 4 | */ |
| @@ -68,35 +68,35 @@ | |||
| 68 | * key. | 68 | * key. |
| 69 | */ | 69 | */ |
| 70 | 70 | ||
| 71 | static int hmac_size(const EVP_PKEY *pkey) | 71 | static int |
| 72 | { | 72 | hmac_size(const EVP_PKEY *pkey) |
| 73 | { | ||
| 73 | return EVP_MAX_MD_SIZE; | 74 | return EVP_MAX_MD_SIZE; |
| 74 | } | 75 | } |
| 75 | 76 | ||
| 76 | static void hmac_key_free(EVP_PKEY *pkey) | 77 | static void |
| 77 | { | 78 | hmac_key_free(EVP_PKEY *pkey) |
| 79 | { | ||
| 78 | ASN1_OCTET_STRING *os = (ASN1_OCTET_STRING *)pkey->pkey.ptr; | 80 | ASN1_OCTET_STRING *os = (ASN1_OCTET_STRING *)pkey->pkey.ptr; |
| 79 | if (os) | 81 | |
| 80 | { | 82 | if (os) { |
| 81 | if (os->data) | 83 | if (os->data) |
| 82 | OPENSSL_cleanse(os->data, os->length); | 84 | OPENSSL_cleanse(os->data, os->length); |
| 83 | ASN1_OCTET_STRING_free(os); | 85 | ASN1_OCTET_STRING_free(os); |
| 84 | } | ||
| 85 | } | 86 | } |
| 87 | } | ||
| 86 | 88 | ||
| 87 | 89 | static int | |
| 88 | static int hmac_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2) | 90 | hmac_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2) |
| 89 | { | 91 | { |
| 90 | switch (op) | 92 | switch (op) { |
| 91 | { | 93 | case ASN1_PKEY_CTRL_DEFAULT_MD_NID: |
| 92 | case ASN1_PKEY_CTRL_DEFAULT_MD_NID: | ||
| 93 | *(int *)arg2 = NID_sha1; | 94 | *(int *)arg2 = NID_sha1; |
| 94 | return 1; | 95 | return 1; |
| 95 | 96 | default: | |
| 96 | default: | ||
| 97 | return -2; | 97 | return -2; |
| 98 | } | ||
| 99 | } | 98 | } |
| 99 | } | ||
| 100 | 100 | ||
| 101 | #ifdef HMAC_TEST_PRIVATE_KEY_FORMAT | 101 | #ifdef HMAC_TEST_PRIVATE_KEY_FORMAT |
| 102 | /* A bogus private key format for test purposes. This is simply the | 102 | /* A bogus private key format for test purposes. This is simply the |
| @@ -104,42 +104,44 @@ static int hmac_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2) | |||
| 104 | * genpkey utility can be used to "generate" HMAC keys. | 104 | * genpkey utility can be used to "generate" HMAC keys. |
| 105 | */ | 105 | */ |
| 106 | 106 | ||
| 107 | static int old_hmac_decode(EVP_PKEY *pkey, | 107 | static int |
| 108 | const unsigned char **pder, int derlen) | 108 | old_hmac_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) |
| 109 | { | 109 | { |
| 110 | ASN1_OCTET_STRING *os; | 110 | ASN1_OCTET_STRING *os; |
| 111 | |||
| 111 | os = ASN1_OCTET_STRING_new(); | 112 | os = ASN1_OCTET_STRING_new(); |
| 112 | if (!os || !ASN1_OCTET_STRING_set(os, *pder, derlen)) | 113 | if (!os || !ASN1_OCTET_STRING_set(os, *pder, derlen)) |
| 113 | return 0; | 114 | return 0; |
| 114 | EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, os); | 115 | EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, os); |
| 115 | return 1; | 116 | return 1; |
| 116 | } | 117 | } |
| 117 | 118 | ||
| 118 | static int old_hmac_encode(const EVP_PKEY *pkey, unsigned char **pder) | 119 | static int |
| 119 | { | 120 | old_hmac_encode(const EVP_PKEY *pkey, unsigned char **pder) |
| 121 | { | ||
| 120 | int inc; | 122 | int inc; |
| 121 | ASN1_OCTET_STRING *os = (ASN1_OCTET_STRING *)pkey->pkey.ptr; | 123 | ASN1_OCTET_STRING *os = (ASN1_OCTET_STRING *)pkey->pkey.ptr; |
| 122 | if (pder) | 124 | |
| 123 | { | 125 | if (pder) { |
| 124 | if (!*pder) | 126 | if (!*pder) { |
| 125 | { | ||
| 126 | *pder = malloc(os->length); | 127 | *pder = malloc(os->length); |
| 127 | inc = 0; | 128 | inc = 0; |
| 128 | } | 129 | } else |
| 129 | else inc = 1; | 130 | inc = 1; |
| 130 | 131 | ||
| 131 | memcpy(*pder, os->data, os->length); | 132 | memcpy(*pder, os->data, os->length); |
| 132 | 133 | ||
| 133 | if (inc) | 134 | if (inc) |
| 134 | *pder += os->length; | 135 | *pder += os->length; |
| 135 | } | 136 | } |
| 136 | 137 | ||
| 137 | return os->length; | 138 | return os->length; |
| 138 | } | 139 | } |
| 139 | 140 | ||
| 140 | #endif | 141 | #endif |
| 141 | 142 | ||
| 142 | const EVP_PKEY_ASN1_METHOD hmac_asn1_meth = { | 143 | const EVP_PKEY_ASN1_METHOD |
| 144 | hmac_asn1_meth = { | ||
| 143 | .pkey_id = EVP_PKEY_HMAC, | 145 | .pkey_id = EVP_PKEY_HMAC, |
| 144 | .pkey_base_id = EVP_PKEY_HMAC, | 146 | .pkey_base_id = EVP_PKEY_HMAC, |
| 145 | 147 | ||
| @@ -154,5 +156,4 @@ const EVP_PKEY_ASN1_METHOD hmac_asn1_meth = { | |||
| 154 | .old_priv_decode = old_hmac_decode, | 156 | .old_priv_decode = old_hmac_decode, |
| 155 | .old_priv_encode = old_hmac_encode | 157 | .old_priv_encode = old_hmac_encode |
| 156 | #endif | 158 | #endif |
| 157 | }; | 159 | }; |
| 158 | |||
