Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Macros | Functions | Variables
ossl_bn.c File Reference
`#include "ossl.h"`

Go to the source code of this file.

## Macros
#define | NewBN(klass) TypedData_Wrap_Struct((klass), &ossl_bn_type, 0)
#define | SetBN(obj, bn)
#define | GetBN(obj, bn)
#define | BIGNUM_BOOL1(func)
#define | BIGNUM_1c(func)
#define | BIGNUM_2(func)
#define | BIGNUM_2c(func)
#define | BIGNUM_3c(func)
#define | BIGNUM_BIT(func)
#define | BIGNUM_SHIFT(func)
#define | BIGNUM_SELF_SHIFT(func)
#define | BIGNUM_RAND(func)
#define | BIGNUM_RAND_RANGE(func)
#define | BIGNUM_NUM(func)
#define | BIGNUM_CMP(func)

## Functions
VALUE | ossl_bn_new (const BIGNUM *bn)
BIGNUM * | ossl_bn_value_ptr (volatile VALUE *ptr)
| BIGNUM_1c (sqr)
| BIGNUM_3c (mod_add)
void | Init_ossl_bn (void)

## Variables
VALUE | cBN
VALUE | eBNError
BN_CTX * | ossl_bn_ctx

## Macro Definition Documentation

## ◆ BIGNUM_1c

#define BIGNUM_1c | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_##func(VALUE self) \
{ \
BIGNUM *bn, *result; \
VALUE obj; \
GetBN(self, bn); \
obj = NewBN(rb_obj_class(self)); \
if (!(result = BN_new())) { \
ossl_raise(eBNError, NULL); \
} \
if (!BN_##func(result, bn, ossl_bn_ctx)) { \
BN_free(result); \
ossl_raise(eBNError, NULL); \
} \
SetBN(obj, result); \
return obj; \
}

Definition at line 392 of file ossl_bn.c.

## ◆ BIGNUM_2

#define BIGNUM_2 | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_##func(VALUE self, VALUE other) \
{ \
BIGNUM *bn1, *bn2 = GetBNPtr(other), *result; \
VALUE obj; \
GetBN(self, bn1); \
obj = NewBN(rb_obj_class(self)); \
if (!(result = BN_new())) { \
ossl_raise(eBNError, NULL); \
} \
if (!BN_##func(result, bn1, bn2)) { \
BN_free(result); \
ossl_raise(eBNError, NULL); \
} \
SetBN(obj, result); \
return obj; \
}

## ◆ BIGNUM_2c

#define BIGNUM_2c | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_##func(VALUE self, VALUE other) \
{ \
BIGNUM *bn1, *bn2 = GetBNPtr(other), *result; \
VALUE obj; \
GetBN(self, bn1); \
obj = NewBN(rb_obj_class(self)); \
if (!(result = BN_new())) { \
ossl_raise(eBNError, NULL); \
} \
if (!BN_##func(result, bn1, bn2, ossl_bn_ctx)) { \
BN_free(result); \
ossl_raise(eBNError, NULL); \
} \
SetBN(obj, result); \
return obj; \
}

## ◆ BIGNUM_3c

#define BIGNUM_3c | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_##func(VALUE self, VALUE other1, VALUE other2) \
{ \
BIGNUM *bn1, *bn2 = GetBNPtr(other1); \
BIGNUM *bn3 = GetBNPtr(other2), *result; \
VALUE obj; \
GetBN(self, bn1); \
obj = NewBN(rb_obj_class(self)); \
if (!(result = BN_new())) { \
ossl_raise(eBNError, NULL); \
} \
if (!BN_##func(result, bn1, bn2, bn3, ossl_bn_ctx)) { \
BN_free(result); \
ossl_raise(eBNError, NULL); \
} \
SetBN(obj, result); \
return obj; \
}

Definition at line 547 of file ossl_bn.c.

## ◆ BIGNUM_BIT

#define BIGNUM_BIT | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_##func(VALUE self, VALUE bit) \
{ \
BIGNUM *bn; \
GetBN(self, bn); \
if (!BN_##func(bn, NUM2INT(bit))) { \
ossl_raise(eBNError, NULL); \
} \
return self; \
}

