start aes_gcm
This commit is contained in:
parent
7eceff2ffe
commit
aaa2257716
13
Makefile
13
Makefile
@ -13,15 +13,24 @@ src = $(wildcard *.c) $(wildcard crypto/*.c) crypto/tiny-AES-c/aes.c
|
|||||||
obj = $(src:.c=.o) uECC.o
|
obj = $(src:.c=.o) uECC.o
|
||||||
|
|
||||||
LDFLAGS = -Wl,--gc-sections ./tinycbor/lib/libtinycbor.a
|
LDFLAGS = -Wl,--gc-sections ./tinycbor/lib/libtinycbor.a
|
||||||
CFLAGS = -O2 -fdata-sections -ffunction-sections -I./tinycbor/src -I./crypto -I./crypto/micro-ecc/ -Icrypto/tiny-AES-c/
|
CFLAGS = -O2 -fdata-sections -ffunction-sections -I./tinycbor/src -I./crypto -I./crypto/micro-ecc/ -Icrypto/tiny-AES-c/ -I.
|
||||||
|
|
||||||
name = main
|
name = main
|
||||||
|
|
||||||
|
all: main
|
||||||
|
|
||||||
|
test: testgcm
|
||||||
|
|
||||||
$(name): $(obj)
|
$(name): $(obj)
|
||||||
$(CC) $(LDFLAGS) -o $@ $(obj) $(LDFLAGS)
|
$(CC) $(LDFLAGS) -o $@ $(obj) $(LDFLAGS)
|
||||||
|
|
||||||
|
testgcm: $(obj)
|
||||||
|
$(CC) -c main.c $(CFLAGS) -DTEST -o main.o
|
||||||
|
$(CC) -c crypto/aes_gcm.c $(CFLAGS) -DTEST -o crypto/aes_gcm.o
|
||||||
|
$(CC) $(LDFLAGS) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
uECC.o: ./crypto/micro-ecc/uECC.c
|
uECC.o: ./crypto/micro-ecc/uECC.c
|
||||||
$(CC) -c -o $@ $^ -O2 -fdata-sections -ffunction-sections -DuECC_PLATFORM=$(platform) -I./crypto/micro-ecc/
|
$(CC) -c -o $@ $^ -O2 -fdata-sections -ffunction-sections -DuECC_PLATFORM=$(platform) -I./crypto/micro-ecc/
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o main.exe main
|
rm -f *.o main.exe main crypto/tiny-AES-c/*.o crypto/*.o crypto/micro-ecc/*.o
|
||||||
|
10
crypto.h
10
crypto.h
@ -1,6 +1,7 @@
|
|||||||
#ifndef _CRYPTO_H
|
#ifndef _CRYPTO_H
|
||||||
#define _CRYPTO_H
|
#define _CRYPTO_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#define USE_SOFTWARE_IMPLEMENTATION
|
#define USE_SOFTWARE_IMPLEMENTATION
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ void crypto_sha256_hmac_final(uint8_t * key, uint32_t klen, uint8_t * hmac);
|
|||||||
void crypto_ecc256_init();
|
void crypto_ecc256_init();
|
||||||
void crypto_ecc256_derive_public_key(uint8_t * data, int len, uint8_t * x, uint8_t * y);
|
void crypto_ecc256_derive_public_key(uint8_t * data, int len, uint8_t * x, uint8_t * y);
|
||||||
|
|
||||||
void crypto_ecc256_load_key(uint8_t * data, int len);
|
void crypto_ecc256_load_key(uint8_t * data, int len, uint8_t * data2, int len2);
|
||||||
void crypto_ecc256_load_attestation_key();
|
void crypto_ecc256_load_attestation_key();
|
||||||
void crypto_ecc256_sign(uint8_t * data, int len, uint8_t * sig);
|
void crypto_ecc256_sign(uint8_t * data, int len, uint8_t * sig);
|
||||||
|
|
||||||
@ -26,8 +27,11 @@ void crypto_ecc256_make_key_pair(uint8_t * pubkey, uint8_t * privkey);
|
|||||||
void crypto_ecc256_shared_secret(const uint8_t * pubkey, const uint8_t * privkey, uint8_t * shared_secret);
|
void crypto_ecc256_shared_secret(const uint8_t * pubkey, const uint8_t * privkey, uint8_t * shared_secret);
|
||||||
|
|
||||||
// Key must be 32 bytes
|
// Key must be 32 bytes
|
||||||
void crypto_aes256_init(uint8_t * key);
|
#define CRYPTO_TRANSPORT_KEY NULL
|
||||||
void crypto_aes256_reset_iv();
|
#define CRYPTO_MASTER_KEY NULL
|
||||||
|
|
||||||
|
void crypto_aes256_init(uint8_t * key, uint8_t * nonce);
|
||||||
|
void crypto_aes256_reset_iv(uint8_t * nonce);
|
||||||
|
|
||||||
// buf length must be multiple of 16 bytes
|
// buf length must be multiple of 16 bytes
|
||||||
void crypto_aes256_decrypt(uint8_t * buf, int lenth);
|
void crypto_aes256_decrypt(uint8_t * buf, int lenth);
|
||||||
|
47
crypto/aes_gcm.c
Normal file
47
crypto/aes_gcm.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "aes.h"
|
||||||
|
#include "crypto.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#define BLOCK_SIZE 16
|
||||||
|
|
||||||
|
static struct AES_ctx aes_ctx;
|
||||||
|
|
||||||
|
// void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
|
||||||
|
|
||||||
|
int8_t crypto_aes256_gcm_encrypt(uint8_t * data, uint32_t length, uint8_t * authtag)
|
||||||
|
{
|
||||||
|
memset(authtag, 0, BLOCK_SIZE);
|
||||||
|
AES_CTR_xcrypt_buffer(&aes_ctx, authtag, BLOCK_SIZE);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TEST
|
||||||
|
|
||||||
|
int main(int argc, char * argv[])
|
||||||
|
{
|
||||||
|
uint8_t nonce[16];
|
||||||
|
uint8_t key[32];
|
||||||
|
uint8_t authtag[BLOCK_SIZE];
|
||||||
|
|
||||||
|
uint8_t * authtag1 = "\x53\x0f\x8a\xfb\xc7\x45\x36\xb9\xa9\x63\xb4\xf1\xc4\xcb\x73\x8b";
|
||||||
|
|
||||||
|
memset(nonce,0,16);
|
||||||
|
memset(key,0,16);
|
||||||
|
|
||||||
|
AES_init_ctx_iv(&aes_ctx, key, nonce);
|
||||||
|
|
||||||
|
crypto_aes256_gcm_encrypt(NULL, 0, authtag);
|
||||||
|
|
||||||
|
printf("Auth tag: "); dump_hex(authtag, BLOCK_SIZE);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
3
main.c
3
main.c
@ -19,7 +19,7 @@ static void check_ret(CborError ret)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef TEST
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
set_logging_mask(
|
set_logging_mask(
|
||||||
@ -61,3 +61,4 @@ int main(int argc, char * argv[])
|
|||||||
printf("done\n");
|
printf("done\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user