diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/o_str.c (renamed from src/lib/libssl/src/fips/sha1/fips_standalone_sha1.c) | 147 |
1 files changed, 51 insertions, 96 deletions
diff --git a/src/lib/libssl/src/fips/sha1/fips_standalone_sha1.c b/src/lib/libcrypto/o_str.c index 1c2ec469e9..56104a6c34 100644 --- a/src/lib/libssl/src/fips/sha1/fips_standalone_sha1.c +++ b/src/lib/libcrypto/o_str.c | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | /* crypto/o_str.c -*- mode:C; c-file-style: "eay" -*- */ | ||
| 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | ||
| 3 | * project 2003. | ||
| 4 | */ | ||
| 1 | /* ==================================================================== | 5 | /* ==================================================================== |
| 2 | * Copyright (c) 2003 The OpenSSL Project. All rights reserved. | 6 | * Copyright (c) 2003 The OpenSSL Project. All rights reserved. |
| 3 | * | 7 | * |
| @@ -44,113 +48,64 @@ | |||
| 44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 46 | * OF THE POSSIBILITY OF SUCH DAMAGE. | 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 47 | * | 56 | * |
| 48 | */ | 57 | */ |
| 49 | 58 | ||
| 50 | #include <openssl/sha.h> | 59 | #include <ctype.h> |
| 51 | #include <openssl/hmac.h> | 60 | #include <e_os.h> |
| 52 | #include <openssl/opensslconf.h> | 61 | #include "o_str.h" |
| 53 | #include <stdio.h> | ||
| 54 | #include <stdlib.h> | ||
| 55 | #include <string.h> | ||
| 56 | |||
| 57 | int FIPS_selftest_failed() { return 0; } | ||
| 58 | 62 | ||
| 59 | #ifdef OPENSSL_FIPS | 63 | #if !defined(OPENSSL_IMPLEMENTS_strncasecmp) && \ |
| 60 | 64 | !defined(OPENSSL_SYSNAME_WIN32) && \ | |
| 61 | static void hmac_init(SHA_CTX *md_ctx,SHA_CTX *o_ctx, | 65 | !defined(NETWARE_CLIB) |
| 62 | const char *key) | 66 | # include <strings.h> |
| 63 | { | 67 | #endif |
| 64 | int len=strlen(key); | ||
| 65 | int i; | ||
| 66 | unsigned char keymd[HMAC_MAX_MD_CBLOCK]; | ||
| 67 | unsigned char pad[HMAC_MAX_MD_CBLOCK]; | ||
| 68 | 68 | ||
| 69 | if (len > SHA_CBLOCK) | 69 | int OPENSSL_strncasecmp(const char *str1, const char *str2, size_t n) |
| 70 | { | 70 | { |
| 71 | SHA1_Init(md_ctx); | 71 | #if defined(OPENSSL_IMPLEMENTS_strncasecmp) |
| 72 | SHA1_Update(md_ctx,key,len); | 72 | while (*str1 && *str2 && n) |
| 73 | SHA1_Final(keymd,md_ctx); | 73 | { |
| 74 | len=20; | 74 | int res = toupper(*str1) - toupper(*str2); |
| 75 | } | 75 | if (res) return res < 0 ? -1 : 1; |
| 76 | else | 76 | str1++; |
| 77 | memcpy(keymd,key,len); | 77 | str2++; |
| 78 | memset(&keymd[len],'\0',HMAC_MAX_MD_CBLOCK-len); | 78 | n--; |
| 79 | 79 | } | |
| 80 | for(i=0 ; i < HMAC_MAX_MD_CBLOCK ; i++) | 80 | if (n == 0) |
| 81 | pad[i]=0x36^keymd[i]; | 81 | return 0; |
| 82 | SHA1_Init(md_ctx); | 82 | if (*str1) |
| 83 | SHA1_Update(md_ctx,pad,SHA_CBLOCK); | 83 | return 1; |
| 84 | 84 | if (*str2) | |
| 85 | for(i=0 ; i < HMAC_MAX_MD_CBLOCK ; i++) | 85 | return -1; |
| 86 | pad[i]=0x5c^keymd[i]; | 86 | return 0; |
| 87 | SHA1_Init(o_ctx); | 87 | #else |
| 88 | SHA1_Update(o_ctx,pad,SHA_CBLOCK); | 88 | /* Recursion hazard warning! Whenever strncasecmp is #defined as |
| 89 | } | 89 | * OPENSSL_strncasecmp, OPENSSL_IMPLEMENTS_strncasecmp must be |
| 90 | 90 | * defined as well. */ | |
| 91 | static void hmac_final(unsigned char *md,SHA_CTX *md_ctx,SHA_CTX *o_ctx) | 91 | return strncasecmp(str1, str2, n); |
| 92 | { | ||
| 93 | unsigned char buf[20]; | ||
| 94 | |||
| 95 | SHA1_Final(buf,md_ctx); | ||
| 96 | SHA1_Update(o_ctx,buf,sizeof buf); | ||
| 97 | SHA1_Final(md,o_ctx); | ||
| 98 | } | ||
| 99 | |||
| 100 | #endif | 92 | #endif |
| 101 | 93 | } | |
| 102 | int main(int argc,char **argv) | 94 | int OPENSSL_strcasecmp(const char *str1, const char *str2) |
| 103 | { | ||
| 104 | #ifdef OPENSSL_FIPS | ||
| 105 | static char key[]="etaonrishdlcupfm"; | ||
| 106 | int n; | ||
| 107 | |||
| 108 | if(argc < 2) | ||
| 109 | { | 95 | { |
| 110 | fprintf(stderr,"%s [<file>]+\n",argv[0]); | 96 | #if defined(OPENSSL_IMPLEMENTS_strncasecmp) |
| 111 | exit(1); | 97 | return OPENSSL_strncasecmp(str1, str2, (size_t)-1); |
| 98 | #else | ||
| 99 | return strcasecmp(str1, str2); | ||
| 100 | #endif | ||
| 112 | } | 101 | } |
| 113 | 102 | ||
| 114 | for(n=1 ; n < argc ; ++n) | 103 | int OPENSSL_memcmp(const void *v1,const void *v2,size_t n) |
| 115 | { | 104 | { |
| 116 | FILE *f=fopen(argv[n],"rb"); | 105 | const unsigned char *c1=v1,*c2=v2; |
| 117 | SHA_CTX md_ctx,o_ctx; | 106 | int ret=0; |
| 118 | unsigned char md[20]; | ||
| 119 | int i; | ||
| 120 | |||
| 121 | if(!f) | ||
| 122 | { | ||
| 123 | perror(argv[n]); | ||
| 124 | exit(2); | ||
| 125 | } | ||
| 126 | 107 | ||
| 127 | hmac_init(&md_ctx,&o_ctx,key); | 108 | while(n && (ret=*c1-*c2)==0) n--,c1++,c2++; |
| 128 | for( ; ; ) | ||
| 129 | { | ||
| 130 | char buf[1024]; | ||
| 131 | int l=fread(buf,1,sizeof buf,f); | ||
| 132 | 109 | ||
| 133 | if(l == 0) | 110 | return ret; |
| 134 | { | ||
| 135 | if(ferror(f)) | ||
| 136 | { | ||
| 137 | perror(argv[n]); | ||
| 138 | exit(3); | ||
| 139 | } | ||
| 140 | else | ||
| 141 | break; | ||
| 142 | } | ||
| 143 | SHA1_Update(&md_ctx,buf,l); | ||
| 144 | } | ||
| 145 | hmac_final(md,&md_ctx,&o_ctx); | ||
| 146 | |||
| 147 | printf("HMAC-SHA1(%s)= ",argv[n]); | ||
| 148 | for(i=0 ; i < 20 ; ++i) | ||
| 149 | printf("%02x",md[i]); | ||
| 150 | printf("\n"); | ||
| 151 | } | 111 | } |
| 152 | #endif | ||
| 153 | return 0; | ||
| 154 | } | ||
| 155 | |||
| 156 | |||
