diff options
author | jsing <> | 2023-07-07 10:22:28 +0000 |
---|---|---|
committer | jsing <> | 2023-07-07 10:22:28 +0000 |
commit | 7e8c1dd29d6e69da1876294635c98160b2707e56 (patch) | |
tree | 183c5d685d617ed6e0b40d1e9182543437e1c144 /src | |
parent | f8c386b4497320d43da02ba9bffc5aa7062baa43 (diff) | |
download | openbsd-7e8c1dd29d6e69da1876294635c98160b2707e56.tar.gz openbsd-7e8c1dd29d6e69da1876294635c98160b2707e56.tar.bz2 openbsd-7e8c1dd29d6e69da1876294635c98160b2707e56.zip |
Replace HOST_l2c() with htob32() or crypto_store_htobe32().
ok beck@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/sha/sha256.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/lib/libcrypto/sha/sha256.c b/src/lib/libcrypto/sha/sha256.c index 8432f5fce4..0ed4129f3d 100644 --- a/src/lib/libcrypto/sha/sha256.c +++ b/src/lib/libcrypto/sha/sha256.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sha256.c,v 1.22 2023/05/28 14:54:37 jsing Exp $ */ | 1 | /* $OpenBSD: sha256.c,v 1.23 2023/07/07 10:22:28 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -61,8 +61,13 @@ | |||
61 | #include <openssl/crypto.h> | 61 | #include <openssl/crypto.h> |
62 | #include <openssl/sha.h> | 62 | #include <openssl/sha.h> |
63 | 63 | ||
64 | #include "crypto_internal.h" | ||
65 | |||
64 | #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA256) | 66 | #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA256) |
65 | 67 | ||
68 | /* Ensure that SHA_LONG and uint32_t are equivalent. */ | ||
69 | CTASSERT(sizeof(SHA_LONG) == sizeof(uint32_t)); | ||
70 | |||
66 | #define DATA_ORDER_IS_BIG_ENDIAN | 71 | #define DATA_ORDER_IS_BIG_ENDIAN |
67 | 72 | ||
68 | #define HASH_LONG SHA_LONG | 73 | #define HASH_LONG SHA_LONG |
@@ -462,7 +467,6 @@ SHA256_Final(unsigned char *md, SHA256_CTX *c) | |||
462 | { | 467 | { |
463 | unsigned char *p = (unsigned char *)c->data; | 468 | unsigned char *p = (unsigned char *)c->data; |
464 | size_t n = c->num; | 469 | size_t n = c->num; |
465 | unsigned long ll; | ||
466 | unsigned int nn; | 470 | unsigned int nn; |
467 | 471 | ||
468 | p[n] = 0x80; /* there is always room for one */ | 472 | p[n] = 0x80; /* there is always room for one */ |
@@ -473,17 +477,11 @@ SHA256_Final(unsigned char *md, SHA256_CTX *c) | |||
473 | n = 0; | 477 | n = 0; |
474 | sha256_block_data_order(c, p, 1); | 478 | sha256_block_data_order(c, p, 1); |
475 | } | 479 | } |
480 | |||
476 | memset(p + n, 0, SHA_CBLOCK - 8 - n); | 481 | memset(p + n, 0, SHA_CBLOCK - 8 - n); |
482 | c->data[SHA_LBLOCK - 2] = htobe32(c->Nh); | ||
483 | c->data[SHA_LBLOCK - 1] = htobe32(c->Nl); | ||
477 | 484 | ||
478 | p += SHA_CBLOCK - 8; | ||
479 | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | ||
480 | HOST_l2c(c->Nh, p); | ||
481 | HOST_l2c(c->Nl, p); | ||
482 | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) | ||
483 | HOST_l2c(c->Nl, p); | ||
484 | HOST_l2c(c->Nh, p); | ||
485 | #endif | ||
486 | p -= SHA_CBLOCK; | ||
487 | sha256_block_data_order(c, p, 1); | 485 | sha256_block_data_order(c, p, 1); |
488 | c->num = 0; | 486 | c->num = 0; |
489 | memset(p, 0, SHA_CBLOCK); | 487 | memset(p, 0, SHA_CBLOCK); |
@@ -499,15 +497,15 @@ SHA256_Final(unsigned char *md, SHA256_CTX *c) | |||
499 | switch (c->md_len) { | 497 | switch (c->md_len) { |
500 | case SHA224_DIGEST_LENGTH: | 498 | case SHA224_DIGEST_LENGTH: |
501 | for (nn = 0; nn < SHA224_DIGEST_LENGTH / 4; nn++) { | 499 | for (nn = 0; nn < SHA224_DIGEST_LENGTH / 4; nn++) { |
502 | ll = c->h[nn]; | 500 | crypto_store_htobe32(md, c->h[nn]); |
503 | HOST_l2c(ll, md); | 501 | md += 4; |
504 | } | 502 | } |
505 | break; | 503 | break; |
506 | 504 | ||
507 | case SHA256_DIGEST_LENGTH: | 505 | case SHA256_DIGEST_LENGTH: |
508 | for (nn = 0; nn < SHA256_DIGEST_LENGTH / 4; nn++) { | 506 | for (nn = 0; nn < SHA256_DIGEST_LENGTH / 4; nn++) { |
509 | ll = c->h[nn]; | 507 | crypto_store_htobe32(md, c->h[nn]); |
510 | HOST_l2c(ll, md); | 508 | md += 4; |
511 | } | 509 | } |
512 | break; | 510 | break; |
513 | 511 | ||
@@ -515,8 +513,8 @@ SHA256_Final(unsigned char *md, SHA256_CTX *c) | |||
515 | if (c->md_len > SHA256_DIGEST_LENGTH) | 513 | if (c->md_len > SHA256_DIGEST_LENGTH) |
516 | return 0; | 514 | return 0; |
517 | for (nn = 0; nn < c->md_len / 4; nn++) { | 515 | for (nn = 0; nn < c->md_len / 4; nn++) { |
518 | ll = c->h[nn]; | 516 | crypto_store_htobe32(md, c->h[nn]); |
519 | HOST_l2c(ll, md); | 517 | md += 4; |
520 | } | 518 | } |
521 | break; | 519 | break; |
522 | } | 520 | } |