diff options
| author | jsing <> | 2014-04-21 15:39:52 +0000 |
|---|---|---|
| committer | jsing <> | 2014-04-21 15:39:52 +0000 |
| commit | b746bd9fb2cff6fc7b6ddd888ba614ad9bdb077b (patch) | |
| tree | 5061a725ebf8b95e2ec5deb1a93f1ba043db4ec8 /src/lib/libcrypto/pem/pem_all.c | |
| parent | dfe511c9e1293ae4ceb37e5ed8d5cf8073dc33f3 (diff) | |
| download | openbsd-b746bd9fb2cff6fc7b6ddd888ba614ad9bdb077b.tar.gz openbsd-b746bd9fb2cff6fc7b6ddd888ba614ad9bdb077b.tar.bz2 openbsd-b746bd9fb2cff6fc7b6ddd888ba614ad9bdb077b.zip | |
KNF.
Diffstat (limited to 'src/lib/libcrypto/pem/pem_all.c')
| -rw-r--r-- | src/lib/libcrypto/pem/pem_all.c | 94 |
1 files changed, 55 insertions, 39 deletions
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c index 6ff6be7fbe..8b54d1a698 100644 --- a/src/lib/libcrypto/pem/pem_all.c +++ b/src/lib/libcrypto/pem/pem_all.c | |||
| @@ -5,21 +5,21 @@ | |||
| 5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
| 6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
| 7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
| 8 | * | 8 | * |
| 9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
| 10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 15 | * | 15 | * |
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
| 18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
| 19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
| 20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
| 21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
| 22 | * | 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
| 25 | * are met: | 25 | * are met: |
| @@ -34,10 +34,10 @@ | |||
| 34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
| 36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 40 | * | 40 | * |
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -49,7 +49,7 @@ | |||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
| 52 | * | 52 | * |
| 53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
| @@ -63,7 +63,7 @@ | |||
| 63 | * are met: | 63 | * are met: |
| 64 | * | 64 | * |
| 65 | * 1. Redistributions of source code must retain the above copyright | 65 | * 1. Redistributions of source code must retain the above copyright |
| 66 | * notice, this list of conditions and the following disclaimer. | 66 | * notice, this list of conditions and the following disclaimer. |
| 67 | * | 67 | * |
| 68 | * 2. Redistributions in binary form must reproduce the above copyright | 68 | * 2. Redistributions in binary form must reproduce the above copyright |
| 69 | * notice, this list of conditions and the following disclaimer in | 69 | * notice, this list of conditions and the following disclaimer in |
| @@ -146,7 +146,7 @@ IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL) | |||
| 146 | IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7) | 146 | IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7) |
| 147 | 147 | ||
| 148 | IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE, | 148 | IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE, |
| 149 | PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE) | 149 | PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE) |
| 150 | 150 | ||
| 151 | 151 | ||
| 152 | #ifndef OPENSSL_NO_RSA | 152 | #ifndef OPENSSL_NO_RSA |
| @@ -159,34 +159,40 @@ IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE, | |||
| 159 | * transparently. | 159 | * transparently. |
| 160 | */ | 160 | */ |
| 161 | 161 | ||
| 162 | static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa) | 162 | static RSA * |
| 163 | pkey_get_rsa(EVP_PKEY *key, RSA **rsa) | ||
| 163 | { | 164 | { |
| 164 | RSA *rtmp; | 165 | RSA *rtmp; |
| 165 | if(!key) return NULL; | 166 | |
| 167 | if (!key) | ||
| 168 | return NULL; | ||
| 166 | rtmp = EVP_PKEY_get1_RSA(key); | 169 | rtmp = EVP_PKEY_get1_RSA(key); |
| 167 | EVP_PKEY_free(key); | 170 | EVP_PKEY_free(key); |
| 168 | if(!rtmp) return NULL; | 171 | if (!rtmp) |
| 169 | if(rsa) { | 172 | return NULL; |
| 173 | if (rsa) { | ||
| 170 | RSA_free(*rsa); | 174 | RSA_free(*rsa); |
| 171 | *rsa = rtmp; | 175 | *rsa = rtmp; |
| 172 | } | 176 | } |
| 173 | return rtmp; | 177 | return rtmp; |
| 174 | } | 178 | } |
| 175 | 179 | ||
| 176 | RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb, | 180 | RSA * |
| 177 | void *u) | 181 | PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb, void *u) |
| 178 | { | 182 | { |
| 179 | EVP_PKEY *pktmp; | 183 | EVP_PKEY *pktmp; |
| 184 | |||
| 180 | pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); | 185 | pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); |
| 181 | return pkey_get_rsa(pktmp, rsa); | 186 | return pkey_get_rsa(pktmp, rsa); |
| 182 | } | 187 | } |
| 183 | 188 | ||
| 184 | #ifndef OPENSSL_NO_FP_API | 189 | #ifndef OPENSSL_NO_FP_API |
| 185 | 190 | ||
| 186 | RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb, | 191 | RSA * |
| 187 | void *u) | 192 | PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb, void *u) |
| 188 | { | 193 | { |
| 189 | EVP_PKEY *pktmp; | 194 | EVP_PKEY *pktmp; |
| 195 | |||
| 190 | pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); | 196 | pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); |
| 191 | return pkey_get_rsa(pktmp, rsa); | 197 | return pkey_get_rsa(pktmp, rsa); |
| 192 | } | 198 | } |
| @@ -202,24 +208,29 @@ IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY) | |||
| 202 | 208 | ||
| 203 | #ifndef OPENSSL_NO_DSA | 209 | #ifndef OPENSSL_NO_DSA |
| 204 | 210 | ||
| 205 | static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa) | 211 | static DSA * |
| 212 | pkey_get_dsa(EVP_PKEY *key, DSA **dsa) | ||
| 206 | { | 213 | { |
| 207 | DSA *dtmp; | 214 | DSA *dtmp; |
| 208 | if(!key) return NULL; | 215 | |
| 216 | if (!key) | ||
| 217 | return NULL; | ||
| 209 | dtmp = EVP_PKEY_get1_DSA(key); | 218 | dtmp = EVP_PKEY_get1_DSA(key); |
| 210 | EVP_PKEY_free(key); | 219 | EVP_PKEY_free(key); |
| 211 | if(!dtmp) return NULL; | 220 | if (!dtmp) |
| 212 | if(dsa) { | 221 | return NULL; |
| 222 | if (dsa) { | ||
| 213 | DSA_free(*dsa); | 223 | DSA_free(*dsa); |
| 214 | *dsa = dtmp; | 224 | *dsa = dtmp; |
| 215 | } | 225 | } |
| 216 | return dtmp; | 226 | return dtmp; |
| 217 | } | 227 | } |
| 218 | 228 | ||
| 219 | DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb, | 229 | DSA * |
| 220 | void *u) | 230 | PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb, void *u) |
| 221 | { | 231 | { |
| 222 | EVP_PKEY *pktmp; | 232 | EVP_PKEY *pktmp; |
| 233 | |||
| 223 | pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); | 234 | pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); |
| 224 | return pkey_get_dsa(pktmp, dsa); /* will free pktmp */ | 235 | return pkey_get_dsa(pktmp, dsa); /* will free pktmp */ |
| 225 | } | 236 | } |
| @@ -230,10 +241,11 @@ IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY) | |||
| 230 | 241 | ||
| 231 | #ifndef OPENSSL_NO_FP_API | 242 | #ifndef OPENSSL_NO_FP_API |
| 232 | 243 | ||
| 233 | DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb, | 244 | DSA * |
| 234 | void *u) | 245 | PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb, void *u) |
| 235 | { | 246 | { |
| 236 | EVP_PKEY *pktmp; | 247 | EVP_PKEY *pktmp; |
| 248 | |||
| 237 | pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); | 249 | pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); |
| 238 | return pkey_get_dsa(pktmp, dsa); /* will free pktmp */ | 250 | return pkey_get_dsa(pktmp, dsa); /* will free pktmp */ |
| 239 | } | 251 | } |
| @@ -246,43 +258,47 @@ IMPLEMENT_PEM_rw_const(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams) | |||
| 246 | 258 | ||
| 247 | 259 | ||
| 248 | #ifndef OPENSSL_NO_EC | 260 | #ifndef OPENSSL_NO_EC |
| 249 | static EC_KEY *pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey) | 261 | static EC_KEY * |
| 262 | pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey) | ||
| 250 | { | 263 | { |
| 251 | EC_KEY *dtmp; | 264 | EC_KEY *dtmp; |
| 252 | if(!key) return NULL; | 265 | |
| 266 | if (!key) | ||
| 267 | return NULL; | ||
| 253 | dtmp = EVP_PKEY_get1_EC_KEY(key); | 268 | dtmp = EVP_PKEY_get1_EC_KEY(key); |
| 254 | EVP_PKEY_free(key); | 269 | EVP_PKEY_free(key); |
| 255 | if(!dtmp) return NULL; | 270 | if (!dtmp) |
| 256 | if(eckey) | 271 | return NULL; |
| 257 | { | 272 | if (eckey) { |
| 258 | EC_KEY_free(*eckey); | 273 | EC_KEY_free(*eckey); |
| 259 | *eckey = dtmp; | 274 | *eckey = dtmp; |
| 260 | } | 275 | } |
| 261 | return dtmp; | 276 | return dtmp; |
| 262 | } | 277 | } |
| 263 | 278 | ||
| 264 | EC_KEY *PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb, | 279 | EC_KEY * |
| 265 | void *u) | 280 | PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb, void *u) |
| 266 | { | 281 | { |
| 267 | EVP_PKEY *pktmp; | 282 | EVP_PKEY *pktmp; |
| 268 | pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); | 283 | pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); |
| 269 | return pkey_get_eckey(pktmp, key); /* will free pktmp */ | 284 | return pkey_get_eckey(pktmp, key); /* will free pktmp */ |
| 270 | } | 285 | } |
| 271 | 286 | ||
| 272 | IMPLEMENT_PEM_rw_const(ECPKParameters, EC_GROUP, PEM_STRING_ECPARAMETERS, ECPKParameters) | 287 | IMPLEMENT_PEM_rw_const(ECPKParameters, EC_GROUP, PEM_STRING_ECPARAMETERS, |
| 288 | ECPKParameters) | ||
| 273 | 289 | ||
| 274 | 290 | IMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY, | |
| 275 | 291 | ECPrivateKey) | |
| 276 | IMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY, ECPrivateKey) | ||
| 277 | 292 | ||
| 278 | IMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY) | 293 | IMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY) |
| 279 | 294 | ||
| 280 | #ifndef OPENSSL_NO_FP_API | 295 | #ifndef OPENSSL_NO_FP_API |
| 281 | 296 | ||
| 282 | EC_KEY *PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb, | 297 | EC_KEY * |
| 283 | void *u) | 298 | PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb, void *u) |
| 284 | { | 299 | { |
| 285 | EVP_PKEY *pktmp; | 300 | EVP_PKEY *pktmp; |
| 301 | |||
| 286 | pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); | 302 | pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); |
| 287 | return pkey_get_eckey(pktmp, eckey); /* will free pktmp */ | 303 | return pkey_get_eckey(pktmp, eckey); /* will free pktmp */ |
| 288 | } | 304 | } |
