Tweak hash_test.c further, passing sizeof(str)
(cherry picked from commit8997fc0a3f) (cherry picked from commitfc7ed600ae) (cherry picked from commitf3e90ace9d)
This commit is contained in:
+16
-20
@@ -42,8 +42,6 @@ const char *s;
|
||||
char str[2 * ISC_SHA512_DIGESTLENGTH + 3];
|
||||
unsigned char key[20];
|
||||
|
||||
isc_result_t
|
||||
tohexstr(unsigned char *d, unsigned int len, char *out);
|
||||
/*
|
||||
* Precondition: a hexadecimal number in *d, the length of that number in len,
|
||||
* and a pointer to a character array to put the output (*out).
|
||||
@@ -54,18 +52,16 @@ tohexstr(unsigned char *d, unsigned int len, char *out);
|
||||
*
|
||||
* Return values: ISC_R_SUCCESS if the operation is sucessful
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
tohexstr(unsigned char *d, unsigned int len, char *out) {
|
||||
static isc_result_t
|
||||
tohexstr(unsigned char *d, unsigned int len, char *out, size_t out_size) {
|
||||
char c_ret[] = "AA";
|
||||
unsigned int i;
|
||||
int size = 2 + (len * 2) + 1;
|
||||
|
||||
out[0] = '\0';
|
||||
strlcat(out, "0x", size);
|
||||
strlcat(out, "0x", out_size);
|
||||
for (i = 0; i < len; i++) {
|
||||
snprintf(c_ret, sizeof(c_ret), "%02X", d[i]);
|
||||
strlcat(out, c_ret, size);
|
||||
strlcat(out, c_ret, out_size);
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
@@ -209,7 +205,7 @@ ATF_TC_BODY(isc_sha1, tc) {
|
||||
testcase->input_len);
|
||||
}
|
||||
isc_sha1_final(&sha1, digest);
|
||||
tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -342,7 +338,7 @@ ATF_TC_BODY(isc_sha224, tc) {
|
||||
* functions the call should be
|
||||
* isc_sha224_final(&sha224, digest);
|
||||
*/
|
||||
tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -474,7 +470,7 @@ ATF_TC_BODY(isc_sha256, tc) {
|
||||
* functions the call should be
|
||||
* isc_sha224_final(&sha224, digest);
|
||||
*/
|
||||
tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -620,7 +616,7 @@ ATF_TC_BODY(isc_sha384, tc) {
|
||||
* functions the call should be
|
||||
* isc_sha224_final(&sha224, digest);
|
||||
*/
|
||||
tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -767,7 +763,7 @@ ATF_TC_BODY(isc_sha512, tc) {
|
||||
* functions the call should be
|
||||
* isc_sha224_final(&sha224, digest);
|
||||
*/
|
||||
tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -840,7 +836,7 @@ ATF_TC_BODY(isc_md5, tc) {
|
||||
testcase->input_len);
|
||||
}
|
||||
isc_md5_final(&md5, digest);
|
||||
tohexstr(digest, ISC_MD5_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_MD5_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -969,7 +965,7 @@ ATF_TC_BODY(isc_hmacsha1, tc) {
|
||||
(const isc_uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
isc_hmacsha1_sign(&hmacsha1, digest, ISC_SHA1_DIGESTLENGTH);
|
||||
tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -1132,7 +1128,7 @@ ATF_TC_BODY(isc_hmacsha224, tc) {
|
||||
(const isc_uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
isc_hmacsha224_sign(&hmacsha224, digest, ISC_SHA224_DIGESTLENGTH);
|
||||
tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -1295,7 +1291,7 @@ ATF_TC_BODY(isc_hmacsha256, tc) {
|
||||
(const isc_uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
isc_hmacsha256_sign(&hmacsha256, digest, ISC_SHA256_DIGESTLENGTH);
|
||||
tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -1464,7 +1460,7 @@ ATF_TC_BODY(isc_hmacsha384, tc) {
|
||||
(const isc_uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
isc_hmacsha384_sign(&hmacsha384, digest, ISC_SHA384_DIGESTLENGTH);
|
||||
tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -1633,7 +1629,7 @@ ATF_TC_BODY(isc_hmacsha512, tc) {
|
||||
(const isc_uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
isc_hmacsha512_sign(&hmacsha512, digest, ISC_SHA512_DIGESTLENGTH);
|
||||
tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
@@ -1776,7 +1772,7 @@ ATF_TC_BODY(isc_hmacmd5, tc) {
|
||||
(const isc_uint8_t *) testcase->input,
|
||||
testcase->input_len);
|
||||
isc_hmacmd5_sign(&hmacmd5, digest);
|
||||
tohexstr(digest, ISC_MD5_DIGESTLENGTH, str);
|
||||
tohexstr(digest, ISC_MD5_DIGESTLENGTH, str, sizeof(str));
|
||||
ATF_CHECK_STREQ(str, testcase->result);
|
||||
|
||||
testcase++;
|
||||
|
||||
Reference in New Issue
Block a user