mirror of https://github.com/ntop/n2n.git
Browse Source
* Make it clear which hash we are testing * Coverage for all pearson hash variants * Initial coverage for auth.c * Add some more auth.c coverage * Ensure new bins are added to both build systems * Ensure new source files are fully lintedpull/906/head
Hamish Coleman
3 years ago
committed by
GitHub
8 changed files with 231 additions and 4 deletions
@ -0,0 +1,31 @@ |
|||
bin_to_ascii: input size = 0x10 |
|||
000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f | | |
|||
bin_to_ascii: output: 00420mG51WS82GeB30qE3m |
|||
|
|||
ascii_to_bin: input = 00420mG51WS82GeB30qE3m |
|||
ascii_to_bin: output: |
|||
000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f | | |
|||
010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | | |
|||
|
|||
generate_private_key: input = 00420mG51WS82GeB30qE3m |
|||
generate_private_key: output: |
|||
000: a4 f4 b5 1c 8a 0a 09 f9 7e 98 22 ca 8a cc b3 f9 | ~ " | |
|||
010: 4d 5a 0d 02 0b 9d 08 ea 03 9b 46 41 8e 3c 0d 49 |MZ FA < I| |
|||
|
|||
generate_public_key: input: |
|||
000: a4 f4 b5 1c 8a 0a 09 f9 7e 98 22 ca 8a cc b3 f9 | ~ " | |
|||
010: 4d 5a 0d 02 0b 9d 08 ea 03 9b 46 41 8e 3c 0d 49 |MZ FA < I| |
|||
generate_public_key: output: |
|||
000: ca 58 61 6f f9 25 d0 cd 1d a5 62 48 a0 15 5e ad | Xao % bH ^ | |
|||
010: a9 f3 5c 10 5f 20 b6 42 b0 a9 7c 1e 0e d7 e9 4b | \ _ B | K| |
|||
|
|||
generate_shared_secret: input: prv |
|||
000: a4 f4 b5 1c 8a 0a 09 f9 7e 98 22 ca 8a cc b3 f9 | ~ " | |
|||
010: 4d 5a 0d 02 0b 9d 08 ea 03 9b 46 41 8e 3c 0d 49 |MZ FA < I| |
|||
generate_shared_secret: input: pub |
|||
000: ca 58 61 6f f9 25 d0 cd 1d a5 62 48 a0 15 5e ad | Xao % bH ^ | |
|||
010: a9 f3 5c 10 5f 20 b6 42 b0 a9 7c 1e 0e d7 e9 4b | \ _ B | K| |
|||
generate_shared_secret: output: |
|||
000: 5d 94 7b 0b db 54 e8 70 8a 09 b0 db 6f 0b 0d 31 |] { T p o 1| |
|||
010: 1b b8 5f ba 57 74 34 bd 3b c5 c4 6c d5 ae a4 84 | _ Wt4 ; l | |
|||
|
@ -0,0 +1,128 @@ |
|||
/*
|
|||
* (C) 2007-21 - ntop.org and contributors |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, see <http://www.gnu.org/licenses/>
|
|||
* |
|||
*/ |
|||
|
|||
#include <inttypes.h> |
|||
|
|||
#include "n2n.h" |
|||
#include "hexdump.h" |
|||
|
|||
|
|||
uint8_t PKT_CONTENT1[]={ |
|||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|||
}; |
|||
|
|||
char *PKT_CONTENT2 = "00420mG51WS82GeB30qE3m"; |
|||
|
|||
void test_bin_to_ascii (void *buf, unsigned int bufsize) { |
|||
char *test_name = "bin_to_ascii"; |
|||
char out[32]; |
|||
|
|||
printf("%s: input size = 0x%x\n", test_name, bufsize); |
|||
fhexdump(0, buf, bufsize, stdout); |
|||
|
|||
bin_to_ascii(out, buf, bufsize); |
|||
|
|||
printf("%s: output: %s\n", test_name, out); |
|||
|
|||
fprintf(stderr, "%s: tested\n", test_name); |
|||
printf("\n"); |
|||
} |
|||
|
|||
void test_ascii_to_bin (char *buf) { |
|||
char *test_name = "ascii_to_bin"; |
|||
uint8_t out[32]; |
|||
memset(out, 0, sizeof(out)); |
|||
|
|||
printf("%s: input = %s\n", test_name, buf); |
|||
|
|||
ascii_to_bin(out, buf); |
|||
// TODO:
|
|||
// - it would be nice if the function returned the bufsize,
|
|||
// - or took an allocation size as input
|
|||
|
|||
printf("%s: output:\n", test_name); |
|||
fhexdump(0, out, sizeof(out), stdout); |
|||
|
|||
fprintf(stderr, "%s: tested\n", test_name); |
|||
printf("\n"); |
|||
} |
|||
|
|||
void test_generate_private_key (char *in, n2n_private_public_key_t prv) { |
|||
char *test_name = "generate_private_key"; |
|||
|
|||
printf("%s: input = %s\n", test_name, in); |
|||
|
|||
generate_private_key(prv, in); |
|||
|
|||
printf("%s: output:\n", test_name); |
|||
fhexdump(0, prv, sizeof(n2n_private_public_key_t), stdout); |
|||
|
|||
fprintf(stderr, "%s: tested\n", test_name); |
|||
printf("\n"); |
|||
} |
|||
|
|||
void test_generate_public_key (n2n_private_public_key_t prv, n2n_private_public_key_t pub) { |
|||
char *test_name = "generate_public_key"; |
|||
|
|||
printf("%s: input:\n", test_name); |
|||
fhexdump(0, prv, sizeof(n2n_private_public_key_t), stdout); |
|||
|
|||
generate_public_key(pub, prv); |
|||
|
|||
printf("%s: output:\n", test_name); |
|||
fhexdump(0, pub, sizeof(n2n_private_public_key_t), stdout); |
|||
|
|||
fprintf(stderr, "%s: tested\n", test_name); |
|||
printf("\n"); |
|||
} |
|||
|
|||
void test_generate_shared_secret (n2n_private_public_key_t prv, n2n_private_public_key_t pub) { |
|||
char *test_name = "generate_shared_secret"; |
|||
n2n_private_public_key_t out; |
|||
|
|||
printf("%s: input: prv\n", test_name); |
|||
fhexdump(0, prv, sizeof(n2n_private_public_key_t), stdout); |
|||
printf("%s: input: pub\n", test_name); |
|||
fhexdump(0, pub, sizeof(n2n_private_public_key_t), stdout); |
|||
|
|||
generate_shared_secret(out, prv, pub); |
|||
|
|||
printf("%s: output:\n", test_name); |
|||
fhexdump(0, out, sizeof(out), stdout); |
|||
|
|||
fprintf(stderr, "%s: tested\n", test_name); |
|||
printf("\n"); |
|||
} |
|||
|
|||
int main (int argc, char * argv[]) { |
|||
|
|||
test_bin_to_ascii(PKT_CONTENT1, sizeof(PKT_CONTENT1)); |
|||
test_ascii_to_bin(PKT_CONTENT2); |
|||
|
|||
n2n_private_public_key_t prv; |
|||
memset(prv, 0, sizeof(prv)); |
|||
n2n_private_public_key_t pub; |
|||
memset(pub, 0, sizeof(pub)); |
|||
|
|||
test_generate_private_key(PKT_CONTENT2, prv); |
|||
test_generate_public_key(prv, pub); |
|||
test_generate_shared_secret(prv, pub); |
|||
|
|||
return 0; |
|||
} |
|||
|
Loading…
Reference in new issue