~increscent/aes-ccm

aes-ccm/lib.c -rw-r--r-- 638 bytes
6fdb84d8 — Robert Williams Found the issue: the msg_len parameter should be 16-bit, but it's 8-bit 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <stdlib.h>

void handleErrors(const char *str) {
    fprintf(stderr, "Error: %s\n", str);
    exit(1);
}

void printHex(unsigned char *buf, int len) {
    for (int i = 0; i < len; i++) {
        printf("%02x", buf[i]);
    }

    printf("\n");
}

int hexValue(char 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;
}

void hexToBytes(char *str, int len, unsigned char *buf) {
    for (int i = 0; i < len; i += 2) {
        buf[i / 2] = (hexValue(str[i]) << 4) | hexValue(str[i + 1]);
    }
}