在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            博客專欄

            EEPW首頁 > 博客 > SM2算法第二十七篇: openssl庫中的BIGNUM(超贊)

            SM2算法第二十七篇: openssl庫中的BIGNUM(超贊)

            發(fā)布人:電子禪石 時間:2023-09-05 來源:工程師 發(fā)布文章

            openssl庫中的BIGNUM,處理大數(shù)比較好,可以用在很多方面。

            BIGNUM是一個typedef的結構,可以直接使用。但一般來說,使用它的指針結構。如:BIGNUM *p;

            BIGNUM的創(chuàng)建與釋放
            函數(shù)原型解釋示例
            BIGNUM * BN_new (void);創(chuàng)建一個BIGNUM的結構,返回新BIGNUM結構的指針BIGNUM *a = BN_new ();
            void BN_free (BIGNUM *);釋放一個BIGNUMfree (a);
            BIGNUM的值測試
            函數(shù)原型解釋示例
            int BN_cmp (BIGNUM *a, BIGNUM *b);| 判斷a與b是否相等if (BN_cmp (a, b) { printf ("a equ b/n"); }
            <verbatim>int BN_ucmp (BIGNUM *a, BIGNUM *b);判斷a與b的絕對值是否相等if (BN_ucmp (a, b)
            int BN_is_zero(BIGNUM *a);判斷a是不是為0if (BN_is_zero (a))
            int BN_is_one(BIGNUM *a);判斷a是不是1if (BN_is_one (a))
            int BN_is_word(BIGNUM *a, BN_ULONG w);判斷a是不是值wif (BN_is_word (a, 12))
            int BN_is_odd(BIGNUM *a);判斷a是不是一個奇數(shù)if (BN_is_odd (a))
            BIGNUM的賦值與取值
            函數(shù)原型解釋示例
            int BN_num_bytes(BIGNUM *a);返回a的字節(jié)數(shù)printf ("length: %d/n", BN_num_tytes (a));
            int BN_num_bits(BIGNUM *a);返回a的二進制位數(shù)printf ("bits: %d/n", BN_num_bits (a));
            int BN_one(BIGNUM *a);設置a為1BN_one (a);
            int BN_zero(BIGNUM *a);設置a為0BN_zero (a);
            int BN_bn2bin(const BIGNUM *a, unsigned char *to);取a為二進制到to中,返回字符串長度char s[1024];
            int length = BN_bn2bin (a, s);
            BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);賦二進制值s到ret中,返回retchar s[] = "1001001";
            BN_bin2bn (s, strlen (s), a);
            char *BN_bn2hex(const BIGNUM *a);取a的16進制值,返回一個字符串的指針。此指針要使用完后,手動使用OPENSSL_free釋放char *p = BN_bn2hex (a); 
            if (p)
            {
            printf ("number is 0x%s/n", p);
            OPENSSL_free (p);
            }
            char *BN_bn2dec(const BIGNUM *a);取a的10進制值,返回一個字符串的指針。此指針要使用完后,手動使用OPENSSL_free釋放p = BN_bn2dec (a);
            int BN_hex2bn(BIGNUM **a, const char *str);賦16進制值str到*a中,返回成功與否BN_hex2bn (&a, "0x123F23D12");
            int BN_dec2bn(BIGNUM **a, const char *str);賦10進制值str到*a中,返回成功與否BN_dec2bn (&a, "1999");
            BIGNUM的計算
            函數(shù)原型解釋示例
            int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);計算a與b的和,值儲存在r中。如果成功,返回1;否則,返回0BIGNUM *a = BN_new (), *b = BN_new (), *r = BN_new ();
            BN_dec2bn (&a, "1234");
            BN_dec2bn (&b, "2345");
            BN_add (r, a, b);
            int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);計算a與b的差,值儲存在r中。返回1或者0BN_sum (r, a, b);
            int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);計算a與b的積,值儲存在r中。返回1或者0。ctx為一個上下文相關的結構,可以用BN_CTX_new與BN_CTX_free來創(chuàng)建與釋放它BN_CTX *ctx = BN_CTX_new ();
            BN_mul (r, a, b, ctx);
            BN_CTX_free (ctx);
            int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);計算a的平方,值儲存在r中。返回1或者0BN_sqr (r, a, ctx);
            int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d, BN_CTX *ctx);計算a與d的商,值儲存在dv中,余數(shù)儲存在rem中。返回1或者0BN_div (dv, r, a, b);
            int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);計算a與m的模,值儲存在rem中。返回1或者0BN_mod (r, a, m, ctx);
            int BN_nnmod(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);計算a與m的模,并且結果如果小于0,就加上m,值儲存在r中。返回1或者0BN_nnmod (r, a, m, ctx);
            int BN_mod_add(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);計算a與b的和,再模m,值儲存在r中。返回1或者0BN_mod_add (r, a, b, m, ctx);
            int BN_mod_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);計算a與b的差,再模m,值儲存在r中。返回1或者0BN_mod_sub (r, a, b, m, ctx);
            int BN_mod_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);計算a與b的積,再模m,值儲存在r中。返回1或者0BN_mod_mul (r, a, b, m, ctx);
            int BN_mod_sqr(BIGNUM *r, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);計算a的平方根,再模m,值儲存在r中。返回1或者0BN_mod_sqr (r, a, m, ctx);
            int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);計算a的p次方,值儲存在r中。返回1或者0BN_exp (r, a, p, ctx);
            int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx);計算a的p次方,再模m,值儲存在r中。返回1或者0BN_mod_exp (r, a, p, m, ctx);
            int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);計算a與b的最大公約數(shù),值儲存在r中。返回1或者0BN_gcd (r, a, b, ctx);
            int BN_add_word(BIGNUM *a, BN_ULONG w);大數(shù)a加上w,值儲存在a中,返回1或者0BN_dec2bn (a, "1234");
            BN_add_word (a, 1);
            int BN_sub_word(BIGNUM *a, BN_ULONG w);大數(shù)a減去w,值儲存在a中,返回1或者0BN_sub_word (a, 23);
            int BN_mul_word(BIGNUM *a, BN_ULONG w);大數(shù)a乘以w,值儲存在a中,返回1或者0BN_mul_word (a, 2);
            BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);大數(shù)a除以w,值儲存在a中,返回余數(shù)BN_ULONG ru = BN_div_word (a, 256);
            BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);大數(shù)a模w,返回余數(shù)ru = BN_mod_word (a, 256);

            轉自:http://blogold.chinaunix.net/u/19628/showart_2081074.html


            *博客內容為網友個人發(fā)布,僅代表博主個人觀點,如有侵權請聯(lián)系工作人員刪除。



            關鍵詞: openssl

            技術專區(qū)

            關閉