SEC_ASN1_BIT_STRING's shift when using nsslowkey_RSAPublicKeyTemplate

Andrew Cagney <[email protected]> Thu, 30 Jun 2022 15:06:51 -0400
Newsgroups gmane.comp.mozilla.crypto
Message-ID <CAJeAr6sqVsB26Qri3utMAf3BXXNv=fcAkn1iJCy2+J-+pBKZ-Q@mail.gmail.com>
Hi,

I'm reading this code:

        NSSLOWKEYSubjectPublicKeyInfo spki;
        NSSLOWKEYPublicKey pubk;
        SECItem *publicKeyInfo;

        if (SEC_ASN1EncodeItem(arena, &spki.subjectPublicKey,
                               &pubk, nsslowkey_RSAPublicKeyTemplate) == NULL) {
            crv = CKR_HOST_MEMORY;
            goto loser;
        }

        publicKeyInfo = SEC_ASN1EncodeItem(arena, NULL,
                                           &spki,
nsslowkey_SubjectPublicKeyInfoTemplate);
        if (!publicKeyInfo) {
            crv = CKR_HOST_MEMORY;
            goto loser;
        }

in nss/lib/softoken/pkcs11c.c:sftk_unwrapPrivateKey()

In my version of this code I'm finding that I need to convert the
returned subjectPublicKey's length to bits, something like:

    spki.subjectPublicKey *= 8;

before making the second SEC_ASN1EncodeItem() call.  I believe this is
because that field is encoded using:

    { SEC_ASN1_BIT_STRING,
      offsetof(NSSLOWKEYSubjectPublicKeyInfo, subjectPublicKey) },

and SEC_ASN1_BIT_STRING expects the SECItem.len to be in bits not bytes.

could the above have the same problem?

Andrew

-- 
You received this message because you are subscribed to the Google Groups "[email protected]" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/mozilla.org/d/msgid/dev-tech-crypto/CAJeAr6sqVsB26Qri3utMAf3BXXNv%3DfcAkn1iJCy2%2BJ-%2BpBKZ-Q%40mail.gmail.com.