@@ -75,18 +75,22 @@ private void jca_verifySecretKeyReverseEncoding()
75
75
// Legacy key uses reversed encoding
76
76
PGPKeyPair pgpECDHKeyPair = new JcaPGPKeyPair (PublicKeyAlgorithmTags .ECDH , kp , date );
77
77
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 )));
79
80
80
81
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 );
82
84
83
85
// X25519 key uses native encoding
84
86
PGPKeyPair pgpX25519KeyPair = new JcaPGPKeyPair (PublicKeyAlgorithmTags .X25519 , kp , date );
85
87
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 ));
87
90
88
91
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 );
90
94
}
91
95
92
96
/**
@@ -122,18 +126,22 @@ private void bc_verifySecretKeyReverseEncoding()
122
126
// Legacy key uses reversed encoding
123
127
PGPKeyPair pgpECDHKeyPair = new BcPGPKeyPair (PublicKeyAlgorithmTags .ECDH , kp , date );
124
128
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 )));
126
131
127
132
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 );
129
135
130
136
// X25519 key uses native encoding
131
137
PGPKeyPair pgpX25519KeyPair = new BcPGPKeyPair (PublicKeyAlgorithmTags .X25519 , kp , date );
132
138
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 ));
134
141
135
142
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 );
137
145
}
138
146
139
147
/**
0 commit comments