Ruby  2.4.2p198(2017-09-14revision59899)
Macros | Functions | Variables
ossl_bn.c File Reference
#include "ossl.h"
Include dependency graph for ossl_bn.c:

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 SafeGetBN(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

static void ossl_bn_free (void *ptr)
 
VALUE ossl_bn_new (const BIGNUM *bn)
 
static BIGNUM * integer_to_bnptr (VALUE obj, BIGNUM *orig)
 
static VALUE try_convert_to_bn (VALUE obj)
 
BIGNUM * ossl_bn_value_ptr (volatile VALUE *ptr)
 
static VALUE ossl_bn_alloc (VALUE klass)
 
static VALUE ossl_bn_initialize (int argc, VALUE *argv, VALUE self)
 
static VALUE ossl_bn_to_s (int argc, VALUE *argv, VALUE self)
 
static VALUE ossl_bn_to_i (VALUE self)
 
static VALUE ossl_bn_to_bn (VALUE self)
 
static VALUE ossl_bn_coerce (VALUE self, VALUE other)
 
 BIGNUM_1c (sqr)
 
 BIGNUM_3c (mod_add)
 
static VALUE ossl_bn_s_generate_prime (int argc, VALUE *argv, VALUE klass)
 
static VALUE ossl_bn_copy (VALUE self, VALUE other)
 
static VALUE ossl_bn_eq (VALUE self, VALUE other)
 
static VALUE ossl_bn_eql (VALUE self, VALUE other)
 
static VALUE ossl_bn_hash (VALUE self)
 
static VALUE ossl_bn_is_prime (int argc, VALUE *argv, VALUE self)
 
static VALUE ossl_bn_is_prime_fasttest (int argc, VALUE *argv, VALUE self)
 
void Init_ossl_bn (void)
 

Variables

static const rb_data_type_t ossl_bn_type
 
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; \
}
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
#define NewBN(klass)
Definition: ossl_bn.c:13
unsigned long VALUE
Definition: ruby.h:85
static VALUE result
Definition: nkf.c:40
BN_CTX * ossl_bn_ctx
Definition: ossl_bn.c:163
#define NULL
Definition: _sdbm.c:102
VALUE eBNError
Definition: ossl_bn.c:57
VALUE rb_obj_class(VALUE)
Definition: object.c:229

Definition at line 380 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; \
}
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
#define GetBNPtr(obj)
Definition: ossl_bn.h:18
#define NewBN(klass)
Definition: ossl_bn.c:13
unsigned long VALUE
Definition: ruby.h:85
static VALUE result
Definition: nkf.c:40
#define NULL
Definition: _sdbm.c:102
VALUE eBNError
Definition: ossl_bn.c:57
VALUE rb_obj_class(VALUE)
Definition: object.c:229

◆ 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; \
}
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
#define GetBNPtr(obj)
Definition: ossl_bn.h:18
#define NewBN(klass)
Definition: ossl_bn.c:13
unsigned long VALUE
Definition: ruby.h:85
static VALUE result
Definition: nkf.c:40
BN_CTX * ossl_bn_ctx
Definition: ossl_bn.c:163
#define NULL
Definition: _sdbm.c:102
VALUE eBNError
Definition: ossl_bn.c:57
VALUE rb_obj_class(VALUE)
Definition: object.c:229

◆ 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; \
}
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
#define GetBNPtr(obj)
Definition: ossl_bn.h:18
#define NewBN(klass)
Definition: ossl_bn.c:13
unsigned long VALUE
Definition: ruby.h:85
static VALUE result
Definition: nkf.c:40
BN_CTX * ossl_bn_ctx
Definition: ossl_bn.c:163
#define NULL
Definition: _sdbm.c:102
VALUE eBNError
Definition: ossl_bn.c:57
VALUE rb_obj_class(VALUE)
Definition: object.c:229

Definition at line 536 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; \
}
#define NUM2INT(x)
Definition: ruby.h:684
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
unsigned long VALUE
Definition: ruby.h:85
#define NULL
Definition: _sdbm.c:102
VALUE eBNError
Definition: ossl_bn.c:57

◆ 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; \
}
#define Qtrue
Definition: ruby.h:437
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
#define Qfalse
Definition: ruby.h:436
unsigned long VALUE
Definition: ruby.h:85

Definition at line 347 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)); \
}
#define INT2NUM(x)
Definition: ruby.h:1538
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
#define GetBNPtr(obj)
Definition: ossl_bn.h:18
unsigned long VALUE
Definition: ruby.h:85

