example_encryption.c 1.85 KB
Newer Older
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
#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 m[64] = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
      0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
      0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
      0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
      0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
      0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
      0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
      0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 };
    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 = 64;
    unsigned long long clen = 0;
    unsigned char c[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_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k);
    if (res  == 0) {
        printf("Local encryption test workerino!\n");
    } else {
        printf("Local test failed -.-\n");
    }

}

int main(void) {
    //mbedtls_gcm_self_test(1);
    single_encryption();
    return 0;
}