# Big Numbers

**API Group:** `xmlsec_core_bn`

Big-number (arbitrary-precision integer) utility functions.

Big numbers support functions.

## Typedefs

### `xmlSecBn`

```c
typedef xmlSecBuffer xmlSecBn;
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L24)

Big Number (arbitrary-precision integer).

---

### `xmlSecBnPtr`

```c
typedef xmlSecBn* xmlSecBnPtr;
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L28)

Pointer to `xmlSecBn`.

---

## Enumerations

### `xmlSecBnFormat`

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L33)

The big numbers formats.

| Value | Initializer | Description |
|-------|-------------|-------------|
| `xmlSecBnBase64` | `` |  |
| `xmlSecBnHex` | `` |  |
| `xmlSecBnDec` | `` |  |

---

## Functions

### `xmlSecBnCreate`

```c
xmlSecBnPtr xmlSecBnCreate(xmlSecSize size);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L39)

Creates a new BN object.

Creates a new BN object. Caller is responsible for destroying it by calling `xmlSecBnDestroy` function. 

**Parameters:**

- `size` — the initial allocated BN size.


**Returns:** the newly BN or a NULL if an error occurs.

---

### `xmlSecBnDestroy`

```c
void xmlSecBnDestroy(xmlSecBnPtr bn);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L40)

Destroys `bn` object.

Destroys `bn` object created with `xmlSecBnCreate` function. 

**Parameters:**

- `bn` — the pointer to BN.

---

### `xmlSecBnInitialize`

```c
int xmlSecBnInitialize(xmlSecBnPtr bn, xmlSecSize size);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L41)

Initializes a BN object.

Initializes a BN object. Caller is responsible for destroying it by calling `xmlSecBnFinalize` function. 

**Parameters:**

- `bn` — the pointer to BN.
- `size` — the initial allocated BN size.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBnFinalize`

```c
void xmlSecBnFinalize(xmlSecBnPtr bn);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L43)

Destroys `bn` object.

Destroys `bn` object created with `xmlSecBnInitialize` function. 

**Parameters:**

- `bn` — the pointer to BN.

---

### `xmlSecBnGetData`

```c
xmlSecByte * xmlSecBnGetData(xmlSecBnPtr bn);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L44)

Gets pointer to the binary `bn` representation.

**Parameters:**

- `bn` — the pointer to BN.


**Returns:** pointer to binary BN data or NULL if an error occurs.

---

### `xmlSecBnSetData`

```c
int xmlSecBnSetData(xmlSecBnPtr bn, const xmlSecByte *data, xmlSecSize size);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L45)

Sets the value of `bn` to `data`.

**Parameters:**

- `bn` — the pointer to BN.
- `data` — the pointer to new BN binary data.
- `size` — the size of new BN data.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBnGetSize`

```c
xmlSecSize xmlSecBnGetSize(xmlSecBnPtr bn);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L48)

Gets the size of binary data in `bn`.

**Parameters:**

- `bn` — the pointer to BN.


**Returns:** the size of binary data.

---

### `xmlSecBnZero`

```c
void xmlSecBnZero(xmlSecBnPtr bn);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L49)

Sets the value of `bn` to zero.

**Parameters:**

- `bn` — the pointer to BN.

---

### `xmlSecBnFromString`

```c
int xmlSecBnFromString(xmlSecBnPtr bn, const xmlChar *str, xmlSecSize base);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L51)

Reads `bn` from string `str` in given base.

Reads `bn` from string `str` assuming it has base `base`. 

**Parameters:**

- `bn` — the pointer to BN.
- `str` — the string with BN.
- `base` — the base for `str`.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBnToString`

```c
xmlChar * xmlSecBnToString(xmlSecBnPtr bn, xmlSecSize base);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L54)

Writes `bn` to string with given base.

Writes `bn` to string with base `base`. Caller is responsible for freeing returned string with xmlFree. 

**Parameters:**

- `bn` — the pointer to BN.
- `base` — the base for returned string.


**Returns:** the string represenataion if BN or a NULL if an error occurs.

---

### `xmlSecBnFromHexString`

```c
int xmlSecBnFromHexString(xmlSecBnPtr bn, const xmlChar *str);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L56)

Reads `bn` from hex string `str`.

**Parameters:**

- `bn` — the pointer to BN.
- `str` — the string with BN.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBnToHexString`

```c
xmlChar * xmlSecBnToHexString(xmlSecBnPtr bn);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L58)

Writes `bn` to hex string.

Writes `bn` to hex string. Caller is responsible for freeing returned string with xmlFree. 

**Parameters:**

- `bn` — the pointer to BN.


**Returns:** the string represenataion if BN or a NULL if an error occurs.

