scram_rs/
lib.rs

1/*-
2 * Scram-rs - a SCRAM authentification authorization library
3 * 
4 * Copyright (C) 2021  Aleksandr Morozov
5 * Copyright (C) 2025 Aleksandr Morozov
6 * 
7 * The syslog-rs crate can be redistributed and/or modified
8 * under the terms of either of the following licenses:
9 *
10 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
11 *
12 *   2. The MIT License (MIT)
13 *                     
14 *   3. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
15 */
16
17
18/*! Scram-RS (Sync and Async)
19 
20 
21 Provides a SASL SCRAM:
22 - SHA1 
23 - SHA256 
24 - SHA512 
25 - -PLUS
26
27 Features:
28 - default: "std", "use_ring"
29
30 - `use_ring` - adds crate: [ring] as an alternative hashing and other crypto functions.
31
32 - `exclude_sha1` - if enabled excludes the SHA1.
33 
34 - `std` - when set uses std lib, if removed, a no_std + alloc
35    A program which includes this crate is based on standart library i.e std.
36    For non-std an alloc crate is exported.
37    Enabled by default.
38    If CAPI was NOT excluded, and std was excluded, the crate will not be able to 
39    allocate memory in heap. For this reason, the set_allocator() should be called 
40    before using this crate in C program.
41 
42 - `without_async` - excludes the async code
43
44 - `without_capi` - do not build CAPI code.
45 - `xor_without_u128` - do not use the u128 type while performing XOR of arrays
46 
47 For default crypto crates:
48 scram-rs = { version = "0.13", default-features = true}
49 
50 For `ring` crypto crates:
51 scram-rs = { version = "0.13", default-features = false, features = ["use_ring"]}
52 
53 ### scram_sha256_server() sync tests (DEBUG) on AMD Ryzen 5 7600X 6-Core Processor 5453 MHz
54 
55 | iteration | rust-native | use_ring |
56 |-----------|-------------|----------|
57 | 1         | 30.481112ms | 7.813466ms  |
58 
59 
60 ### scram_sha256_works() async tests (DEBUG)
61 
62 | iteration | rust-native | use_ring |
63 |-----------|-------------|----------|
64 | 1         | 30.935835ms | 7.913466ms|
65 
66 For usage see ./examples/
67 For C usage see ./tests/
68 
69 Files:
70 - scram.rs contains client/server sync and async protocol handler
71 - scram_sync.rs a synchronious realization of the protocol handler
72 - scram_async.rs an asynchronious realization of the protocol handler
73 - scram_parser.rs a scram message parser
74 - scram_state.rs a global state of the protocol handler
75 - scram_hashing.rs contains all supported hashers implementation
76 - scram_error.rs error reporting code
77 - scram_common.rs a common code
78 - scram_cb.rs a channel bind code
79 - scram_auth.rs a authentification callbacks and interface
80*/
81
82#![cfg_attr(not(feature = "std"), no_std)]
83
84#[cfg(not(feature = "std"))]
85extern crate alloc;
86
87extern crate async_trait;
88extern crate getrandom;
89extern crate base64;
90extern crate pbkdf2;
91extern crate hmac;
92extern crate sha2;
93extern crate sha1;
94extern crate md5;
95
96//extern crate polyval;
97
98#[cfg(feature = "use_ring")]
99extern crate ring;
100
101pub mod scram;
102pub mod scram_cb;
103pub mod scram_auth;
104pub mod scram_hashing;
105pub mod scram_common;
106pub mod scram_error;
107#[cfg(not(feature = "without_async"))]
108pub mod scram_async;
109pub mod scram_parser;
110pub mod scram_state;
111pub mod scram_sync;
112pub mod scram_sync_client;
113pub mod scram_sync_server;
114#[macro_use]
115pub mod scram_cbh;
116pub mod scram_hashing_sha1;
117pub mod scram_hashing_sha2;
118pub mod scram_hashing_sha5;
119
120#[cfg(not(feature = "without_capi"))]
121pub mod c_api;
122
123pub mod scram_dyn;
124
125pub use scram::*;
126pub use scram_auth::*;
127pub use scram_common::*;
128pub use scram_cb::ChannelBindType;
129pub use scram_hashing::*;
130pub use scram_error::*;
131pub use scram_cbh::*;
132pub use scram_dyn::*;
133pub use scram_common::ScramTypes;
134
135pub use async_trait::async_trait;
136
137