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 * 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 | 6 * Open Source Project (platorm/system/core.git/libmincrypt/sha.c |
8 */ | 7 */ |
9 | 8 |
10 #include "sha.h" | 9 #include "cryptolib.h" |
| 10 #include "utility.h" |
| 11 |
11 | 12 |
12 /* 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 |
13 * slower code, even if they're little-endian. | 14 * slower code, even if they're little-endian. |
14 */ | 15 */ |
15 | 16 |
16 #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN) | 17 #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN) |
17 | 18 |
18 #include <byteswap.h> | 19 #include <byteswap.h> |
19 #include <memory.h> | 20 #include <memory.h> |
20 | 21 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ctx->state[4] += E; | 128 ctx->state[4] += E; |
128 } | 129 } |
129 | 130 |
130 void SHA1_update(SHA1_CTX* ctx, const uint8_t* data, uint64_t len) { | 131 void SHA1_update(SHA1_CTX* ctx, const uint8_t* data, uint64_t len) { |
131 int i = ctx->count % sizeof(ctx->buf); | 132 int i = ctx->count % sizeof(ctx->buf); |
132 const uint8_t* p = (const uint8_t*)data; | 133 const uint8_t* p = (const uint8_t*)data; |
133 | 134 |
134 ctx->count += len; | 135 ctx->count += len; |
135 | 136 |
136 while (len > sizeof(ctx->buf) - i) { | 137 while (len > sizeof(ctx->buf) - i) { |
137 memcpy(&ctx->buf.b[i], p, sizeof(ctx->buf) - i); | 138 Memcpy(&ctx->buf.b[i], p, sizeof(ctx->buf) - i); |
138 len -= sizeof(ctx->buf) - i; | 139 len -= sizeof(ctx->buf) - i; |
139 p += sizeof(ctx->buf) - i; | 140 p += sizeof(ctx->buf) - i; |
140 SHA1_Transform(ctx); | 141 SHA1_Transform(ctx); |
141 i = 0; | 142 i = 0; |
142 } | 143 } |
143 | 144 |
144 while (len--) { | 145 while (len--) { |
145 ctx->buf.b[i++] = *p++; | 146 ctx->buf.b[i++] = *p++; |
146 if (i == sizeof(ctx->buf)) { | 147 if (i == sizeof(ctx->buf)) { |
147 SHA1_Transform(ctx); | 148 SHA1_Transform(ctx); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 int i; | 281 int i; |
281 SHA1_CTX ctx; | 282 SHA1_CTX ctx; |
282 SHA1_init(&ctx); | 283 SHA1_init(&ctx); |
283 SHA1_update(&ctx, data, len); | 284 SHA1_update(&ctx, data, len); |
284 p = SHA1_final(&ctx); | 285 p = SHA1_final(&ctx); |
285 for (i = 0; i < SHA1_DIGEST_SIZE; ++i) { | 286 for (i = 0; i < SHA1_DIGEST_SIZE; ++i) { |
286 digest[i] = *p++; | 287 digest[i] = *p++; |
287 } | 288 } |
288 return digest; | 289 return digest; |
289 } | 290 } |
OLD | NEW |