diff options
author | Richard van der Hoff <richard@matrix.org> | 2016-05-13 12:56:23 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2016-05-23 18:55:05 +0100 |
commit | e533b0dc8ef606aa808b38d2f49d9baf438dae47 (patch) | |
tree | 5d49a825bdfbc9e3a71d96c357ab9375fb17b695 /include | |
parent | 4f1bb49d20ff7e9583a764b5d7d6d6cd9dc26870 (diff) |
Give SHA256 functions C bindings
Diffstat (limited to 'include')
-rw-r--r-- | include/olm/crypto.h | 65 | ||||
-rw-r--r-- | include/olm/crypto.hh | 37 |
2 files changed, 70 insertions, 32 deletions
diff --git a/include/olm/crypto.h b/include/olm/crypto.h new file mode 100644 index 0000000..1357834 --- /dev/null +++ b/include/olm/crypto.h @@ -0,0 +1,65 @@ +/* Copyright 2015 OpenMarket Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* C-compatible crpyto utility functions. At some point all of crypto.hh will + * move here. + */ + +#ifndef OLM_CRYPTO_H_ +#define OLM_CRYPTO_H_ + +#include <stdint.h> +#include <stdlib.h> + +#ifdef __cplusplus +extern "C" { +#endif + +const size_t SHA256_OUTPUT_LENGTH = 32; + +/** Computes SHA-256 of the input. The output buffer must be a least 32 + * bytes long. */ +void crypto_sha256( + uint8_t const * input, size_t input_length, + uint8_t * output +); + +/** HMAC: Keyed-Hashing for Message Authentication + * http://tools.ietf.org/html/rfc2104 + * Computes HMAC-SHA-256 of the input for the key. The output buffer must + * be at least 32 bytes long. */ +void crypto_hmac_sha256( + uint8_t const * key, size_t key_length, + uint8_t const * input, size_t input_length, + uint8_t * output +); + + +/** HMAC-based Key Derivation Function (HKDF) + * https://tools.ietf.org/html/rfc5869 + * Derives key material from the input bytes. */ +void crypto_hkdf_sha256( + uint8_t const * input, size_t input_length, + uint8_t const * info, size_t info_length, + uint8_t const * salt, size_t salt_length, + uint8_t * output, size_t output_length +); + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* OLM_CRYPTO_H_ */ diff --git a/include/olm/crypto.hh b/include/olm/crypto.hh index 7a05f8d..64e8f7d 100644 --- a/include/olm/crypto.hh +++ b/include/olm/crypto.hh @@ -18,6 +18,11 @@ #include <cstdint> #include <cstddef> +// eventually all of this needs to move into crypto.h, and everything should +// use that. For now, include crypto.h here. + +#include "olm/crypto.h" + namespace olm { static const std::size_t KEY_LENGTH = 32; @@ -142,38 +147,6 @@ std::size_t aes_decrypt_cbc( ); -/** Computes SHA-256 of the input. The output buffer must be a least 32 - * bytes long. */ -void sha256( - std::uint8_t const * input, std::size_t input_length, - std::uint8_t * output -); - - -const std::size_t SHA256_OUTPUT_LENGTH = 32; - - -/** HMAC: Keyed-Hashing for Message Authentication - * http://tools.ietf.org/html/rfc2104 - * Computes HMAC-SHA-256 of the input for the key. The output buffer must - * be at least 32 bytes long. */ -void hmac_sha256( - std::uint8_t const * key, std::size_t key_length, - std::uint8_t const * input, std::size_t input_length, - std::uint8_t * output -); - - -/** HMAC-based Key Derivation Function (HKDF) - * https://tools.ietf.org/html/rfc5869 - * Derives key material from the input bytes. */ -void hkdf_sha256( - std::uint8_t const * input, std::size_t input_length, - std::uint8_t const * info, std::size_t info_length, - std::uint8_t const * salt, std::size_t salt_length, - std::uint8_t * output, std::size_t output_length -); - } // namespace olm #endif /* OLM_CRYPTO_HH_ */ |