/* --------- printing keys --------------------------------*/ static int print_gost_94(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx, int type) { int param_nid = NID_undef; if (type == 2) { BIGNUM *key; if (!BIO_indent(out,indent,128)) return 0; BIO_printf(out,"Private key: "); key = gost_get0_priv_key(pkey); if (!key) BIO_printf(out,"<undefined>"); else BN_print(out,key); BIO_printf(out,"\n"); } if (type >= 1) { BIGNUM *pubkey; pubkey = ((DSA *)EVP_PKEY_get0((EVP_PKEY *)pkey))->pub_key; BIO_indent(out,indent,128); BIO_printf(out,"Public key: "); BN_print(out,pubkey); BIO_printf(out,"\n"); } param_nid = gost94_nid_by_params(EVP_PKEY_get0((EVP_PKEY *)pkey)); BIO_indent(out,indent,128); BIO_printf(out, "Parameter set: %s\n",OBJ_nid2ln(param_nid)); return 1; }
static int print_gost_01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx, int type) { int param_nid = NID_undef; if (type == 2) { BIGNUM *key; if (!BIO_indent(out,indent,128)) return 0; BIO_printf(out,"Private key: "); key = gost_get0_priv_key(pkey); if (!key) BIO_printf(out,"<undefined)"); else BN_print(out,key); BIO_printf(out,"\n"); } if (type >= 1) { BN_CTX *ctx = BN_CTX_new(); BIGNUM *X,*Y; const EC_POINT *pubkey; const EC_GROUP *group; if (!ctx) { GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_MALLOC_FAILURE); return 0; } BN_CTX_start(ctx); X = BN_CTX_get(ctx); Y = BN_CTX_get(ctx); pubkey = EC_KEY_get0_public_key((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey)); group = EC_KEY_get0_group((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey)); if (!EC_POINT_get_affine_coordinates_GFp(group,pubkey,X,Y,ctx)) { GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_EC_LIB); BN_CTX_free(ctx); return 0; } if (!BIO_indent(out,indent,128)) return 0; BIO_printf(out,"Public key:\n"); if (!BIO_indent(out,indent+3,128)) return 0; BIO_printf(out,"X:"); BN_print(out,X); BIO_printf(out,"\n"); BIO_indent(out,indent+3,128); BIO_printf(out,"Y:"); BN_print(out,Y); BIO_printf(out,"\n"); BN_CTX_end(ctx); BN_CTX_free(ctx); } param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey))); if (!BIO_indent(out,indent,128)) return 0; BIO_printf(out,"Parameter set: %s\n",OBJ_nid2ln(param_nid)); return 1; }
int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, unsigned char *buf, int off) { int n, i; const char *neg; if (num == NULL) return (1); neg = (BN_is_negative(num)) ? "-" : ""; if (!BIO_indent(bp, off, 128)) return 0; if (BN_is_zero(num)) { if (BIO_printf(bp, "%s 0\n", number) <= 0) return 0; return 1; } if (BN_num_bytes(num) <= BN_BYTES) { if (BIO_printf(bp, "%s %s%lu (%s0x%lx)\n", number, neg, (unsigned long)num->d[0], neg, (unsigned long)num->d[0]) <= 0) return (0); } else { buf[0] = 0; if (BIO_printf(bp, "%s%s", number, (neg[0] == '-') ? " (Negative)" : "") <= 0) return (0); n = BN_bn2bin(num, &buf[1]); if (buf[1] & 0x80) n++; else buf++; for (i = 0; i < n; i++) { if ((i % 15) == 0) { if (BIO_puts(bp, "\n") <= 0 || !BIO_indent(bp, off + 4, 128)) return 0; } if (BIO_printf(bp, "%02x%s", buf[i], ((i + 1) == n) ? "" : ":") <= 0) return (0); } if (BIO_write(bp, "\n", 1) <= 0) return (0); } return (1); }
static int param_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx) { int param_nid = EC_GROUP_get_curve_name(GOST_KEY_get0_group(pkey->pkey.gost)); if (BIO_indent(out, indent, 128) == 0) return 0; BIO_printf(out, "Parameter set: %s\n", OBJ_nid2ln(param_nid)); if (BIO_indent(out, indent, 128) == 0) return 0; BIO_printf(out, "Digest Algorithm: %s\n", OBJ_nid2ln(GOST_KEY_get_digest(pkey->pkey.gost))); return 1; }
static int print_unsupported(BIO *out, const EVP_PKEY *pkey, int indent, const char *kstr) { BIO_indent(out, indent, 128); BIO_printf(out, "%s algorithm \"%s\" unsupported\n", kstr, OBJ_nid2ln(pkey->type)); return 1; }
static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, int indent) { static const char fmt[] = "%-18s"; char str[128]; const char *p; if (constructed & V_ASN1_CONSTRUCTED) p = "cons: "; else p = "prim: "; if (BIO_write(bp, p, 6) < 6) goto err; BIO_indent(bp, indent, 128); p = str; if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) BIO_snprintf(str, sizeof str, "priv [ %d ] ", tag); else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) BIO_snprintf(str, sizeof str, "cont [ %d ]", tag); else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) BIO_snprintf(str, sizeof str, "appl [ %d ]", tag); else if (tag > 30) BIO_snprintf(str, sizeof str, "<ASN1 %d>", tag); else p = ASN1_tag2str(tag); if (BIO_printf(bp, fmt, p) <= 0) goto err; return (1); err: return (0); }
static int pub_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx) { BN_CTX *ctx = BN_CTX_new(); BIGNUM *X, *Y; const EC_POINT *pubkey; const EC_GROUP *group; if (ctx == NULL) { GOSTerr(GOST_F_PUB_PRINT_GOST01, ERR_R_MALLOC_FAILURE); return 0; } BN_CTX_start(ctx); if ((X = BN_CTX_get(ctx)) == NULL) goto err; if ((Y = BN_CTX_get(ctx)) == NULL) goto err; pubkey = GOST_KEY_get0_public_key(pkey->pkey.gost); group = GOST_KEY_get0_group(pkey->pkey.gost); if (EC_POINT_get_affine_coordinates_GFp(group, pubkey, X, Y, ctx) == 0) { GOSTerr(GOST_F_PUB_PRINT_GOST01, ERR_R_EC_LIB); goto err; } if (BIO_indent(out, indent, 128) == 0) goto err; BIO_printf(out, "Public key:\n"); if (BIO_indent(out, indent + 3, 128) == 0) goto err; BIO_printf(out, "X:"); BN_print(out, X); BIO_printf(out, "\n"); BIO_indent(out, indent + 3, 128); BIO_printf(out, "Y:"); BN_print(out, Y); BIO_printf(out, "\n"); BN_CTX_end(ctx); BN_CTX_free(ctx); return param_print_gost01(out, pkey, indent, pctx); err: BN_CTX_end(ctx); BN_CTX_free(ctx); return 0; }
static int print_gost_ec_pub(BIO *out, const EVP_PKEY *pkey, int indent) { BN_CTX *ctx; BIGNUM *X, *Y; const EC_POINT *pubkey; const EC_GROUP *group; EC_KEY *key = (EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey); int ok = 0; ctx = BN_CTX_new(); if (!ctx) { GOSTerr(GOST_F_PRINT_GOST_EC_PUB, ERR_R_MALLOC_FAILURE); return 0; } BN_CTX_start(ctx); X = BN_CTX_get(ctx); Y = BN_CTX_get(ctx); pubkey = (key) ? EC_KEY_get0_public_key(key) : NULL; group = (key) ? EC_KEY_get0_group(key) : NULL; if (!pubkey || !group) goto err; if (!EC_POINT_get_affine_coordinates_GFp(group, pubkey, X, Y, ctx)) { GOSTerr(GOST_F_PRINT_GOST_EC_PUB, ERR_R_EC_LIB); goto err; } if (!BIO_indent(out, indent, 128)) goto err; BIO_printf(out, "Public key:\n"); if (!BIO_indent(out, indent + 3, 128)) goto err; BIO_printf(out, "X:"); BN_print(out, X); BIO_printf(out, "\n"); if (!BIO_indent(out, indent + 3, 128)) goto err; BIO_printf(out, "Y:"); BN_print(out, Y); BIO_printf(out, "\n"); ok = 1; err: BN_CTX_end(ctx); BN_CTX_free(ctx); return ok; }
static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) { unsigned char *m=NULL; int ret=0; size_t buf_len=0; const char *ktype = NULL; const BIGNUM *priv_key, *pub_key; if (ptype == 2) priv_key = x->priv_key; else priv_key = NULL; if (ptype > 0) pub_key = x->pub_key; else pub_key = NULL; if (ptype == 2) ktype = "Private-Key"; else if (ptype == 1) ktype = "Public-Key"; else ktype = "DSA-Parameters"; update_buflen(x->p, &buf_len); update_buflen(x->q, &buf_len); update_buflen(x->g, &buf_len); update_buflen(priv_key, &buf_len); update_buflen(pub_key, &buf_len); m=(unsigned char *)OPENSSL_malloc(buf_len+10); if (m == NULL) { DSAerr(DSA_F_DO_DSA_PRINT,ERR_R_MALLOC_FAILURE); goto err; } if (priv_key) { if(!BIO_indent(bp,off,128)) goto err; if (BIO_printf(bp,"%s: (%d bit)\n",ktype, BN_num_bits(x->p)) <= 0) goto err; } if (!ASN1_bn_print(bp,"priv:",priv_key,m,off)) goto err; if (!ASN1_bn_print(bp,"pub: ",pub_key,m,off)) goto err; if (!ASN1_bn_print(bp,"P: ",x->p,m,off)) goto err; if (!ASN1_bn_print(bp,"Q: ",x->q,m,off)) goto err; if (!ASN1_bn_print(bp,"G: ",x->g,m,off)) goto err; ret=1; err: if (m != NULL) OPENSSL_free(m); return(ret); }
static int KA_CTX_print_private(BIO *out, const KA_CTX *ctx, int indent) { if (ctx) { if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "Key Agreement Parameters:\n")) return 0; if (ctx->key) if (ctx->shared_secret) { /* If we have a shared secret, we also must have a private key * which we can print. This is a bit clumsy but unfortunately * OpenSSL doesn't offer a function to check whether or not an * EVP_PKEY contains a private key. */ if (!EVP_PKEY_print_private(out, ctx->key, indent+4, NULL)) return 0; } else { if (!EVP_PKEY_print_params(out, ctx->key, indent+4, NULL)) return 0; } else { if (!BIO_indent(out, indent+4, 80) || !BIO_printf(out, "<ABSENT>\n")) return 0; } if (!BIO_indent(out, indent, 80)) return 0; if (ctx->cipher) { if (!BIO_printf(out, "Cipher: %s\n", EVP_CIPHER_name(ctx->cipher))) return 0; } else if (!BIO_printf(out, "Cipher: %s\n", "<ABSENT>")) return 0; if (!BIO_indent(out, indent, 80)) return 0; if (ctx->md) { if (!BIO_printf(out, "Message Digest: %s\n", EVP_MD_name(ctx->md))) return 0; } else if (!BIO_printf(out, "Message Digest: %s\n", "<ABSENT>")) return 0; if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "Shared Secret:\n") || !BUF_MEM_print(out, ctx->shared_secret, indent+4) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "K_enc:\n") || !BUF_MEM_print(out, ctx->k_enc, indent+4) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "K_mac:\n") || !BUF_MEM_print(out, ctx->k_mac, indent+4)) return 0; } else { if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "<ABSENT>\n")) return 0; } return 1; }
static int ssl_print_random(BIO *bio, int indent, const unsigned char **pmsg, size_t *pmsglen) { unsigned int tm; const unsigned char *p = *pmsg; if (*pmsglen < 32) return 0; tm = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; p += 4; BIO_indent(bio, indent, 80); BIO_puts(bio, "Random:\n"); BIO_indent(bio, indent + 2, 80); BIO_printf(bio, "gmt_unix_time=0x%08X\n", tm); ssl_print_hex(bio, indent + 2, "random_bytes", p, 28); *pmsg += 32; *pmsglen -= 32; return 1; }
static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) { uint8_t *m = NULL; int ret = 0; size_t buf_len = 0; const char *ktype = NULL; const BIGNUM *priv_key, *pub_key; priv_key = NULL; if (ptype == 2) { priv_key = x->priv_key; } pub_key = NULL; if (ptype > 0) { pub_key = x->pub_key; } ktype = "DSA-Parameters"; if (ptype == 2) { ktype = "Private-Key"; } else if (ptype == 1) { ktype = "Public-Key"; } update_buflen(x->p, &buf_len); update_buflen(x->q, &buf_len); update_buflen(x->g, &buf_len); update_buflen(priv_key, &buf_len); update_buflen(pub_key, &buf_len); m = (uint8_t *)OPENSSL_malloc(buf_len + 10); if (m == NULL) { OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE); goto err; } if (priv_key) { if (!BIO_indent(bp, off, 128) || BIO_printf(bp, "%s: (%d bit)\n", ktype, BN_num_bits(x->p)) <= 0) { goto err; } } if (!ASN1_bn_print(bp, "priv:", priv_key, m, off) || !ASN1_bn_print(bp, "pub: ", pub_key, m, off) || !ASN1_bn_print(bp, "P: ", x->p, m, off) || !ASN1_bn_print(bp, "Q: ", x->q, m, off) || !ASN1_bn_print(bp, "G: ", x->g, m, off)) { goto err; } ret = 1; err: OPENSSL_free(m); return ret; }
static void ssl_print_hex(BIO *bio, int indent, const char *name, const unsigned char *msg, size_t msglen) { size_t i; BIO_indent(bio, indent, 80); BIO_printf(bio, "%s (len=%d): ", name, (int)msglen); for (i = 0; i < msglen; i++) BIO_printf(bio, "%02X", msg[i]); BIO_puts(bio, "\n"); }
int PACE_SEC_print_private(BIO *out, const PACE_SEC *sec, int indent) { const char *s; if (sec) { switch (sec->type) { case PACE_RAW: s = raw_str; break; case PACE_PIN: s = pin_str; break; case PACE_PUK: s = puk_str; break; case PACE_CAN: s = can_str; break; case PACE_MRZ: s = mrz_str; break; case PACE_SEC_UNDEF: /* fall through */ default: s = undef_str; break; } if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "%s\n", s) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "Secret:\n") || !BUF_MEM_print(out, sec->mem, indent) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "Encoded Secret:\n") || !BUF_MEM_print(out, sec->encoded, indent)) return 0; } else { if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "<ABSENT>\n")) return 0; } return 1; }
static int CA_CTX_print_private(BIO *out, const CA_CTX *ctx, int indent) { if (ctx) { if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "keyID: 0x%02X\n", ctx->id) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "OID: %s\n", OBJ_nid2sn(ctx->protocol)) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "Version: %d\n", ctx->version) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "PICC's Static Domain Parameters:\n") || !KA_CTX_print_private(out, ctx->ka_ctx, indent+4)) return 0; } else { if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "<ABSENT>\n")) return 0; } return 1; }
int DSA_print(BIO *bp, const DSA *x, int off) { unsigned char *m=NULL; int ret=0; size_t buf_len=0,i; if (x->p) buf_len = (size_t)BN_num_bytes(x->p); else { DSAerr(DSA_F_DSA_PRINT,DSA_R_MISSING_PARAMETERS); goto err; } if (x->q) if (buf_len < (i = (size_t)BN_num_bytes(x->q))) buf_len = i; if (x->g) if (buf_len < (i = (size_t)BN_num_bytes(x->g))) buf_len = i; if (x->priv_key) if (buf_len < (i = (size_t)BN_num_bytes(x->priv_key))) buf_len = i; if (x->pub_key) if (buf_len < (i = (size_t)BN_num_bytes(x->pub_key))) buf_len = i; m=(unsigned char *)OPENSSL_malloc(buf_len+10); if (m == NULL) { DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE); goto err; } if (x->priv_key != NULL) { if(!BIO_indent(bp,off,128)) goto err; if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p)) <= 0) goto err; } if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off)) goto err; if ((x->pub_key != NULL) && !print(bp,"pub: ",x->pub_key,m,off)) goto err; if ((x->p != NULL) && !print(bp,"P: ",x->p,m,off)) goto err; if ((x->q != NULL) && !print(bp,"Q: ",x->q,m,off)) goto err; if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err; ret=1; err: if (m != NULL) OPENSSL_free(m); return(ret); }
int BUF_MEM_print(BIO *out, const BUF_MEM *buf, int indent) { if (buf) { if (!BIO_dump_indent(out, buf->data, buf->length, indent)) return 0; } else { if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "<ABSENT>\n")) return 0; } return 1; }
static int ssl_print_version(BIO *bio, int indent, const char *name, const unsigned char **pmsg, size_t *pmsglen) { int vers; if (*pmsglen < 2) return 0; vers = ((*pmsg)[0] << 8) | (*pmsg)[1]; BIO_indent(bio, indent, 80); BIO_printf(bio, "%s=0x%x (%s)\n", name, vers, ssl_trace_str(vers, ssl_version_tbl)); *pmsg += 2; *pmsglen -= 2; return 1; }
int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, unsigned char *ign, int indent) { int n, rv = 0; const char *neg; unsigned char *buf = NULL, *tmp = NULL; int buflen; if (num == NULL) return 1; neg = BN_is_negative(num) ? "-" : ""; if (!BIO_indent(bp, indent, ASN1_PRINT_MAX_INDENT)) return 0; if (BN_is_zero(num)) { if (BIO_printf(bp, "%s 0\n", number) <= 0) return 0; return 1; } if (BN_num_bytes(num) <= BN_BYTES) { if (BIO_printf(bp, "%s %s%lu (%s0x%lx)\n", number, neg, (unsigned long)bn_get_words(num)[0], neg, (unsigned long)bn_get_words(num)[0]) <= 0) return 0; return 1; } buflen = BN_num_bytes(num) + 1; buf = tmp = OPENSSL_malloc(buflen); if (buf == NULL) goto err; buf[0] = 0; if (BIO_printf(bp, "%s%s\n", number, (neg[0] == '-') ? " (Negative)" : "") <= 0) goto err; n = BN_bn2bin(num, buf + 1); if (buf[1] & 0x80) n++; else tmp++; if (ASN1_buf_print(bp, tmp, n, indent + 4) == 0) goto err; rv = 1; err: OPENSSL_clear_free(buf, buflen); return rv; }
int EAC_CTX_print_private(BIO *out, const EAC_CTX *ctx, int indent) { if (ctx) { if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "%d Context%s for PACE (default has parameterID 0x%02X)\n", sk_num((_STACK*) ctx->pace_ctxs), sk_num((_STACK*) ctx->pace_ctxs) > 1 ? "s" : "", ctx->pace_ctx ? ctx->pace_ctx->id : -1)) return 0; stack_print_private(PACE_CTX, out, ctx->pace_ctxs, indent+4); if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "Context for TA\n") || !TA_CTX_print_private(out, ctx->ta_ctx, indent+4) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "%d Context%s for CA (default has keyID 0x%02X)\n", sk_num((_STACK*) ctx->ca_ctxs), sk_num((_STACK*) ctx->ca_ctxs) > 1 ? "s" : "", ctx->ca_ctx ? ctx->ca_ctx->id : -1)) return 0; stack_print_private(CA_CTX, out, ctx->ca_ctxs, indent+4); if (!BIO_indent(out, indent, 80) /* FIXME segfaults for me */ || !BIO_printf(out, "%d Context%s for RI (default has keyID 0x%02X)\n", sk_num((_STACK*) ctx->ri_ctxs), sk_num((_STACK*) ctx->ri_ctxs) > 1 ? "s" : "", ctx->ri_ctx ? ctx->ri_ctx->id : -1)) return 0; stack_print_private(RI_CTX, out, ctx->ri_ctxs, indent); } else { if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "<ABSENT>\n")) return 0; } return 1; }
static int print_gost_ec_param(BIO *out, const EVP_PKEY *pkey, int indent) { EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pkey); const EC_GROUP *group = (ec) ? EC_KEY_get0_group(ec) : NULL; int param_nid; if (!group) return 0; param_nid = EC_GROUP_get_curve_name(group); if (!BIO_indent(out, indent, 128)) return 0; BIO_printf(out, "Parameter set: %s\n", OBJ_nid2ln(param_nid)); return 1; }
/* --------- printing keys --------------------------------*/ static int print_gost_priv(BIO *out, const EVP_PKEY *pkey, int indent) { BIGNUM *key; if (!BIO_indent(out, indent, 128)) return 0; BIO_printf(out, "Private key: "); key = gost_get0_priv_key(pkey); if (!key) BIO_printf(out, "<undefined>"); else BN_print(out, key); BIO_printf(out, "\n"); return 1; }
static int ssl_print_signature(BIO *bio, int indent, SSL *s, const unsigned char **pmsg, size_t *pmsglen) { if (*pmsglen < 2) return 0; if (SSL_USE_SIGALGS(s)) { const unsigned char *p = *pmsg; BIO_indent(bio, indent, 80); BIO_printf(bio, "Signature Algorithm %s+%s (%d+%d)\n", ssl_trace_str(p[0], ssl_md_tbl), ssl_trace_str(p[1], ssl_sig_tbl), p[0], p[1]); *pmsg += 2; *pmsglen -= 2; } return ssl_print_hexbuf(bio, indent, "Signature", 2, pmsg, pmsglen); }
static int priv_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx) { const BIGNUM *key; if (BIO_indent(out, indent, 128) == 0) return 0; BIO_printf(out, "Private key: "); key = GOST_KEY_get0_private_key(pkey->pkey.gost); if (key == NULL) BIO_printf(out, "<undefined)"); else BN_print(out, key); BIO_printf(out, "\n"); return pub_print_gost01(out, pkey, indent, pctx); }
static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) { int ret = 0; const char *ktype = NULL; const BIGNUM *priv_key, *pub_key; if (ptype == 2) priv_key = x->priv_key; else priv_key = NULL; if (ptype > 0) pub_key = x->pub_key; else pub_key = NULL; if (ptype == 2) ktype = "Private-Key"; else if (ptype == 1) ktype = "Public-Key"; else ktype = "DSA-Parameters"; if (priv_key) { if (!BIO_indent(bp, off, 128)) goto err; if (BIO_printf(bp, "%s: (%d bit)\n", ktype, BN_num_bits(x->p)) <= 0) goto err; } if (!ASN1_bn_print(bp, "priv:", priv_key, NULL, off)) goto err; if (!ASN1_bn_print(bp, "pub: ", pub_key, NULL, off)) goto err; if (!ASN1_bn_print(bp, "P: ", x->p, NULL, off)) goto err; if (!ASN1_bn_print(bp, "Q: ", x->q, NULL, off)) goto err; if (!ASN1_bn_print(bp, "G: ", x->g, NULL, off)) goto err; ret = 1; err: return ret; }
static int do_rsa_print(BIO *bp, const RSA *x, int off, int priv) { char *str; const char *s; int ret = 0, mod_len = 0; if (x->n != NULL) mod_len = BN_num_bits(x->n); if (!BIO_indent(bp, off, 128)) goto err; if (priv && x->d) { if (BIO_printf(bp, "Private-Key: (%d bit)\n", mod_len) <= 0) goto err; str = "modulus:"; s = "publicExponent:"; } else { if (BIO_printf(bp, "Public-Key: (%d bit)\n", mod_len) <= 0) goto err; str = "Modulus:"; s = "Exponent:"; } if (!ASN1_bn_print(bp, str, x->n, NULL, off)) goto err; if (!ASN1_bn_print(bp, s, x->e, NULL, off)) goto err; if (priv) { if (!ASN1_bn_print(bp, "privateExponent:", x->d, NULL, off)) goto err; if (!ASN1_bn_print(bp, "prime1:", x->p, NULL, off)) goto err; if (!ASN1_bn_print(bp, "prime2:", x->q, NULL, off)) goto err; if (!ASN1_bn_print(bp, "exponent1:", x->dmp1, NULL, off)) goto err; if (!ASN1_bn_print(bp, "exponent2:", x->dmq1, NULL, off)) goto err; if (!ASN1_bn_print(bp, "coefficient:", x->iqmp, NULL, off)) goto err; } ret = 1; err: return (ret); }
static int do_ssl_trace_list(BIO *bio, int indent, const unsigned char *msg, size_t msglen, size_t vlen, ssl_trace_tbl *tbl, size_t ntbl) { int val; if (msglen % vlen) return 0; while (msglen) { val = msg[0]; if (vlen == 2) val = (val << 8) | msg[1]; BIO_indent(bio, indent, 80); BIO_printf(bio, "%s (%d)\n", do_ssl_trace_str(val, tbl, ntbl), val); msg += vlen; msglen -= vlen; } return 1; }
int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) { const unsigned char *s; int i, n; n=sig->length; s=sig->data; for (i=0; i<n; i++) { if ((i%18) == 0) { if (BIO_write(bp,"\n",1) <= 0) return 0; if (BIO_indent(bp, indent, indent) <= 0) return 0; } if (BIO_printf(bp,"%02x%s",s[i], ((i+1) == n)?"":":") <= 0) return 0; } if (BIO_write(bp,"\n",1) != 1) return 0; return 1; }
static int PACE_CTX_print_private(BIO *out, const PACE_CTX *ctx, int indent) { if (ctx) { if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "parameterID: 0x%02X\n", ctx->id) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "OID: %s\n", OBJ_nid2sn(ctx->protocol)) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "Version: %d\n", ctx->version) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "PICC's Static Domain Parameters:\n")) return 0; if (ctx->static_key) { if (!EVP_PKEY_print_params(out, ctx->static_key, indent+4, NULL)) return 0; else { if (!BIO_indent(out, indent+4, 80) || !BIO_printf(out, "<ABSENT>\n")) return 0; } } if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "Nonce:\n") || !BUF_MEM_print(out, ctx->nonce, indent+4) || !BIO_indent(out, indent, 80) || !BIO_printf(out, "Ephemeral Domain Parameters:\n") || !KA_CTX_print_private(out, ctx->ka_ctx, indent+4)) return 0; } else { if (!BIO_indent(out, indent, 80) || !BIO_printf(out, "<ABSENT>\n")) return 0; } return 1; }
static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, int indent) { static const char fmt[]="%-18s"; static const char fmt2[]="%2d %-15s"; char str[128]; const char *p,*p2=NULL; if (constructed & V_ASN1_CONSTRUCTED) p="cons: "; else p="prim: "; if (BIO_write(bp,p,6) < 6) goto err; #if OPENSSL_VERSION_NUMBER >= 0x0090701fL BIO_indent(bp,indent,128); #endif p=str; if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) sprintf(str,"priv [ %d ] ",tag); else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) sprintf(str,"cont [ %d ]",tag); else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) sprintf(str,"appl [ %d ]",tag); else p = ASN1_tag2str(tag); if (p2 != NULL) { if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err; } else { if (BIO_printf(bp,fmt,p) <= 0) goto err; } return(1); err: return(0); }