Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: src/platform/vboot_reference/crypto/sha1.c

Issue 1593002: Revert "VBoot Reference: Refactor Part 2 - Crypto Libraries" (Closed)
Patch Set: Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
6 /* SHA-1 implementation largely based on libmincrypt in the the Android
6 * Open Source Project (platorm/system/core.git/libmincrypt/sha.c 7 * Open Source Project (platorm/system/core.git/libmincrypt/sha.c
7 */ 8 */
8 9
9 #include "cryptolib.h" 10 #include "sha.h"
10 #include "utility.h"
11
12 11
13 /* 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
14 * slower code, even if they're little-endian. 13 * slower code, even if they're little-endian.
15 */ 14 */
16 15
17 #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN) 16 #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN)
18 17
19 #include <byteswap.h> 18 #include <byteswap.h>
20 #include <memory.h> 19 #include <memory.h>
21 20
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 ctx->state[4] += E; 127 ctx->state[4] += E;
129 } 128 }
130 129
131 void SHA1_update(SHA1_CTX* ctx, const uint8_t* data, uint64_t len) { 130 void SHA1_update(SHA1_CTX* ctx, const uint8_t* data, uint64_t len) {
132 int i = ctx->count % sizeof(ctx->buf); 131 int i = ctx->count % sizeof(ctx->buf);
133 const uint8_t* p = (const uint8_t*)data; 132 const uint8_t* p = (const uint8_t*)data;
134 133
135 ctx->count += len; 134 ctx->count += len;
136 135
137 while (len > sizeof(ctx->buf) - i) { 136 while (len > sizeof(ctx->buf) - i) {
138 Memcpy(&ctx->buf.b[i], p, sizeof(ctx->buf) - i); 137 memcpy(&ctx->buf.b[i], p, sizeof(ctx->buf) - i);
139 len -= sizeof(ctx->buf) - i; 138 len -= sizeof(ctx->buf) - i;
140 p += sizeof(ctx->buf) - i; 139 p += sizeof(ctx->buf) - i;
141 SHA1_Transform(ctx); 140 SHA1_Transform(ctx);
142 i = 0; 141 i = 0;
143 } 142 }
144 143
145 while (len--) { 144 while (len--) {
146 ctx->buf.b[i++] = *p++; 145 ctx->buf.b[i++] = *p++;
147 if (i == sizeof(ctx->buf)) { 146 if (i == sizeof(ctx->buf)) {
148 SHA1_Transform(ctx); 147 SHA1_Transform(ctx);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 int i; 280 int i;
282 SHA1_CTX ctx; 281 SHA1_CTX ctx;
283 SHA1_init(&ctx); 282 SHA1_init(&ctx);
284 SHA1_update(&ctx, data, len); 283 SHA1_update(&ctx, data, len);
285 p = SHA1_final(&ctx); 284 p = SHA1_final(&ctx);
286 for (i = 0; i < SHA1_DIGEST_SIZE; ++i) { 285 for (i = 0; i < SHA1_DIGEST_SIZE; ++i) {
287 digest[i] = *p++; 286 digest[i] = *p++;
288 } 287 }
289 return digest; 288 return digest;
290 } 289 }
OLDNEW
« no previous file with comments | « src/platform/vboot_reference/crypto/rsa_utility.c ('k') | src/platform/vboot_reference/crypto/sha2.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698