Definition at line 859 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)); \
}
#define INT2NUM(x)
Definition: ruby.h:1538
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
unsigned long VALUE
Definition: ruby.h:85

Definition at line 818 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; \
}
#define NUM2INT(x)
Definition: ruby.h:684
#define Qtrue
Definition: ruby.h:437
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
int argc
Definition: ruby.c:183
#define NewBN(klass)
Definition: ossl_bn.c:13
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1919
unsigned long VALUE
Definition: ruby.h:85
static VALUE result
Definition: nkf.c:40
unsigned int top
Definition: nkf.c:4310
switch(hval)
Definition: zonetab.h:84
#define NULL
Definition: _sdbm.c:102
VALUE eBNError
Definition: ossl_bn.c:57
char ** argv
Definition: ruby.c:184

Definition at line 700 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; \
}
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
#define GetBNPtr(obj)
Definition: ossl_bn.h:18
#define range(low, item, hi)
Definition: date_strftime.c:21
#define NewBN(klass)
Definition: ossl_bn.c:13
unsigned long VALUE
Definition: ruby.h:85
static VALUE result
Definition: nkf.c:40
#define NULL
Definition: _sdbm.c:102
VALUE eBNError
Definition: ossl_bn.c:57

Definition at line 740 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; \
}
#define NUM2INT(x)
Definition: ruby.h:684
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
unsigned long VALUE
Definition: ruby.h:85
#define NULL
Definition: _sdbm.c:102
VALUE eBNError
Definition: ossl_bn.c:57

Definition at line 673 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; \
}
#define NUM2INT(x)
Definition: ruby.h:684
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
#define NewBN(klass)
Definition: ossl_bn.c:13
unsigned long VALUE
Definition: ruby.h:85
static VALUE result
Definition: nkf.c:40
#define NULL
Definition: _sdbm.c:102
VALUE eBNError
Definition: ossl_bn.c:57
VALUE rb_obj_class(VALUE)
Definition: object.c:229

Definition at line 638 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)
static const rb_data_type_t ossl_bn_type
Definition: ossl_bn.c:40
VALUE rb_eRuntimeError
Definition: error.c:761

Definition at line 22 of file ossl_bn.c.

Referenced by BIGNUM_1c(), BIGNUM_3c(), ossl_bn_copy(), ossl_bn_eq(), ossl_bn_eql(), ossl_bn_hash(), ossl_bn_initialize(), ossl_bn_is_prime(), ossl_bn_is_prime_fasttest(), ossl_bn_to_i(), ossl_bn_to_s(), and ossl_bn_value_ptr().

◆ NewBN

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

◆ SafeGetBN

#define SafeGetBN (   obj,
  bn 
)
Value:
do { \
OSSL_Check_Kind((obj), cBN); \
GetBN((obj), (bn)); \
} while (0)
VALUE cBN
Definition: ossl_bn.c:51

Definition at line 29 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)
VALUE rb_eRuntimeError
Definition: error.c:761

Definition at line 15 of file ossl_bn.c.

Referenced by BIGNUM_1c(), ossl_bn_alloc(), ossl_bn_new(), ossl_bn_s_generate_prime(), and try_convert_to_bn().

Function Documentation

◆ BIGNUM_1c()

BIGNUM_1c ( sqr  )

Definition at line 404 of file ossl_bn.c.

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

◆ BIGNUM_3c()

BIGNUM_3c ( mod_add  )

Definition at line 561 of file ossl_bn.c.

References GetBN, NUM2INT, Qfalse, and Qtrue.

◆ Init_ossl_bn()

void Init_ossl_bn ( void  )

◆ integer_to_bnptr()

static BIGNUM* integer_to_bnptr ( VALUE  obj,
BIGNUM *  orig 
)
static

◆ ossl_bn_alloc()

static VALUE ossl_bn_alloc ( VALUE  klass)
static

Definition at line 166 of file ossl_bn.c.

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

Referenced by Init_ossl_bn().

◆ ossl_bn_coerce()

static VALUE ossl_bn_coerce ( VALUE  self,
VALUE  other 
)
static

◆ ossl_bn_copy()

static VALUE ossl_bn_copy ( VALUE  self,
VALUE  other 
)
static

Definition at line 842 of file ossl_bn.c.

References eBNError, GetBN, GetBNPtr, NULL, ossl_raise(), and rb_check_frozen.

Referenced by Init_ossl_bn().

◆ ossl_bn_eq()

