1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2020 The Exonum Team
//
// 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.
//! This module implements cryptographic backend based
//! on [Sodium library](https://github.com/jedisct1/libsodium)
//! through [sodiumoxide rust bindings](https://github.com/dnaq/sodiumoxide).
//! The constants in this module are imported from Sodium.
//!
//! The SHA-256 function applied in this backend splits the input data into blocks
//! and runs each block through a cycle of 64 iterations. The result of the
//! function is a cryptographic hash 256 bits or 32 bytes in length. This
//! hash can later be used to verify the integrity of data without accessing the
//! data itself.
//!
//! This backend also makes use of Ed25519 keys. Ed25519 is a signature system that ensures
//! fast signing and key generation, as well as security and collision
//! resilience.
// spell-checker:ignore DIGESTBYTES, PUBLICKEYBYTES, SECRETKEYBYTES, SEEDBYTES, SIGNATUREBYTES
use exonum_sodiumoxide as sodiumoxide;
/// Digest type for sodiumoxide-based implementation.
pub use Digest as Hash;
/// Signature type for sodiumoxide-based implementation.
pub use Signature;
/// Secret key type for sodiumoxide-based implementation.
pub use SecretKey;
/// Public key type for sodiumoxide-based implementation.
pub use PublicKey;
/// Seed type for sodiumoxide-based implementation.
pub use Seed;
/// State for multi-part (streaming) computation of signature for sodiumoxide-based
/// implementation.
pub use State as SignState;
/// Contains the state for multi-part (streaming) hash computations
/// for sodiumoxide-based implementation.
pub use State as HashState;
use ;
/// Number of bytes in a `Hash`.
pub const HASH_SIZE: usize = DIGESTBYTES;
/// Number of bytes in a public key.
pub const PUBLIC_KEY_LENGTH: usize = PUBLICKEYBYTES;
/// Number of bytes in a secret key.
pub const SECRET_KEY_LENGTH: usize = SECRETKEYBYTES;
/// Number of bytes in a seed.
pub const SEED_LENGTH: usize = SEEDBYTES;
/// Number of bytes in a signature.
pub const SIGNATURE_LENGTH: usize = SIGNATUREBYTES;
/// Initializes the sodium library and automatically selects faster versions
/// of the primitives, if possible.
/// Signs a slice of bytes using the signer's secret key and returns the
/// resulting `Signature`.
/// Computes a secret key and a corresponding public key from a `Seed`.
/// Generates a secret key and a corresponding public key using a cryptographically secure
/// pseudo-random number generator.
/// Verifies that `data` is signed with a secret key corresponding to the
/// given public key.
/// Calculates hash of a bytes slice.
/// Verifies that public key matches provided secret key.
pub