@@ -75,18 +75,22 @@ private void jca_verifySecretKeyReverseEncoding()
7575 // Legacy key uses reversed encoding
7676 PGPKeyPair pgpECDHKeyPair = new JcaPGPKeyPair (PublicKeyAlgorithmTags .ECDH , kp , date );
7777 byte [] encodedECDHPrivateKey = pgpECDHKeyPair .getPrivateKey ().getPrivateKeyDataPacket ().getEncoded ();
78- isTrue (containsSubsequence (encodedECDHPrivateKey , Arrays .reverse (rawPrivateKey )));
78+ isTrue ("ECDH Curve25519Legacy (X25519) key MUST encode secret key in 'reverse' (big-endian MPI encoding) (JCE implementation)" ,
79+ containsSubsequence (encodedECDHPrivateKey , Arrays .reverse (rawPrivateKey )));
7980
8081 byte [] decodedECDHPrivateKey = jcaNativePrivateKey (c .getPrivateKey (pgpECDHKeyPair .getPrivateKey ()));
81- isEncodingEqual (decodedECDHPrivateKey , rawPrivateKey );
82+ isEncodingEqual ("Decoded ECDH Curve25519Legacy (X25519) key MUST match original raw key (JCE implementation)" ,
83+ decodedECDHPrivateKey , rawPrivateKey );
8284
8385 // X25519 key uses native encoding
8486 PGPKeyPair pgpX25519KeyPair = new JcaPGPKeyPair (PublicKeyAlgorithmTags .X25519 , kp , date );
8587 byte [] encodedX25519PrivateKey = pgpX25519KeyPair .getPrivateKey ().getPrivateKeyDataPacket ().getEncoded ();
86- isTrue (containsSubsequence (encodedX25519PrivateKey , rawPrivateKey ));
88+ isTrue ("X25519 key MUST use native encoding (little-endian) to encode the secret key material (JCE implementation)" ,
89+ containsSubsequence (encodedX25519PrivateKey , rawPrivateKey ));
8790
8891 byte [] decodedX25519PrivateKey = jcaNativePrivateKey (c .getPrivateKey (pgpX25519KeyPair .getPrivateKey ()));
89- isEncodingEqual (rawPrivateKey , decodedX25519PrivateKey );
92+ isEncodingEqual ("Decoded X25519 key MUST match original raw key (JCE implementation)" ,
93+ rawPrivateKey , decodedX25519PrivateKey );
9094 }
9195
9296 /**
@@ -122,18 +126,22 @@ private void bc_verifySecretKeyReverseEncoding()
122126 // Legacy key uses reversed encoding
123127 PGPKeyPair pgpECDHKeyPair = new BcPGPKeyPair (PublicKeyAlgorithmTags .ECDH , kp , date );
124128 byte [] encodedECDHPrivateKey = pgpECDHKeyPair .getPrivateKey ().getPrivateKeyDataPacket ().getEncoded ();
125- isTrue (containsSubsequence (encodedECDHPrivateKey , Arrays .reverse (rawPrivateKey )));
129+ isTrue ("ECDH Curve25519Legacy (X25519) key MUST encode secret key in 'reverse' (big-endian MPI encoding) (BC implementation)" ,
130+ containsSubsequence (encodedECDHPrivateKey , Arrays .reverse (rawPrivateKey )));
126131
127132 byte [] decodedECDHPrivateKey = ((X25519PrivateKeyParameters ) c .getPrivateKey (pgpECDHKeyPair .getPrivateKey ())).getEncoded ();
128- isEncodingEqual (decodedECDHPrivateKey , rawPrivateKey );
133+ isEncodingEqual ("Decoded ECDH Curve25519Legacy (X25519) key MUST match original raw key (BC implementation)" ,
134+ decodedECDHPrivateKey , rawPrivateKey );
129135
130136 // X25519 key uses native encoding
131137 PGPKeyPair pgpX25519KeyPair = new BcPGPKeyPair (PublicKeyAlgorithmTags .X25519 , kp , date );
132138 byte [] encodedX25519PrivateKey = pgpX25519KeyPair .getPrivateKey ().getPrivateKeyDataPacket ().getEncoded ();
133- isTrue (containsSubsequence (encodedX25519PrivateKey , rawPrivateKey ));
139+ isTrue ("X25519 key MUST use native encoding (little-endian) to encode the secret key material (BC implementation)" ,
140+ containsSubsequence (encodedX25519PrivateKey , rawPrivateKey ));
134141
135142 byte [] decodedX25519PrivateKey = ((X25519PrivateKeyParameters ) c .getPrivateKey (pgpX25519KeyPair .getPrivateKey ())).getEncoded ();
136- isEncodingEqual (rawPrivateKey , decodedX25519PrivateKey );
143+ isEncodingEqual ("Decoded X25519 key MUST match original raw key (BC implementation)" ,
144+ rawPrivateKey , decodedX25519PrivateKey );
137145 }
138146
139147 /**
0 commit comments