Turnstone Operating System
Loading...
Searching...
No Matches
bigint.64.c File Reference

Big integer arithmetic. More...

#include <bigint.h>
#include <memory.h>
#include <strings.h>
#include <buffer.h>
#include <utils.h>
#include <logging.h>
#include <random.h>

Classes

struct  bigint_item_t
 
struct  bigint_t
 

Macros

#define BIGINT_ITEM_BITS   48
 
#define BIGINT_ITEM_HEX_DIGITS   12
 
#define BIGINT_ITEM_MAX   0x0000FFFFFFFFFFFFUL
 
#define BIGINT_ITEM_MSB   0x0000800000000000UL
 
#define BIGINT_ITEM_CARRY   0x0001000000000000UL
 

Typedefs

typedef struct bigint_item_t bigint_item_t
 

Functions

 MODULE ("turnstone.lib")
 
bigint_tbigint_create (void)
 
static void bigint_destroy_items (bigint_t *bigint)
 
void bigint_destroy (bigint_t *bigint)
 
static uint64_t bigint_item_count (const bigint_t *bigint)
 
int8_t bigint_set_int64 (bigint_t *bigint, int64_t value)
 
int8_t bigint_set_uint64 (bigint_t *bigint, uint64_t value)
 
bigint_tbigint_one (void)
 
bigint_tbigint_two (void)
 
int8_t bigint_set_bigint (bigint_t *bigint, const bigint_t *src)
 
bigint_tbigint_clone (const bigint_t *src)
 
int8_t bigint_set_str (bigint_t *bigint, const char_t *str)
 
static int8_t bigint_inc_with_overflow (bigint_t *bigint)
 
static int8_t bigint_remove_leading_zeros (bigint_t *bigint)
 
static int8_t bigint_neg_with_sign_inplace (bigint_t *a, boolean_t force)
 
static int8_t bigint_neg_with_sign (bigint_t *result, const bigint_t *a, boolean_t force)
 
const char_tbigint_to_str (const bigint_t *bigint)
 
boolean_t bigint_is_zero (const bigint_t *a)
 
boolean_t bigint_is_negative (const bigint_t *a)
 
boolean_t bigint_is_odd (const bigint_t *a)
 
boolean_t bigint_is_even (const bigint_t *a)
 
boolean_t bigint_is_int64 (const bigint_t *a, int64_t value)
 
boolean_t bigint_is_uint64 (const bigint_t *a, uint64_t value)
 
static int8_t bigint_sign_extend (bigint_t *bigint, uint64_t item_count)
 
int8_t bigint_neg (bigint_t *result, const bigint_t *a)
 
int8_t bigint_and (bigint_t *result, const bigint_t *a, const bigint_t *b)
 
static int8_t bigint_or_inplace (bigint_t *result, const bigint_t *a)
 
int8_t bigint_or (bigint_t *result, const bigint_t *a, const bigint_t *b)
 
int8_t bigint_xor (bigint_t *result, const bigint_t *a, const bigint_t *b)
 
static int8_t bigint_not_inplace (bigint_t *a)
 
int8_t bigint_not (bigint_t *result, const bigint_t *a)
 
int8_t bigint_shl_one (bigint_t *a)
 
int8_t bigint_shr_one (bigint_t *a)
 
int8_t bigint_shl (bigint_t *result, const bigint_t *a, int64_t shift)
 
int8_t bigint_shr (bigint_t *result, const bigint_t *a, int64_t shift)
 
int8_t bigint_set_bit (bigint_t *bigint, uint64_t bit, boolean_t value)
 
int8_t bigint_get_bit (const bigint_t *bigint, uint64_t bit, boolean_t *value)
 
int8_t bigint_flip_bit (bigint_t *bigint, uint64_t bit)
 
int8_t bigint_clear_bit (bigint_t *bigint, uint64_t bit)
 
int8_t bigint_sub (bigint_t *result, const bigint_t *a, const bigint_t *b)
 
int8_t bigint_add (bigint_t *result, const bigint_t *a, const bigint_t *b)
 
uint64_t bigint_bit_length (const bigint_t *bigint)
 
int8_t bigint_cmp (const bigint_t *a, const bigint_t *b)
 
int8_t bigint_mul (bigint_t *result, const bigint_t *a, const bigint_t *b)
 
int8_t bigint_pow (bigint_t *result, const bigint_t *a, const bigint_t *b)
 
int8_t bigint_mul_mod (bigint_t *result, const bigint_t *a, const bigint_t *b, const bigint_t *c)
 
int8_t bigint_pow_mod (bigint_t *result, const bigint_t *a, const bigint_t *b, const bigint_t *c)
 
int8_t bigint_div_with_remainder (bigint_t *result, bigint_t *remainder, const bigint_t *a, const bigint_t *b)
 
int8_t bigint_div_unsigned (bigint_t *result, bigint_t *remainder, const bigint_t *a, const bigint_t *b)
 
int8_t bigint_div (bigint_t *result, const bigint_t *a, const bigint_t *b)
 
int8_t bigint_mod (bigint_t *result, const bigint_t *a, const bigint_t *b)
 
int8_t bigint_gcd (bigint_t *result, const bigint_t *a, const bigint_t *b)
 
static bigint_tbigint_random_internal (uint64_t bits, boolean_t force_msb)
 
bigint_tbigint_random (uint64_t bits)
 
bigint_tbigint_random_range (const bigint_t *min, const bigint_t *max)
 
static boolean_t bigint_is_prime_miller_rabin (const bigint_t *a, uint64_t try)
 
boolean_t bigint_is_prime (const bigint_t *a)
 
bigint_tbigint_random_prime (uint64_t bits)
 

Detailed Description

Big integer arithmetic.

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Macro Definition Documentation

◆ BIGINT_ITEM_BITS

#define BIGINT_ITEM_BITS   48

each value is 48 bits