OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 /* SHA-1 implementation largely based on libmincrypt in the the Android | 6 /* SHA-1 implementation largely based on libmincrypt in the the Android |
7 * Open Source Project (platorm/system/core.git/libmincrypt/sha.c | 7 * Open Source Project (platorm/system/core.git/libmincrypt/sha.c |
8 */ | 8 */ |
9 | 9 |
10 #include "sha.h" | 10 #include "sha.h" |
11 | 11 |
12 /* Some machines lack byteswap.h and endian.h. These have to use the | 12 /* Some machines lack byteswap.h and endian.h. These have to use the |
13 * slower code, even if they're little-endian. | 13 * slower code, even if they're little-endian. |
14 */ | 14 */ |
15 | 15 |
16 #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN) | 16 #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN) |
17 | 17 |
18 #include <byteswap.h> | 18 #include <byteswap.h> |
19 #include <memory.h> | 19 #include <memory.h> |
20 | 20 |
21 /* This version is about 28% faster than the generic version below, | 21 /* This version is about 28% faster than the generic version below, |
22 * but assumes little-endianness. | 22 * but assumes little-endianness. |
23 */ | 23 */ |
24 static inline uint32_t ror27(uint32_t val) { | 24 static uint32_t ror27(uint32_t val) { |
25 return (val >> 27) | (val << 5); | 25 return (val >> 27) | (val << 5); |
26 } | 26 } |
27 static inline uint32_t ror2(uint32_t val) { | 27 static uint32_t ror2(uint32_t val) { |
28 return (val >> 2) | (val << 30); | 28 return (val >> 2) | (val << 30); |
29 } | 29 } |
30 static inline uint32_t ror31(uint32_t val) { | 30 static uint32_t ror31(uint32_t val) { |
31 return (val >> 31) | (val << 1); | 31 return (val >> 31) | (val << 1); |
32 } | 32 } |
33 | 33 |
34 static void SHA1_Transform(SHA_CTX* ctx) { | 34 static void SHA1_Transform(SHA1_CTX* ctx) { |
35 uint32_t W[80]; | 35 uint32_t W[80]; |
36 register uint32_t A, B, C, D, E; | 36 register uint32_t A, B, C, D, E; |
37 int t; | 37 int t; |
38 | 38 |
39 A = ctx->state[0]; | 39 A = ctx->state[0]; |
40 B = ctx->state[1]; | 40 B = ctx->state[1]; |
41 C = ctx->state[2]; | 41 C = ctx->state[2]; |
42 D = ctx->state[3]; | 42 D = ctx->state[3]; |
43 E = ctx->state[4]; | 43 E = ctx->state[4]; |
44 | 44 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 int i; | 280 int i; |
281 SHA1_CTX ctx; | 281 SHA1_CTX ctx; |
282 SHA1_init(&ctx); | 282 SHA1_init(&ctx); |
283 SHA1_update(&ctx, data, len); | 283 SHA1_update(&ctx, data, len); |
284 p = SHA1_final(&ctx); | 284 p = SHA1_final(&ctx); |
285 for (i = 0; i < SHA1_DIGEST_SIZE; ++i) { | 285 for (i = 0; i < SHA1_DIGEST_SIZE; ++i) { |
286 digest[i] = *p++; | 286 digest[i] = *p++; |
287 } | 287 } |
288 return digest; | 288 return digest; |
289 } | 289 } |
OLD | NEW |