## ◆ BIGNUM_BOOL1

#define BIGNUM_BOOL1 | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_##func(VALUE self) \
{ \
BIGNUM *bn; \
GetBN(self, bn); \
if (BN_##func(bn)) { \
return Qtrue; \
} \
return Qfalse; \
}

Definition at line 344 of file ossl_bn.c.

## ◆ BIGNUM_CMP

#define BIGNUM_CMP | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_##func(VALUE self, VALUE other) \
{ \
BIGNUM *bn1, *bn2 = GetBNPtr(other); \
GetBN(self, bn1); \
return INT2NUM(BN_##func(bn1, bn2)); \
}

Definition at line 900 of file ossl_bn.c.

## ◆ BIGNUM_NUM

#define BIGNUM_NUM | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_##func(VALUE self) \
{ \
BIGNUM *bn; \
GetBN(self, bn); \
return INT2NUM(BN_##func(bn)); \
}

Definition at line 828 of file ossl_bn.c.

## ◆ BIGNUM_RAND

#define BIGNUM_RAND | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_s_##func(int argc, VALUE *argv, VALUE klass) \
{ \
BIGNUM *result; \
int bottom = 0, top = 0, b; \
VALUE bits, fill, odd, obj; \
\
switch (rb_scan_args(argc, argv, "12", &bits, &fill, &odd)) { \
case 3: \
bottom = (odd == Qtrue) ? 1 : 0; \
/* FALLTHROUGH */ \
case 2: \
top = NUM2INT(fill); \
} \
b = NUM2INT(bits); \
obj = NewBN(klass); \
if (!(result = BN_new())) { \
ossl_raise(eBNError, NULL); \
} \
if (!BN_##func(result, b, top, bottom)) { \
BN_free(result); \
ossl_raise(eBNError, NULL); \
} \
SetBN(obj, result); \
return obj; \
}

Definition at line 710 of file ossl_bn.c.

## ◆ BIGNUM_RAND_RANGE

#define BIGNUM_RAND_RANGE | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_s_##func##_range(VALUE klass, VALUE range) \
{ \
BIGNUM *bn = GetBNPtr(range), *result; \
VALUE obj = NewBN(klass); \
if (!(result = BN_new())) { \
ossl_raise(eBNError, NULL); \
} \
if (!BN_##func##_range(result, bn)) { \
BN_free(result); \
ossl_raise(eBNError, NULL); \
} \
SetBN(obj, result); \
return obj; \
}

Definition at line 750 of file ossl_bn.c.

## ◆ BIGNUM_SELF_SHIFT

#define BIGNUM_SELF_SHIFT | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_self_##func(VALUE self, VALUE bits) \
{ \
BIGNUM *bn; \
int b; \
b = NUM2INT(bits); \
GetBN(self, bn); \
if (!BN_##func(bn, bn, b)) \
ossl_raise(eBNError, NULL); \
return self; \
}

Definition at line 683 of file ossl_bn.c.

## ◆ BIGNUM_SHIFT

#define BIGNUM_SHIFT | ( |  | func | ) |

Value:
static VALUE \
ossl_bn_##func(VALUE self, VALUE bits) \
{ \
BIGNUM *bn, *result; \
int b; \
VALUE obj; \
b = NUM2INT(bits); \
GetBN(self, bn); \
obj = NewBN(rb_obj_class(self)); \
if (!(result = BN_new())) { \
ossl_raise(eBNError, NULL); \
} \
if (!BN_##func(result, bn, b)) { \
BN_free(result); \
ossl_raise(eBNError, NULL); \
} \
SetBN(obj, result); \
return obj; \
}

Definition at line 648 of file ossl_bn.c.

## ◆ GetBN

#define GetBN | ( |  | obj,
|  |  | bn
| ) |  |

Value:
do { \
TypedData_Get_Struct((obj), BIGNUM, &ossl_bn_type, (bn)); \
if (!(bn)) { \
ossl_raise(rb_eRuntimeError, "BN wasn't initialized!"); \
} \
} while (0)

Definition at line 22 of file ossl_bn.c.

## ◆ NewBN

#define NewBN | ( |  | klass | ) | TypedData_Wrap_Struct((klass), &ossl_bn_type, 0)

Definition at line 13 of file ossl_bn.c.

## ◆ SetBN

#define SetBN | ( |  | obj,
|  |  | bn
| ) |  |

Value:
do { \
if (!(bn)) { \
ossl_raise(rb_eRuntimeError, "BN wasn't initialized!"); \
} \
RTYPEDDATA_DATA(obj) = (bn); \
} while (0)

Definition at line 15 of file ossl_bn.c.

## Function Documentation

## ◆ BIGNUM_1c()

BIGNUM_1c | ( | sqr |  | ) |

Definition at line 416 of file ossl_bn.c.

References eBNError, GetBN, GetBNPtr, klass, NewBN, NULL, obj2, ossl_bn_ctx, ossl_raise(), r1, r2, rb_ary_new3, rb_obj_class(), and SetBN.

## ◆ BIGNUM_3c()

BIGNUM_3c | ( | mod_add |  | ) |

Definition at line 572 of file ossl_bn.c.

References GetBN, NUM2INT, Qfalse, and Qtrue.

## ◆ Init_ossl_bn()

void Init_ossl_bn | ( | void |  | ) |

Definition at line 1085 of file ossl_bn.c.

References cBN, eBNError, eOSSLError, mOSSL, ossl_bn_ctx, ossl_raise(), rb_cObject, rb_define_alloc_func(), rb_define_class_under(), rb_define_module(), rb_eRuntimeError, and rb_eStandardError.

## ◆ ossl_bn_new()

VALUE ossl_bn_new | ( | const BIGNUM * | bn | ) |

Definition at line 58 of file ossl_bn.c.

References cBN, eBNError, NewBN, NULL, obj, ossl_raise(), and SetBN.

Referenced by asn1integer_to_num().

## ◆ ossl_bn_value_ptr()

BIGNUM* ossl_bn_value_ptr | ( | volatile VALUE * | ptr | ) |

Definition at line 136 of file ossl_bn.c.

## Variable Documentation

## ◆ cBN

VALUE cBN

Definition at line 46 of file ossl_bn.c.

Referenced by Init_ossl_bn(), and ossl_bn_new().

## ◆ eBNError

VALUE eBNError

Definition at line 52 of file ossl_bn.c.

Referenced by BIGNUM_1c(), Init_ossl_bn(), and ossl_bn_new().

## ◆ ossl_bn_ctx

BN_CTX* ossl_bn_ctx

Definition at line 158 of file ossl_bn.c.

Referenced by BIGNUM_1c(), and Init_ossl_bn().

range
#define range(low, item, hi)
Definition: date_strftime.c:21
rb_scan_args
#define rb_scan_args(argc, argvp, fmt,...)
Definition: rb_mjit_min_header-2.7.0.h:6372
VALUE
unsigned long VALUE
Definition: ruby.h:102
INT2NUM
#define INT2NUM(x)
Definition: ruby.h:1609
Qfalse
#define Qfalse
Definition: ruby.h:467
NULL
#define NULL
Definition: _sdbm.c:101
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.0.h:5742
rb_obj_class
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
Definition: object.c:217
eBNError
VALUE eBNError
Definition: ossl_bn.c:52
rb_eRuntimeError
VALUE rb_eRuntimeError
Definition: error.c:920
ossl_bn_ctx
BN_CTX * ossl_bn_ctx
Definition: ossl_bn.c:158
argv
char ** argv
Definition: ruby.c:223
klass
VALUE klass
Definition: rb_mjit_min_header-2.7.0.h:13254
NewBN
#define NewBN(klass)
Definition: ossl_bn.c:13
argc
int argc
Definition: ruby.c:222
GetBNPtr
#define GetBNPtr(obj)
Definition: ossl_bn.h:18
Qtrue
#define Qtrue
Definition: ruby.h:468
top
unsigned int top
Definition: nkf.c:4323
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:715