diff options
Diffstat (limited to 'include/olm')
-rw-r--r-- | include/olm/olm.hh | 43 | ||||
-rw-r--r-- | include/olm/utility.hh | 52 |
2 files changed, 95 insertions, 0 deletions
diff --git a/include/olm/olm.hh b/include/olm/olm.hh index a5a50de..34d84fd 100644 --- a/include/olm/olm.hh +++ b/include/olm/olm.hh @@ -27,6 +27,7 @@ static const size_t OLM_MESSAGE_TYPE_MESSAGE = 1; struct OlmAccount; struct OlmSession; +struct OlmUtility; /** The size of an account object in bytes */ size_t olm_account_size(); @@ -34,6 +35,9 @@ size_t olm_account_size(); /** The size of a session object in bytes */ size_t olm_session_size(); +/** The size of a utility object in bytes */ +size_t olm_utility_size(); + /** Initialise an account object using the supplied memory * The supplied memory must be at least olm_account_size() bytes */ OlmAccount * olm_account( @@ -46,6 +50,12 @@ OlmSession * olm_session( void * memory ); +/** Initialise a utility object using the supplied memory + * The supplied memory must be at least olm_session_size() bytes */ +OlmUtility * olm_utility( + void * memory +); + /** The value that olm will return from a function if there was an error */ size_t olm_error(); @@ -61,6 +71,12 @@ const char * olm_session_last_error( OlmSession * session ); +/** A null terminated string describing the most recent error to happen to a + * utility */ +const char * olm_utility_last_error( + OlmUtility * utility +); + /** Clears the memory used to back this account */ size_t olm_clear_account( OlmAccount * account @@ -71,6 +87,11 @@ size_t olm_clear_session( OlmSession * session ); +/** Clears the memory used to back this utility */ +size_t olm_clear_utility( + OlmUtility * utility +); + /** Returns the number of bytes needed to store an account */ size_t olm_pickle_account_length( OlmAccount * account @@ -370,7 +391,29 @@ size_t olm_decrypt( void * plaintext, size_t max_plaintext_length ); +/** The length of the buffer needed to hold the SHA-256 hash. */ +size_t olm_sha256_length( + OlmUtility * utility +); + +/** Calculates the SHA-256 hash of the input and encodes it as base64. If the + * output buffer is smaller than olm_sha256_length() then + * olm_session_last_error() will be "OUTPUT_BUFFER_TOO_SMALL". */ +size_t olm_sha256( + OlmUtility * utility, + void const * input, size_t input_length, + void * output, size_t output_length +); +/** Verify an ed25519 signature. If the key was too small then + * olm_session_last_error will be "INVALID_BASE64". If the signature was invalid + * then olm_session_last_error() will be "BAD_MESSAGE_MAC". */ +size_t olm_ed25519_verify( + OlmUtility * utility, + void const * key, size_t key_length, + void const * message, size_t message_length, + void * signature, size_t signature_length +); #ifdef __cplusplus } diff --git a/include/olm/utility.hh b/include/olm/utility.hh new file mode 100644 index 0000000..241d7e0 --- /dev/null +++ b/include/olm/utility.hh @@ -0,0 +1,52 @@ +/* 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. + */ + +#ifndef UTILITY_HH_ +#define UTILITY_HH_ + +#include "olm/error.hh" + +#include <cstddef> +#include <cstdint> + +namespace olm { + +class Ed25519PublicKey; + +struct Utility { + + Utility(); + + ErrorCode last_error; + + std::size_t sha256_length(); + + std::size_t sha256( + std::uint8_t const * input, std::size_t input_length, + std::uint8_t * output, std::size_t output_length + ); + + std::size_t ed25519_verify( + Ed25519PublicKey const & key, + std::uint8_t const * message, std::size_t message_length, + std::uint8_t const * signature, std::size_t signature_length + ); + +}; + + +} // namespace olm + +#endif /* UTILITY_HH_ */ |