1#![no_std]
2
3extern crate alloc;
4
5#[cfg(not(feature = "expose-hacl"))]
6mod hacl {
7 pub(crate) mod rsapss;
8
9 use libcrux_hacl_rs::streaming_types;
10 use libcrux_sha2::hacl as hash_sha2;
11}
12
13#[cfg(feature = "expose-hacl")]
15pub mod hacl {
16 pub mod rsapss;
18
19 use libcrux_hacl_rs::streaming_types;
20 use libcrux_sha2::hacl as hash_sha2;
21}
22
23#[derive(Clone, Copy, Debug)]
25pub enum DigestAlgorithm {
26 Sha2_256,
28
29 Sha2_384,
31
32 Sha2_512,
34}
35
36impl DigestAlgorithm {
37 const fn hash_len(&self) -> u8 {
39 match self {
40 DigestAlgorithm::Sha2_256 => 32,
41 DigestAlgorithm::Sha2_384 => 48,
42 DigestAlgorithm::Sha2_512 => 64,
43 }
44 }
45}
46
47#[derive(Debug, PartialEq, Eq)]
49pub enum Error {
50 SaltTooLarge,
52
53 MessageTooLarge,
55
56 VerificationFailed,
58
59 SigningFailed,
61
62 KeyLengthMismatch,
64
65 InvalidKeyLength,
67
68 InvalidSignatureLength,
70}
71
72impl alloc::fmt::Display for Error {
73 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
74 let text = match self {
75 Error::SaltTooLarge => "Indicates that the salt is too large.",
76 Error::MessageTooLarge => "Indicates that the message is too large.",
77 Error::VerificationFailed => "Indicates that the verification of a signature failed.",
78 Error::SigningFailed => "Indicates that signing a message failed.",
79 Error::KeyLengthMismatch => {
80 "The lengths of the public and private parts of the key do not match"
81 }
82 Error::InvalidKeyLength => "The length of the provided key is invalid",
83 Error::InvalidSignatureLength => "The length of the provided signature is invalid",
84 };
85
86 f.write_str(text)
87 }
88}
89
90impl core::error::Error for Error {}
91
92mod impl_hacl;
93
94pub use impl_hacl::*;