diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /security/nss/cmd/bltest/tests/aes_gcm/hex.c | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'security/nss/cmd/bltest/tests/aes_gcm/hex.c')
-rw-r--r-- | security/nss/cmd/bltest/tests/aes_gcm/hex.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/security/nss/cmd/bltest/tests/aes_gcm/hex.c b/security/nss/cmd/bltest/tests/aes_gcm/hex.c new file mode 100644 index 0000000000..cdf583da2f --- /dev/null +++ b/security/nss/cmd/bltest/tests/aes_gcm/hex.c @@ -0,0 +1,78 @@ +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> + +int +tohex(int c) +{ + if ((c >= '0') && (c <= '9')) { + return c - '0'; + } + if ((c >= 'a') && (c <= 'f')) { + return c - 'a' + 10; + } + if ((c >= 'A') && (c <= 'F')) { + return c - 'A' + 10; + } + return 0; +} + +int +isspace(int c) +{ + if (c <= ' ') + return 1; + if (c == '\n') + return 1; + if (c == '\t') + return 1; + if (c == ':') + return 1; + if (c == ';') + return 1; + if (c == ',') + return 1; + return 0; +} + +void +verify_nibble(int nibble, int current) +{ + if (nibble != 0) { + fprintf(stderr, "count mismatch %d (nibbles=0x%x)\n", nibble, current); + fflush(stderr); + } +} + +int +main(int argc, char **argv) +{ + int c; + int current = 0; + int nibble = 0; + int skip = 0; + + if (argv[1]) { + skip = atoi(argv[1]); + } + +#define NIBBLE_COUNT 2 + while ((c = getchar()) != EOF) { + if (isspace(c)) { + verify_nibble(nibble, current); + continue; + } + if (skip) { + skip--; + continue; + } + current = current << 4 | tohex(c); + nibble++; + if (nibble == NIBBLE_COUNT) { + putchar(current); + nibble = 0; + current = 0; + } + } + return 0; +} |