📄 t_pkey.c
字号:
int basis_type = EC_GROUP_get_basis_type(x); if (basis_type == 0) goto err; if (!BIO_indent(bp, off, 128)) goto err; if (BIO_printf(bp, "Basis Type: %s\n", OBJ_nid2sn(basis_type)) <= 0) goto err; /* print the polynomial */ if ((p != NULL) && !print(bp, "Polynomial:", p, buffer, off)) goto err; } else { if ((p != NULL) && !print(bp, "Prime:", p, buffer,off)) goto err; } if ((a != NULL) && !print(bp, "A: ", a, buffer, off)) goto err; if ((b != NULL) && !print(bp, "B: ", b, buffer, off)) goto err; if (form == POINT_CONVERSION_COMPRESSED) { if ((gen != NULL) && !print(bp, gen_compressed, gen, buffer, off)) goto err; } else if (form == POINT_CONVERSION_UNCOMPRESSED) { if ((gen != NULL) && !print(bp, gen_uncompressed, gen, buffer, off)) goto err; } else /* form == POINT_CONVERSION_HYBRID */ { if ((gen != NULL) && !print(bp, gen_hybrid, gen, buffer, off)) goto err; } if ((order != NULL) && !print(bp, "Order: ", order, buffer, off)) goto err; if ((cofactor != NULL) && !print(bp, "Cofactor: ", cofactor, buffer, off)) goto err; if (seed && !print_bin(bp, "Seed:", seed, seed_len, off)) goto err; } ret=1;err: if (!ret) ECerr(EC_F_ECPKPARAMETERS_PRINT, reason); if (p) BN_free(p); if (a) BN_free(a); if (b) BN_free(b); if (gen) BN_free(gen); if (order) BN_free(order); if (cofactor) BN_free(cofactor); if (ctx) BN_CTX_free(ctx); if (buffer != NULL) OPENSSL_free(buffer); return(ret); }int EC_KEY_print(BIO *bp, const EC_KEY *x, int off) { unsigned char *buffer=NULL; size_t buf_len=0, i; int ret=0, reason=ERR_R_BIO_LIB; BIGNUM *pub_key=NULL, *order=NULL; BN_CTX *ctx=NULL; const EC_GROUP *group; const EC_POINT *public_key; const BIGNUM *priv_key; if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL) { reason = ERR_R_PASSED_NULL_PARAMETER; goto err; } public_key = EC_KEY_get0_public_key(x); if ((pub_key = EC_POINT_point2bn(group, public_key, EC_KEY_get_conv_form(x), NULL, ctx)) == NULL) { reason = ERR_R_EC_LIB; goto err; } buf_len = (size_t)BN_num_bytes(pub_key); priv_key = EC_KEY_get0_private_key(x); if (priv_key != NULL) { if ((i = (size_t)BN_num_bytes(priv_key)) > buf_len) buf_len = i; } buf_len += 10; if ((buffer = OPENSSL_malloc(buf_len)) == NULL) { reason = ERR_R_MALLOC_FAILURE; goto err; } if (priv_key != NULL) { if (!BIO_indent(bp, off, 128)) goto err; if ((order = BN_new()) == NULL) goto err; if (!EC_GROUP_get_order(group, order, NULL)) goto err; if (BIO_printf(bp, "Private-Key: (%d bit)\n", BN_num_bits(order)) <= 0) goto err; } if ((priv_key != NULL) && !print(bp, "priv:", priv_key, buffer, off)) goto err; if ((pub_key != NULL) && !print(bp, "pub: ", pub_key, buffer, off)) goto err; if (!ECPKParameters_print(bp, group, off)) goto err; ret=1;err: if (!ret) ECerr(EC_F_EC_KEY_PRINT, reason); if (pub_key) BN_free(pub_key); if (order) BN_free(order); if (ctx) BN_CTX_free(ctx); if (buffer != NULL) OPENSSL_free(buffer); return(ret); }#endif /* OPENSSL_NO_EC */static int 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); }#ifndef OPENSSL_NO_ECstatic int print_bin(BIO *fp, const char *name, const unsigned char *buf, size_t len, int off) { size_t i; char str[128]; if (buf == NULL) return 1; if (off) { if (off > 128) off=128; memset(str,' ',off); if (BIO_write(fp, str, off) <= 0) return 0; } if (BIO_printf(fp,"%s", name) <= 0) return 0; for (i=0; i<len; i++) { if ((i%15) == 0) { str[0]='\n'; memset(&(str[1]),' ',off+4); if (BIO_write(fp, str, off+1+4) <= 0) return 0; } if (BIO_printf(fp,"%02x%s",buf[i],((i+1) == len)?"":":") <= 0) return 0; } if (BIO_write(fp,"\n",1) <= 0) return 0; return 1; }#endif#ifndef OPENSSL_NO_DH#ifndef OPENSSL_NO_FP_APIint DHparams_print_fp(FILE *fp, const DH *x) { BIO *b; int ret; if ((b=BIO_new(BIO_s_file())) == NULL) { DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB); return(0); } BIO_set_fp(b,fp,BIO_NOCLOSE); ret=DHparams_print(b, x); BIO_free(b); return(ret); }#endifint DHparams_print(BIO *bp, const DH *x) { unsigned char *m=NULL; int reason=ERR_R_BUF_LIB,ret=0; size_t buf_len=0, i; if (x->p) buf_len = (size_t)BN_num_bytes(x->p); else { reason = ERR_R_PASSED_NULL_PARAMETER; goto err; } if (x->g) if (buf_len < (i = (size_t)BN_num_bytes(x->g))) buf_len = i; m=(unsigned char *)OPENSSL_malloc(buf_len+10); if (m == NULL) { reason=ERR_R_MALLOC_FAILURE; goto err; } if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n", BN_num_bits(x->p)) <= 0) goto err; if (!print(bp,"prime:",x->p,m,4)) goto err; if (!print(bp,"generator:",x->g,m,4)) goto err; if (x->length != 0) { if (BIO_printf(bp," recommended-private-length: %d bits\n", (int)x->length) <= 0) goto err; } ret=1; if (0) {err: DHerr(DH_F_DHPARAMS_PRINT,reason); } if (m != NULL) OPENSSL_free(m); return(ret); }#endif#ifndef OPENSSL_NO_DSA#ifndef OPENSSL_NO_FP_APIint DSAparams_print_fp(FILE *fp, const DSA *x) { BIO *b; int ret; if ((b=BIO_new(BIO_s_file())) == NULL) { DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB); return(0); } BIO_set_fp(b,fp,BIO_NOCLOSE); ret=DSAparams_print(b, x); BIO_free(b); return(ret); }#endifint DSAparams_print(BIO *bp, const DSA *x) { 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_DSAPARAMS_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; m=(unsigned char *)OPENSSL_malloc(buf_len+10); if (m == NULL) { DSAerr(DSA_F_DSAPARAMS_PRINT,ERR_R_MALLOC_FAILURE); goto err; } if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n", BN_num_bits(x->p)) <= 0) goto err; if (!print(bp,"p:",x->p,m,4)) goto err; if ((x->q != NULL) && !print(bp,"q:",x->q,m,4)) goto err; if ((x->g != NULL) && !print(bp,"g:",x->g,m,4)) goto err; ret=1;err: if (m != NULL) OPENSSL_free(m); return(ret); }#endif /* !OPENSSL_NO_DSA */#ifndef OPENSSL_NO_EC#ifndef OPENSSL_NO_FP_APIint ECParameters_print_fp(FILE *fp, const EC_KEY *x) { BIO *b; int ret; if ((b=BIO_new(BIO_s_file())) == NULL) { ECerr(EC_F_ECPARAMETERS_PRINT_FP, ERR_R_BIO_LIB); return(0); } BIO_set_fp(b, fp, BIO_NOCLOSE); ret = ECParameters_print(b, x); BIO_free(b); return(ret); }#endifint ECParameters_print(BIO *bp, const EC_KEY *x) { int reason=ERR_R_EC_LIB, ret=0; BIGNUM *order=NULL; const EC_GROUP *group; if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL) { reason = ERR_R_PASSED_NULL_PARAMETER;; goto err; } if ((order = BN_new()) == NULL) { reason = ERR_R_MALLOC_FAILURE; goto err; } if (!EC_GROUP_get_order(group, order, NULL)) { reason = ERR_R_EC_LIB; goto err; } if (BIO_printf(bp, "ECDSA-Parameters: (%d bit)\n", BN_num_bits(order)) <= 0) goto err; if (!ECPKParameters_print(bp, group, 4)) goto err; ret=1;err: if (order) BN_free(order); ECerr(EC_F_ECPARAMETERS_PRINT, reason); return(ret); } #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -