Robert Sloan | 2424d84 | 2017-05-01 07:46:28 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2017, Google Inc. |
| 2 | * |
| 3 | * Permission to use, copy, modify, and/or distribute this software for any |
| 4 | * purpose with or without fee is hereby granted, provided that the above |
| 5 | * copyright notice and this permission notice appear in all copies. |
| 6 | * |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 | |
| 15 | #ifndef OPENSSL_HEADER_CRYPTO_FIPSMODULE_CAVP_TEST_UTIL_H |
| 16 | #define OPENSSL_HEADER_CRYPTO_FIPSMODULE_CAVP_TEST_UTIL_H |
| 17 | |
| 18 | #include <stdlib.h> |
| 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
| 22 | #include <openssl/aead.h> |
| 23 | #include <openssl/cipher.h> |
| 24 | |
| 25 | #include "../crypto/test/file_test.h" |
| 26 | |
| 27 | |
| 28 | std::string EncodeHex(const uint8_t *in, size_t in_len); |
| 29 | |
| 30 | const EVP_CIPHER *GetCipher(const std::string &name); |
| 31 | |
| 32 | bool CipherOperation(const EVP_CIPHER *cipher, std::vector<uint8_t> *out, |
| 33 | bool encrypt, const std::vector<uint8_t> &key, |
| 34 | const std::vector<uint8_t> &iv, |
| 35 | const std::vector<uint8_t> &in); |
| 36 | |
| 37 | bool AEADEncrypt(const EVP_AEAD *aead, std::vector<uint8_t> *ct, |
| 38 | std::vector<uint8_t> *tag, size_t tag_len, |
| 39 | const std::vector<uint8_t> &key, |
| 40 | const std::vector<uint8_t> &pt, |
| 41 | const std::vector<uint8_t> &aad, std::vector<uint8_t> *iv); |
| 42 | |
| 43 | bool AEADDecrypt(const EVP_AEAD *aead, std::vector<uint8_t> *pt, |
| 44 | std::vector<uint8_t> *aad, size_t pt_len, size_t aad_len, |
| 45 | const std::vector<uint8_t> &key, |
| 46 | const std::vector<uint8_t> &ct, |
| 47 | const std::vector<uint8_t> &tag, std::vector<uint8_t> &iv); |
| 48 | |
| 49 | bssl::UniquePtr<BIGNUM> GetBIGNUM(FileTest *t, const char *attribute); |
| 50 | |
| 51 | int GetECGroupNIDFromInstruction(FileTest *t); |
| 52 | |
| 53 | const EVP_MD *GetDigestFromInstruction(FileTest *t); |
| 54 | |
| 55 | |
| 56 | #endif // OPENSSL_HEADER_CRYPTO_FIPSMODULE_CAVP_TEST_UTIL_H |