29
29
#define DEBUG_WARN (...) ZCRYPT_DBF(DBF_WARN, ##__VA_ARGS__)
30
30
#define DEBUG_ERR (...) ZCRYPT_DBF(DBF_ERR, ##__VA_ARGS__)
31
31
32
+ #define EP11_PINBLOB_V1_BYTES 56
33
+
32
34
/* default iv used here */
33
35
static const u8 def_iv [16 ] = { 0x00 , 0x11 , 0x22 , 0x33 , 0x44 , 0x55 , 0x66 , 0x77 ,
34
36
0x88 , 0x99 , 0xaa , 0xbb , 0xcc , 0xdd , 0xee , 0xff };
@@ -592,7 +594,7 @@ static int ep11_query_info(u16 cardnr, u16 domain, u32 query_type,
592
594
struct ep11_cprb * req = NULL , * rep = NULL ;
593
595
struct ep11_target_dev target ;
594
596
struct ep11_urb * urb = NULL ;
595
- int api = 1 , rc = - ENOMEM ;
597
+ int api = EP11_API_V1 , rc = - ENOMEM ;
596
598
597
599
/* request cprb and payload */
598
600
req = alloc_cprb (sizeof (struct ep11_info_req_pl ));
@@ -789,8 +791,7 @@ static int _ep11_genaeskey(u16 card, u16 domain,
789
791
u32 attr_bool_bits ;
790
792
u32 attr_val_len_type ;
791
793
u32 attr_val_len_value ;
792
- u8 pin_tag ;
793
- u8 pin_len ;
794
+ /* followed by empty pin tag or empty pinblob tag */
794
795
} __packed * req_pl ;
795
796
struct keygen_rep_pl {
796
797
struct pl_head head ;
@@ -803,9 +804,11 @@ static int _ep11_genaeskey(u16 card, u16 domain,
803
804
u8 data [512 ];
804
805
} __packed * rep_pl ;
805
806
struct ep11_cprb * req = NULL , * rep = NULL ;
807
+ size_t req_pl_size , pinblob_size = 0 ;
806
808
struct ep11_target_dev target ;
807
809
struct ep11_urb * urb = NULL ;
808
810
int api , rc = - ENOMEM ;
811
+ u8 * p ;
809
812
810
813
switch (keybitsize ) {
811
814
case 128 :
@@ -821,12 +824,22 @@ static int _ep11_genaeskey(u16 card, u16 domain,
821
824
}
822
825
823
826
/* request cprb and payload */
824
- req = alloc_cprb (sizeof (struct keygen_req_pl ));
827
+ api = (!keygenflags || keygenflags & 0x00200000 ) ?
828
+ EP11_API_V4 : EP11_API_V1 ;
829
+ if (ap_is_se_guest ()) {
830
+ /*
831
+ * genkey within SE environment requires API ordinal 6
832
+ * with empty pinblob
833
+ */
834
+ api = EP11_API_V6 ;
835
+ pinblob_size = EP11_PINBLOB_V1_BYTES ;
836
+ }
837
+ req_pl_size = sizeof (struct keygen_req_pl ) + ASN1TAGLEN (pinblob_size );
838
+ req = alloc_cprb (req_pl_size );
825
839
if (!req )
826
840
goto out ;
827
841
req_pl = (struct keygen_req_pl * )(((u8 * )req ) + sizeof (* req ));
828
- api = (!keygenflags || keygenflags & 0x00200000 ) ? 4 : 1 ;
829
- prep_head (& req_pl -> head , sizeof (* req_pl ), api , 21 ); /* GenerateKey */
842
+ prep_head (& req_pl -> head , req_pl_size , api , 21 ); /* GenerateKey */
830
843
req_pl -> var_tag = 0x04 ;
831
844
req_pl -> var_len = sizeof (u32 );
832
845
req_pl -> keybytes_tag = 0x04 ;
@@ -842,7 +855,10 @@ static int _ep11_genaeskey(u16 card, u16 domain,
842
855
req_pl -> attr_bool_bits = keygenflags ? keygenflags : KEY_ATTR_DEFAULTS ;
843
856
req_pl -> attr_val_len_type = 0x00000161 ; /* CKA_VALUE_LEN */
844
857
req_pl -> attr_val_len_value = keybitsize / 8 ;
845
- req_pl -> pin_tag = 0x04 ;
858
+ p = ((u8 * )req_pl ) + sizeof (* req_pl );
859
+ /* pin tag */
860
+ * p ++ = 0x04 ;
861
+ * p ++ = pinblob_size ;
846
862
847
863
/* reply cprb and payload */
848
864
rep = alloc_cprb (sizeof (struct keygen_rep_pl ));
@@ -857,7 +873,7 @@ static int _ep11_genaeskey(u16 card, u16 domain,
857
873
target .ap_id = card ;
858
874
target .dom_id = domain ;
859
875
prep_urb (urb , & target , 1 ,
860
- req , sizeof (* req ) + sizeof ( * req_pl ) ,
876
+ req , sizeof (* req ) + req_pl_size ,
861
877
rep , sizeof (* rep ) + sizeof (* rep_pl ));
862
878
863
879
rc = zcrypt_send_ep11_cprb (urb );
@@ -965,7 +981,7 @@ static int ep11_cryptsingle(u16 card, u16 domain,
965
981
struct ep11_target_dev target ;
966
982
struct ep11_urb * urb = NULL ;
967
983
size_t req_pl_size , rep_pl_size ;
968
- int n , api = 1 , rc = - ENOMEM ;
984
+ int n , api = EP11_API_V1 , rc = - ENOMEM ;
969
985
u8 * p ;
970
986
971
987
/* the simple asn1 coding used has length limits */
@@ -1084,7 +1100,7 @@ static int _ep11_unwrapkey(u16 card, u16 domain,
1084
1100
* maybe followed by iv data
1085
1101
* followed by kek tag + kek blob
1086
1102
* followed by empty mac tag
1087
- * followed by empty pin tag
1103
+ * followed by empty pin tag or empty pinblob tag
1088
1104
* followed by encryted key tag + bytes
1089
1105
*/
1090
1106
} __packed * req_pl ;
@@ -1099,20 +1115,30 @@ static int _ep11_unwrapkey(u16 card, u16 domain,
1099
1115
u8 data [512 ];
1100
1116
} __packed * rep_pl ;
1101
1117
struct ep11_cprb * req = NULL , * rep = NULL ;
1118
+ size_t req_pl_size , pinblob_size = 0 ;
1102
1119
struct ep11_target_dev target ;
1103
1120
struct ep11_urb * urb = NULL ;
1104
- size_t req_pl_size ;
1105
1121
int api , rc = - ENOMEM ;
1106
1122
u8 * p ;
1107
1123
1108
1124
/* request cprb and payload */
1125
+ api = (!keygenflags || keygenflags & 0x00200000 ) ?
1126
+ EP11_API_V4 : EP11_API_V1 ;
1127
+ if (ap_is_se_guest ()) {
1128
+ /*
1129
+ * unwrap within SE environment requires API ordinal 6
1130
+ * with empty pinblob
1131
+ */
1132
+ api = EP11_API_V6 ;
1133
+ pinblob_size = EP11_PINBLOB_V1_BYTES ;
1134
+ }
1109
1135
req_pl_size = sizeof (struct uw_req_pl ) + (iv ? 16 : 0 )
1110
- + ASN1TAGLEN (keksize ) + 4 + ASN1TAGLEN (enckeysize );
1136
+ + ASN1TAGLEN (keksize ) + ASN1TAGLEN (0 )
1137
+ + ASN1TAGLEN (pinblob_size ) + ASN1TAGLEN (enckeysize );
1111
1138
req = alloc_cprb (req_pl_size );
1112
1139
if (!req )
1113
1140
goto out ;
1114
1141
req_pl = (struct uw_req_pl * )(((u8 * )req ) + sizeof (* req ));
1115
- api = (!keygenflags || keygenflags & 0x00200000 ) ? 4 : 1 ;
1116
1142
prep_head (& req_pl -> head , req_pl_size , api , 34 ); /* UnwrapKey */
1117
1143
req_pl -> attr_tag = 0x04 ;
1118
1144
req_pl -> attr_len = 7 * sizeof (u32 );
@@ -1137,9 +1163,10 @@ static int _ep11_unwrapkey(u16 card, u16 domain,
1137
1163
/* empty mac key tag */
1138
1164
* p ++ = 0x04 ;
1139
1165
* p ++ = 0 ;
1140
- /* empty pin tag */
1166
+ /* pin tag */
1141
1167
* p ++ = 0x04 ;
1142
- * p ++ = 0 ;
1168
+ * p ++ = pinblob_size ;
1169
+ p += pinblob_size ;
1143
1170
/* encrypted key value tag and bytes */
1144
1171
p += asn1tag_write (p , 0x04 , enckey , enckeysize );
1145
1172
@@ -1275,7 +1302,8 @@ static int _ep11_wrapkey(u16 card, u16 domain,
1275
1302
if (!mech || mech == 0x80060001 )
1276
1303
req -> flags |= 0x20 ; /* CPACF_WRAP needs special bit */
1277
1304
req_pl = (struct wk_req_pl * )(((u8 * )req ) + sizeof (* req ));
1278
- api = (!mech || mech == 0x80060001 ) ? 4 : 1 ; /* CKM_IBM_CPACF_WRAP */
1305
+ api = (!mech || mech == 0x80060001 ) ? /* CKM_IBM_CPACF_WRAP */
1306
+ EP11_API_V4 : EP11_API_V1 ;
1279
1307
prep_head (& req_pl -> head , req_pl_size , api , 33 ); /* WrapKey */
1280
1308
req_pl -> var_tag = 0x04 ;
1281
1309
req_pl -> var_len = sizeof (u32 );
0 commit comments