@@ -178,16 +178,20 @@ public PGPSignature generate()
178178 sigValues = new MPInteger [1 ];
179179 sigValues [0 ] = new MPInteger (new BigInteger (1 , contentSigner .getSignature ()));
180180 }
181- else if (contentSigner .getKeyAlgorithm () == PublicKeyAlgorithmTags .EDDSA_LEGACY ||
182- contentSigner .getKeyAlgorithm () == PublicKeyAlgorithmTags .Ed25519 ||
183- contentSigner .getKeyAlgorithm () == PublicKeyAlgorithmTags .Ed448 )
181+ else if (contentSigner .getKeyAlgorithm () == PublicKeyAlgorithmTags .EDDSA_LEGACY )
184182 {
185183 byte [] enc = contentSigner .getSignature ();
186184 sigValues = new MPInteger []{
187185 new MPInteger (new BigInteger (1 , Arrays .copyOfRange (enc , 0 , enc .length / 2 ))),
188186 new MPInteger (new BigInteger (1 , Arrays .copyOfRange (enc , enc .length / 2 , enc .length )))
189187 };
190188 }
189+ else if (contentSigner .getKeyAlgorithm () == PublicKeyAlgorithmTags .Ed25519 ||
190+ contentSigner .getKeyAlgorithm () == PublicKeyAlgorithmTags .Ed448 )
191+ {
192+ // Contrary to EDDSA_LEGACY, the new PK algorithms Ed25519, Ed448 do not use MPI encoding
193+ sigValues = null ;
194+ }
191195 else
192196 {
193197 sigValues = PGPUtil .dsaSigToMpi (contentSigner .getSignature ());
@@ -199,7 +203,14 @@ else if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.EDDSA_LEGACY
199203 fingerPrint [0 ] = digest [0 ];
200204 fingerPrint [1 ] = digest [1 ];
201205
202- return new PGPSignature (new SignaturePacket (sigType , contentSigner .getKeyID (), contentSigner .getKeyAlgorithm (), contentSigner .getHashAlgorithm (), hPkts , unhPkts , fingerPrint , sigValues ));
206+ if (sigValues != null ) {
207+ return new PGPSignature (new SignaturePacket (sigType , contentSigner .getKeyID (), contentSigner .getKeyAlgorithm (),
208+ contentSigner .getHashAlgorithm (), hPkts , unhPkts , fingerPrint , sigValues ));
209+ } else {
210+ // Ed25519, Ed448 use raw encoding instead of MPI
211+ return new PGPSignature (new SignaturePacket (4 , sigType , contentSigner .getKeyID (), contentSigner .getKeyAlgorithm (),
212+ contentSigner .getHashAlgorithm (), hPkts , unhPkts , fingerPrint , contentSigner .getSignature ()));
213+ }
203214 }
204215
205216 /**
0 commit comments