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

Side by Side Diff: core/src/fdrm/crypto/fx_crypt_sha.cpp

Issue 1171733003: Remove typdefs for pointer types in fx_system.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual fixes. Created 5 years, 6 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
« no previous file with comments | « core/src/fdrm/crypto/fx_crypt_aes.cpp ('k') | core/src/fpdfapi/fpdf_basic_module.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../include/fxcrt/fx_basic.h" 7 #include "../../../include/fxcrt/fx_basic.h"
8 #include "../../../include/fdrm/fx_crypt.h" 8 #include "../../../include/fdrm/fx_crypt.h"
9 #ifdef __cplusplus 9 #ifdef __cplusplus
10 extern "C" { 10 extern "C" {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 c = rol(b, 30); 75 c = rol(b, 30);
76 b = a; 76 b = a;
77 a = tmp; 77 a = tmp;
78 } 78 }
79 digest[0] += a; 79 digest[0] += a;
80 digest[1] += b; 80 digest[1] += b;
81 digest[2] += c; 81 digest[2] += c;
82 digest[3] += d; 82 digest[3] += d;
83 digest[4] += e; 83 digest[4] += e;
84 } 84 }
85 void CRYPT_SHA1Start(FX_LPVOID context) 85 void CRYPT_SHA1Start(void* context)
86 { 86 {
87 SHA_State * s = (SHA_State*)context; 87 SHA_State * s = (SHA_State*)context;
88 SHA_Core_Init(s->h); 88 SHA_Core_Init(s->h);
89 s->blkused = 0; 89 s->blkused = 0;
90 s->lenhi = s->lenlo = 0; 90 s->lenhi = s->lenlo = 0;
91 } 91 }
92 void CRYPT_SHA1Update(FX_LPVOID context, FX_LPCBYTE data, FX_DWORD size) 92 void CRYPT_SHA1Update(void* context, const uint8_t* data, FX_DWORD size)
93 { 93 {
94 SHA_State * s = (SHA_State*)context; 94 SHA_State * s = (SHA_State*)context;
95 unsigned char *q = (unsigned char *)data; 95 unsigned char *q = (unsigned char *)data;
96 unsigned int wordblock[16]; 96 unsigned int wordblock[16];
97 int len = size; 97 int len = size;
98 unsigned int lenw = len; 98 unsigned int lenw = len;
99 int i; 99 int i;
100 s->lenlo += lenw; 100 s->lenlo += lenw;
101 s->lenhi += (s->lenlo < lenw); 101 s->lenhi += (s->lenlo < lenw);
102 if (s->blkused && s->blkused + len < 64) { 102 if (s->blkused && s->blkused + len < 64) {
(...skipping 11 matching lines...) Expand all
114 (((unsigned int) s->block[i * 4 + 2]) << 8) | 114 (((unsigned int) s->block[i * 4 + 2]) << 8) |
115 (((unsigned int) s->block[i * 4 + 3]) << 0); 115 (((unsigned int) s->block[i * 4 + 3]) << 0);
116 } 116 }
117 SHATransform(s->h, wordblock); 117 SHATransform(s->h, wordblock);
118 s->blkused = 0; 118 s->blkused = 0;
119 } 119 }
120 FXSYS_memcpy32(s->block, q, len); 120 FXSYS_memcpy32(s->block, q, len);
121 s->blkused = len; 121 s->blkused = len;
122 } 122 }
123 } 123 }
124 void CRYPT_SHA1Finish(FX_LPVOID context, uint8_t digest[20]) 124 void CRYPT_SHA1Finish(void* context, uint8_t digest[20])
125 { 125 {
126 SHA_State * s = (SHA_State*)context; 126 SHA_State * s = (SHA_State*)context;
127 int i; 127 int i;
128 int pad; 128 int pad;
129 unsigned char c[64]; 129 unsigned char c[64];
130 unsigned int lenhi, lenlo; 130 unsigned int lenhi, lenlo;
131 if (s->blkused >= 56) { 131 if (s->blkused >= 56) {
132 pad = 56 + 64 - s->blkused; 132 pad = 56 + 64 - s->blkused;
133 } else { 133 } else {
134 pad = 56 - s->blkused; 134 pad = 56 - s->blkused;
(...skipping 12 matching lines...) Expand all
147 c[6] = (lenlo >> 8) & 0xFF; 147 c[6] = (lenlo >> 8) & 0xFF;
148 c[7] = (lenlo >> 0) & 0xFF; 148 c[7] = (lenlo >> 0) & 0xFF;
149 CRYPT_SHA1Update(s, c, 8); 149 CRYPT_SHA1Update(s, c, 8);
150 for (i = 0; i < 5; i++) { 150 for (i = 0; i < 5; i++) {
151 digest[i * 4] = (s->h[i] >> 24) & 0xFF; 151 digest[i * 4] = (s->h[i] >> 24) & 0xFF;
152 digest[i * 4 + 1] = (s->h[i] >> 16) & 0xFF; 152 digest[i * 4 + 1] = (s->h[i] >> 16) & 0xFF;
153 digest[i * 4 + 2] = (s->h[i] >> 8) & 0xFF; 153 digest[i * 4 + 2] = (s->h[i] >> 8) & 0xFF;
154 digest[i * 4 + 3] = (s->h[i]) & 0xFF; 154 digest[i * 4 + 3] = (s->h[i]) & 0xFF;
155 } 155 }
156 } 156 }
157 void CRYPT_SHA1Generate(FX_LPCBYTE data, FX_DWORD size, uint8_t digest[20]) 157 void CRYPT_SHA1Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[20])
158 { 158 {
159 SHA_State s; 159 SHA_State s;
160 CRYPT_SHA1Start(&s); 160 CRYPT_SHA1Start(&s);
161 CRYPT_SHA1Update(&s, data, size); 161 CRYPT_SHA1Update(&s, data, size);
162 CRYPT_SHA1Finish(&s, digest); 162 CRYPT_SHA1Finish(&s, digest);
163 } 163 }
164 typedef struct { 164 typedef struct {
165 FX_DWORD total[2]; 165 FX_DWORD total[2];
166 FX_DWORD state[8]; 166 FX_DWORD state[8];
167 uint8_t buffer[64]; 167 uint8_t buffer[64];
168 } 168 }
169 sha256_context; 169 sha256_context;
170 #define GET_FX_DWORD(n,b,i) \ 170 #define GET_FX_DWORD(n,b,i) \
171 { \ 171 { \
172 (n) = ( (FX_DWORD) (b)[(i) ] << 24 ) \ 172 (n) = ( (FX_DWORD) (b)[(i) ] << 24 ) \
173 | ( (FX_DWORD) (b)[(i) + 1] << 16 ) \ 173 | ( (FX_DWORD) (b)[(i) + 1] << 16 ) \
174 | ( (FX_DWORD) (b)[(i) + 2] << 8 ) \ 174 | ( (FX_DWORD) (b)[(i) + 2] << 8 ) \
175 | ( (FX_DWORD) (b)[(i) + 3] ); \ 175 | ( (FX_DWORD) (b)[(i) + 3] ); \
176 } 176 }
177 #define PUT_FX_DWORD(n,b,i) \ 177 #define PUT_FX_DWORD(n,b,i) \
178 { \ 178 { \
179 (b)[(i) ] = (uint8_t) ( (n) >> 24 ); \ 179 (b)[(i) ] = (uint8_t) ( (n) >> 24 ); \
180 (b)[(i) + 1] = (uint8_t) ( (n) >> 16 ); \ 180 (b)[(i) + 1] = (uint8_t) ( (n) >> 16 ); \
181 (b)[(i) + 2] = (uint8_t) ( (n) >> 8 ); \ 181 (b)[(i) + 2] = (uint8_t) ( (n) >> 8 ); \
182 (b)[(i) + 3] = (uint8_t) ( (n) ); \ 182 (b)[(i) + 3] = (uint8_t) ( (n) ); \
183 } 183 }
184 void CRYPT_SHA256Start( FX_LPVOID context ) 184 void CRYPT_SHA256Start( void* context )
185 { 185 {
186 sha256_context *ctx = (sha256_context *)context; 186 sha256_context *ctx = (sha256_context *)context;
187 ctx->total[0] = 0; 187 ctx->total[0] = 0;
188 ctx->total[1] = 0; 188 ctx->total[1] = 0;
189 ctx->state[0] = 0x6A09E667; 189 ctx->state[0] = 0x6A09E667;
190 ctx->state[1] = 0xBB67AE85; 190 ctx->state[1] = 0xBB67AE85;
191 ctx->state[2] = 0x3C6EF372; 191 ctx->state[2] = 0x3C6EF372;
192 ctx->state[3] = 0xA54FF53A; 192 ctx->state[3] = 0xA54FF53A;
193 ctx->state[4] = 0x510E527F; 193 ctx->state[4] = 0x510E527F;
194 ctx->state[5] = 0x9B05688C; 194 ctx->state[5] = 0x9B05688C;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 ); 308 P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 );
309 ctx->state[0] += A; 309 ctx->state[0] += A;
310 ctx->state[1] += B; 310 ctx->state[1] += B;
311 ctx->state[2] += C; 311 ctx->state[2] += C;
312 ctx->state[3] += D; 312 ctx->state[3] += D;
313 ctx->state[4] += E; 313 ctx->state[4] += E;
314 ctx->state[5] += F; 314 ctx->state[5] += F;
315 ctx->state[6] += G; 315 ctx->state[6] += G;
316 ctx->state[7] += H; 316 ctx->state[7] += H;
317 } 317 }
318 void CRYPT_SHA256Update( void* context, FX_LPCBYTE input, FX_DWORD length ) 318 void CRYPT_SHA256Update( void* context, const uint8_t* input, FX_DWORD length )
319 { 319 {
320 sha256_context *ctx = (sha256_context *)context; 320 sha256_context *ctx = (sha256_context *)context;
321 FX_DWORD left, fill; 321 FX_DWORD left, fill;
322 if( ! length ) { 322 if( ! length ) {
323 return; 323 return;
324 } 324 }
325 left = ctx->total[0] & 0x3F; 325 left = ctx->total[0] & 0x3F;
326 fill = 64 - left; 326 fill = 64 - left;
327 ctx->total[0] += length; 327 ctx->total[0] += length;
328 ctx->total[0] &= 0xFFFFFFFF; 328 ctx->total[0] &= 0xFFFFFFFF;
(...skipping 17 matching lines...) Expand all
346 FXSYS_memcpy32( (void *) (ctx->buffer + left), 346 FXSYS_memcpy32( (void *) (ctx->buffer + left),
347 (void *) input, length ); 347 (void *) input, length );
348 } 348 }
349 } 349 }
350 static const uint8_t sha256_padding[64] = { 350 static const uint8_t sha256_padding[64] = {
351 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 351 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
352 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 352 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
353 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 353 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
354 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 354 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
355 }; 355 };
356 void CRYPT_SHA256Finish( FX_LPVOID context, uint8_t digest[32] ) 356 void CRYPT_SHA256Finish( void* context, uint8_t digest[32] )
357 { 357 {
358 sha256_context *ctx = (sha256_context *)context; 358 sha256_context *ctx = (sha256_context *)context;
359 FX_DWORD last, padn; 359 FX_DWORD last, padn;
360 FX_DWORD high, low; 360 FX_DWORD high, low;
361 uint8_t msglen[8]; 361 uint8_t msglen[8];
362 high = ( ctx->total[0] >> 29 ) 362 high = ( ctx->total[0] >> 29 )
363 | ( ctx->total[1] << 3 ); 363 | ( ctx->total[1] << 3 );
364 low = ( ctx->total[0] << 3 ); 364 low = ( ctx->total[0] << 3 );
365 PUT_FX_DWORD( high, msglen, 0 ); 365 PUT_FX_DWORD( high, msglen, 0 );
366 PUT_FX_DWORD( low, msglen, 4 ); 366 PUT_FX_DWORD( low, msglen, 4 );
367 last = ctx->total[0] & 0x3F; 367 last = ctx->total[0] & 0x3F;
368 padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); 368 padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
369 CRYPT_SHA256Update( ctx, sha256_padding, padn ); 369 CRYPT_SHA256Update( ctx, sha256_padding, padn );
370 CRYPT_SHA256Update( ctx, msglen, 8 ); 370 CRYPT_SHA256Update( ctx, msglen, 8 );
371 PUT_FX_DWORD( ctx->state[0], digest, 0 ); 371 PUT_FX_DWORD( ctx->state[0], digest, 0 );
372 PUT_FX_DWORD( ctx->state[1], digest, 4 ); 372 PUT_FX_DWORD( ctx->state[1], digest, 4 );
373 PUT_FX_DWORD( ctx->state[2], digest, 8 ); 373 PUT_FX_DWORD( ctx->state[2], digest, 8 );
374 PUT_FX_DWORD( ctx->state[3], digest, 12 ); 374 PUT_FX_DWORD( ctx->state[3], digest, 12 );
375 PUT_FX_DWORD( ctx->state[4], digest, 16 ); 375 PUT_FX_DWORD( ctx->state[4], digest, 16 );
376 PUT_FX_DWORD( ctx->state[5], digest, 20 ); 376 PUT_FX_DWORD( ctx->state[5], digest, 20 );
377 PUT_FX_DWORD( ctx->state[6], digest, 24 ); 377 PUT_FX_DWORD( ctx->state[6], digest, 24 );
378 PUT_FX_DWORD( ctx->state[7], digest, 28 ); 378 PUT_FX_DWORD( ctx->state[7], digest, 28 );
379 } 379 }
380 void CRYPT_SHA256Generate(FX_LPCBYTE data, FX_DWORD size, uint8_t digest[32]) 380 void CRYPT_SHA256Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[32] )
381 { 381 {
382 sha256_context ctx; 382 sha256_context ctx;
383 CRYPT_SHA256Start(&ctx); 383 CRYPT_SHA256Start(&ctx);
384 CRYPT_SHA256Update(&ctx, data, size); 384 CRYPT_SHA256Update(&ctx, data, size);
385 CRYPT_SHA256Finish(&ctx, digest); 385 CRYPT_SHA256Finish(&ctx, digest);
386 } 386 }
387 typedef struct { 387 typedef struct {
388 uint64_t total[2]; 388 uint64_t total[2];
389 uint64_t state[8]; 389 uint64_t state[8];
390 uint8_t buffer[128]; 390 uint8_t buffer[128];
391 } sha384_context; 391 } sha384_context;
392 uint64_t FX_ato64i(FX_LPCSTR str) 392 uint64_t FX_ato64i(const FX_CHAR* str)
393 { 393 {
394 FXSYS_assert(str != NULL); 394 FXSYS_assert(str != NULL);
395 uint64_t ret = 0; 395 uint64_t ret = 0;
396 int len = (int)FXSYS_strlen(str); 396 int len = (int)FXSYS_strlen(str);
397 len = len > 16 ? 16 : len; 397 len = len > 16 ? 16 : len;
398 for (int i = 0; i < len; ++i) { 398 for (int i = 0; i < len; ++i) {
399 if (i) { 399 if (i) {
400 ret <<= 4; 400 ret <<= 4;
401 } 401 }
402 if (str[i] >= '0' && str[i] <= '9') { 402 if (str[i] >= '0' && str[i] <= '9') {
403 ret |= (str[i] - '0') & 0xFF; 403 ret |= (str[i] - '0') & 0xFF;
404 } else if (str[i] >= 'a' && str[i] <= 'f') { 404 } else if (str[i] >= 'a' && str[i] <= 'f') {
405 ret |= (str[i] - 'a' + 10) & 0xFF; 405 ret |= (str[i] - 'a' + 10) & 0xFF;
406 } else if (str[i] >= 'A' && str[i] <= 'F') { 406 } else if (str[i] >= 'A' && str[i] <= 'F') {
407 ret |= (str[i] - 'A' + 10) & 0xFF; 407 ret |= (str[i] - 'A' + 10) & 0xFF;
408 } else { 408 } else {
409 FXSYS_assert(FALSE); 409 FXSYS_assert(FALSE);
410 } 410 }
411 } 411 }
412 return ret; 412 return ret;
413 } 413 }
414 void CRYPT_SHA384Start(FX_LPVOID context) 414 void CRYPT_SHA384Start(void* context)
415 { 415 {
416 if (context == NULL) { 416 if (context == NULL) {
417 return; 417 return;
418 } 418 }
419 sha384_context *ctx = (sha384_context *)context; 419 sha384_context *ctx = (sha384_context *)context;
420 FXSYS_memset32(ctx, 0, sizeof(sha384_context)); 420 FXSYS_memset32(ctx, 0, sizeof(sha384_context));
421 ctx->state[0] = FX_ato64i("cbbb9d5dc1059ed8"); 421 ctx->state[0] = FX_ato64i("cbbb9d5dc1059ed8");
422 ctx->state[1] = FX_ato64i("629a292a367cd507"); 422 ctx->state[1] = FX_ato64i("629a292a367cd507");
423 ctx->state[2] = FX_ato64i("9159015a3070dd17"); 423 ctx->state[2] = FX_ato64i("9159015a3070dd17");
424 ctx->state[3] = FX_ato64i("152fecd8f70e5939"); 424 ctx->state[3] = FX_ato64i("152fecd8f70e5939");
(...skipping 20 matching lines...) Expand all
445 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 445 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
446 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 446 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
447 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 447 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
448 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 448 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
449 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 449 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
450 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 450 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
451 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 451 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
452 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 452 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
453 }; 453 };
454 #define SHA384_R(t) (W[t] = SHA384_S1(W[t - 2]) + W[t - 7] + SHA384_S0(W[t - 1 5]) + W[t - 16]) 454 #define SHA384_R(t) (W[t] = SHA384_S1(W[t - 2]) + W[t - 7] + SHA384_S0(W[t - 1 5]) + W[t - 16])
455 static FX_LPCSTR constants[] = { 455 static const FX_CHAR* constants[] = {
456 "428a2f98d728ae22", 456 "428a2f98d728ae22",
457 "7137449123ef65cd", 457 "7137449123ef65cd",
458 "b5c0fbcfec4d3b2f", 458 "b5c0fbcfec4d3b2f",
459 "e9b5dba58189dbbc", 459 "e9b5dba58189dbbc",
460 "3956c25bf348b538", 460 "3956c25bf348b538",
461 "59f111f1b605d019", 461 "59f111f1b605d019",
462 "923f82a4af194f9b", 462 "923f82a4af194f9b",
463 "ab1c5ed5da6d8118", 463 "ab1c5ed5da6d8118",
464 "d807aa98a3030242", 464 "d807aa98a3030242",
465 "12835b0145706fbe", 465 "12835b0145706fbe",
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 } 617 }
618 ctx->state[0] += A; 618 ctx->state[0] += A;
619 ctx->state[1] += B; 619 ctx->state[1] += B;
620 ctx->state[2] += C; 620 ctx->state[2] += C;
621 ctx->state[3] += D; 621 ctx->state[3] += D;
622 ctx->state[4] += E; 622 ctx->state[4] += E;
623 ctx->state[5] += F; 623 ctx->state[5] += F;
624 ctx->state[6] += G; 624 ctx->state[6] += G;
625 ctx->state[7] += H; 625 ctx->state[7] += H;
626 } 626 }
627 void CRYPT_SHA384Update(FX_LPVOID context, FX_LPCBYTE input, FX_DWORD length) 627 void CRYPT_SHA384Update(void* context, const uint8_t* input, FX_DWORD length)
628 { 628 {
629 sha384_context *ctx = (sha384_context *)context; 629 sha384_context *ctx = (sha384_context *)context;
630 FX_DWORD left, fill; 630 FX_DWORD left, fill;
631 if( ! length ) { 631 if( ! length ) {
632 return; 632 return;
633 } 633 }
634 left = (FX_DWORD)ctx->total[0] & 0x7F; 634 left = (FX_DWORD)ctx->total[0] & 0x7F;
635 fill = 128 - left; 635 fill = 128 - left;
636 ctx->total[0] += length; 636 ctx->total[0] += length;
637 if( ctx->total[0] < length ) { 637 if( ctx->total[0] < length ) {
(...skipping 10 matching lines...) Expand all
648 while( length >= 128 ) { 648 while( length >= 128 ) {
649 sha384_process( ctx, input ); 649 sha384_process( ctx, input );
650 length -= 128; 650 length -= 128;
651 input += 128; 651 input += 128;
652 } 652 }
653 if( length ) { 653 if( length ) {
654 FXSYS_memcpy32( (void *) (ctx->buffer + left), 654 FXSYS_memcpy32( (void *) (ctx->buffer + left),
655 (void *) input, length ); 655 (void *) input, length );
656 } 656 }
657 } 657 }
658 void CRYPT_SHA384Finish(FX_LPVOID context, uint8_t digest[48]) 658 void CRYPT_SHA384Finish(void* context, uint8_t digest[48])
659 { 659 {
660 sha384_context *ctx = (sha384_context *)context; 660 sha384_context *ctx = (sha384_context *)context;
661 FX_DWORD last, padn; 661 FX_DWORD last, padn;
662 uint8_t msglen[16]; 662 uint8_t msglen[16];
663 FXSYS_memset32(msglen, 0, 16); 663 FXSYS_memset32(msglen, 0, 16);
664 uint64_t high, low; 664 uint64_t high, low;
665 high = ( ctx->total[0] >> 29 ) 665 high = ( ctx->total[0] >> 29 )
666 | ( ctx->total[1] << 3 ); 666 | ( ctx->total[1] << 3 );
667 low = ( ctx->total[0] << 3 ); 667 low = ( ctx->total[0] << 3 );
668 PUT_FX_64DWORD( high, msglen, 0 ); 668 PUT_FX_64DWORD( high, msglen, 0 );
669 PUT_FX_64DWORD( low, msglen, 8 ); 669 PUT_FX_64DWORD( low, msglen, 8 );
670 last = (FX_DWORD)ctx->total[0] & 0x7F; 670 last = (FX_DWORD)ctx->total[0] & 0x7F;
671 padn = ( last < 112 ) ? ( 112 - last ) : ( 240 - last ); 671 padn = ( last < 112 ) ? ( 112 - last ) : ( 240 - last );
672 CRYPT_SHA384Update( ctx, sha384_padding, padn ); 672 CRYPT_SHA384Update( ctx, sha384_padding, padn );
673 CRYPT_SHA384Update( ctx, msglen, 16 ); 673 CRYPT_SHA384Update( ctx, msglen, 16 );
674 PUT_FX_64DWORD(ctx->state[0], digest, 0); 674 PUT_FX_64DWORD(ctx->state[0], digest, 0);
675 PUT_FX_64DWORD(ctx->state[1], digest, 8); 675 PUT_FX_64DWORD(ctx->state[1], digest, 8);
676 PUT_FX_64DWORD(ctx->state[2], digest, 16); 676 PUT_FX_64DWORD(ctx->state[2], digest, 16);
677 PUT_FX_64DWORD(ctx->state[3], digest, 24); 677 PUT_FX_64DWORD(ctx->state[3], digest, 24);
678 PUT_FX_64DWORD(ctx->state[4], digest, 32); 678 PUT_FX_64DWORD(ctx->state[4], digest, 32);
679 PUT_FX_64DWORD(ctx->state[5], digest, 40); 679 PUT_FX_64DWORD(ctx->state[5], digest, 40);
680 } 680 }
681 void CRYPT_SHA384Generate(FX_LPCBYTE data, FX_DWORD size, uint8_t digest[64]) 681 void CRYPT_SHA384Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[64] )
682 { 682 {
683 sha384_context context; 683 sha384_context context;
684 CRYPT_SHA384Start(&context); 684 CRYPT_SHA384Start(&context);
685 CRYPT_SHA384Update(&context, data, size); 685 CRYPT_SHA384Update(&context, data, size);
686 CRYPT_SHA384Finish(&context, digest); 686 CRYPT_SHA384Finish(&context, digest);
687 } 687 }
688 void CRYPT_SHA512Start(FX_LPVOID context) 688 void CRYPT_SHA512Start(void* context)
689 { 689 {
690 if (context == NULL) { 690 if (context == NULL) {
691 return; 691 return;
692 } 692 }
693 sha384_context *ctx = (sha384_context *)context; 693 sha384_context *ctx = (sha384_context *)context;
694 FXSYS_memset32(ctx, 0, sizeof(sha384_context)); 694 FXSYS_memset32(ctx, 0, sizeof(sha384_context));
695 ctx->state[0] = FX_ato64i("6a09e667f3bcc908"); 695 ctx->state[0] = FX_ato64i("6a09e667f3bcc908");
696 ctx->state[1] = FX_ato64i("bb67ae8584caa73b"); 696 ctx->state[1] = FX_ato64i("bb67ae8584caa73b");
697 ctx->state[2] = FX_ato64i("3c6ef372fe94f82b"); 697 ctx->state[2] = FX_ato64i("3c6ef372fe94f82b");
698 ctx->state[3] = FX_ato64i("a54ff53a5f1d36f1"); 698 ctx->state[3] = FX_ato64i("a54ff53a5f1d36f1");
699 ctx->state[4] = FX_ato64i("510e527fade682d1"); 699 ctx->state[4] = FX_ato64i("510e527fade682d1");
700 ctx->state[5] = FX_ato64i("9b05688c2b3e6c1f"); 700 ctx->state[5] = FX_ato64i("9b05688c2b3e6c1f");
701 ctx->state[6] = FX_ato64i("1f83d9abfb41bd6b"); 701 ctx->state[6] = FX_ato64i("1f83d9abfb41bd6b");
702 ctx->state[7] = FX_ato64i("5be0cd19137e2179"); 702 ctx->state[7] = FX_ato64i("5be0cd19137e2179");
703 } 703 }
704 void CRYPT_SHA512Update(FX_LPVOID context, FX_LPCBYTE data, FX_DWORD size) 704 void CRYPT_SHA512Update(void* context, const uint8_t* data, FX_DWORD size)
705 { 705 {
706 CRYPT_SHA384Update(context, data, size); 706 CRYPT_SHA384Update(context, data, size);
707 } 707 }
708 void CRYPT_SHA512Finish(FX_LPVOID context, uint8_t digest[64]) 708 void CRYPT_SHA512Finish(void* context, uint8_t digest[64])
709 { 709 {
710 sha384_context *ctx = (sha384_context *)context; 710 sha384_context *ctx = (sha384_context *)context;
711 FX_DWORD last, padn; 711 FX_DWORD last, padn;
712 uint8_t msglen[16]; 712 uint8_t msglen[16];
713 FXSYS_memset32(msglen, 0, 16); 713 FXSYS_memset32(msglen, 0, 16);
714 uint64_t high, low; 714 uint64_t high, low;
715 high = ( ctx->total[0] >> 29 ) 715 high = ( ctx->total[0] >> 29 )
716 | ( ctx->total[1] << 3 ); 716 | ( ctx->total[1] << 3 );
717 low = ( ctx->total[0] << 3 ); 717 low = ( ctx->total[0] << 3 );
718 PUT_FX_64DWORD( high, msglen, 0 ); 718 PUT_FX_64DWORD( high, msglen, 0 );
719 PUT_FX_64DWORD( low, msglen, 8 ); 719 PUT_FX_64DWORD( low, msglen, 8 );
720 last = (FX_DWORD)ctx->total[0] & 0x7F; 720 last = (FX_DWORD)ctx->total[0] & 0x7F;
721 padn = ( last < 112 ) ? ( 112 - last ) : ( 240 - last ); 721 padn = ( last < 112 ) ? ( 112 - last ) : ( 240 - last );
722 CRYPT_SHA512Update( ctx, sha384_padding, padn ); 722 CRYPT_SHA512Update( ctx, sha384_padding, padn );
723 CRYPT_SHA512Update( ctx, msglen, 16 ); 723 CRYPT_SHA512Update( ctx, msglen, 16 );
724 PUT_FX_64DWORD(ctx->state[0], digest, 0); 724 PUT_FX_64DWORD(ctx->state[0], digest, 0);
725 PUT_FX_64DWORD(ctx->state[1], digest, 8); 725 PUT_FX_64DWORD(ctx->state[1], digest, 8);
726 PUT_FX_64DWORD(ctx->state[2], digest, 16); 726 PUT_FX_64DWORD(ctx->state[2], digest, 16);
727 PUT_FX_64DWORD(ctx->state[3], digest, 24); 727 PUT_FX_64DWORD(ctx->state[3], digest, 24);
728 PUT_FX_64DWORD(ctx->state[4], digest, 32); 728 PUT_FX_64DWORD(ctx->state[4], digest, 32);
729 PUT_FX_64DWORD(ctx->state[5], digest, 40); 729 PUT_FX_64DWORD(ctx->state[5], digest, 40);
730 PUT_FX_64DWORD(ctx->state[6], digest, 48); 730 PUT_FX_64DWORD(ctx->state[6], digest, 48);
731 PUT_FX_64DWORD(ctx->state[7], digest, 56); 731 PUT_FX_64DWORD(ctx->state[7], digest, 56);
732 } 732 }
733 void CRYPT_SHA512Generate(FX_LPCBYTE data, FX_DWORD size, uint8_t digest[64]) 733 void CRYPT_SHA512Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[64] )
734 { 734 {
735 sha384_context context; 735 sha384_context context;
736 CRYPT_SHA512Start(&context); 736 CRYPT_SHA512Start(&context);
737 CRYPT_SHA512Update(&context, data, size); 737 CRYPT_SHA512Update(&context, data, size);
738 CRYPT_SHA512Finish(&context, digest); 738 CRYPT_SHA512Finish(&context, digest);
739 } 739 }
740 #ifdef __cplusplus 740 #ifdef __cplusplus
741 }; 741 };
742 #endif 742 #endif
OLDNEW
« no previous file with comments | « core/src/fdrm/crypto/fx_crypt_aes.cpp ('k') | core/src/fpdfapi/fpdf_basic_module.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698