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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/* automatically generated by rust-bindgen 0.57.0 */

pub const true_: u32 = 1;
pub const false_: u32 = 0;
pub const __bool_true_false_are_defined: u32 = 1;
pub const include_p256_verify: u32 = 1;
pub const include_p256_sign: u32 = 1;
pub const include_p256_keygen: u32 = 1;
pub const include_p256_ecdh: u32 = 1;
pub const include_p256_raw_scalarmult_generic: u32 = 1;
pub const include_p256_raw_scalarmult_base: u32 = 1;
pub const include_p256_to_octet_string_uncompressed: u32 = 1;
pub const include_p256_to_octet_string_compressed: u32 = 1;
pub const include_p256_to_octet_string_hybrid: u32 = 1;
pub const include_p256_decompress_point: u32 = 1;
pub const include_p256_decode_point: u32 = 1;
pub const has_fpu: u32 = 0;
pub const has_d_cache: u32 = 0;
pub const use_fast_p256_basemult: u32 = 1;
pub const use_mul_for_sqr: u32 = 0;
pub type int_least64_t = i64;
pub type uint_least64_t = u64;
pub type int_fast64_t = i64;
pub type uint_fast64_t = u64;
pub type int_least32_t = i32;
pub type uint_least32_t = u32;
pub type int_fast32_t = i32;
pub type uint_fast32_t = u32;
pub type int_least16_t = i16;
pub type uint_least16_t = u16;
pub type int_fast16_t = i16;
pub type uint_fast16_t = u16;
pub type int_least8_t = i8;
pub type uint_least8_t = u8;
pub type int_fast8_t = i8;
pub type uint_fast8_t = u8;
pub type intmax_t = cty::c_longlong;
pub type uintmax_t = cty::c_ulonglong;
pub type size_t = cty::c_uint;
pub type wchar_t = cty::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct max_align_t {
    pub __clang_max_align_nonce1: cty::c_longlong,
    pub __clang_max_align_nonce2: f64,
}
#[test]
fn bindgen_test_layout_max_align_t() {
    assert_eq!(
        ::core::mem::size_of::<max_align_t>(),
        16usize,
        concat!("Size of: ", stringify!(max_align_t))
    );
    assert_eq!(
        ::core::mem::align_of::<max_align_t>(),
        8usize,
        concat!("Alignment of ", stringify!(max_align_t))
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<max_align_t>())).__clang_max_align_nonce1 as *const _ as usize
        },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(max_align_t),
            "::",
            stringify!(__clang_max_align_nonce1)
        )
    );
    assert_eq!(
        unsafe {
            &(*(::core::ptr::null::<max_align_t>())).__clang_max_align_nonce2 as *const _ as usize
        },
        8usize,
        concat!(
            "Offset of field: ",
            stringify!(max_align_t),
            "::",
            stringify!(__clang_max_align_nonce2)
        )
    );
}
extern "C" {
    #[doc = " Converts endianness by reversing the input value."]
    #[doc = ""]
    #[doc = " The output and input pointers may refer to the same location and have no alignment requirements."]
    pub fn p256_convert_endianness(
        output: *mut cty::c_void,
        input: *const cty::c_void,
        byte_len: size_t,
    );
}
extern "C" {
    #[doc = " Verifies an ECDSA signature."]
    #[doc = ""]
    #[doc = " Returns true if the signature is valid for the given input, otherwise false."]
    pub fn p256_verify(
        public_key_x: *const u32,
        public_key_y: *const u32,
        hash: *const u8,
        hashlen_in_bytes: u32,
        r: *const u32,
        s: *const u32,
    ) -> bool;
}
extern "C" {
    #[doc = " Creates an ECDSA signature."]
    #[doc = ""]
    #[doc = " The parameter \"k\" shall consist of a 256-bit random integer value. This random value MUST be generated from"]
    #[doc = " a cryptographically secure random number generator, and MUST be unique for every pair of message hash and"]
    #[doc = " private key."]
    #[doc = ""]
    #[doc = " With a small probability (~ 2^-32), this function will fail and return false for the given \"k\" and this"]
    #[doc = " function MUST in that case be called again with a new random \"k\", until true is returned. This is in line"]
    #[doc = " with the ECDSA standard."]
    #[doc = ""]
    #[doc = " As an alternative to using a random \"k\", \"k\" might be derived deterministically from the input, using a"]
    #[doc = " sophisticated hash construction such as RFC 6979, or e.g. by hashing the private key, message hash and a"]
    #[doc = " retry counter, using a secure hash function such as SHA-256."]
    pub fn p256_sign(
        r: *mut u32,
        s: *mut u32,
        hash: *const u8,
        hashlen_in_bytes: u32,
        private_key: *const u32,
        k: *const u32,
    ) -> bool;
}
#[doc = " Sign precomputation state."]
#[doc = ""]
#[doc = " The content shall be treated as opaque to the API user and shall not be inspected or modified."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct SignPrecomp {
    pub r: [u32; 8usize],
    pub k_inv: [u32; 8usize],
}
#[test]
fn bindgen_test_layout_SignPrecomp() {
    assert_eq!(
        ::core::mem::size_of::<SignPrecomp>(),
        64usize,
        concat!("Size of: ", stringify!(SignPrecomp))
    );
    assert_eq!(
        ::core::mem::align_of::<SignPrecomp>(),
        4usize,
        concat!("Alignment of ", stringify!(SignPrecomp))
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<SignPrecomp>())).r as *const _ as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(SignPrecomp),
            "::",
            stringify!(r)
        )
    );
    assert_eq!(
        unsafe { &(*(::core::ptr::null::<SignPrecomp>())).k_inv as *const _ as usize },
        32usize,
        concat!(
            "Offset of field: ",
            stringify!(SignPrecomp),
            "::",
            stringify!(k_inv)
        )
    );
}
extern "C" {
    #[doc = " Creates an ECDSA signature, using a two-step procedure."]
    #[doc = ""]
    #[doc = " This function performs the first of two steps, and accounts for 99% of the time spent for generating an"]
    #[doc = " ECDSA signature."]
    #[doc = ""]
    #[doc = " By splitting up into two steps, most of the work could be spent before deciding what message to sign, or"]
    #[doc = " which private key to use."]
    #[doc = ""]
    #[doc = " The parameter \"k\" shall consist of a 256-bit random integer value. This random value MUST be generated from"]
    #[doc = " a cryptographically secure random number generator, and MUST be unique for every pair of message hash and"]
    #[doc = " private key."]
    #[doc = ""]
    #[doc = " With a small probability (~ 2^-32), this function will fail and return false for the given \"k\" and this"]
    #[doc = " function MUST in that case be called again with a new random \"k\", until true is returned. This is in line"]
    #[doc = " with the ECDSA standard."]
    #[doc = ""]
    #[doc = " As an alternative to using a random \"k\", \"k\" might be derived deterministically from the input, using a"]
    #[doc = " sophisticated hash construction such as RFC 6979, or e.g. by hashing the private key, message hash and a"]
    #[doc = " retry counter, using a secure hash function such as SHA-256."]
    #[doc = ""]
    #[doc = " The \"result\" parameter will contain the computed state, that is later to be passed to p256_sign_step2."]
    #[doc = " A result state MUST NOT be reused for generating multiple signatures."]
    pub fn p256_sign_step1(result: *mut SignPrecomp, k: *const u32) -> bool;
}
extern "C" {
    #[doc = " Second step of creating an ECDSA signature, using a two-step procedure."]
    #[doc = ""]
    #[doc = " This function performs the second of two steps, and accounts for the last 1% of the time spent for generating"]
    #[doc = " an ECDSA signature."]
    #[doc = ""]
    #[doc = " The \"sign_precomp\" parameter shall contain a pointer to a state generated by p256_sign_step1."]
    #[doc = ""]
    #[doc = " With a small probability (~ 2^-256), this function will fail, due to the given \"k\" from the first step is"]
    #[doc = " not compatible with the rest of the input, and return false. In this case, the procedure MUST be started"]
    #[doc = " over from step 1 with a new random \"k\".  This is in line with the ECDSA standard. Otherwise true is returned"]
    #[doc = " and the signature is placed in \"r\" and \"s\"."]
    #[doc = ""]
    #[doc = " When this function returns, \"sign_precomp\" is also zeroed out and may hence not be reused."]
    pub fn p256_sign_step2(
        r: *mut u32,
        s: *mut u32,
        hash: *const u8,
        hashlen_in_bytes: u32,
        private_key: *const u32,
        sign_precomp: *mut SignPrecomp,
    ) -> bool;
}
extern "C" {
    #[doc = " Calculates the public key from a given private key for use by either ECDSA or ECDH."]
    #[doc = ""]
    #[doc = " The private key shall be taken from a random value that MUST have been generated by a cryptographically"]
    #[doc = " secure random number generator that generates 256 random bits. This function validates that the private key"]
    #[doc = " lies in the accepted range 1 to n-1, where n is the order of the elliptic curve, and returns true only if"]
    #[doc = " this validation succeeds. If random value is out of that range, false is returned and in this case a new"]
    #[doc = " random value needs to be generated and this function MUST be called again until true is returned."]
    #[doc = ""]
    #[doc = " The public key is created by performing a scalar multiplication of the private key and the base point of"]
    #[doc = " the curve."]
    #[doc = ""]
    #[doc = " Only use a keypair for either ECDSA or ECDH, not both, and don't use the private key for any other purposes."]
    pub fn p256_keygen(
        public_key_x: *mut u32,
        public_key_y: *mut u32,
        private_key: *const u32,
    ) -> bool;
}
extern "C" {
    #[doc = " Generates the shared secret according to the ECDH standard."]
    #[doc = ""]
    #[doc = " The shared secret parameter will contain the big endian encoding for the x coordinate of the scalar"]
    #[doc = " multiplication of the private key and the input point (other's public key), if the function succeeds."]
    #[doc = ""]
    #[doc = " If the other's public key point does not lie on the curve, this function fails and false is returned."]
    #[doc = " Otherwise, shared secret is calculated and true is returned."]
    #[doc = ""]
    #[doc = " NOTE: The return value MUST be checked since the other's public key point cannot generally be trusted."]
    pub fn p256_ecdh_calc_shared_secret(
        shared_secret: *mut u8,
        private_key: *const u32,
        others_public_key_x: *const u32,
        others_public_key_y: *const u32,
    ) -> bool;
}
extern "C" {
    #[doc = " Raw scalar multiplication by the base point of the elliptic curve."]
    #[doc = ""]
    #[doc = " This function can be used to implement custom algorithms using the P-256 curve."]
    #[doc = ""]
    #[doc = " This function validates that the scalar lies in the accepted range 1 to n-1, where n is the order of the"]
    #[doc = " elliptic curve, and returns true only if this validation succeeds. Otherwise false is returned."]
    pub fn p256_scalarmult_base(result_x: *mut u32, result_y: *mut u32, scalar: *const u32)
        -> bool;
}
extern "C" {
    #[doc = " Raw scalar multiplication by any point on the elliptic curve."]
    #[doc = ""]
    #[doc = " This function can be used to implement custom algorithms using the P-256 curve."]
    #[doc = ""]
    #[doc = " This function validates all inputs and proceeds only if the scalar is within the range 1 to n-1, where n"]
    #[doc = " is the order of the elliptic curve, and the input point's coordinates are each less than the order of"]
    #[doc = " the prime field. If validation succeeds, true is returned. Otherwise false is returned."]
    pub fn p256_scalarmult_generic(
        result_x: *mut u32,
        result_y: *mut u32,
        scalar: *const u32,
        in_x: *const u32,
        in_y: *const u32,
    ) -> bool;
}
extern "C" {
    #[doc = " Uncompressed encoding: \"04 || Px || Py\"."]
    pub fn p256_point_to_octet_string_uncompressed(out: *mut u8, x: *const u32, y: *const u32);
}
extern "C" {
    #[doc = " Compressed encoding: \"02 || Px\" if Py is even and \"03 || Px\" if Py is odd."]
    pub fn p256_point_to_octet_string_compressed(out: *mut u8, x: *const u32, y: *const u32);
}
extern "C" {
    #[doc = " Hybrid encoding: \"06 || Px || Py\" if Py is even and \"07 || Px || Py\" if Py is odd (a pretty useless encoding)."]
    pub fn p256_point_to_octet_string_hybrid(out: *mut u8, x: *const u32, y: *const u32);
}
extern "C" {
    #[doc = " Decodes a point according to the three encodings above."]
    #[doc = ""]
    #[doc = " include_p256_decode_point: first byte is \"04\", \"06\" or \"07\" and input length is 65 bytes"]
    #[doc = " include_p256_decompress_point: first byte is \"02\" or \"03\" and input length is 33 bytes"]
    #[doc = ""]
    #[doc = " Returns true if the input string confirms to a valid encoding and the point lies on the curve,"]
    #[doc = " otherwise false."]
    #[doc = ""]
    #[doc = " NOTE: The return value MUST be checked in case the point is not guaranteed to lie on the curve (e.g. if it"]
    #[doc = " is received from an untrusted party)."]
    pub fn p256_octet_string_to_point(
        x: *mut u32,
        y: *mut u32,
        input: *const u8,
        input_len_in_bytes: u32,
    ) -> bool;
}
extern "C" {
    #[doc = " Checks that the argument, as little-endian integer, is a reduced non-zero element of the scalar field."]
    #[doc = ""]
    #[doc = " In other words, that it is in the range `1..=n-1`, where `n = 2^256 - 2^224 + 2^192 - 0x4319055258e8617b0c46353d039cdaaf`."]
    #[doc = ""]
    pub fn P256_check_range_n(a: *const u32) -> bool;
}
extern "C" {
    #[doc = " Checks that the argument, as little-endian integer, is a reduced element of the base field."]
    #[doc = ""]
    #[doc = " In other words, that it is in the range `0..=p-1`, where `p = 2^256 - 2^224 + 2^192 + 2^96 - 1`."]
    pub fn P256_check_range_p(a: *const u32) -> bool;
}