| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sha2.c,v 1.10.8.1 2017/06/21 18:03:45 snj Exp $ */ | | 1 | /* $NetBSD: sha2.c,v 1.10.8.2 2020/05/05 18:51:08 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (C) 2005-2007, 2009, 2011, 2012, 2014, 2016 Internet Systems Consortium, Inc. ("ISC") | | 4 | * Copyright (C) 2005-2007, 2009, 2011, 2012, 2014, 2016 Internet Systems Consortium, Inc. ("ISC") |
5 | * | | 5 | * |
6 | * Permission to use, copy, modify, and/or distribute this software for any | | 6 | * Permission to use, copy, modify, and/or distribute this software for any |
7 | * purpose with or without fee is hereby granted, provided that the above | | 7 | * purpose with or without fee is hereby granted, provided that the above |
8 | * copyright notice and this permission notice appear in all copies. | | 8 | * copyright notice and this permission notice appear in all copies. |
9 | * | | 9 | * |
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH | | 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH |
11 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | | 11 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
12 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, | | 12 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, |
13 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | | 13 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
14 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE | | 14 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE |
| @@ -1493,26 +1493,28 @@ void isc_sha512_last(isc_sha512_t *conte | | | @@ -1493,26 +1493,28 @@ void isc_sha512_last(isc_sha512_t *conte |
1493 | (isc_uint64_t*)context->buffer); | | 1493 | (isc_uint64_t*)context->buffer); |
1494 | | | 1494 | |
1495 | /* And set-up for the last transform: */ | | 1495 | /* And set-up for the last transform: */ |
1496 | memset(context->buffer, 0, ISC_SHA512_BLOCK_LENGTH - 2); | | 1496 | memset(context->buffer, 0, ISC_SHA512_BLOCK_LENGTH - 2); |
1497 | } | | 1497 | } |
1498 | } else { | | 1498 | } else { |
1499 | /* Prepare for final transform: */ | | 1499 | /* Prepare for final transform: */ |
1500 | memset(context->buffer, 0, ISC_SHA512_SHORT_BLOCK_LENGTH); | | 1500 | memset(context->buffer, 0, ISC_SHA512_SHORT_BLOCK_LENGTH); |
1501 | | | 1501 | |
1502 | /* Begin padding with a 1 bit: */ | | 1502 | /* Begin padding with a 1 bit: */ |
1503 | *context->buffer = 0x80; | | 1503 | *context->buffer = 0x80; |
1504 | } | | 1504 | } |
1505 | /* Store the length of input data (in bits): */ | | 1505 | /* Store the length of input data (in bits): */ |
| | | 1506 | memcpy(&context->buffer[ISC_SHA512_SHORT_BLOCK_LENGTH], |
| | | 1507 | &context->bitcount[1], sizeof(isc_uint64_t)); |
1506 | memcpy(&context->buffer[ISC_SHA512_SHORT_BLOCK_LENGTH+8], | | 1508 | memcpy(&context->buffer[ISC_SHA512_SHORT_BLOCK_LENGTH+8], |
1507 | &context->bitcount[0], sizeof(isc_uint64_t)); | | 1509 | &context->bitcount[0], sizeof(isc_uint64_t)); |
1508 | | | 1510 | |
1509 | /* Final transform: */ | | 1511 | /* Final transform: */ |
1510 | isc_sha512_transform(context, (isc_uint64_t*)context->buffer); | | 1512 | isc_sha512_transform(context, (isc_uint64_t*)context->buffer); |
1511 | } | | 1513 | } |
1512 | | | 1514 | |
1513 | void isc_sha512_final(isc_uint8_t digest[], isc_sha512_t *context) { | | 1515 | void isc_sha512_final(isc_uint8_t digest[], isc_sha512_t *context) { |
1514 | isc_uint64_t *d = (isc_uint64_t*)digest; | | 1516 | isc_uint64_t *d = (isc_uint64_t*)digest; |
1515 | | | 1517 | |
1516 | /* Sanity check: */ | | 1518 | /* Sanity check: */ |
1517 | REQUIRE(context != (isc_sha512_t *)0); | | 1519 | REQUIRE(context != (isc_sha512_t *)0); |
1518 | | | 1520 | |