static int generate_spc_digest_info(cms_context *cms, SECItem *dip) { DigestInfo di; memset(&di, '\0', sizeof (di)); if (generate_algorithm_id(cms, &di.digestAlgorithm, digest_get_digest_oid(cms)) < 0) return -1; int i = cms->selected_digest; memcpy(&di.digest, cms->digests[i].pe_digest, sizeof (di.digest)); if (content_is_empty(di.digest.data, di.digest.len)) { cms->log(cms, LOG_ERR, "got empty digest"); return -1; } if (SEC_ASN1EncodeItem(cms->arena, dip, &di, DigestInfoTemplate) == NULL) { cms->log(cms, LOG_ERR, "could not encode DigestInfo: %s", PORT_ErrorToString(PORT_GetError())); return -1; } return 0; }
static int generate_algorithm_id_list(cms_context *cms, SECAlgorithmID ***algorithm_list_p) { SECAlgorithmID **algorithms = NULL; int err = 0; algorithms = PORT_ArenaZAlloc(cms->arena, sizeof (SECAlgorithmID *) * 2); if (!algorithms) return -1; algorithms[0] = PORT_ArenaZAlloc(cms->arena, sizeof(SECAlgorithmID)); if (!algorithms[0]) { err = PORT_GetError(); goto err_list; } if (generate_algorithm_id(cms, algorithms[0], digest_get_digest_oid(cms)) < 0) { err = PORT_GetError(); goto err_item; } *algorithm_list_p = algorithms; return 0; err_item: PORT_ZFree(algorithms[0], sizeof (SECAlgorithmID)); err_list: PORT_ZFree(algorithms, sizeof (SECAlgorithmID *) * 2); PORT_SetError(err); return -1; }
generate_cinfo_digest(cms_context *cms, SpcContentInfo *cip) { /* I have exactly no idea why the thing I need to digest is 2 bytes * in to the content data, but the hash winds up identical to what * Microsoft is embedding in their binaries if I do, so I'm calling * that "correct", where "correct" means "there's not enough booze * in the world." */ SECItem encoded = { .type = cip->content.type, .data = cip->content.data + 2, .len = cip->content.len - 2 }; PK11Context *ctx = NULL; SECOidData *oid = SECOID_FindOIDByTag(digest_get_digest_oid(cms)); if (oid == NULL) return -1; cms->ci_digest = SECITEM_AllocItem(cms->arena, NULL, digest_get_digest_size(cms)); if (!cms->ci_digest) goto err; ctx = PK11_CreateDigestContext(oid->offset); if (ctx == NULL) goto err; if (PK11_DigestBegin(ctx) != SECSuccess) goto err; if (PK11_DigestOp(ctx, encoded.data, encoded.len) != SECSuccess)