Giter Club home page Giter Club logo

Comments (2)

xhanulik avatar xhanulik commented on July 1, 2024 1

Yes, when extracting pad_algo from flags, the code now does not handle when both SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 and SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 are set. In pad_algo the SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 should be excluded.
I will create PR with patch for this.

from opensc.

dengert avatar dengert commented on July 1, 2024

padding.c:614:sc_pkcs1_encode: hash algorithm 0x2000, pad algorithm 0xC0 calls the switch statement:

switch(pad_algo) {
case SC_ALGORITHM_RSA_PAD_NONE:
/* padding done by card => nothing to do */
if (out != tmp)
memcpy(out, tmp, tmp_len);
*out_len = tmp_len;
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
case SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01:
/* add pkcs1 bt01 padding */
rv = sc_pkcs1_add_01_padding(tmp, tmp_len, out, out_len, mod_len);
LOG_FUNC_RETURN(ctx, rv);
case SC_ALGORITHM_RSA_PAD_PSS:
/* add PSS padding */
#ifdef ENABLE_OPENSSL
mgf1_hash = flags & SC_ALGORITHM_MGF1_HASHES;
if (hash_algo == SC_ALGORITHM_RSA_HASH_NONE) {
/* this is generic RSA_PKCS1_PSS mechanism with hash
* already done outside of the module. The parameters
* were already checked so we need to adjust the hash
* algorithm to do the padding with the correct hash
* function.
*/
hash_algo = hash_len2algo(tmp_len);
}
/* sLen is by default same as hash length */
if (!(md = hash_flag2md(ctx, hash_algo)))
return SC_ERROR_NOT_SUPPORTED;
sLen = EVP_MD_size(md);
sc_evp_md_free(md);
/* if application provide sLen, use it */
if (pMechanism != NULL) {
CK_MECHANISM *mech = (CK_MECHANISM *)pMechanism;
CK_RSA_PKCS_PSS_PARAMS *pss_params;
if (mech->pParameter && sizeof(CK_RSA_PKCS_PSS_PARAMS) == mech->ulParameterLen) {
pss_params = mech->pParameter;
sLen = pss_params->sLen;
}
}
rv = sc_pkcs1_add_pss_padding(ctx, hash_algo, mgf1_hash,
tmp, tmp_len, out, out_len, mod_bits, sLen);
#else
rv = SC_ERROR_NOT_SUPPORTED;
#endif
LOG_FUNC_RETURN(ctx, rv);
default:
/* We shouldn't be called with an unexpected padding type, we've already
* returned SC_ERROR_NOT_SUPPORTED if the card can't be used. */
LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);

But both SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 and SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 are both set. Only one pad_algo bit should be set.

This may be related to e8883b1

@xhanulik any ideas?

from opensc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.