1 /* Copyright 2015 OpenMarket Ltd
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef UTILITY_HH_
17 #define UTILITY_HH_
18 
19 #include "olm/error.h"
20 
21 #include <cstddef>
22 #include <cstdint>
23 
24 struct _olm_ed25519_public_key;
25 
26 namespace olm {
27 
28 struct Utility {
29 
30     Utility();
31 
32     OlmErrorCode last_error;
33 
34     /** The length of a SHA-256 hash in bytes. */
35     std::size_t sha256_length() const;
36 
37     /** Compute a SHA-256 hash. Returns the length of the SHA-256 hash in bytes
38      * on success. Returns std::size_t(-1) on failure. On failure last_error
39      * will be set with an error code. If the output buffer was too small then
40      * last error will be OUTPUT_BUFFER_TOO_SMALL. */
41     std::size_t sha256(
42         std::uint8_t const * input, std::size_t input_length,
43         std::uint8_t * output, std::size_t output_length
44     );
45 
46     /** Verify a ed25519 signature. Returns std::size_t(0) on success. Returns
47      * std::size_t(-1) on failure or if the signature was invalid. On failure
48      * last_error will be set with an error code. If the signature was too short
49      * or was not a valid signature then last_error will be BAD_MESSAGE_MAC. */
50     std::size_t ed25519_verify(
51         _olm_ed25519_public_key const & key,
52         std::uint8_t const * message, std::size_t message_length,
53         std::uint8_t const * signature, std::size_t signature_length
54     );
55 
56 };
57 
58 
59 } // namespace olm
60 
61 #endif /* UTILITY_HH_ */
62