From 7143b09786179bf776e107ac8b7dfef32d687587 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Thu, 8 Feb 2018 14:32:38 -0700 Subject: [PATCH] pack PKCS7 structure --- wolfcrypt/test/test.c | 18 +++++----- wolfssl/wolfcrypt/pkcs7.h | 71 +++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 9875d18e2..9107223e3 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -16464,13 +16464,13 @@ int pkcs7encrypted_test(void) PKCS7Attrib attribs[] = { - { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) } + { genAttrOid, genAttr, sizeof(genAttrOid), sizeof(genAttr) } }; PKCS7Attrib multiAttribs[] = { - { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) }, - { genAttrOid2, sizeof(genAttrOid2), genAttr2, sizeof(genAttr2) } + { genAttrOid, genAttr, sizeof(genAttrOid), sizeof(genAttr) }, + { genAttrOid2, genAttr2, sizeof(genAttrOid2), sizeof(genAttr2) } }; #endif /* NO_AES */ @@ -16638,12 +16638,12 @@ static int pkcs7signed_run_vectors(byte* rsaCert, word32 rsaCertSz, PKCS7Attrib attribs[] = { - { transIdOid, sizeof(transIdOid), - transId, sizeof(transId) - 1 }, /* take off the null */ - { messageTypeOid, sizeof(messageTypeOid), - messageType, sizeof(messageType) }, - { senderNonceOid, sizeof(senderNonceOid), - senderNonce, sizeof(senderNonce) } + { transIdOid, transId, sizeof(transIdOid), + sizeof(transId) - 1 }, /* take off the null */ + { messageTypeOid, messageType, sizeof(messageTypeOid), + sizeof(messageType) }, + { senderNonceOid, senderNonce, sizeof(senderNonceOid), + sizeof(senderNonce) } }; const pkcs7SignedVector testVectors[] = diff --git a/wolfssl/wolfcrypt/pkcs7.h b/wolfssl/wolfcrypt/pkcs7.h index 1cb37cc84..fa90ae928 100644 --- a/wolfssl/wolfcrypt/pkcs7.h +++ b/wolfssl/wolfcrypt/pkcs7.h @@ -77,63 +77,60 @@ enum Pkcs7_Misc { typedef struct PKCS7Attrib { byte* oid; - word32 oidSz; byte* value; + word32 oidSz; word32 valueSz; } PKCS7Attrib; typedef struct PKCS7DecodedAttrib { - byte* oid; - word32 oidSz; - byte* value; - word32 valueSz; struct PKCS7DecodedAttrib* next; + byte* oid; + byte* value; + word32 oidSz; + word32 valueSz; } PKCS7DecodedAttrib; typedef struct PKCS7 { - byte* content; /* inner content, not owner */ - word32 contentSz; /* content size */ - int contentOID; /* PKCS#7 content type OID sum */ - + byte issuerHash[KEYID_SIZE]; /* hash of all alt Names */ + byte issuerSn[MAX_SN_SZ]; /* singleCert's serial number */ + byte publicKey[MAX_RSA_INT_SZ + MAX_RSA_E_SZ ];/*MAX RSA key size (m + e)*/ + word32 certSz[MAX_PKCS7_CERTS]; WC_RNG* rng; - - int hashOID; - int encryptOID; /* key encryption algorithm OID */ - int keyWrapOID; /* key wrap algorithm OID */ - int keyAgreeOID; /* key agreement algorithm OID */ - + PKCS7Attrib* signedAttribs; + byte* content; /* inner content, not owner */ + byte* singleCert; /* recipient cert, DER, not owner */ + byte* issuer; /* issuer name of singleCert */ + byte* privateKey; /* private key, DER, not owner */ void* heap; /* heap hint for dynamic memory */ byte* cert[MAX_PKCS7_CERTS]; - word32 certSz[MAX_PKCS7_CERTS]; - byte* singleCert; /* recipient cert, DER, not owner */ - word32 singleCertSz; /* size of recipient cert buffer, bytes */ - byte issuerHash[KEYID_SIZE]; /* hash of all alt Names */ - byte* issuer; /* issuer name of singleCert */ - word32 issuerSz; /* length of issuer name */ - byte issuerSn[MAX_SN_SZ]; /* singleCert's serial number */ - word32 issuerSnSz; /* length of serial number */ - byte publicKey[MAX_RSA_INT_SZ + MAX_RSA_E_SZ ];/*MAX RSA key size (m + e)*/ - word32 publicKeySz; - word32 publicKeyOID; /* key OID (RSAk, ECDSAk, etc) */ - byte* privateKey; /* private key, DER, not owner */ - word32 privateKeySz; /* size of private key buffer, bytes */ - - PKCS7Attrib* signedAttribs; - word32 signedAttribsSz; + /* Encrypted-data Content Type */ + byte* encryptionKey; /* block cipher encryption key */ + PKCS7Attrib* unprotectedAttribs; /* optional */ + PKCS7DecodedAttrib* decodedAttrib; /* linked list of decoded attribs */ /* Enveloped-data optional ukm, not owner */ byte* ukm; word32 ukmSz; - /* Encrypted-data Content Type */ - byte* encryptionKey; /* block cipher encryption key */ - word32 encryptionKeySz; /* size of key buffer, bytes */ - PKCS7Attrib* unprotectedAttribs; /* optional */ - word32 unprotectedAttribsSz; - PKCS7DecodedAttrib* decodedAttrib; /* linked list of decoded attribs */ + word32 encryptionKeySz; /* size of key buffer, bytes */ + word32 unprotectedAttribsSz; + word32 contentSz; /* content size */ + word32 singleCertSz; /* size of recipient cert buffer, bytes */ + word32 issuerSz; /* length of issuer name */ + word32 issuerSnSz; /* length of serial number */ + + word32 publicKeySz; + word32 publicKeyOID; /* key OID (RSAk, ECDSAk, etc) */ + word32 privateKeySz; /* size of private key buffer, bytes */ + word32 signedAttribsSz; + int contentOID; /* PKCS#7 content type OID sum */ + int hashOID; + int encryptOID; /* key encryption algorithm OID */ + int keyWrapOID; /* key wrap algorithm OID */ + int keyAgreeOID; /* key agreement algorithm OID */ } PKCS7;