@@ -23,8 +23,8 @@ use p256::{ecdsa, FieldBytes, ProjectivePoint, PublicKey};
2323use rand_chacha:: ChaCha20Rng ;
2424use sha2:: { Digest , Sha256 } ;
2525use signature:: { Signer , Verifier as SignatureVerifier } ;
26- use std :: collections:: BTreeMap ;
27- use std :: io :: Write ;
26+ use alloc :: collections:: BTreeMap ;
27+ use alloc :: vec :: Vec ;
2828
2929pub ( crate ) struct Verifier {
3030 blinded_subscriber_share : p256:: Scalar ,
@@ -46,18 +46,41 @@ pub(crate) struct Pass {
4646impl Pass {
4747 pub ( crate ) fn to_bytes ( & self ) -> [ u8 ; 308 ] {
4848 let mut encoded = [ 0u8 ; 308 ] ;
49- let mut buf = & mut encoded[ ..] ;
50- buf. write_all ( & challenge_to_bytes ( self . subscriber_commitments ) )
51- . unwrap ( ) ; // 66
52- buf. write_all ( & self . authenticator_proof . sig_device . to_bytes ( ) )
53- . unwrap ( ) ; // 64
54- buf. write_all ( self . binding . pk . to_encoded_point ( true ) . as_bytes ( ) )
55- . unwrap ( ) ; // 33
56- buf. write_all ( & self . binding . signature . to_bytes ( ) ) . unwrap ( ) ; // 64
57- buf. write_all ( & pk_sender_to_bytes ( & self . pk_kem_sender ) )
58- . unwrap ( ) ; // 33
59- buf. write_all ( & self . sealed_signature_share ) . unwrap ( ) ; // 32
60- buf. write_all ( & self . tag . to_bytes ( ) ) . unwrap ( ) ; // 16
49+ let mut offset = 0 ;
50+
51+ // 66 bytes
52+ let challenge_bytes = challenge_to_bytes ( self . subscriber_commitments ) ;
53+ encoded[ offset..offset + 66 ] . copy_from_slice ( & challenge_bytes) ;
54+ offset += 66 ;
55+
56+ // 64 bytes
57+ let sig_device_bytes = self . authenticator_proof . sig_device . to_bytes ( ) ;
58+ encoded[ offset..offset + 64 ] . copy_from_slice ( & sig_device_bytes) ;
59+ offset += 64 ;
60+
61+ // 33 bytes
62+ let pk_bytes = self . binding . pk . to_encoded_point ( true ) ;
63+ encoded[ offset..offset + 33 ] . copy_from_slice ( pk_bytes. as_bytes ( ) ) ;
64+ offset += 33 ;
65+
66+ // 64 bytes
67+ let signature_bytes = self . binding . signature . to_bytes ( ) ;
68+ encoded[ offset..offset + 64 ] . copy_from_slice ( & signature_bytes) ;
69+ offset += 64 ;
70+
71+ // 33 bytes
72+ let pk_sender_bytes = pk_sender_to_bytes ( & self . pk_kem_sender ) ;
73+ encoded[ offset..offset + 33 ] . copy_from_slice ( & pk_sender_bytes) ;
74+ offset += 33 ;
75+
76+ // 32 bytes
77+ encoded[ offset..offset + 32 ] . copy_from_slice ( & self . sealed_signature_share ) ;
78+ offset += 32 ;
79+
80+ // 16 bytes
81+ let tag_bytes = self . tag . to_bytes ( ) ;
82+ encoded[ offset..offset + 16 ] . copy_from_slice ( & tag_bytes) ;
83+
6184 encoded
6285 }
6386
@@ -151,11 +174,22 @@ impl ClientExtensionTranscript {
151174impl ClientExtensionTranscript {
152175 pub ( crate ) fn to_bytes ( & self ) -> [ u8 ; 129 ] {
153176 let mut encoded = [ 0u8 ; 129 ] ;
154- let mut buf = & mut encoded[ ..] ;
155- buf. write_all ( & self . pk_binding . to_encoded_point ( true ) . as_bytes ( ) )
156- . unwrap ( ) ;
157- buf. write_all ( & self . sig_binding . to_bytes ( ) ) . unwrap ( ) ;
158- buf. write_all ( & self . sig_joint_second . to_bytes ( ) ) . unwrap ( ) ;
177+ let mut offset = 0 ;
178+
179+ // 33 bytes
180+ let pk_binding_bytes = self . pk_binding . to_encoded_point ( true ) ;
181+ encoded[ offset..offset + 33 ] . copy_from_slice ( pk_binding_bytes. as_bytes ( ) ) ;
182+ offset += 33 ;
183+
184+ // 64 bytes
185+ let sig_binding_bytes = self . sig_binding . to_bytes ( ) ;
186+ encoded[ offset..offset + 64 ] . copy_from_slice ( & sig_binding_bytes) ;
187+ offset += 64 ;
188+
189+ // 32 bytes
190+ let sig_joint_second_bytes = self . sig_joint_second . to_bytes ( ) ;
191+ encoded[ offset..offset + 32 ] . copy_from_slice ( & sig_joint_second_bytes) ;
192+
159193 encoded
160194 }
161195}
@@ -187,7 +221,7 @@ pub(crate) struct Provider {
187221#[ derive( Debug , PartialEq ) ]
188222pub ( crate ) struct VerificationError ;
189223
190- pub ( crate ) type Result = std :: result:: Result < ( ) , VerificationError > ;
224+ pub ( crate ) type Result = core :: result:: Result < ( ) , VerificationError > ;
191225
192226fn aad ( masked_subscriber_share : & p256:: Scalar , pk_joint : & frost:: VerifyingKey ) -> Vec < u8 > {
193227 [
@@ -665,7 +699,7 @@ mod test {
665699 let mut rng_hpke = rand_chacha:: ChaCha20Rng :: from_seed ( seed) ;
666700 let ( sk_r, pk_r) = DhP256HkdfSha256 :: gen_keypair ( & mut rng_hpke) ;
667701 let verifier = Verifier :: new ( & pk_r, & mask, & mut rng_hpke) ;
668- println ! ( "size of share: {:?}" , verifier . sealed_provider_share . len ( ) ) ;
702+ // Removed println! for no_std compatibility
669703 let shared_secret = dh ( & sk_r, & verifier. pk_kem_subscriber ) ;
670704 let s = verifier. verify ( shared_secret, & pk_r) ;
671705 assert ! ( s. is_some( ) ) ;
0 commit comments