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 * SHA-1 implementation largely based on libmincrypt in the the Android | 5 * SHA-1 implementation largely based on libmincrypt in the the Android |
6 * Open Source Project (platorm/system/core.git/libmincrypt/sha.c | 6 * Open Source Project (platorm/system/core.git/libmincrypt/sha.c |
7 */ | 7 */ |
8 | 8 |
9 #include "cryptolib.h" | 9 #include "cryptolib.h" |
10 #include "utility.h" | 10 #include "utility.h" |
11 | 11 |
12 | 12 |
13 /* Some machines lack byteswap.h and endian.h. These have to use the | 13 /* Some machines lack byteswap.h and endian.h. These have to use the |
14 * slower code, even if they're little-endian. | 14 * slower code, even if they're little-endian. |
15 */ | 15 */ |
16 | 16 |
17 #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN) | 17 #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN) |
18 | 18 |
19 #include <byteswap.h> | |
20 #include <memory.h> | |
21 | |
22 /* This version is about 28% faster than the generic version below, | 19 /* This version is about 28% faster than the generic version below, |
23 * but assumes little-endianness. | 20 * but assumes little-endianness. |
24 */ | 21 */ |
25 static uint32_t ror27(uint32_t val) { | 22 static uint32_t ror27(uint32_t val) { |
26 return (val >> 27) | (val << 5); | 23 return (val >> 27) | (val << 5); |
27 } | 24 } |
28 static uint32_t ror2(uint32_t val) { | 25 static uint32_t ror2(uint32_t val) { |
29 return (val >> 2) | (val << 30); | 26 return (val >> 2) | (val << 30); |
30 } | 27 } |
31 static uint32_t ror31(uint32_t val) { | 28 static uint32_t ror31(uint32_t val) { |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 int i; | 278 int i; |
282 SHA1_CTX ctx; | 279 SHA1_CTX ctx; |
283 SHA1_init(&ctx); | 280 SHA1_init(&ctx); |
284 SHA1_update(&ctx, data, len); | 281 SHA1_update(&ctx, data, len); |
285 p = SHA1_final(&ctx); | 282 p = SHA1_final(&ctx); |
286 for (i = 0; i < SHA1_DIGEST_SIZE; ++i) { | 283 for (i = 0; i < SHA1_DIGEST_SIZE; ++i) { |
287 digest[i] = *p++; | 284 digest[i] = *p++; |
288 } | 285 } |
289 return digest; | 286 return digest; |
290 } | 287 } |
OLD | NEW |