1BN_BN2BIN(3)                        OpenSSL                       BN_BN2BIN(3)
2
3
4

NAME

6       BN_bn2binpad, BN_bn2bin, BN_bin2bn, BN_bn2lebinpad, BN_lebin2bn,
7       BN_bn2hex, BN_bn2dec, BN_hex2bn, BN_dec2bn, BN_print, BN_print_fp,
8       BN_bn2mpi, BN_mpi2bn - format conversions
9

SYNOPSIS

11        #include <openssl/bn.h>
12
13        int BN_bn2bin(const BIGNUM *a, unsigned char *to);
14        int BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen);
15        BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
16
17        int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen);
18        BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret);
19
20        char *BN_bn2hex(const BIGNUM *a);
21        char *BN_bn2dec(const BIGNUM *a);
22        int BN_hex2bn(BIGNUM **a, const char *str);
23        int BN_dec2bn(BIGNUM **a, const char *str);
24
25        int BN_print(BIO *fp, const BIGNUM *a);
26        int BN_print_fp(FILE *fp, const BIGNUM *a);
27
28        int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
29        BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
30

DESCRIPTION

32       BN_bn2bin() converts the absolute value of a into big-endian form and
33       stores it at to. to must point to BN_num_bytes(a) bytes of memory.
34
35       BN_bn2binpad() also converts the absolute value of a into big-endian
36       form and stores it at to. tolen indicates the length of the output
37       buffer to. The result is padded with zeroes if necessary. If tolen is
38       less than BN_num_bytes(a) an error is returned.
39
40       BN_bin2bn() converts the positive integer in big-endian form of length
41       len at s into a BIGNUM and places it in ret. If ret is NULL, a new
42       BIGNUM is created.
43
44       BN_bn2lebinpad() and BN_lebin2bn() are identical to BN_bn2binpad() and
45       BN_bin2bn() except the buffer is in little-endian format.
46
47       BN_bn2hex() and BN_bn2dec() return printable strings containing the
48       hexadecimal and decimal encoding of a respectively. For negative
49       numbers, the string is prefaced with a leading '-'. The string must be
50       freed later using OPENSSL_free().
51
52       BN_hex2bn() takes as many characters as possible from the string str,
53       including the leading character '-' which means negative, to form a
54       valid hexadecimal number representation and converts them to a BIGNUM
55       and stores it in **a. If *a is NULL, a new BIGNUM is created. If a is
56       NULL, it only computes the length of valid representation.  A "negative
57       zero" is converted to zero.  BN_dec2bn() is the same using the decimal
58       system.
59
60       BN_print() and BN_print_fp() write the hexadecimal encoding of a, with
61       a leading '-' for negative numbers, to the BIO or FILE fp.
62
63       BN_bn2mpi() and BN_mpi2bn() convert BIGNUMs from and to a format that
64       consists of the number's length in bytes represented as a 4-byte big-
65       endian number, and the number itself in big-endian format, where the
66       most significant bit signals a negative number (the representation of
67       numbers with the MSB set is prefixed with null byte).
68
69       BN_bn2mpi() stores the representation of a at to, where to must be
70       large enough to hold the result. The size can be determined by calling
71       BN_bn2mpi(a, NULL).
72
73       BN_mpi2bn() converts the len bytes long representation at s to a BIGNUM
74       and stores it at ret, or in a newly allocated BIGNUM if ret is NULL.
75

RETURN VALUES

77       BN_bn2bin() returns the length of the big-endian number placed at to.
78       BN_bin2bn() returns the BIGNUM, NULL on error.
79
80       BN_bn2binpad() returns the number of bytes written or -1 if the
81       supplied buffer is too small.
82
83       BN_bn2hex() and BN_bn2dec() return a null-terminated string, or NULL on
84       error. BN_hex2bn() and BN_dec2bn() return the number of characters used
85       in parsing, or 0 on error, in which case no new BIGNUM will be created.
86
87       BN_print_fp() and BN_print() return 1 on success, 0 on write errors.
88
89       BN_bn2mpi() returns the length of the representation. BN_mpi2bn()
90       returns the BIGNUM, and NULL on error.
91
92       The error codes can be obtained by ERR_get_error(3).
93

SEE ALSO

95       ERR_get_error(3), BN_zero(3), ASN1_INTEGER_to_BN(3), BN_num_bytes(3)
96
98       Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
99
100       Licensed under the OpenSSL license (the "License").  You may not use
101       this file except in compliance with the License.  You can obtain a copy
102       in the file LICENSE in the source distribution or at
103       <https://www.openssl.org/source/license.html>.
104
105
106
1071.1.1d                            2019-10-03                      BN_BN2BIN(3)
Impressum