DAY17_openssl的正确打开使用方式

来源:互联网 发布:理性上网不做网络喷子 编辑:程序博客网 时间:2024/04/30 13:25

1.openssl文件+openssl算法

http://blog.chinaunix.net/uid-23615729-id-313371.html


2.DH为例,实现在crypt/dh目录中,各个源码功能:

http://blog.csdn.net/sjtu_chenchen/article/details/46404933


3.DH为例,数据结构定义在crypto/dh/dh.h中,主要包含两项:

struct dh_method {    const char *name;    /* Methods here */    int (*generate_key) (DH *dh);    int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh);    /* Can be null */    int (*bn_mod_exp) (const DH *dh, BIGNUM *r, const BIGNUM *a,                       const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,                       BN_MONT_CTX *m_ctx);    int (*init) (DH *dh);    int (*finish) (DH *dh);    int flags;    char *app_data;    /* If this is non-NULL, it will be used to generate parameters */    int (*generate_params) (DH *dh, int prime_len, int generator,                            BN_GENCB *cb);};

DH_METHOD指明了一个DH密钥所有的计算方法函数。用户可以实现自己的DH_METHOD来替换openssl提供默认方法。各项意义如下:

name:DH_METHOD方法名称。

generate_key:生成DH公私钥的函数。

compute_key:根据对方公钥和己方DH密钥来生成共享密钥的函数。

bn_mod_exp:大数模运算函数,如果用户实现了它,生成DH密钥时,将采用用户实现的该回调函数。用于干预DH密钥生成。

init:初始化函数。

finish:结束函数。

flags:用于记录标记。

app_data:用于存放应用数据。

generate_params:生成DH密钥参数的回调函数,生成的密钥参数是可以公开的。

struct dh_st {    /*     * This first argument is used to pick up errors when a DH is passed     * instead of a EVP_PKEY     */    int pad;    int version;    BIGNUM *p;    BIGNUM *g;    long length;                /* optional */    BIGNUM *pub_key;            /* g^x */    BIGNUM *priv_key;           /* x */    int flags;    BN_MONT_CTX *method_mont_p;    /* Place holders if we want to do X9.42 DH */    BIGNUM *q;    BIGNUM *j;    unsigned char *seed;    int seedlen;    BIGNUM *counter;    int references;    CRYPTO_EX_DATA ex_data;    const DH_METHOD *meth;    ENGINE *engine;};

      p、g、length:DH密钥参数;
      pub_key:DH公钥;
       priv_key:DH私钥;
       references:引用;
       ex_data:扩展数据;
       meth:DH_METHOD,本DH密钥的各种计算方法,明确指明了DH的各种运算方式;
       engine:硬件引擎。








0 0
原创粉丝点击