File tree Expand file tree Collapse file tree
j2me/org/bouncycastle/math/ec
jdk1.2/org/bouncycastle/math/ec Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818import org .bouncycastle .util .BigIntegers ;
1919import org .bouncycastle .util .Integers ;
2020import org .bouncycastle .util .Properties ;
21+ import org .bouncycastle .util .Strings ;
2122
2223/**
2324 * base class for an elliptic curve
@@ -381,6 +382,14 @@ public ECPoint decodePoint(byte[] encoded)
381382 ECPoint p = null ;
382383 int expectedLength = (this .getFieldSize () + 7 ) / 8 ;
383384
385+ if (encoded == null || encoded .length < 1 )
386+ {
387+ // An empty (or null) encoding must be reported as a malformed encoding, not leak an
388+ // ArrayIndexOutOfBoundsException out of the point decoder to every caller that decodes
389+ // an untrusted point (EC key parse, ECDH/ECIES/TLS ephemeral points).
390+ throw new IllegalArgumentException ("Invalid point encoding: empty" );
391+ }
392+
384393 byte type = encoded [0 ];
385394 switch (type )
386395 {
@@ -446,7 +455,8 @@ public ECPoint decodePoint(byte[] encoded)
446455 break ;
447456 }
448457 default :
449- throw new IllegalArgumentException ("Invalid point encoding type: 0x" + Integer .toString (type , 16 ));
458+ throw new IllegalArgumentException ("Invalid point encoding type: 0x"
459+ + Strings .toUpperCase (Integer .toHexString (0x100 | (type & 0xFF )).substring (1 )));
450460 }
451461
452462 if (type != 0x00 && p .isInfinity ())
Original file line number Diff line number Diff line change 99import org .bouncycastle .crypto .params .ECDomainParameters ;
1010import org .bouncycastle .crypto .params .ECPublicKeyParameters ;
1111import org .bouncycastle .math .ec .ECCurve ;
12+ import org .bouncycastle .util .Strings ;
1213import org .bouncycastle .util .io .Streams ;
1314
1415public class ECIESPublicKeyParser
@@ -50,7 +51,7 @@ public AsymmetricKeyParameter readKey(InputStream stream)
5051
5152 default :
5253 throw new IOException ("Sender's public key has invalid point encoding type: 0x"
53- + String . format ( "%02X" , first ));
54+ + Strings . toUpperCase ( Integer . toHexString ( 0x100 | first ). substring ( 1 ) ));
5455 }
5556
5657 ECCurve curve = ecParams .getCurve ();
Original file line number Diff line number Diff line change 1818import org .bouncycastle .util .BigIntegers ;
1919import org .bouncycastle .util .Integers ;
2020import org .bouncycastle .util .Properties ;
21+ import org .bouncycastle .util .Strings ;
2122
2223/**
2324 * base class for an elliptic curve
@@ -467,7 +468,8 @@ public ECPoint decodePoint(byte[] encoded)
467468 break ;
468469 }
469470 default :
470- throw new IllegalArgumentException ("Invalid point encoding type: 0x" + String .format ("%02X" , type ));
471+ throw new IllegalArgumentException ("Invalid point encoding type: 0x"
472+ + Strings .toUpperCase (Integer .toHexString (0x100 | (type & 0xFF )).substring (1 )));
471473 }
472474
473475 if (type != 0x00 && p .isInfinity ())
Original file line number Diff line number Diff line change 1818import org .bouncycastle .util .BigIntegers ;
1919import org .bouncycastle .util .Integers ;
2020import org .bouncycastle .util .Properties ;
21+ import org .bouncycastle .util .Strings ;
2122
2223/**
2324 * base class for an elliptic curve
@@ -394,6 +395,14 @@ public ECPoint decodePoint(byte[] encoded)
394395 ECPoint p = null ;
395396 int expectedLength = getFieldElementEncodingLength ();
396397
398+ if (encoded == null || encoded .length < 1 )
399+ {
400+ // An empty (or null) encoding must be reported as a malformed encoding, not leak an
401+ // ArrayIndexOutOfBoundsException out of the point decoder to every caller that decodes
402+ // an untrusted point (EC key parse, ECDH/ECIES/TLS ephemeral points).
403+ throw new IllegalArgumentException ("Invalid point encoding: empty" );
404+ }
405+
397406 byte type = encoded [0 ];
398407 switch (type )
399408 {
@@ -459,7 +468,8 @@ public ECPoint decodePoint(byte[] encoded)
459468 break ;
460469 }
461470 default :
462- throw new IllegalArgumentException ("Invalid point encoding type: 0x" + Integer .toString (type , 16 ));
471+ throw new IllegalArgumentException ("Invalid point encoding type: 0x"
472+ + Strings .toUpperCase (Integer .toHexString (0x100 | (type & 0xFF )).substring (1 )));
463473 }
464474
465475 if (type != 0x00 && p .isInfinity ())
You can’t perform that action at this time.
0 commit comments