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

NAME

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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUES

86       BN_bn2bin() returns the length of the big-endian number placed at to.
87       BN_bin2bn() returns the BIGNUM, NULL on error.
88
89       BN_bn2binpad(), BN_bn2lebinpad(), and BN_bn2nativepad() return the
90       number of bytes written or -1 if the supplied buffer is too small.
91
92       BN_bn2hex() and BN_bn2dec() return a NUL-terminated string, or NULL on
93       error. BN_hex2bn() and BN_dec2bn() return the number of characters used
94       in parsing, or 0 on error, in which case no new BIGNUM will be created.
95
96       BN_print_fp() and BN_print() return 1 on success, 0 on write errors.
97
98       BN_bn2mpi() returns the length of the representation. BN_mpi2bn()
99       returns the BIGNUM, and NULL on error.
100
101       The error codes can be obtained by ERR_get_error(3).
102

SEE ALSO

104       ERR_get_error(3), BN_zero(3), ASN1_INTEGER_to_BN(3), BN_num_bytes(3)
105
107       Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
108
109       Licensed under the Apache License 2.0 (the "License").  You may not use
110       this file except in compliance with the License.  You can obtain a copy
111       in the file LICENSE in the source distribution or at
112       <https://www.openssl.org/source/license.html>.
113
114
115
1163.0.5                             2022-11-01                  BN_BN2BIN(3ossl)
Impressum