diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/ui/ui_util.c (renamed from src/lib/libssl/src/fips/sha1/fips_sha1_selftest.c) | 78 |
1 files changed, 36 insertions, 42 deletions
diff --git a/src/lib/libssl/src/fips/sha1/fips_sha1_selftest.c b/src/lib/libcrypto/ui/ui_util.c index 248539acb0..5d9760bb7b 100644 --- a/src/lib/libssl/src/fips/sha1/fips_sha1_selftest.c +++ b/src/lib/libcrypto/ui/ui_util.c | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | /* crypto/ui/ui_util.c -*- mode:C; c-file-style: "eay" -*- */ | ||
| 1 | /* ==================================================================== | 2 | /* ==================================================================== |
| 2 | * Copyright (c) 2003 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved. |
| 3 | * | 4 | * |
| 4 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| @@ -44,54 +45,47 @@ | |||
| 44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 46 | * OF THE POSSIBILITY OF SUCH DAMAGE. | 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 47 | * | 53 | * |
| 48 | */ | 54 | */ |
| 49 | 55 | ||
| 50 | #include <string.h> | 56 | #include <string.h> |
| 51 | #include <openssl/err.h> | 57 | #include "ui_locl.h" |
| 52 | #include <openssl/fips.h> | ||
| 53 | #include <openssl/sha.h> | ||
| 54 | |||
| 55 | #ifdef OPENSSL_FIPS | ||
| 56 | static char *test[]= | ||
| 57 | { | ||
| 58 | "", | ||
| 59 | "abc", | ||
| 60 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | ||
| 61 | NULL, | ||
| 62 | }; | ||
| 63 | 58 | ||
| 64 | static unsigned char ret[][SHA_DIGEST_LENGTH]= | 59 | int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify) |
| 65 | { | 60 | { |
| 66 | { 0xda,0x39,0xa3,0xee,0x5e,0x6b,0x4b,0x0d,0x32,0x55, | 61 | char buff[BUFSIZ]; |
| 67 | 0xbf,0xef,0x95,0x60,0x18,0x90,0xaf,0xd8,0x07,0x09 }, | 62 | int ret; |
| 68 | { 0xa9,0x99,0x3e,0x36,0x47,0x06,0x81,0x6a,0xba,0x3e, | ||
| 69 | 0x25,0x71,0x78,0x50,0xc2,0x6c,0x9c,0xd0,0xd8,0x9d }, | ||
| 70 | { 0x84,0x98,0x3e,0x44,0x1c,0x3b,0xd2,0x6e,0xba,0xae, | ||
| 71 | 0x4a,0xa1,0xf9,0x51,0x29,0xe5,0xe5,0x46,0x70,0xf1 }, | ||
| 72 | }; | ||
| 73 | |||
| 74 | void FIPS_corrupt_sha1() | ||
| 75 | { | ||
| 76 | ret[0][0]++; | ||
| 77 | } | ||
| 78 | 63 | ||
| 79 | int FIPS_selftest_sha1() | 64 | ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify); |
| 80 | { | 65 | OPENSSL_cleanse(buff,BUFSIZ); |
| 81 | int n; | 66 | return(ret); |
| 67 | } | ||
| 82 | 68 | ||
| 83 | for(n=0 ; test[n] ; ++n) | 69 | int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify) |
| 84 | { | 70 | { |
| 85 | unsigned char md[SHA_DIGEST_LENGTH]; | 71 | int ok = 0; |
| 72 | UI *ui; | ||
| 86 | 73 | ||
| 87 | SHA1((unsigned char*)test[n],strlen(test[n]),md); | 74 | if (size < 1) |
| 88 | if(memcmp(md,ret[n],sizeof md)) | 75 | return -1; |
| 89 | { | ||
| 90 | FIPSerr(FIPS_F_FIPS_SELFTEST_SHA1,FIPS_R_SELFTEST_FAILED); | ||
| 91 | return 0; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | return 1; | ||
| 95 | } | ||
| 96 | 76 | ||
| 97 | #endif | 77 | ui = UI_new(); |
| 78 | if (ui) | ||
| 79 | { | ||
| 80 | ok = UI_add_input_string(ui,prompt,0,buf,0,size-1); | ||
| 81 | if (ok >= 0 && verify) | ||
| 82 | ok = UI_add_verify_string(ui,prompt,0,buff,0,size-1, | ||
| 83 | buf); | ||
| 84 | if (ok >= 0) | ||
| 85 | ok=UI_process(ui); | ||
| 86 | UI_free(ui); | ||
| 87 | } | ||
| 88 | if (ok > 0) | ||
| 89 | ok = 0; | ||
| 90 | return(ok); | ||
| 91 | } | ||
