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

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

Issue 744002: Vboot Reference: Make length types explicitly sized. (Closed)
Patch Set: Created 10 years, 9 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 * Utility functions for message digest functions. 5 * Utility functions for message digest functions.
6 */ 6 */
7 7
8 #include "sha_utility.h" 8 #include "sha_utility.h"
9 9
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 ctx->sha256_ctx = (SHA256_CTX*) Malloc(sizeof(SHA256_CTX)); 44 ctx->sha256_ctx = (SHA256_CTX*) Malloc(sizeof(SHA256_CTX));
45 SHA256_init(ctx->sha256_ctx); 45 SHA256_init(ctx->sha256_ctx);
46 break; 46 break;
47 case SHA512_DIGEST_ALGORITHM: 47 case SHA512_DIGEST_ALGORITHM:
48 ctx->sha512_ctx = (SHA512_CTX*) Malloc(sizeof(SHA512_CTX)); 48 ctx->sha512_ctx = (SHA512_CTX*) Malloc(sizeof(SHA512_CTX));
49 SHA512_init(ctx->sha512_ctx); 49 SHA512_init(ctx->sha512_ctx);
50 break; 50 break;
51 }; 51 };
52 } 52 }
53 53
54 void DigestUpdate(DigestContext* ctx, const uint8_t* data, int len) { 54 void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint64_t len) {
55 switch(ctx->algorithm) { 55 switch(ctx->algorithm) {
56 case SHA1_DIGEST_ALGORITHM: 56 case SHA1_DIGEST_ALGORITHM:
57 SHA1_update(ctx->sha1_ctx, data, len); 57 SHA1_update(ctx->sha1_ctx, data, len);
58 break; 58 break;
59 case SHA256_DIGEST_ALGORITHM: 59 case SHA256_DIGEST_ALGORITHM:
60 SHA256_update(ctx->sha256_ctx, data, len); 60 SHA256_update(ctx->sha256_ctx, data, len);
61 break; 61 break;
62 case SHA512_DIGEST_ALGORITHM: 62 case SHA512_DIGEST_ALGORITHM:
63 SHA512_update(ctx->sha512_ctx, data, len); 63 SHA512_update(ctx->sha512_ctx, data, len);
64 break; 64 break;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 while ( (len = read(input_fd, data, SHA1_BLOCK_SIZE)) == 101 while ( (len = read(input_fd, data, SHA1_BLOCK_SIZE)) ==
102 SHA1_BLOCK_SIZE) 102 SHA1_BLOCK_SIZE)
103 DigestUpdate(&ctx, data, len); 103 DigestUpdate(&ctx, data, len);
104 if (len != -1) 104 if (len != -1)
105 DigestUpdate(&ctx, data, len); 105 DigestUpdate(&ctx, data, len);
106 digest = DigestFinal(&ctx); 106 digest = DigestFinal(&ctx);
107 close(input_fd); 107 close(input_fd);
108 return digest; 108 return digest;
109 } 109 }
110 110
111 uint8_t* DigestBuf(const uint8_t* buf, int len, int sig_algorithm) { 111 uint8_t* DigestBuf(const uint8_t* buf, uint64_t len, int sig_algorithm) {
112 uint8_t* digest = (uint8_t*) Malloc(SHA512_DIGEST_SIZE); /* Use the max. */ 112 uint8_t* digest = (uint8_t*) Malloc(SHA512_DIGEST_SIZE); /* Use the max. */
113 /* Define an array mapping [sig_algorithm] to function pointers to the 113 /* Define an array mapping [sig_algorithm] to function pointers to the
114 * SHA{1|256|512} functions. 114 * SHA{1|256|512} functions.
115 */ 115 */
116 typedef uint8_t* (*Hash_ptr) (const uint8_t*, int, uint8_t*); 116 typedef uint8_t* (*Hash_ptr) (const uint8_t*, uint64_t, uint8_t*);
117 Hash_ptr hash[] = { 117 Hash_ptr hash[] = {
118 SHA1, /* RSA 1024 */ 118 SHA1, /* RSA 1024 */
119 SHA256, 119 SHA256,
120 SHA512, 120 SHA512,
121 SHA1, /* RSA 2048 */ 121 SHA1, /* RSA 2048 */
122 SHA256, 122 SHA256,
123 SHA512, 123 SHA512,
124 SHA1, /* RSA 4096 */ 124 SHA1, /* RSA 4096 */
125 SHA256, 125 SHA256,
126 SHA512, 126 SHA512,
127 SHA1, /* RSA 8192 */ 127 SHA1, /* RSA 8192 */
128 SHA256, 128 SHA256,
129 SHA512, 129 SHA512,
130 }; 130 };
131 /* Call the appropriate hash function. */ 131 /* Call the appropriate hash function. */
132 return hash[sig_algorithm](buf, len, digest); 132 return hash[sig_algorithm](buf, len, digest);
133 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698