---

### `xmlSecBnFromDecString`

```c
int xmlSecBnFromDecString(xmlSecBnPtr bn, const xmlChar *str);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L60)

Reads `bn` from decimal string `str`.

**Parameters:**

- `bn` — the pointer to BN.
- `str` — the string with BN.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBnToDecString`

```c
xmlChar * xmlSecBnToDecString(xmlSecBnPtr bn);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L62)

Writes `bn` to decimal string.

Writes `bn` to decimal string. Caller is responsible for freeing returned string with xmlFree. 

**Parameters:**

- `bn` — the pointer to BN.


**Returns:** the string represenataion if BN or a NULL if an error occurs.

---

### `xmlSecBnMul`

```c
int xmlSecBnMul(xmlSecBnPtr bn, int multiplier);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L64)

Multiplies `bn` with `multiplier`.

**Parameters:**

- `bn` — the pointer to BN.
- `multiplier` — the multiplier.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBnDiv`

```c
int xmlSecBnDiv(xmlSecBnPtr bn, int divider, int *mod);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L66)

Divides `bn` by `divider`.

Divides `bn` by `divider` and places modulus into `mod`. 

**Parameters:**

- `bn` — the pointer to BN.
- `divider` — the divider
- `mod` — the pointer for modulus result.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBnAdd`

```c
int xmlSecBnAdd(xmlSecBnPtr bn, int delta);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L69)

Adds `delta` to `bn`.

**Parameters:**

- `bn` — the pointer to BN.
- `delta` — the delta.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBnReverse`

```c
int xmlSecBnReverse(xmlSecBnPtr bn);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L71)

Reverses bytes order in `bn`.

**Parameters:**

- `bn` — the pointer to BN.


**Returns:** 0 on success or a negative value if an error occurs.

---

### `xmlSecBnCompare`

```c
int xmlSecBnCompare(xmlSecBnPtr bn, const xmlSecByte *data, xmlSecSize dataSize);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L72)

Compares the `bn` with `data`.

**Parameters:**

- `bn` — the pointer to BN.
- `data` — the data to compare BN to.
- `dataSize` — the `data` size.


**Returns:** 0 if data is equal, negative value if `bn` is less or positive value if `bn` is greater than `data`.

---

### `xmlSecBnCompareReverse`

```c
int xmlSecBnCompareReverse(xmlSecBnPtr bn, const xmlSecByte *data, xmlSecSize dataSize);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L75)

Compares the `bn` with reverse `data`.

**Parameters:**

- `bn` — the pointer to BN.
- `data` — the data to compare BN to.
- `dataSize` — the `data` size.


**Returns:** 0 if data is equal, negative value if `bn` is less or positive value if `bn` is greater than `data`.

---

### `xmlSecBnGetNodeValue`

```c
int xmlSecBnGetNodeValue(xmlSecBnPtr bn, xmlNodePtr cur, xmlSecBnFormat format, int reverse);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L78)

Converts node content to BN value.

Converts the node content from `format` to `bn`. 

**Parameters:**

- `bn` — the pointer to BN.
- `cur` — the pointer to an XML node.
- `format` — the BN format.
- `reverse` — if set then reverse read buffer after reading.


**Returns:** 0 on success and a negative values if an error occurs.

---

### `xmlSecBnSetNodeValue`

```c
int xmlSecBnSetNodeValue(xmlSecBnPtr bn, xmlNodePtr cur, xmlSecBnFormat format, int reverse, int addLineBreaks);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L82)

Converts the `bn` and sets it to node content.

**Parameters:**

- `bn` — the pointer to BN.
- `cur` — the pointer to an XML node.
- `format` — the BN format.
- `reverse` — the flag that indicates whether to reverse the buffer before writing.
- `addLineBreaks` — the flag; it is equal to 1 then linebreaks will be added before and after new buffer content.


**Returns:** 0 on success and a negative values if an error occurs.

---

### `xmlSecBnBlobSetNodeValue`

```c
int xmlSecBnBlobSetNodeValue(const xmlSecByte *data, xmlSecSize dataSize, xmlNodePtr cur, xmlSecBnFormat format, int reverse, int addLineBreaks);
```

*Source:* [include/xmlsec/bn.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/bn.h#L87)

Converts the `blob` and sets it to node content.

**Parameters:**

- `data` — the pointer to BN blob.
- `dataSize` — the size of BN blob.
- `cur` — the pointer to an XML node.
- `format` — the BN format.
- `reverse` — the flag that indicates whether to reverse the buffer before writing.
- `addLineBreaks` — if the flag is equal to 1 then linebreaks will be added before and after new buffer content.


**Returns:** 0 on success and a negative values if an error occurs.

---
