int CipherContext::writeTag(State & state, mbedtls_cipher_context_t * context){ Stack * stack = state.stack; if (stack->is<LUA_TNUMBER>(1)){ size_t outputSize = stack->to<int>(1); unsigned char * tag = new unsigned char[outputSize]; int result = mbedtls_cipher_write_tag(context, tag, outputSize); if (result == 0){ stack->pushLString(std::string(reinterpret_cast<char*>(tag), outputSize)); } else{ stack->push<int>(result); } return 1; } return 0; }
int cipher_ctx_get_tag(cipher_ctx_t *ctx, uint8_t *tag, int tag_len) { #ifdef HAVE_AEAD_CIPHER_MODES if (tag_len > SIZE_MAX) { return 0; } if (!mbed_ok(mbedtls_cipher_write_tag(ctx, (unsigned char *) tag, tag_len))) { return 0; } return 1; #else /* ifdef HAVE_AEAD_CIPHER_MODES */ ASSERT(0); #endif /* HAVE_AEAD_CIPHER_MODES */ }