diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa.h | 39 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_asn1.c | 82 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_err.c | 10 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_gen.c | 3 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_key.c | 4 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_lib.c | 49 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_ossl.c | 3 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_sign.c | 31 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_vrf.c | 32 |
9 files changed, 193 insertions, 60 deletions
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h index 3a8fe5b56b..702c50d6dc 100644 --- a/src/lib/libcrypto/dsa/dsa.h +++ b/src/lib/libcrypto/dsa/dsa.h | |||
| @@ -88,6 +88,8 @@ | |||
| 88 | # define OPENSSL_DSA_MAX_MODULUS_BITS 10000 | 88 | # define OPENSSL_DSA_MAX_MODULUS_BITS 10000 |
| 89 | #endif | 89 | #endif |
| 90 | 90 | ||
| 91 | #define OPENSSL_DSA_FIPS_MIN_MODULUS_BITS 1024 | ||
| 92 | |||
| 91 | #define DSA_FLAG_CACHE_MONT_P 0x01 | 93 | #define DSA_FLAG_CACHE_MONT_P 0x01 |
| 92 | #define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA | 94 | #define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA |
| 93 | * implementation now uses constant time | 95 | * implementation now uses constant time |
| @@ -97,6 +99,25 @@ | |||
| 97 | * be used for all exponents. | 99 | * be used for all exponents. |
| 98 | */ | 100 | */ |
| 99 | 101 | ||
| 102 | /* If this flag is set the DSA method is FIPS compliant and can be used | ||
| 103 | * in FIPS mode. This is set in the validated module method. If an | ||
| 104 | * application sets this flag in its own methods it is its reposibility | ||
| 105 | * to ensure the result is compliant. | ||
| 106 | */ | ||
| 107 | |||
| 108 | #define DSA_FLAG_FIPS_METHOD 0x0400 | ||
| 109 | |||
| 110 | /* If this flag is set the operations normally disabled in FIPS mode are | ||
| 111 | * permitted it is then the applications responsibility to ensure that the | ||
| 112 | * usage is compliant. | ||
| 113 | */ | ||
| 114 | |||
| 115 | #define DSA_FLAG_NON_FIPS_ALLOW 0x0400 | ||
| 116 | |||
| 117 | #ifdef OPENSSL_FIPS | ||
| 118 | #define FIPS_DSA_SIZE_T int | ||
| 119 | #endif | ||
| 120 | |||
| 100 | #ifdef __cplusplus | 121 | #ifdef __cplusplus |
| 101 | extern "C" { | 122 | extern "C" { |
| 102 | #endif | 123 | #endif |
| @@ -189,6 +210,11 @@ void DSA_set_default_method(const DSA_METHOD *); | |||
| 189 | const DSA_METHOD *DSA_get_default_method(void); | 210 | const DSA_METHOD *DSA_get_default_method(void); |
| 190 | int DSA_set_method(DSA *dsa, const DSA_METHOD *); | 211 | int DSA_set_method(DSA *dsa, const DSA_METHOD *); |
| 191 | 212 | ||
| 213 | #ifdef OPENSSL_FIPS | ||
| 214 | DSA * FIPS_dsa_new(void); | ||
| 215 | void FIPS_dsa_free (DSA *r); | ||
| 216 | #endif | ||
| 217 | |||
| 192 | DSA * DSA_new(void); | 218 | DSA * DSA_new(void); |
| 193 | DSA * DSA_new_method(ENGINE *engine); | 219 | DSA * DSA_new_method(ENGINE *engine); |
| 194 | void DSA_free (DSA *r); | 220 | void DSA_free (DSA *r); |
| @@ -249,6 +275,11 @@ int DSA_print_fp(FILE *bp, const DSA *x, int off); | |||
| 249 | DH *DSA_dup_DH(const DSA *r); | 275 | DH *DSA_dup_DH(const DSA *r); |
| 250 | #endif | 276 | #endif |
| 251 | 277 | ||
| 278 | #ifdef OPENSSL_FIPS | ||
| 279 | int FIPS_dsa_sig_encode(unsigned char *out, DSA_SIG *sig); | ||
| 280 | int FIPS_dsa_sig_decode(DSA_SIG *sig, const unsigned char *in, int inlen); | ||
| 281 | #endif | ||
| 282 | |||
| 252 | /* BEGIN ERROR CODES */ | 283 | /* BEGIN ERROR CODES */ |
| 253 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 284 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
| 254 | * made after this point may be overwritten when the script is next run. | 285 | * made after this point may be overwritten when the script is next run. |
| @@ -261,11 +292,16 @@ void ERR_load_DSA_strings(void); | |||
| 261 | #define DSA_F_D2I_DSA_SIG 110 | 292 | #define DSA_F_D2I_DSA_SIG 110 |
| 262 | #define DSA_F_DSAPARAMS_PRINT 100 | 293 | #define DSA_F_DSAPARAMS_PRINT 100 |
| 263 | #define DSA_F_DSAPARAMS_PRINT_FP 101 | 294 | #define DSA_F_DSAPARAMS_PRINT_FP 101 |
| 295 | #define DSA_F_DSA_BUILTIN_KEYGEN 119 | ||
| 296 | #define DSA_F_DSA_BUILTIN_PARAMGEN 118 | ||
| 264 | #define DSA_F_DSA_DO_SIGN 112 | 297 | #define DSA_F_DSA_DO_SIGN 112 |
| 265 | #define DSA_F_DSA_DO_VERIFY 113 | 298 | #define DSA_F_DSA_DO_VERIFY 113 |
| 299 | #define DSA_F_DSA_GENERATE_PARAMETERS 117 | ||
| 266 | #define DSA_F_DSA_NEW_METHOD 103 | 300 | #define DSA_F_DSA_NEW_METHOD 103 |
| 267 | #define DSA_F_DSA_PRINT 104 | 301 | #define DSA_F_DSA_PRINT 104 |
| 268 | #define DSA_F_DSA_PRINT_FP 105 | 302 | #define DSA_F_DSA_PRINT_FP 105 |
| 303 | #define DSA_F_DSA_SET_DEFAULT_METHOD 115 | ||
| 304 | #define DSA_F_DSA_SET_METHOD 116 | ||
| 269 | #define DSA_F_DSA_SIGN 106 | 305 | #define DSA_F_DSA_SIGN 106 |
| 270 | #define DSA_F_DSA_SIGN_SETUP 107 | 306 | #define DSA_F_DSA_SIGN_SETUP 107 |
| 271 | #define DSA_F_DSA_SIG_NEW 109 | 307 | #define DSA_F_DSA_SIG_NEW 109 |
| @@ -276,8 +312,11 @@ void ERR_load_DSA_strings(void); | |||
| 276 | /* Reason codes. */ | 312 | /* Reason codes. */ |
| 277 | #define DSA_R_BAD_Q_VALUE 102 | 313 | #define DSA_R_BAD_Q_VALUE 102 |
| 278 | #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 | 314 | #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 |
| 315 | #define DSA_R_KEY_SIZE_TOO_SMALL 106 | ||
| 279 | #define DSA_R_MISSING_PARAMETERS 101 | 316 | #define DSA_R_MISSING_PARAMETERS 101 |
| 280 | #define DSA_R_MODULUS_TOO_LARGE 103 | 317 | #define DSA_R_MODULUS_TOO_LARGE 103 |
| 318 | #define DSA_R_NON_FIPS_METHOD 104 | ||
| 319 | #define DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE 105 | ||
| 281 | 320 | ||
| 282 | #ifdef __cplusplus | 321 | #ifdef __cplusplus |
| 283 | } | 322 | } |
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c index 23fce555aa..0645facb4b 100644 --- a/src/lib/libcrypto/dsa/dsa_asn1.c +++ b/src/lib/libcrypto/dsa/dsa_asn1.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* dsa_asn1.c */ | 1 | /* dsa_asn1.c */ |
| 2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project 2000. | 3 | * project 2000. |
| 4 | */ | 4 | */ |
| 5 | /* ==================================================================== | 5 | /* ==================================================================== |
| @@ -61,6 +61,11 @@ | |||
| 61 | #include <openssl/dsa.h> | 61 | #include <openssl/dsa.h> |
| 62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
| 63 | #include <openssl/asn1t.h> | 63 | #include <openssl/asn1t.h> |
| 64 | #include <openssl/bn.h> | ||
| 65 | #ifdef OPENSSL_FIPS | ||
| 66 | #include <openssl/fips.h> | ||
| 67 | #endif | ||
| 68 | |||
| 64 | 69 | ||
| 65 | /* Override the default new methods */ | 70 | /* Override the default new methods */ |
| 66 | static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | 71 | static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) |
| @@ -83,7 +88,7 @@ ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = { | |||
| 83 | ASN1_SIMPLE(DSA_SIG, s, CBIGNUM) | 88 | ASN1_SIMPLE(DSA_SIG, s, CBIGNUM) |
| 84 | } ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG) | 89 | } ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG) |
| 85 | 90 | ||
| 86 | IMPLEMENT_ASN1_FUNCTIONS_const(DSA_SIG) | 91 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA_SIG,DSA_SIG,DSA_SIG) |
| 87 | 92 | ||
| 88 | /* Override the default free and new methods */ | 93 | /* Override the default free and new methods */ |
| 89 | static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | 94 | static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) |
| @@ -138,3 +143,76 @@ ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = { | |||
| 138 | } ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params) | 143 | } ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params) |
| 139 | 144 | ||
| 140 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey) | 145 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey) |
| 146 | |||
| 147 | int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, | ||
| 148 | unsigned int *siglen, DSA *dsa) | ||
| 149 | { | ||
| 150 | DSA_SIG *s; | ||
| 151 | #ifdef OPENSSL_FIPS | ||
| 152 | if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW)) | ||
| 153 | { | ||
| 154 | DSAerr(DSA_F_DSA_SIGN, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE); | ||
| 155 | return 0; | ||
| 156 | } | ||
| 157 | #endif | ||
| 158 | s=DSA_do_sign(dgst,dlen,dsa); | ||
| 159 | if (s == NULL) | ||
| 160 | { | ||
| 161 | *siglen=0; | ||
| 162 | return(0); | ||
| 163 | } | ||
| 164 | *siglen=i2d_DSA_SIG(s,&sig); | ||
| 165 | DSA_SIG_free(s); | ||
| 166 | return(1); | ||
| 167 | } | ||
| 168 | |||
| 169 | int DSA_size(const DSA *r) | ||
| 170 | { | ||
| 171 | int ret,i; | ||
| 172 | ASN1_INTEGER bs; | ||
| 173 | unsigned char buf[4]; /* 4 bytes looks really small. | ||
| 174 | However, i2d_ASN1_INTEGER() will not look | ||
| 175 | beyond the first byte, as long as the second | ||
| 176 | parameter is NULL. */ | ||
| 177 | |||
| 178 | i=BN_num_bits(r->q); | ||
| 179 | bs.length=(i+7)/8; | ||
| 180 | bs.data=buf; | ||
| 181 | bs.type=V_ASN1_INTEGER; | ||
| 182 | /* If the top bit is set the asn1 encoding is 1 larger. */ | ||
| 183 | buf[0]=0xff; | ||
| 184 | |||
| 185 | i=i2d_ASN1_INTEGER(&bs,NULL); | ||
| 186 | i+=i; /* r and s */ | ||
| 187 | ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE); | ||
| 188 | return(ret); | ||
| 189 | } | ||
| 190 | |||
| 191 | /* data has already been hashed (probably with SHA or SHA-1). */ | ||
| 192 | /* returns | ||
| 193 | * 1: correct signature | ||
| 194 | * 0: incorrect signature | ||
| 195 | * -1: error | ||
| 196 | */ | ||
| 197 | int DSA_verify(int type, const unsigned char *dgst, int dgst_len, | ||
| 198 | const unsigned char *sigbuf, int siglen, DSA *dsa) | ||
| 199 | { | ||
| 200 | DSA_SIG *s; | ||
| 201 | int ret=-1; | ||
| 202 | #ifdef OPENSSL_FIPS | ||
| 203 | if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW)) | ||
| 204 | { | ||
| 205 | DSAerr(DSA_F_DSA_VERIFY, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE); | ||
| 206 | return 0; | ||
| 207 | } | ||
| 208 | #endif | ||
| 209 | |||
| 210 | s = DSA_SIG_new(); | ||
| 211 | if (s == NULL) return(ret); | ||
| 212 | if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err; | ||
| 213 | ret=DSA_do_verify(dgst,dgst_len,s,dsa); | ||
| 214 | err: | ||
| 215 | DSA_SIG_free(s); | ||
| 216 | return(ret); | ||
| 217 | } | ||
| 218 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c index 768711994b..872839af94 100644 --- a/src/lib/libcrypto/dsa/dsa_err.c +++ b/src/lib/libcrypto/dsa/dsa_err.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* crypto/dsa/dsa_err.c */ | 1 | /* crypto/dsa/dsa_err.c */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -73,11 +73,16 @@ static ERR_STRING_DATA DSA_str_functs[]= | |||
| 73 | {ERR_FUNC(DSA_F_D2I_DSA_SIG), "d2i_DSA_SIG"}, | 73 | {ERR_FUNC(DSA_F_D2I_DSA_SIG), "d2i_DSA_SIG"}, |
| 74 | {ERR_FUNC(DSA_F_DSAPARAMS_PRINT), "DSAparams_print"}, | 74 | {ERR_FUNC(DSA_F_DSAPARAMS_PRINT), "DSAparams_print"}, |
| 75 | {ERR_FUNC(DSA_F_DSAPARAMS_PRINT_FP), "DSAparams_print_fp"}, | 75 | {ERR_FUNC(DSA_F_DSAPARAMS_PRINT_FP), "DSAparams_print_fp"}, |
| 76 | {ERR_FUNC(DSA_F_DSA_BUILTIN_KEYGEN), "DSA_BUILTIN_KEYGEN"}, | ||
| 77 | {ERR_FUNC(DSA_F_DSA_BUILTIN_PARAMGEN), "DSA_BUILTIN_PARAMGEN"}, | ||
| 76 | {ERR_FUNC(DSA_F_DSA_DO_SIGN), "DSA_do_sign"}, | 78 | {ERR_FUNC(DSA_F_DSA_DO_SIGN), "DSA_do_sign"}, |
| 77 | {ERR_FUNC(DSA_F_DSA_DO_VERIFY), "DSA_do_verify"}, | 79 | {ERR_FUNC(DSA_F_DSA_DO_VERIFY), "DSA_do_verify"}, |
| 80 | {ERR_FUNC(DSA_F_DSA_GENERATE_PARAMETERS), "DSA_generate_parameters"}, | ||
| 78 | {ERR_FUNC(DSA_F_DSA_NEW_METHOD), "DSA_new_method"}, | 81 | {ERR_FUNC(DSA_F_DSA_NEW_METHOD), "DSA_new_method"}, |
| 79 | {ERR_FUNC(DSA_F_DSA_PRINT), "DSA_print"}, | 82 | {ERR_FUNC(DSA_F_DSA_PRINT), "DSA_print"}, |
| 80 | {ERR_FUNC(DSA_F_DSA_PRINT_FP), "DSA_print_fp"}, | 83 | {ERR_FUNC(DSA_F_DSA_PRINT_FP), "DSA_print_fp"}, |
| 84 | {ERR_FUNC(DSA_F_DSA_SET_DEFAULT_METHOD), "DSA_set_default_method"}, | ||
| 85 | {ERR_FUNC(DSA_F_DSA_SET_METHOD), "DSA_set_method"}, | ||
| 81 | {ERR_FUNC(DSA_F_DSA_SIGN), "DSA_sign"}, | 86 | {ERR_FUNC(DSA_F_DSA_SIGN), "DSA_sign"}, |
| 82 | {ERR_FUNC(DSA_F_DSA_SIGN_SETUP), "DSA_sign_setup"}, | 87 | {ERR_FUNC(DSA_F_DSA_SIGN_SETUP), "DSA_sign_setup"}, |
| 83 | {ERR_FUNC(DSA_F_DSA_SIG_NEW), "DSA_SIG_new"}, | 88 | {ERR_FUNC(DSA_F_DSA_SIG_NEW), "DSA_SIG_new"}, |
| @@ -91,8 +96,11 @@ static ERR_STRING_DATA DSA_str_reasons[]= | |||
| 91 | { | 96 | { |
| 92 | {ERR_REASON(DSA_R_BAD_Q_VALUE) ,"bad q value"}, | 97 | {ERR_REASON(DSA_R_BAD_Q_VALUE) ,"bad q value"}, |
| 93 | {ERR_REASON(DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"}, | 98 | {ERR_REASON(DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"}, |
| 99 | {ERR_REASON(DSA_R_KEY_SIZE_TOO_SMALL) ,"key size too small"}, | ||
| 94 | {ERR_REASON(DSA_R_MISSING_PARAMETERS) ,"missing parameters"}, | 100 | {ERR_REASON(DSA_R_MISSING_PARAMETERS) ,"missing parameters"}, |
| 95 | {ERR_REASON(DSA_R_MODULUS_TOO_LARGE) ,"modulus too large"}, | 101 | {ERR_REASON(DSA_R_MODULUS_TOO_LARGE) ,"modulus too large"}, |
| 102 | {ERR_REASON(DSA_R_NON_FIPS_METHOD) ,"non fips method"}, | ||
| 103 | {ERR_REASON(DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE),"operation not allowed in fips mode"}, | ||
| 96 | {0,NULL} | 104 | {0,NULL} |
| 97 | }; | 105 | }; |
| 98 | 106 | ||
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c index ca0b86a6cf..6f1728e3cf 100644 --- a/src/lib/libcrypto/dsa/dsa_gen.c +++ b/src/lib/libcrypto/dsa/dsa_gen.c | |||
| @@ -82,6 +82,8 @@ | |||
| 82 | #include <openssl/rand.h> | 82 | #include <openssl/rand.h> |
| 83 | #include <openssl/sha.h> | 83 | #include <openssl/sha.h> |
| 84 | 84 | ||
| 85 | #ifndef OPENSSL_FIPS | ||
| 86 | |||
| 85 | static int dsa_builtin_paramgen(DSA *ret, int bits, | 87 | static int dsa_builtin_paramgen(DSA *ret, int bits, |
| 86 | unsigned char *seed_in, int seed_len, | 88 | unsigned char *seed_in, int seed_len, |
| 87 | int *counter_ret, unsigned long *h_ret, BN_GENCB *cb); | 89 | int *counter_ret, unsigned long *h_ret, BN_GENCB *cb); |
| @@ -320,3 +322,4 @@ err: | |||
| 320 | return ok; | 322 | return ok; |
| 321 | } | 323 | } |
| 322 | #endif | 324 | #endif |
| 325 | #endif | ||
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c index c4aa86bc6d..5e39124230 100644 --- a/src/lib/libcrypto/dsa/dsa_key.c +++ b/src/lib/libcrypto/dsa/dsa_key.c | |||
| @@ -64,6 +64,8 @@ | |||
| 64 | #include <openssl/dsa.h> | 64 | #include <openssl/dsa.h> |
| 65 | #include <openssl/rand.h> | 65 | #include <openssl/rand.h> |
| 66 | 66 | ||
| 67 | #ifndef OPENSSL_FIPS | ||
| 68 | |||
| 67 | static int dsa_builtin_keygen(DSA *dsa); | 69 | static int dsa_builtin_keygen(DSA *dsa); |
| 68 | 70 | ||
| 69 | int DSA_generate_key(DSA *dsa) | 71 | int DSA_generate_key(DSA *dsa) |
| @@ -126,3 +128,5 @@ err: | |||
| 126 | return(ok); | 128 | return(ok); |
| 127 | } | 129 | } |
| 128 | #endif | 130 | #endif |
| 131 | |||
| 132 | #endif | ||
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c index e9b75902db..7ac9dc8c89 100644 --- a/src/lib/libcrypto/dsa/dsa_lib.c +++ b/src/lib/libcrypto/dsa/dsa_lib.c | |||
| @@ -76,6 +76,14 @@ static const DSA_METHOD *default_DSA_method = NULL; | |||
| 76 | 76 | ||
| 77 | void DSA_set_default_method(const DSA_METHOD *meth) | 77 | void DSA_set_default_method(const DSA_METHOD *meth) |
| 78 | { | 78 | { |
| 79 | #ifdef OPENSSL_FIPS | ||
| 80 | if (FIPS_mode() && !(meth->flags & DSA_FLAG_FIPS_METHOD)) | ||
| 81 | { | ||
| 82 | DSAerr(DSA_F_DSA_SET_DEFAULT_METHOD, DSA_R_NON_FIPS_METHOD); | ||
| 83 | return; | ||
| 84 | } | ||
| 85 | #endif | ||
| 86 | |||
| 79 | default_DSA_method = meth; | 87 | default_DSA_method = meth; |
| 80 | } | 88 | } |
| 81 | 89 | ||
| @@ -96,6 +104,13 @@ int DSA_set_method(DSA *dsa, const DSA_METHOD *meth) | |||
| 96 | /* NB: The caller is specifically setting a method, so it's not up to us | 104 | /* NB: The caller is specifically setting a method, so it's not up to us |
| 97 | * to deal with which ENGINE it comes from. */ | 105 | * to deal with which ENGINE it comes from. */ |
| 98 | const DSA_METHOD *mtmp; | 106 | const DSA_METHOD *mtmp; |
| 107 | #ifdef OPENSSL_FIPS | ||
| 108 | if (FIPS_mode() && !(meth->flags & DSA_FLAG_FIPS_METHOD)) | ||
| 109 | { | ||
| 110 | DSAerr(DSA_F_DSA_SET_METHOD, DSA_R_NON_FIPS_METHOD); | ||
| 111 | return 0; | ||
| 112 | } | ||
| 113 | #endif | ||
| 99 | mtmp = dsa->meth; | 114 | mtmp = dsa->meth; |
| 100 | if (mtmp->finish) mtmp->finish(dsa); | 115 | if (mtmp->finish) mtmp->finish(dsa); |
| 101 | #ifndef OPENSSL_NO_ENGINE | 116 | #ifndef OPENSSL_NO_ENGINE |
| @@ -147,6 +162,18 @@ DSA *DSA_new_method(ENGINE *engine) | |||
| 147 | } | 162 | } |
| 148 | } | 163 | } |
| 149 | #endif | 164 | #endif |
| 165 | #ifdef OPENSSL_FIPS | ||
| 166 | if (FIPS_mode() && !(ret->meth->flags & DSA_FLAG_FIPS_METHOD)) | ||
| 167 | { | ||
| 168 | DSAerr(DSA_F_DSA_NEW_METHOD, DSA_R_NON_FIPS_METHOD); | ||
| 169 | #ifndef OPENSSL_NO_ENGINE | ||
| 170 | if (ret->engine) | ||
| 171 | ENGINE_finish(ret->engine); | ||
| 172 | #endif | ||
| 173 | OPENSSL_free(ret); | ||
| 174 | return NULL; | ||
| 175 | } | ||
| 176 | #endif | ||
| 150 | 177 | ||
| 151 | ret->pad=0; | 178 | ret->pad=0; |
| 152 | ret->version=0; | 179 | ret->version=0; |
| @@ -233,28 +260,6 @@ int DSA_up_ref(DSA *r) | |||
| 233 | return ((i > 1) ? 1 : 0); | 260 | return ((i > 1) ? 1 : 0); |
| 234 | } | 261 | } |
| 235 | 262 | ||
| 236 | int DSA_size(const DSA *r) | ||
| 237 | { | ||
| 238 | int ret,i; | ||
| 239 | ASN1_INTEGER bs; | ||
| 240 | unsigned char buf[4]; /* 4 bytes looks really small. | ||
| 241 | However, i2d_ASN1_INTEGER() will not look | ||
| 242 | beyond the first byte, as long as the second | ||
| 243 | parameter is NULL. */ | ||
| 244 | |||
| 245 | i=BN_num_bits(r->q); | ||
| 246 | bs.length=(i+7)/8; | ||
| 247 | bs.data=buf; | ||
| 248 | bs.type=V_ASN1_INTEGER; | ||
| 249 | /* If the top bit is set the asn1 encoding is 1 larger. */ | ||
| 250 | buf[0]=0xff; | ||
| 251 | |||
| 252 | i=i2d_ASN1_INTEGER(&bs,NULL); | ||
| 253 | i+=i; /* r and s */ | ||
| 254 | ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE); | ||
| 255 | return(ret); | ||
| 256 | } | ||
| 257 | |||
| 258 | int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 263 | int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
| 259 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 264 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) |
| 260 | { | 265 | { |
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c index 75ff7cc4af..412cf1d88b 100644 --- a/src/lib/libcrypto/dsa/dsa_ossl.c +++ b/src/lib/libcrypto/dsa/dsa_ossl.c | |||
| @@ -65,6 +65,8 @@ | |||
| 65 | #include <openssl/rand.h> | 65 | #include <openssl/rand.h> |
| 66 | #include <openssl/asn1.h> | 66 | #include <openssl/asn1.h> |
| 67 | 67 | ||
| 68 | #ifndef OPENSSL_FIPS | ||
| 69 | |||
| 68 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | 70 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); |
| 69 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); | 71 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); |
| 70 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | 72 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, |
| @@ -391,3 +393,4 @@ static int dsa_finish(DSA *dsa) | |||
| 391 | return(1); | 393 | return(1); |
| 392 | } | 394 | } |
| 393 | 395 | ||
| 396 | #endif | ||
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c index 89205026f0..4cfbbe57a8 100644 --- a/src/lib/libcrypto/dsa/dsa_sign.c +++ b/src/lib/libcrypto/dsa/dsa_sign.c | |||
| @@ -64,29 +64,32 @@ | |||
| 64 | #include <openssl/dsa.h> | 64 | #include <openssl/dsa.h> |
| 65 | #include <openssl/rand.h> | 65 | #include <openssl/rand.h> |
| 66 | #include <openssl/asn1.h> | 66 | #include <openssl/asn1.h> |
| 67 | #ifdef OPENSSL_FIPS | ||
| 68 | #include <openssl/fips.h> | ||
| 69 | #endif | ||
| 67 | 70 | ||
| 68 | DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
| 69 | { | ||
| 70 | return dsa->meth->dsa_do_sign(dgst, dlen, dsa); | ||
| 71 | } | ||
| 72 | 71 | ||
| 73 | int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, | 72 | DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) |
| 74 | unsigned int *siglen, DSA *dsa) | ||
| 75 | { | 73 | { |
| 76 | DSA_SIG *s; | 74 | #ifdef OPENSSL_FIPS |
| 77 | s=DSA_do_sign(dgst,dlen,dsa); | 75 | if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW)) |
| 78 | if (s == NULL) | ||
| 79 | { | 76 | { |
| 80 | *siglen=0; | 77 | DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE); |
| 81 | return(0); | 78 | return NULL; |
| 82 | } | 79 | } |
| 83 | *siglen=i2d_DSA_SIG(s,&sig); | 80 | #endif |
| 84 | DSA_SIG_free(s); | 81 | return dsa->meth->dsa_do_sign(dgst, dlen, dsa); |
| 85 | return(1); | ||
| 86 | } | 82 | } |
| 87 | 83 | ||
| 88 | int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | 84 | int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) |
| 89 | { | 85 | { |
| 86 | #ifdef OPENSSL_FIPS | ||
| 87 | if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW)) | ||
| 88 | { | ||
| 89 | DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE); | ||
| 90 | return 0; | ||
| 91 | } | ||
| 92 | #endif | ||
| 90 | return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp); | 93 | return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp); |
| 91 | } | 94 | } |
| 92 | 95 | ||
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c index c4aeddd056..c75e423048 100644 --- a/src/lib/libcrypto/dsa/dsa_vrf.c +++ b/src/lib/libcrypto/dsa/dsa_vrf.c | |||
| @@ -64,31 +64,21 @@ | |||
| 64 | #include <openssl/dsa.h> | 64 | #include <openssl/dsa.h> |
| 65 | #include <openssl/rand.h> | 65 | #include <openssl/rand.h> |
| 66 | #include <openssl/asn1.h> | 66 | #include <openssl/asn1.h> |
| 67 | #ifdef OPENSSL_FIPS | ||
| 68 | #include <openssl/fips.h> | ||
| 69 | #endif | ||
| 70 | |||
| 67 | #include <openssl/asn1_mac.h> | 71 | #include <openssl/asn1_mac.h> |
| 68 | 72 | ||
| 69 | int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | 73 | int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, |
| 70 | DSA *dsa) | 74 | DSA *dsa) |
| 71 | { | 75 | { |
| 76 | #ifdef OPENSSL_FIPS | ||
| 77 | if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW)) | ||
| 78 | { | ||
| 79 | DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE); | ||
| 80 | return 0; | ||
| 81 | } | ||
| 82 | #endif | ||
| 72 | return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa); | 83 | return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa); |
| 73 | } | 84 | } |
| 74 | |||
| 75 | /* data has already been hashed (probably with SHA or SHA-1). */ | ||
| 76 | /* returns | ||
| 77 | * 1: correct signature | ||
| 78 | * 0: incorrect signature | ||
| 79 | * -1: error | ||
| 80 | */ | ||
| 81 | int DSA_verify(int type, const unsigned char *dgst, int dgst_len, | ||
| 82 | const unsigned char *sigbuf, int siglen, DSA *dsa) | ||
| 83 | { | ||
| 84 | DSA_SIG *s; | ||
| 85 | int ret=-1; | ||
| 86 | |||
| 87 | s = DSA_SIG_new(); | ||
| 88 | if (s == NULL) return(ret); | ||
| 89 | if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err; | ||
| 90 | ret=DSA_do_verify(dgst,dgst_len,s,dsa); | ||
| 91 | err: | ||
| 92 | DSA_SIG_free(s); | ||
| 93 | return(ret); | ||
| 94 | } | ||