static VALUE ossl_bn_eq ( VALUE  self,
VALUE  other 
)
static

Definition at line 895 of file ossl_bn.c.

References GetBN, NIL_P, Qfalse, Qtrue, and try_convert_to_bn().

Referenced by Init_ossl_bn().

◆ ossl_bn_eql()

static VALUE ossl_bn_eql ( VALUE  self,
VALUE  other 
)
static

Definition at line 920 of file ossl_bn.c.

References cBN, GetBN, Qfalse, Qtrue, and rb_obj_is_kind_of().

Referenced by Init_ossl_bn().

◆ ossl_bn_free()

static void ossl_bn_free ( void *  ptr)
static

Definition at line 35 of file ossl_bn.c.

◆ ossl_bn_hash()

static VALUE ossl_bn_hash ( VALUE  self)
static

Definition at line 941 of file ossl_bn.c.

References buf, eBNError, GetBN, hash(), len, NULL, ossl_raise(), rb_memhash(), ST2FIX, xfree(), and xmalloc.

Referenced by Init_ossl_bn().

◆ ossl_bn_initialize()

static VALUE ossl_bn_initialize ( int  argc,
VALUE argv,
VALUE  self 
)
static

◆ ossl_bn_is_prime()

static VALUE ossl_bn_is_prime ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 975 of file ossl_bn.c.

References eBNError, GetBN, NULL, NUM2INT, ossl_bn_ctx, ossl_raise(), Qfalse, Qnil, Qtrue, and rb_scan_args().

Referenced by Init_ossl_bn().

◆ ossl_bn_is_prime_fasttest()

static VALUE ossl_bn_is_prime_fasttest ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 1011 of file ossl_bn.c.

References eBNError, GetBN, NIL_P, NULL, NUM2INT, ossl_bn_ctx, ossl_raise(), Qfalse, Qnil, Qtrue, and rb_scan_args().

Referenced by Init_ossl_bn().

◆ ossl_bn_new()

VALUE ossl_bn_new ( const BIGNUM *  bn)

◆ ossl_bn_s_generate_prime()

static VALUE ossl_bn_s_generate_prime ( int  argc,
VALUE argv,
VALUE  klass 
)
static

Definition at line 788 of file ossl_bn.c.

References add, eBNError, GetBNPtr, NewBN, NIL_P, NULL, NUM2INT, ossl_raise(), Qfalse, rb_scan_args(), result, and SetBN.

Referenced by Init_ossl_bn().

◆ ossl_bn_to_bn()

static VALUE ossl_bn_to_bn ( VALUE  self)
static

Definition at line 323 of file ossl_bn.c.

Referenced by Init_ossl_bn().

◆ ossl_bn_to_i()

static VALUE ossl_bn_to_i ( VALUE  self)
static

Definition at line 305 of file ossl_bn.c.

References eBNError, GetBN, NULL, ossl_raise(), Qtrue, and rb_cstr_to_inum().

Referenced by Init_ossl_bn(), and ossl_bn_coerce().

◆ ossl_bn_to_s()

static VALUE ossl_bn_to_s ( int  argc,
VALUE argv,
VALUE  self 
)
static

◆ ossl_bn_value_ptr()

BIGNUM* ossl_bn_value_ptr ( volatile VALUE ptr)

Definition at line 141 of file ossl_bn.c.

References GetBN, NIL_P, ossl_raise(), rb_eTypeError, and try_convert_to_bn().

◆ try_convert_to_bn()

static VALUE try_convert_to_bn ( VALUE  obj)
static

Definition at line 124 of file ossl_bn.c.

References cBN, integer_to_bnptr(), NewBN, NULL, Qnil, RB_INTEGER_TYPE_P, rb_obj_is_kind_of(), and SetBN.

Referenced by ossl_bn_eq(), and ossl_bn_value_ptr().

Variable Documentation

◆ cBN

VALUE cBN

◆ eBNError

VALUE eBNError

◆ ossl_bn_ctx

BN_CTX* ossl_bn_ctx

Definition at line 163 of file ossl_bn.c.

Referenced by BIGNUM_1c(), Init_ossl_bn(), ossl_bn_is_prime(), and ossl_bn_is_prime_fasttest().

◆ ossl_bn_type

const rb_data_type_t ossl_bn_type
static
Initial value:
= {
"OpenSSL/BN",
{
},
}
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1145
static void ossl_bn_free(void *ptr)
Definition: ossl_bn.c:35

Definition at line 40 of file ossl_bn.c.