OLD | NEW |
1 /* | 1 /* |
2 * sha512.c - implementation of SHA256, SHA384 and SHA512 | 2 * sha512.c - implementation of SHA256, SHA384 and SHA512 |
3 * | 3 * |
4 * ***** BEGIN LICENSE BLOCK ***** | 4 * ***** BEGIN LICENSE BLOCK ***** |
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
6 * | 6 * |
7 * The contents of this file are subject to the Mozilla Public License Version | 7 * The contents of this file are subject to the Mozilla Public License Version |
8 * 1.1 (the "License"); you may not use this file except in compliance with | 8 * 1.1 (the "License"); you may not use this file except in compliance with |
9 * the License. You may obtain a copy of the License at | 9 * the License. You may obtain a copy of the License at |
10 * http://www.mozilla.org/MPL/ | 10 * http://www.mozilla.org/MPL/ |
(...skipping 24 matching lines...) Expand all Loading... |
35 * the provisions above, a recipient may use your version of this file under | 35 * the provisions above, a recipient may use your version of this file under |
36 * the terms of any one of the MPL, the GPL or the LGPL. | 36 * the terms of any one of the MPL, the GPL or the LGPL. |
37 * | 37 * |
38 * ***** END LICENSE BLOCK ***** */ | 38 * ***** END LICENSE BLOCK ***** */ |
39 /* $Id: sha512.c,v 1.9 2006/10/13 16:54:04 wtchang%redhat.com Exp $ */ | 39 /* $Id: sha512.c,v 1.9 2006/10/13 16:54:04 wtchang%redhat.com Exp $ */ |
40 | 40 |
41 // Prevent manual unrolling in the sha256 code, which reduces the binary code | 41 // Prevent manual unrolling in the sha256 code, which reduces the binary code |
42 // size from ~10k to ~1k. The performance should be reasonable for our use. | 42 // size from ~10k to ~1k. The performance should be reasonable for our use. |
43 #define NOUNROLL256 1 | 43 #define NOUNROLL256 1 |
44 | 44 |
| 45 #include "base/third_party/nspr/prcpucfg_mac.h" |
45 #include "base/third_party/nspr/prtypes.h" /* for PRUintXX */ | 46 #include "base/third_party/nspr/prtypes.h" /* for PRUintXX */ |
| 47 #include "base/third_party/nss/blapit.h" |
46 #if defined(_X86_) || defined(SHA_NO_LONG_LONG) | 48 #if defined(_X86_) || defined(SHA_NO_LONG_LONG) |
47 #define NOUNROLL512 1 | 49 #define NOUNROLL512 1 |
48 #undef HAVE_LONG_LONG | 50 #undef HAVE_LONG_LONG |
49 #endif | 51 #endif |
50 #include "base/third_party/nss/blapi.h" | 52 #include <stdlib.h> |
| 53 #include <string.h> |
| 54 |
51 #include "base/third_party/nss/sha256.h" /* for struct SHA256ContextStr */ | 55 #include "base/third_party/nss/sha256.h" /* for struct SHA256ContextStr */ |
52 | 56 |
53 #include <stdlib.h> | |
54 #include <string.h> | |
55 #define PORT_New(type) static_cast<type*>(malloc(sizeof(type))) | 57 #define PORT_New(type) static_cast<type*>(malloc(sizeof(type))) |
56 #define PORT_ZFree(ptr, len) do { memset(ptr, 0, len); free(ptr); } while (0) | 58 #define PORT_ZFree(ptr, len) do { memset(ptr, 0, len); free(ptr); } while (0) |
57 #define PORT_Strlen(s) static_cast<unsigned int>(strlen(s)) | 59 #define PORT_Strlen(s) static_cast<unsigned int>(strlen(s)) |
58 #define PORT_Memcpy memcpy | 60 #define PORT_Memcpy memcpy |
59 | 61 |
60 /* ============= Common constants and defines ======================= */ | 62 /* ============= Common constants and defines ======================= */ |
61 | 63 |
62 #define W ctx->u.w | 64 #define W ctx->u.w |
63 #define B ctx->u.b | 65 #define B ctx->u.b |
64 #define H ctx->h | 66 #define H ctx->h |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 126 |
125 #define SHA_HTONL(x) swap4b(x) | 127 #define SHA_HTONL(x) swap4b(x) |
126 #define BYTESWAP4(x) x = SHA_HTONL(x) | 128 #define BYTESWAP4(x) x = SHA_HTONL(x) |
127 | 129 |
128 #elif defined(LINUX) && defined(_X86_) | 130 #elif defined(LINUX) && defined(_X86_) |
129 #undef __OPTIMIZE__ | 131 #undef __OPTIMIZE__ |
130 #define __OPTIMIZE__ 1 | 132 #define __OPTIMIZE__ 1 |
131 #undef __pentium__ | 133 #undef __pentium__ |
132 #define __pentium__ 1 | 134 #define __pentium__ 1 |
133 #include <byteswap.h> | 135 #include <byteswap.h> |
| 136 |
134 #define SHA_HTONL(x) bswap_32(x) | 137 #define SHA_HTONL(x) bswap_32(x) |
135 #define BYTESWAP4(x) x = SHA_HTONL(x) | 138 #define BYTESWAP4(x) x = SHA_HTONL(x) |
136 | 139 |
137 #else /* neither windows nor Linux PC */ | 140 #else /* neither windows nor Linux PC */ |
138 #define SWAP4MASK 0x00FF00FF | 141 #define SWAP4MASK 0x00FF00FF |
139 #define SHA_HTONL(x) (t1 = (x), t1 = (t1 << 16) | (t1 >> 16), \ | 142 #define SHA_HTONL(x) (t1 = (x), t1 = (t1 << 16) | (t1 >> 16), \ |
140 ((t1 & SWAP4MASK) << 8) | ((t1 >> 8) & SWAP4MASK)) | 143 ((t1 & SWAP4MASK) << 8) | ((t1 >> 8) & SWAP4MASK)) |
141 #define BYTESWAP4(x) x = SHA_HTONL(x) | 144 #define BYTESWAP4(x) x = SHA_HTONL(x) |
142 #endif | 145 #endif |
143 | 146 |
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 } else { | 1385 } else { |
1383 while (i-- > 0) { | 1386 while (i-- > 0) { |
1384 time512(); | 1387 time512(); |
1385 } | 1388 } |
1386 printf("done\n"); | 1389 printf("done\n"); |
1387 } | 1390 } |
1388 return 0; | 1391 return 0; |
1389 } | 1392 } |
1390 | 1393 |
1391 #endif | 1394 #endif |
OLD | NEW |