@@ -5621,27 +5621,36 @@ show_key(CK_SESSION_HANDLE sess, CK_OBJECT_HANDLE obj)
5621
5621
}
5622
5622
if (pub ) {
5623
5623
unsigned char * bytes = NULL ;
5624
+ unsigned char * body ;
5625
+
5624
5626
unsigned long ksize = 0 ;
5625
5627
unsigned int n ;
5626
5628
unsigned long body_len = 0 ;
5627
5629
5628
- bytes = getEC_POINT (sess , obj , & ksize );
5630
+ bytes = getEC_POINT (sess , obj , & size );
5629
5631
/*
5630
5632
* simple parse of DER BIT STRING 0x03 or OCTET STRING 0x04
5631
5633
* good to 65K bytes
5632
5634
*/
5633
- if (ksize > 3 && (bytes [0 ] == 0x03 || bytes [0 ] == 0x04 )) {
5634
- if (bytes [1 ] <= 127 && ksize == (unsigned long )(bytes [1 ] + 2 )) {
5635
- body_len = ksize - 2 ;
5635
+ if (size > 3 && (bytes [0 ] == 0x03 || bytes [0 ] == 0x04 )) {
5636
+ if (bytes [1 ] <= 127 && size == (unsigned long )(bytes [1 ] + 2 )) {
5637
+ body_len = size - 2 ;
5638
+ body = bytes + 2 ;
5636
5639
} else if (bytes [1 ] == 0x81 && size == ((unsigned long )bytes [2 ] + 3 )) {
5637
- body_len = ksize - 3 ;
5640
+ body_len = size - 3 ;
5641
+ body = bytes + 3 ;
5638
5642
} else if (bytes [1 ] == 0x82 && size == ((unsigned long )(bytes [2 ] << 8 ) + (unsigned long )bytes [3 ] + 4 )) {
5639
- body_len = ksize - 4 ;
5643
+ body_len = size - 4 ;
5644
+ body = bytes + 4 ;
5645
+ } else {
5646
+ body_len = 0 ; /* some problem with size */
5640
5647
}
5641
5648
}
5642
5649
/* With BIT STRING remove unused bits in last byte indicator */
5643
- if (body_len > 0 && bytes [0 ] == 0x03 )
5650
+ if (body_len > 0 && bytes [0 ] == 0x03 ) {
5644
5651
body_len -- ;
5652
+ body ++ ;
5653
+ }
5645
5654
5646
5655
if (key_type == CKK_EC && body_len > 0 ) {
5647
5656
/*
@@ -5653,32 +5662,34 @@ show_key(CK_SESSION_HANDLE sess, CK_OBJECT_HANDLE obj)
5653
5662
* Do simple size calculation based on DER encoding
5654
5663
*/
5655
5664
ksize = (body_len - 1 ) * 4 ;
5665
+
5656
5666
} else if (body_len > 0 ) {
5657
5667
/*
5658
5668
* EDDSA and XEDDSA in PKCS11 and only one coordinate
5659
5669
*/
5660
- /* TODO rebase on changes in master in this area */
5661
- ksize = ( body_len ) * 8 - 1 ;
5662
- size = body_len ;
5670
+ ksize = ( body_len ) * 8 ;
5671
+ if ( ksize == 256 )
5672
+ ksize -- ; /* as 25519 uses 255 as bits */
5663
5673
}
5664
5674
5665
5675
if (ksize )
5666
5676
printf (" EC_POINT %lu bits\n" , ksize );
5667
5677
else
5668
5678
printf (" EC_POINT size unknown" );
5669
5679
5670
- if (bytes ) {
5680
+ if (bytes && body ) {
5671
5681
if ((CK_LONG )size > 0 ) { /* Will print the point here */
5672
5682
printf (" EC_POINT: " );
5673
- for (n = 0 ; n < size ; n ++ )
5674
- printf ("%02x" , bytes [n ]);
5683
+ for (n = 0 ; n < body_len ; n ++ )
5684
+ printf ("%02x" , body [n ]);
5675
5685
printf ("\n" );
5676
5686
}
5677
- free (bytes );
5678
5687
}
5688
+ free (bytes );
5679
5689
bytes = NULL ;
5690
+ size = 0 ;
5680
5691
bytes = getEC_PARAMS (sess , obj , & size );
5681
- if (bytes ){
5692
+ if (bytes ) {
5682
5693
if ((CK_LONG )size > 0 ) {
5683
5694
struct sc_object_id oid ;
5684
5695
0 commit comments