ret_type CCM_mode( const unsigned char key[], const unsigned long key_len, /* the key value to be used */ const unsigned char nonce[], /* the nonce value */ const unsigned char auth[], const unsigned long ad_len, /* the additional authenticated data */ unsigned char msg[], const mlen_type msg_len, /* the message data */ const unsigned long auth_field_len, /* the authentication field length */ const int ed_flag) /* 0 = encrypt, 1 = decrypt */ { CCM_ctx ctx[1]; ret_type ec; ec = CCM_init(key, key_len, nonce, auth, ad_len, msg_len, auth_field_len, ctx); return ec != CCM_ok ? ec : ed_flag ? CCM_decrypt(msg, msg, msg_len + auth_field_len, ctx) : CCM_encrypt(msg, msg, msg_len, ctx); }
void sendData(ENC_ctx *ENC_ctx_sender, const unsigned char *input, const unsigned int input_size, message_ctx *ciphermessage) { if (PRINT_inputs_outputs){ printf("\n-->Encrypt: %s\n", input); print_hex_memory(input, input_size); printf("\n"); } CCM_encrypt(ciphermessage, ENC_ctx_sender, input, input_size); ciphermessage->tag=0xFF; if (PRINT_messages){ print_message(ciphermessage); printf("\n"); } }