|
1 | 1 | use core::{fmt, hash};
|
2 |
| -use {types::*, Context, PublicKey, Signature}; |
| 2 | +use {types::*, Context, NonceFn, PublicKey, Signature}; |
3 | 3 |
|
4 | 4 | /// Rangeproof maximum length
|
5 | 5 | pub const RANGEPROOF_MAX_LENGTH: size_t = 5134;
|
6 | 6 | pub const ECDSA_ADAPTOR_SIGNATURE_LENGTH: size_t = 162;
|
7 | 7 |
|
| 8 | +/// The maximum number of whitelist keys. |
| 9 | +pub const WHITELIST_MAX_N_KEYS: size_t = 255; |
| 10 | + |
8 | 11 | extern "C" {
|
9 | 12 | #[cfg_attr(
|
10 | 13 | not(feature = "external-symbols"),
|
@@ -334,6 +337,59 @@ extern "C" {
|
334 | 337 | adaptor_sig162: *const EcdsaAdaptorSignature,
|
335 | 338 | enckey: *const PublicKey,
|
336 | 339 | ) -> c_int;
|
| 340 | + |
| 341 | + #[cfg_attr( |
| 342 | + not(feature = "external-symbols"), |
| 343 | + link_name = "rustsecp256k1zkp_v0_4_0_whitelist_signature_parse" |
| 344 | + )] |
| 345 | + pub fn secp256k1_whitelist_signature_parse( |
| 346 | + cx: *const Context, |
| 347 | + sig: *mut WhitelistSignature, |
| 348 | + input: *const c_uchar, |
| 349 | + input_len: size_t, |
| 350 | + ) -> c_int; |
| 351 | + |
| 352 | + #[cfg_attr( |
| 353 | + not(feature = "external-symbols"), |
| 354 | + link_name = "rustsecp256k1zkp_v0_4_0_whitelist_signature_serialize" |
| 355 | + )] |
| 356 | + pub fn secp256k1_whitelist_signature_serialize( |
| 357 | + ctx: *const Context, |
| 358 | + output: *mut c_uchar, |
| 359 | + outputlen: *mut size_t, |
| 360 | + sig: *const WhitelistSignature, |
| 361 | + ) -> c_int; |
| 362 | + |
| 363 | + #[cfg_attr( |
| 364 | + not(feature = "external-symbols"), |
| 365 | + link_name = "rustsecp256k1zkp_v0_4_0_whitelist_sign" |
| 366 | + )] |
| 367 | + pub fn secp256k1_whitelist_sign( |
| 368 | + ctx: *const Context, |
| 369 | + sig: *mut WhitelistSignature, |
| 370 | + online_keys: *const PublicKey, |
| 371 | + offline_keys: *const PublicKey, |
| 372 | + n_keys: size_t, |
| 373 | + sub_pubkey: *const PublicKey, |
| 374 | + online_seckey: *const c_uchar, |
| 375 | + summed_seckey: *const c_uchar, |
| 376 | + index: size_t, |
| 377 | + noncefp: NonceFn, |
| 378 | + noncedata: *mut c_void, |
| 379 | + ) -> c_int; |
| 380 | + |
| 381 | + #[cfg_attr( |
| 382 | + not(feature = "external-symbols"), |
| 383 | + link_name = "rustsecp256k1zkp_v0_4_0_whitelist_verify" |
| 384 | + )] |
| 385 | + pub fn secp256k1_whitelist_verify( |
| 386 | + ctx: *const Context, |
| 387 | + sig: *const WhitelistSignature, |
| 388 | + online_keys: *const PublicKey, |
| 389 | + offline_keys: *const PublicKey, |
| 390 | + n_keys: size_t, |
| 391 | + sub_pubkey: *const PublicKey, |
| 392 | + ) -> c_int; |
337 | 393 | }
|
338 | 394 |
|
339 | 395 | #[repr(C)]
|
@@ -476,6 +532,39 @@ impl hash::Hash for PedersenCommitment {
|
476 | 532 | }
|
477 | 533 | }
|
478 | 534 |
|
| 535 | +/// A ring signature for the "whitelist" scheme. |
| 536 | +#[repr(C)] |
| 537 | +#[derive(Clone)] |
| 538 | +pub struct WhitelistSignature { |
| 539 | + /// The number of keys. |
| 540 | + pub n_keys: size_t, |
| 541 | + /// The signature in the form of e0 + n_keys s values. |
| 542 | + pub data: [u8; 32 * (1 + WHITELIST_MAX_N_KEYS)], |
| 543 | +} |
| 544 | + |
| 545 | +impl hash::Hash for WhitelistSignature { |
| 546 | + fn hash<H: hash::Hasher>(&self, state: &mut H) { |
| 547 | + self.n_keys.hash(state); |
| 548 | + self.data[..].hash(state); |
| 549 | + } |
| 550 | +} |
| 551 | + |
| 552 | +impl PartialEq for WhitelistSignature { |
| 553 | + fn eq(&self, other: &Self) -> bool { |
| 554 | + self.n_keys == other.n_keys && self.data[..] == other.data[..] |
| 555 | + } |
| 556 | +} |
| 557 | +impl Eq for WhitelistSignature {} |
| 558 | + |
| 559 | +impl Default for WhitelistSignature { |
| 560 | + fn default() -> WhitelistSignature { |
| 561 | + WhitelistSignature { |
| 562 | + n_keys: 0, |
| 563 | + data: [0; 32 * (1 + WHITELIST_MAX_N_KEYS)], |
| 564 | + } |
| 565 | + } |
| 566 | +} |
| 567 | + |
479 | 568 | /// Same as secp256k1_nonce_function_hardened with the exception of using the
|
480 | 569 | /// compressed 33-byte encoding for the pubkey argument.
|
481 | 570 | pub type EcdsaAdaptorNonceFn = Option<
|
|
0 commit comments