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" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 268 |
269 void SHA1_init(SHA1_CTX* ctx) { | 269 void SHA1_init(SHA1_CTX* ctx) { |
270 ctx->state[0] = 0x67452301; | 270 ctx->state[0] = 0x67452301; |
271 ctx->state[1] = 0xEFCDAB89; | 271 ctx->state[1] = 0xEFCDAB89; |
272 ctx->state[2] = 0x98BADCFE; | 272 ctx->state[2] = 0x98BADCFE; |
273 ctx->state[3] = 0x10325476; | 273 ctx->state[3] = 0x10325476; |
274 ctx->state[4] = 0xC3D2E1F0; | 274 ctx->state[4] = 0xC3D2E1F0; |
275 ctx->count = 0; | 275 ctx->count = 0; |
276 } | 276 } |
277 | 277 |
278 uint8_t* SHA1(const void *data, int len, uint8_t *digest) { | 278 uint8_t* SHA1(const uint8_t *data, int len, uint8_t *digest) { |
279 const uint8_t *p; | 279 const uint8_t *p; |
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 |