Changeset 3115
- Timestamp:
- 02/02/07 22:15:14 (2 years ago)
- Location:
- trunk/src
- Files:
-
- 12 modified
-
libopensc/card-cardos.c (modified) (1 diff)
-
libopensc/card-incrypto34.c (modified) (1 diff)
-
libopensc/internal.h (modified) (1 diff)
-
libopensc/opensc.h (modified) (1 diff)
-
libopensc/padding.c (modified) (12 diffs)
-
libopensc/pkcs15-sec.c (modified) (10 diffs)
-
pkcs11/framework-pkcs15.c (modified) (1 diff)
-
pkcs11/openssl.c (modified) (3 diffs)
-
pkcs11/pkcs11-display.c (modified) (2 diffs)
-
pkcs11/pkcs11.h (modified) (2 diffs)
-
tools/pkcs11-tool.c (modified) (3 diffs)
-
tools/pkcs15-crypt.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libopensc/card-cardos.c
r3085 r3115 784 784 r = sc_pkcs1_strip_01_padding(data, datalen, buf, &tmp_len); 785 785 if (r != SC_SUCCESS) { 786 /* no pkcs1 bt01 padding => let's try zero padding */ 786 const u8 *p = data; 787 /* no pkcs1 bt01 padding => let's try zero padding 788 * This can only work if the data tbs doesn't have a 789 * leading 0 byte. */ 787 790 tmp_len = buf_len; 788 r = sc_strip_zero_padding(data, datalen, buf, &tmp_len); 789 if (r != SC_SUCCESS) 790 SC_FUNC_RETURN(ctx, 4, r); 791 while (*p == 0 && tmp_len != 0) { 792 ++p; 793 --tmp_len; 794 } 795 memcpy(buf, p, tmp_len); 791 796 } 792 797 sc_ctx_suppress_errors_on(ctx); -
trunk/src/libopensc/card-incrypto34.c
r3085 r3115 569 569 r = sc_pkcs1_strip_01_padding(data, datalen, buf, &tmp_len); 570 570 if (r != SC_SUCCESS) { 571 /* no pkcs1 bt01 padding => let's try zero padding */ 571 const u8 *p = data; 572 /* no pkcs1 bt01 padding => let's try zero padding. 573 * This can only work if the data tbs doesn't have a 574 * leading 0 byte. */ 572 575 tmp_len = buf_len; 573 r = sc_strip_zero_padding(data, datalen, buf, &tmp_len); 574 if (r != SC_SUCCESS) 575 SC_FUNC_RETURN(ctx, 4, r); 576 while (*p == 0 && tmp_len != 0) { 577 ++p; 578 --tmp_len; 579 } 580 memcpy(buf, p, tmp_len); 576 581 } 577 582 sc_ctx_suppress_errors_on(ctx); -
trunk/src/libopensc/internal.h
r3084 r3115 124 124 /********************************************************************/ 125 125 126 int sc_pkcs1_add_01_padding(const u8 *in, size_t in_len, u8 *out,127 size_t *out_len, size_t mod_length);128 126 int sc_pkcs1_strip_01_padding(const u8 *in_dat, size_t in_len, u8 *out_dat, 129 127 size_t *out_len); 130 128 int sc_pkcs1_strip_02_padding(const u8 *data, size_t len, u8 *out_dat, 131 129 size_t *out_len); 132 int sc_pkcs1_add_digest_info_prefix(unsigned int algorithm, const u8 *in_dat,133 size_t in_len, u8 *out_dat, size_t *out_len);134 130 int sc_pkcs1_strip_digest_info_prefix(unsigned int *algorithm, 135 131 const u8 *in_dat, size_t in_len, u8 *out_dat, size_t *out_len); 132 133 /** 134 * PKCS1 encodes the given data. 135 * @param ctx IN sc_context_t object 136 * @param flags IN the algorithm to use 137 * @param in IN input buffer 138 * @param inlen IN length of the input 139 * @param out OUT output buffer (in == out is allowed) 140 * @param outlen OUT length of the output buffer 141 * @param modlen IN length of the modulus in bytes 142 * @return SC_SUCCESS on success and an error code otherwise 143 */ 136 144 int sc_pkcs1_encode(sc_context_t *ctx, unsigned long flags, 137 const u8 *in, size_t in_len, u8 *out, size_t *out_len, size_t mod_len); 138 int sc_strip_zero_padding(const u8 *in,size_t in_len, u8 *out, size_t *out_len); 145 const u8 *in, size_t inlen, u8 *out, size_t *outlen, size_t modlen); 146 /** 147 * Get the necessary padding and sec. env. flags. 148 * @param ctx IN sc_contex_t object 149 * @param iflags IN the desired algorithms flags 150 * @param caps IN the card / key capabilities 151 * @param pflags OUT the padding flags to use 152 * @param salg OUT the security env. algorithm flag to use 153 * @return SC_SUCCESS on success and an error code otherwise 154 */ 155 int sc_get_encoding_flags(sc_context_t *ctx, 156 unsigned long iflags, unsigned long caps, 157 unsigned long *pflags, unsigned long *salg); 139 158 140 159 /********************************************************************/ -
trunk/src/libopensc/opensc.h
r3114 r3115 182 182 * hash values, set these flags accordingly. */ 183 183 #define SC_ALGORITHM_RSA_HASH_NONE 0x00000010 184 #define SC_ALGORITHM_RSA_HASHES 0x000001E0185 184 #define SC_ALGORITHM_RSA_HASH_SHA1 0x00000020 186 185 #define SC_ALGORITHM_RSA_HASH_MD5 0x00000040 187 186 #define SC_ALGORITHM_RSA_HASH_MD5_SHA1 0x00000080 188 187 #define SC_ALGORITHM_RSA_HASH_RIPEMD160 0x00000100 188 #define SC_ALGORITHM_RSA_HASH_SHA256 0x00000200 189 #define SC_ALGORITHM_RSA_HASH_SHA384 0x00000400 190 #define SC_ALGORITHM_RSA_HASH_SHA512 0x00000800 191 #define SC_ALGORITHM_RSA_HASH_SHA224 0x00001000 192 #define SC_ALGORITHM_RSA_HASHES 0x00001FE0 189 193 190 194 /* Event masks for sc_wait_for_event() */ -
trunk/src/libopensc/padding.c
r3084 r3115 1 1 /* 2 * sc-padding.c: miscellaneous padding functions2 * padding.c: miscellaneous padding functions 3 3 * 4 4 * Copyright (C) 2001, 2002 Juha YrjölÀ <juha.yrjola@iki.fi> 5 * Copyright (C) 2003 Nils Larsch <larsch@trustcenter.de>5 * Copyright (C) 2003 - 2007 Nils Larsch <larsch@trustcenter.de> 6 6 * 7 7 * This library is free software; you can redistribute it and/or … … 23 23 #include <string.h> 24 24 #include <stdlib.h> 25 #include <assert.h>26 25 27 26 /* TODO doxygen comments */ … … 38 37 0x05, 0x00, 0x04, 0x14 39 38 }; 39 static const u8 hdr_sha256[] = { 40 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 41 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 42 }; 43 static const u8 hdr_sha384[] = { 44 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 45 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30 46 }; 47 static const u8 hdr_sha512[] = { 48 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 49 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40 50 }; 51 static const u8 hdr_sha224[] = { 52 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 53 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1c 54 }; 40 55 static const u8 hdr_ripemd160[] = { 41 56 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03, 0x02, 0x01, … … 44 59 45 60 46 #define DIGEST_INFO_COUNT 647 61 static const struct digest_info_prefix { 48 62 unsigned int algorithm; … … 50 64 size_t hdr_len; 51 65 size_t hash_len; 52 } digest_info_prefix[ DIGEST_INFO_COUNT] = {66 } digest_info_prefix[] = { 53 67 { SC_ALGORITHM_RSA_HASH_NONE, NULL, 0, 0 }, 54 68 { SC_ALGORITHM_RSA_HASH_MD5, hdr_md5, sizeof(hdr_md5), 16 }, 55 69 { SC_ALGORITHM_RSA_HASH_SHA1, hdr_sha1, sizeof(hdr_sha1), 20 }, 70 { SC_ALGORITHM_RSA_HASH_SHA256, hdr_sha256, sizeof(hdr_sha256), 32 }, 71 { SC_ALGORITHM_RSA_HASH_SHA384, hdr_sha384, sizeof(hdr_sha384), 48 }, 72 { SC_ALGORITHM_RSA_HASH_SHA512, hdr_sha512, sizeof(hdr_sha512), 64 }, 73 { SC_ALGORITHM_RSA_HASH_SHA224, hdr_sha224, sizeof(hdr_sha224), 28 }, 56 74 { SC_ALGORITHM_RSA_HASH_RIPEMD160,hdr_ripemd160, sizeof(hdr_ripemd160), 20 }, 57 75 { SC_ALGORITHM_RSA_HASH_MD5_SHA1, NULL, 0, 36 }, … … 61 79 /* add/remove pkcs1 BT01 padding */ 62 80 63 int sc_pkcs1_add_01_padding(const u8 *in, size_t in_len, u8 *out,64 size_t *out_len, size_t mod_length)81 static int sc_pkcs1_add_01_padding(const u8 *in, size_t in_len, 82 u8 *out, size_t *out_len, size_t mod_length) 65 83 { 66 84 size_t i; … … 83 101 } 84 102 85 int sc_pkcs1_strip_01_padding(const u8 *in_dat, size_t in_len, u8 *out,86 size_t *out_len)103 int sc_pkcs1_strip_01_padding(const u8 *in_dat, size_t in_len, 104 u8 *out, size_t *out_len) 87 105 { 88 106 const u8 *tmp = in_dat; … … 91 109 if (in_dat == NULL || in_len < 10) 92 110 return SC_ERROR_INTERNAL; 93 /* ignoreleading zero byte */111 /* skip leading zero byte */ 94 112 if (*tmp == 0) { 95 113 tmp++; … … 123 141 if (data == NULL || len < 3) 124 142 return SC_ERROR_INTERNAL; 125 /* skip leading zero octet (not part of the pkcs1 BT02 padding)*/143 /* skip leading zero byte */ 126 144 if (*data == 0) { 127 145 data++; … … 148 166 149 167 /* add/remove DigestInfo prefix */ 150 int sc_pkcs1_add_digest_info_prefix(unsigned int algorithm, const u8 *in,151 size_t in_len, u8 *out, size_t *out_len)168 static int sc_pkcs1_add_digest_info_prefix(unsigned int algorithm, 169 const u8 *in, size_t in_len, u8 *out, size_t *out_len) 152 170 { 153 171 int i; 154 172 155 for (i = 0; i < DIGEST_INFO_COUNT; i++) {173 for (i = 0; digest_info_prefix[i].algorithm != 0; i++) { 156 174 if (algorithm == digest_info_prefix[i].algorithm) { 157 175 const u8 *hdr = digest_info_prefix[i].hdr; … … 176 194 int i; 177 195 178 for (i = 0; i < DIGEST_INFO_COUNT; i++) {196 for (i = 0; digest_info_prefix[i].algorithm != 0; i++) { 179 197 size_t hdr_len = digest_info_prefix[i].hdr_len, 180 198 hash_len = digest_info_prefix[i].hash_len; … … 240 258 } 241 259 242 /* strip leading zero padding (does only really work when a DigestInfo 243 * value has been padded */ 244 int sc_strip_zero_padding(const u8 *in, size_t in_len, u8 *out, 245 size_t *out_len) 246 { 247 while (*in == 0 && in_len) { 248 in++; 249 in_len--; 250 } 251 252 if (*out_len < in_len) 253 return SC_ERROR_INTERNAL; 254 255 memmove(out, in, in_len); 256 *out_len = in_len; 260 int sc_get_encoding_flags(sc_context_t *ctx, 261 unsigned long iflags, unsigned long caps, 262 unsigned long *pflags, unsigned long *sflags) 263 { 264 size_t i; 265 266 if (pflags == NULL || sflags == NULL) 267 return SC_ERROR_INVALID_ARGUMENTS; 268 269 for (i = 0; digest_info_prefix[i].algorithm != 0; i++) { 270 if (iflags & digest_info_prefix[i].algorithm) { 271 if (digest_info_prefix[i].algorithm != SC_ALGORITHM_RSA_HASH_NONE && 272 caps & digest_info_prefix[i].algorithm) 273 *sflags |= digest_info_prefix[i].algorithm; 274 else 275 *pflags |= digest_info_prefix[i].algorithm; 276 break; 277 } 278 } 279 280 if (iflags & SC_ALGORITHM_RSA_PAD_PKCS1) { 281 if (caps & SC_ALGORITHM_RSA_PAD_PKCS1) 282 *sflags |= SC_ALGORITHM_RSA_PAD_PKCS1; 283 else 284 *pflags |= SC_ALGORITHM_RSA_PAD_PKCS1; 285 } else if ((iflags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) { 286 if (!(caps & SC_ALGORITHM_RSA_RAW)) { 287 sc_error(ctx, "raw RSA is not supported"); 288 return SC_ERROR_NOT_SUPPORTED; 289 } 290 *sflags |= SC_ALGORITHM_RSA_RAW; 291 /* in case of raw RSA there is nothing to pad */ 292 *pflags = 0; 293 } else { 294 sc_error(ctx, "unsupported algorithm"); 295 return SC_ERROR_NOT_SUPPORTED; 296 } 257 297 258 298 return SC_SUCCESS; -
trunk/src/libopensc/pkcs15-sec.c
r3084 r3115 3 3 * 4 4 * Copyright (C) 2001, 2002 Juha YrjölÀ <juha.yrjola@iki.fi> 5 * Copyrigth (C) 2007 Nils Larsch <nils@larsch.net> 5 6 * 6 7 * This library is free software; you can redistribute it and/or … … 21 22 #include "internal.h" 22 23 #include "pkcs15.h" 23 #include <assert.h>24 24 #include <string.h> 25 25 #include <stdlib.h> … … 69 69 sc_context_t *ctx = p15card->card->ctx; 70 70 const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data; 71 unsigned long pad_flags = 0 ;71 unsigned long pad_flags = 0, sec_flags = 0; 72 72 73 73 SC_FUNC_CALLED(ctx, 1); … … 88 88 } 89 89 senv.algorithm = SC_ALGORITHM_RSA; 90 senv.algorithm_flags = 0; 91 92 if (flags & SC_ALGORITHM_RSA_PAD_PKCS1) { 93 if (!(alg_info->flags & SC_ALGORITHM_RSA_PAD_PKCS1)) 94 pad_flags |= SC_ALGORITHM_RSA_PAD_PKCS1; 95 else 96 senv.algorithm_flags |= SC_ALGORITHM_RSA_PAD_PKCS1; 97 } else if ((flags & SC_ALGORITHM_RSA_PAD_ANSI) || 98 (flags & SC_ALGORITHM_RSA_PAD_ISO9796)) { 99 sc_error(ctx, "Only PKCS #1 padding method supported\n"); 100 return SC_ERROR_NOT_SUPPORTED; 101 } else { 102 if (!(alg_info->flags & SC_ALGORITHM_RSA_RAW)) { 103 sc_error(ctx, "Card requires RSA padding\n"); 104 return SC_ERROR_NOT_SUPPORTED; 105 } 106 senv.algorithm_flags |= SC_ALGORITHM_RSA_RAW; 107 } 108 109 senv.operation = SC_SEC_OPERATION_DECIPHER; 110 senv.flags = 0; 90 91 r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags); 92 if (r != SC_SUCCESS) 93 return r; 94 95 senv.algorithm_flags = sec_flags; 96 senv.operation = SC_SEC_OPERATION_DECIPHER; 97 senv.flags = 0; 111 98 /* optional keyReference attribute (the default value is -1) */ 112 99 if (prkey->key_reference >= 0) { … … 141 128 if (pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1) { 142 129 r = sc_pkcs1_strip_02_padding(out, (size_t)r, out, (size_t *) &r); 143 SC_TEST_RET(ctx, r, "Invalid PKCS#1 padding");130 SC_TEST_RET(ctx, r, "Invalid PKCS#1 padding"); 144 131 } 145 132 … … 157 144 sc_algorithm_info_t *alg_info; 158 145 const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data; 159 u8 buf[512], *tmp in, *tmpout, *help;160 size_t tmpoutlen;161 unsigned long pad_flags = 0 ;146 u8 buf[512], *tmp; 147 size_t modlen = prkey->modulus_length / 8; 148 unsigned long pad_flags = 0, sec_flags = 0; 162 149 163 150 SC_FUNC_CALLED(ctx, 1); … … 181 168 182 169 /* Probably never happens, but better make sure */ 183 if (inlen > sizeof(buf) )170 if (inlen > sizeof(buf) || outlen < modlen) 184 171 return SC_ERROR_BUFFER_TOO_SMALL; 185 172 memcpy(buf, in, inlen); 186 tmpin = buf; 187 if (outlen < (prkey->modulus_length + 7) / 8) 188 return SC_ERROR_BUFFER_TOO_SMALL; 189 tmpout = out; 173 tmp = buf; 190 174 191 175 /* flags: the requested algo … … 198 182 !(alg_info->flags & (SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE))) { 199 183 unsigned int algo; 200 tmpoutlen = sizeof(buf); 201 r = sc_pkcs1_strip_digest_info_prefix(&algo, tmpin, inlen, tmpout, &tmpoutlen); 202 if (r != SC_SUCCESS || algo == SC_ALGORITHM_RSA_HASH_NONE) 184 size_t tmplen = sizeof(buf); 185 r = sc_pkcs1_strip_digest_info_prefix(&algo, tmp, inlen, tmp, &tmplen); 186 if (r != SC_SUCCESS || algo == SC_ALGORITHM_RSA_HASH_NONE) { 187 sc_mem_clear(buf, sizeof(buf)); 203 188 return SC_ERROR_INVALID_DATA; 204 help = tmpin; 205 tmpin = tmpout; 206 tmpout = help; 207 inlen = tmpoutlen; 189 } 208 190 flags &= ~SC_ALGORITHM_RSA_HASH_NONE; 209 191 flags |= algo; 210 } 211 212 senv.algorithm_flags = 0; 213 if (flags & SC_ALGORITHM_RSA_HASH_SHA1) { 214 if (inlen != 20) 215 SC_FUNC_RETURN(ctx, 0, SC_ERROR_WRONG_LENGTH); 216 if (!(alg_info->flags & SC_ALGORITHM_RSA_HASH_SHA1)) 217 pad_flags |= SC_ALGORITHM_RSA_HASH_SHA1; 218 else 219 senv.algorithm_flags |= SC_ALGORITHM_RSA_HASH_SHA1; 220 } else if (flags & SC_ALGORITHM_RSA_HASH_MD5) { 221 if (inlen != 16) 222 SC_FUNC_RETURN(ctx, 0, SC_ERROR_WRONG_LENGTH); 223 if (!(alg_info->flags & SC_ALGORITHM_RSA_HASH_MD5)) 224 pad_flags |= SC_ALGORITHM_RSA_HASH_MD5; 225 else 226 senv.algorithm_flags |= SC_ALGORITHM_RSA_HASH_MD5; 227 } else if (flags & SC_ALGORITHM_RSA_HASH_RIPEMD160) { 228 if (inlen != 20) 229 SC_FUNC_RETURN(ctx, 0, SC_ERROR_WRONG_LENGTH); 230 if (!(alg_info->flags & SC_ALGORITHM_RSA_HASH_RIPEMD160)) 231 pad_flags |= SC_ALGORITHM_RSA_HASH_RIPEMD160; 232 else 233 senv.algorithm_flags |= SC_ALGORITHM_RSA_HASH_RIPEMD160; 234 } else if (flags & SC_ALGORITHM_RSA_HASH_MD5_SHA1) { 235 if (inlen != 36) 236 SC_FUNC_RETURN(ctx, 0, SC_ERROR_WRONG_LENGTH); 237 if (!(alg_info->flags & SC_ALGORITHM_RSA_HASH_MD5_SHA1)) 238 pad_flags |= SC_ALGORITHM_RSA_HASH_MD5_SHA1; 239 else 240 senv.algorithm_flags |= SC_ALGORITHM_RSA_HASH_MD5_SHA1; 241 } else if (flags & SC_ALGORITHM_RSA_HASH_NONE || 242 (flags & SC_ALGORITHM_RSA_HASHES) == 0) { 243 pad_flags |= SC_ALGORITHM_RSA_HASH_NONE; 244 } 245 246 if (flags & SC_ALGORITHM_RSA_PAD_PKCS1) { 247 if (!(alg_info->flags & SC_ALGORITHM_RSA_PAD_PKCS1)) 248 pad_flags |= SC_ALGORITHM_RSA_PAD_PKCS1; 249 else 250 senv.algorithm_flags |= SC_ALGORITHM_RSA_PAD_PKCS1; 251 } else if ((flags & SC_ALGORITHM_RSA_PAD_ANSI) || 252 (flags & SC_ALGORITHM_RSA_PAD_ISO9796)) { 253 sc_error(ctx, "Only PKCS #1 padding method supported\n"); 254 return SC_ERROR_NOT_SUPPORTED; 255 } else { 256 if (!(alg_info->flags & SC_ALGORITHM_RSA_RAW)) { 257 sc_error(ctx, "Card requires RSA padding\n"); 258 return SC_ERROR_NOT_SUPPORTED; 259 } 260 senv.algorithm_flags |= SC_ALGORITHM_RSA_RAW; 261 pad_flags = 0; 262 263 /* Add zero-padding if input shorter than modulus */ 264 if (inlen < prkey->modulus_length/8) { 265 unsigned int modulus_len = prkey->modulus_length/8; 266 if (modulus_len > sizeof(buf)) 192 inlen = tmplen; 193 } 194 195 r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags); 196 if (r != SC_SUCCESS) { 197 sc_mem_clear(buf, sizeof(buf)); 198 return r; 199 } 200 senv.algorithm_flags = sec_flags; 201 202 /* add the padding bytes (if necessary) */ 203 if (pad_flags != 0) { 204 size_t tmplen = sizeof(buf); 205 r = sc_pkcs1_encode(ctx, pad_flags, tmp, inlen, tmp, &tmplen, modlen); 206 SC_TEST_RET(ctx, r, "Unable to add padding"); 207 inlen = tmplen; 208 } else if ((flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) { 209 /* Add zero-padding if input is shorter than the modulus */ 210 if (inlen < modlen) { 211 if (modlen > sizeof(buf)) 267 212 return SC_ERROR_BUFFER_TOO_SMALL; 268 memset(tmpout, 0, sizeof(buf)); 269 memcpy(tmpout + modulus_len - inlen, tmpin, inlen); 270 inlen = modulus_len; 271 help = tmpin; 272 tmpin = tmpout; 273 tmpout = help; 274 } 275 } 276 277 if (pad_flags) { 278 tmpoutlen = sizeof(buf); 279 r = sc_pkcs1_encode(ctx, pad_flags, tmpin, inlen, tmpout, &tmpoutlen, 280 prkey->modulus_length/8); 281 SC_TEST_RET(ctx, r, "Unable to add padding"); 282 help = tmpin; 283 tmpin = tmpout; 284 tmpout = help; 285 inlen = tmpoutlen; 213 memmove(tmp+modlen-inlen, tmp, inlen); 214 memset(tmp, 0, modlen-inlen); 215 } 286 216 } 287 217 … … 299 229 SC_TEST_RET(ctx, r, "sc_lock() failed"); 300 230 301 if (prkey->path.len != 0) 302 { 231 if (prkey->path.len != 0) { 303 232 r = select_key_file(p15card, prkey, &senv); 304 233 if (r < 0) { … … 314 243 } 315 244 316 /* XXX: Should we adjust outlen to match the size of 317 * the signature we expect? CardOS for instance will 318 * barf if the LE value doesn't match the size of the 319 * signature exactly. 320 * 321 * Right now we work around this by assuming that eToken keys 322 * always have algorithm RSA_PURE_SIG so the input buffer 323 * is padded and has the same length as the signature. --okir 324 */ 325 if (tmpin == out) { 326 memcpy(tmpout, tmpin, inlen); 327 tmpin = tmpout; 328 } 329 r = sc_compute_signature(p15card->card, tmpin, inlen, out, outlen); 245 r = sc_compute_signature(p15card->card, tmp, inlen, out, outlen); 330 246 sc_mem_clear(buf, sizeof(buf)); 331 247 sc_unlock(p15card->card); -
trunk/src/pkcs11/framework-pkcs15.c
r3086 r3115 1948 1948 flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_SHA1; 1949 1949 break; 1950 case CKM_SHA256_RSA_PKCS: 1951 flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_SHA256; 1952 break; 1953 case CKM_SHA384_RSA_PKCS: 1954 flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_SHA384; 1955 break; 1956 case CKM_SHA512_RSA_PKCS: 1957 flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_SHA512; 1958 break; 1950 1959 case CKM_RIPEMD160_RSA_PKCS: 1951 1960 flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_RIPEMD160; -
trunk/src/pkcs11/openssl.c
r2916 r3115 13 13 #include <openssl/rand.h> 14 14 #include <openssl/rsa.h> 15 #include <openssl/opensslv.h> 15 16 16 17 static CK_RV sc_pkcs11_openssl_md_init(sc_pkcs11_operation_t *); … … 31 32 }; 32 33 34 #if OPENSSL_VERSION_NUMBER >= 0x00908000L 35 static sc_pkcs11_mechanism_type_t openssl_sha256_mech = { 36 CKM_SHA256, 37 { 0, 0, CKF_DIGEST }, 0, 38 sizeof(struct sc_pkcs11_operation), 39 sc_pkcs11_openssl_md_release, 40 sc_pkcs11_openssl_md_init, 41 sc_pkcs11_openssl_md_update, 42 sc_pkcs11_openssl_md_final 43 }; 44 45 static sc_pkcs11_mechanism_type_t openssl_sha384_mech = { 46 CKM_SHA384, 47 { 0, 0, CKF_DIGEST }, 0, 48 sizeof(struct sc_pkcs11_operation), 49 sc_pkcs11_openssl_md_release, 50 sc_pkcs11_openssl_md_init, 51 sc_pkcs11_openssl_md_update, 52 sc_pkcs11_openssl_md_final 53 }; 54 55 static sc_pkcs11_mechanism_type_t openssl_sha512_mech = { 56 CKM_SHA512, 57 { 0, 0, CKF_DIGEST }, 0, 58 sizeof(struct sc_pkcs11_operation), 59 sc_pkcs11_openssl_md_release, 60 sc_pkcs11_openssl_md_init, 61 sc_pkcs11_openssl_md_update, 62 sc_pkcs11_openssl_md_final 63 }; 64 #endif 65 33 66 static sc_pkcs11_mechanism_type_t openssl_md5_mech = { 34 67 CKM_MD5, …
