@@ -133,17 +133,17 @@ public IntPtr GetProcAddress(IntPtr dllHandle, string name)
133133 #region Function mapping
134134
135135 private delegate int CreateSeedDelegate (
136- [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] outputSeed
136+ [ MarshalAs ( UnmanagedType . LPArray , SizeConst = 32 ) ] byte [ ] outputSeed
137137 ) ;
138138
139139 private delegate void CreateKeypairDelegate (
140- [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] outputPublicKey ,
141- [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] outputPrivateKey ,
140+ [ MarshalAs ( UnmanagedType . LPArray , SizeConst = 32 ) ] byte [ ] outputPublicKey ,
141+ [ MarshalAs ( UnmanagedType . LPArray , SizeConst = 64 ) ] byte [ ] outputPrivateKey ,
142142 [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] inputSeed
143143 ) ;
144144
145145 private delegate void SignDelegate (
146- [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] outputSignature ,
146+ [ MarshalAs ( UnmanagedType . LPArray , SizeConst = 64 ) ] byte [ ] outputSignature ,
147147 [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] inputMessage ,
148148 [ MarshalAs ( UnmanagedType . U8 ) ] ulong inputMessageLength ,
149149 [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] inputPublicKey ,
@@ -158,20 +158,20 @@ private delegate int VerifyDelegate(
158158 ) ;
159159
160160 private delegate void AddScalarDelegate (
161- [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] outputPublicKey ,
162- [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] outputPrivateKey ,
161+ [ MarshalAs ( UnmanagedType . LPArray , SizeConst = 32 ) ] byte [ ] publicKey ,
162+ [ MarshalAs ( UnmanagedType . LPArray , SizeConst = 64 ) ] byte [ ] privateKey ,
163163 [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] inputScalar
164164 ) ;
165165
166166 private delegate void KeyExchangeDelegate (
167- [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] outputSharedSecret ,
167+ [ MarshalAs ( UnmanagedType . LPArray , SizeConst = 32 ) ] byte [ ] outputSharedSecret ,
168168 [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] inputPublicKey ,
169169 [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] inputPrivateKey
170170 ) ;
171171
172172 private delegate void Ref10KeyConversionDelegate (
173173 [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] inputPrivateKey ,
174- [ MarshalAs ( UnmanagedType . LPArray ) ] byte [ ] outputPrivateKey
174+ [ MarshalAs ( UnmanagedType . LPArray , SizeConst = 64 ) ] byte [ ] outputPrivateKey
175175 ) ;
176176
177177 #endregion
@@ -536,7 +536,12 @@ internal class OrlpEd25519ContextExample
536536 {
537537 static void Main ( )
538538 {
539- Console . WriteLine ( "--- orlp-ed25519 ---\n " ) ;
539+ static string BytesToHexString ( byte [ ] bytes )
540+ {
541+ return BitConverter . ToString ( bytes ) . Replace ( "-" , "" ) ;
542+ }
543+
544+ Console . WriteLine ( "\n --- orlp-ed25519 ---\n " ) ;
540545
541546 const string messageString = "Rise and shine, Dr. Freeman... rise and... shiiine!" ;
542547
@@ -556,14 +561,14 @@ static void Main()
556561
557562 ed25519 . AddScalar ( keypair . Item1 , keypair . Item2 , seed2 ) ;
558563
559- Console . WriteLine ( $ "Generated seed: { BitConverter . ToString ( seed ) . Replace ( "-" , "" ) } \n \n ") ;
560- Console . WriteLine ( $ "Generated public key: { BitConverter . ToString ( keypair . Item1 ) . Replace ( "-" , "" ) } \n \n ") ;
561- Console . WriteLine ( $ "Generated private key: { BitConverter . ToString ( keypair . Item2 ) . Replace ( "-" , "" ) } \n \n ") ;
562- Console . WriteLine ( $ "Message: { messageString } \n \n ") ;
563- Console . WriteLine ( $ "Signature: { BitConverter . ToString ( signature ) . Replace ( "-" , "" ) } \n \n ") ;
564- Console . WriteLine ( $ "Valid: { valid } \n \n ") ;
565- Console . WriteLine ( $ "Public key after adding scalar \" { BitConverter . ToString ( seed2 ) . Replace ( "-" , "" ) } \" : { BitConverter . ToString ( keypair . Item1 ) . Replace ( "-" , "" ) } \n \n ") ;
566- Console . WriteLine ( $ "Private key after adding scalar \" { BitConverter . ToString ( seed2 ) . Replace ( "-" , "" ) } \" : { BitConverter . ToString ( keypair . Item2 ) . Replace ( "-" , "" ) } \n \n ") ;
564+ Console . WriteLine ( $ "Generated seed: { BytesToHexString ( seed ) } \n ") ;
565+ Console . WriteLine ( $ "Generated public key: { BytesToHexString ( keypair . Item1 ) } \n ") ;
566+ Console . WriteLine ( $ "Generated private key: { BytesToHexString ( keypair . Item2 ) } \n ") ;
567+ Console . WriteLine ( $ "Message: { messageString } \n ") ;
568+ Console . WriteLine ( $ "Signature: { BytesToHexString ( signature ) } \n ") ;
569+ Console . WriteLine ( $ "Valid: { valid } \n ") ;
570+ Console . WriteLine ( $ "Public key after adding scalar \" { BytesToHexString ( seed2 ) } \" : { BytesToHexString ( keypair . Item1 ) } \n ") ;
571+ Console . WriteLine ( $ "Private key after adding scalar \" { BytesToHexString ( seed2 ) } \" : { BytesToHexString ( keypair . Item2 ) } \n ") ;
567572 }
568573 }
569574}
0 commit comments