main.
1.85 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "gcm.h"
#include "platform_util.h"
#include "api.h"
#include <stdio.h>
#include "crypto_aead.h"
static void single_encryption(void) {
// 32 bytes.. that's 256 bits
const unsigned char k[32] = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 };
unsigned char c[64] = { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85};
unsigned char npub[12] = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
0xde, 0xca, 0xf8, 0x88 };
unsigned char ad[1400];
unsigned long long adlen = 0;
unsigned long long mlen = 0;
unsigned long long clen = 64;
unsigned char m[1400];
unsigned char nsec[CRYPTO_NSECBYTES];
//mbedtls_gcm_init( &ctx );
// 128 bits, not bytes!
//ret = mbedtls_gcm_setkey( &ctx, cipher, key, 128 );
// Context, flag (1/0), length, nonce, nonce_len, AD, AD_len, PT, output, tag_len, tag
//ret = mbedtls_gcm_crypt_and_tag(&ctx, MBEDTLS_GCM_ENCRYPT, 64, initial_value, 12, additional, 0, plaintext, buf, 16, tag_buf);
//mbedtls_gcm_free( &ctx );
int res;
res = crypto_aead_decrypt(m, mlen, nsec, c, clen, ad, adlen, npub, k);
if (res == 0) {
printf("Local decryption test workerino!\n");
} else {
printf("Local test failed -.-\n");
}
}
int main(void) {
//mbedtls_gcm_self_test(1);
single_encryption();
return 0;
}