From bad9a973b44e3cfcdcc97635dd800db8c300e8bc Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Fri, 30 Jul 2021 07:07:40 +0900 Subject: [PATCH] remove hard tabs and other minor fixes --- tests/api.c | 113 ++++++++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/tests/api.c b/tests/api.c index a601fcb6d..54e8c801d 100644 --- a/tests/api.c +++ b/tests/api.c @@ -36521,19 +36521,19 @@ tgZl96bcAGdru8OpQYP7x/rI4h5+rwA/kwIBAg==\n\ static void binary_dump(void *ptr, int size) { #ifdef WOLFSSL_EVP_PRINT - int i = 0; - unsigned char *p = (unsigned char *) ptr; + int i = 0; + unsigned char *p = (unsigned char *) ptr; - printf("{"); - while((p != NULL) && (i < size)) { - if((i % 8) == 0) { - printf("\n"); - printf(" "); - } - printf("0x%02x, ", p[i]); - i++; - } - printf("\n};\n"); + printf("{"); + while((p != NULL) && (i < size)) { + if((i % 8) == 0) { + printf("\n"); + printf(" "); + } + printf("0x%02x, ", p[i]); + i++; + } + printf("\n};\n"); #else (void) ptr; (void) size; @@ -36544,15 +36544,15 @@ static int last_val = 0x0f; static int check_result(unsigned char *data, int len) { - int i; - - for( ; len; ) { - last_val = (last_val + 1) % 16; - for(i = 0; i < 16; len--, i++, data++) - if(*data != last_val) { - return -1; - } - } + int i; + + for( ; len; ) { + last_val = (last_val + 1) % 16; + for(i = 0; i < 16; len--, i++, data++) + if(*data != last_val) { + return -1; + } + } return 0; } @@ -36566,13 +36566,13 @@ static void init_offset() } static void get_record(unsigned char *data, unsigned char *buf, int len) { - memcpy(buf, data+r_offset, len); + XMEMCPY(buf, data+r_offset, len); r_offset += len; } static void set_record(unsigned char *data, unsigned char *buf, int len) { - memcpy(data+w_offset, buf, len); + XMEMCPY(data+w_offset, buf, len); w_offset += len; } @@ -36587,7 +36587,6 @@ static void set_plain(unsigned char *plain, int rec) for(j=0; j 0 && keylen != klen) { - AssertIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0); - } + klen = EVP_CIPHER_CTX_key_length(evp); + if (klen > 0 && keylen != klen) { + AssertIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0); + } AssertIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0); @@ -36664,9 +36663,9 @@ static int test_wolfSSL_EVP_Cipher_extra(void) set_record(cipher, outb, outl); } - for (i = 0; test_drive[i]; i++) { + for (i = 0; test_drive[i]; i++) { - AssertIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0); + AssertIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0); init_offset(); test_drive_len[i] = 0; @@ -36676,40 +36675,40 @@ static int test_wolfSSL_EVP_Cipher_extra(void) test_drive_len[i] += inl; get_record(plain, inb, inl); - AssertIntNE((ret = EVP_EncryptUpdate(evp, outb, &outl, inb, inl)), 0); + AssertIntNE((ret = EVP_EncryptUpdate(evp, outb, &outl, inb, inl)), 0); /* output to cipher buffer, so that following Dec test can detect if any error */ set_record(cipher, outb, outl); - } + } - EVP_CipherFinal(evp, outb, &outl); + EVP_CipherFinal(evp, outb, &outl); if(outl > 0) set_record(cipher, outb, outl); } - for (i = 0; test_drive[i]; i++) { + for (i = 0; test_drive[i]; i++) { - last_val = 0x0f; + last_val = 0x0f; drive_len = 0; - AssertIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 0)), 0); + AssertIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 0)), 0); init_offset(); - for (j = 0; test_drive[i][j]; j++){ - inl = test_drive[i][j]; - get_record(cipher, inb, inl); + for (j = 0; test_drive[i][j]; j++){ + inl = test_drive[i][j]; + get_record(cipher, inb, inl); - AssertIntNE((ret = EVP_DecryptUpdate(evp, outb, &outl, inb, inl)), 0); + AssertIntNE((ret = EVP_DecryptUpdate(evp, outb, &outl, inb, inl)), 0); - binary_dump(outb, outl); - AssertIntEQ((ret = check_result(outb, outl)), 0); - AssertFalse(outl > ((inl/16+1)*16) && outl > 16); + binary_dump(outb, outl); + AssertIntEQ((ret = check_result(outb, outl)), 0); + AssertFalse(outl > ((inl/16+1)*16) && outl > 16); drive_len += outl; } - ret = EVP_CipherFinal(evp, outb, &outl); + ret = EVP_CipherFinal(evp, outb, &outl); binary_dump(outb, outl); ret = (((test_drive_len[i] % 16) != 0) && (ret == 0)) || @@ -36717,11 +36716,11 @@ static int test_wolfSSL_EVP_Cipher_extra(void) AssertTrue(ret); } - EVP_CIPHER_CTX_free(evp); + EVP_CIPHER_CTX_free(evp); #endif /* test_EVP_Cipher */ - return 0; + return 0; }