Ruby  1.9.3p448(2013-06-27revision41675)
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 WrapBN(klass, 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

VALUE ossl_bn_new (const BIGNUM *bn)
 
BIGNUM * GetBNPtr (VALUE obj)
 
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_eql (VALUE self, VALUE other)
 
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 ()
 

Variables

VALUE cBN
 
VALUE eBNError
 
BN_CTX * ossl_bn_ctx
 

Macro Definition Documentation

#define BIGNUM_1c (   func)
Value:
/* \
* call-seq: \
* bn.##func -> aBN \
* \
*/ \
static VALUE \
ossl_bn_##func(VALUE self) \
{ \
BIGNUM *bn, *result; \
VALUE obj; \
GetBN(self, bn); \
if (!(result = BN_new())) { \
} \
if (!BN_##func(result, bn, ossl_bn_ctx)) { \
BN_free(result); \
} \
WrapBN(CLASS_OF(self), obj, result); \
return obj; \
}
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define CLASS_OF(v)
Definition: ruby.h:376
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
#define NULL
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
return
Definition: name2ctype.h:23857
BN_CTX * ossl_bn_ctx
Definition: ossl_bn.c:89
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319
VALUE eBNError
Definition: ossl_bn.c:37
#define WrapBN(klass, obj, bn)
Definition: ossl_bn.c:14

Definition at line 281 of file ossl_bn.c.

#define BIGNUM_2 (   func)
Value:
/* \
* call-seq: \
* bn.##func(bn2) -> aBN \
* \
*/ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE other) \
{ \
BIGNUM *bn1, *bn2 = GetBNPtr(other), *result; \
VALUE obj; \
GetBN(self, bn1); \
if (!(result = BN_new())) { \
} \
if (!BN_##func(result, bn1, bn2)) { \
BN_free(result); \
} \
WrapBN(CLASS_OF(self), obj, result); \
return obj; \
}
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define CLASS_OF(v)
Definition: ruby.h:376
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
#define NULL
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
return
Definition: name2ctype.h:23857
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319
BIGNUM * GetBNPtr(VALUE obj)
Definition: ossl_bn.c:58
VALUE eBNError
Definition: ossl_bn.c:37
#define WrapBN(klass, obj, bn)
Definition: ossl_bn.c:14
#define BIGNUM_2c (   func)
Value:
/* \
* call-seq: \
* bn.##func(bn2) -> aBN \
* \
*/ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE other) \
{ \
BIGNUM *bn1, *bn2 = GetBNPtr(other), *result; \
VALUE obj; \
GetBN(self, bn1); \
if (!(result = BN_new())) { \
} \
if (!BN_##func(result, bn1, bn2, ossl_bn_ctx)) { \
BN_free(result); \
} \
WrapBN(CLASS_OF(self), obj, result); \
return obj; \
}
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define CLASS_OF(v)
Definition: ruby.h:376
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
#define NULL
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
return
Definition: name2ctype.h:23857
BN_CTX * ossl_bn_ctx
Definition: ossl_bn.c:89
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319
BIGNUM * GetBNPtr(VALUE obj)
Definition: ossl_bn.c:58
VALUE eBNError
Definition: ossl_bn.c:37
#define WrapBN(klass, obj, bn)
Definition: ossl_bn.c:14
#define BIGNUM_3c (   func)
Value:
/* \
* call-seq: \
* bn.##func(bn1, bn2) -> aBN \
* \
*/ \
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); \
if (!(result = BN_new())) { \
} \
if (!BN_##func(result, bn1, bn2, bn3, ossl_bn_ctx)) { \
BN_free(result); \
} \
WrapBN(CLASS_OF(self), obj, result); \
return obj; \
}
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define CLASS_OF(v)
Definition: ruby.h:376
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
#define NULL
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
return
Definition: name2ctype.h:23857
BN_CTX * ossl_bn_ctx
Definition: ossl_bn.c:89
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319
BIGNUM * GetBNPtr(VALUE obj)
Definition: ossl_bn.c:58
VALUE eBNError
Definition: ossl_bn.c:37
#define WrapBN(klass, obj, bn)
Definition: ossl_bn.c:14

Definition at line 389 of file ossl_bn.c.

#define BIGNUM_BIT (   func)
Value:
/* \
* call-seq: \
* bn.##func(bit) -> self \
* \
*/ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE bit) \
{ \
BIGNUM *bn; \
GetBN(self, bn); \
if (!BN_##func(bn, NUM2INT(bit))) { \
} \
return self; \
}
#define NUM2INT(x)
Definition: ruby.h:536
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
#define NULL
unsigned long VALUE
Definition: ruby.h:88
return
Definition: name2ctype.h:23857
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319
VALUE eBNError
Definition: ossl_bn.c:37
#define BIGNUM_BOOL1 (   func)
Value:
/* \
* call-seq: \
* bn.##func -> true | false \
* \
*/ \
static VALUE \
ossl_bn_##func(VALUE self) \
{ \
BIGNUM *bn; \
GetBN(self, bn); \
if (BN_##func(bn)) { \
} \
}
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define Qtrue
Definition: ruby.h:366
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
#define Qfalse
Definition: ruby.h:365
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
unsigned long VALUE
Definition: ruby.h:88
return
Definition: name2ctype.h:23857

Definition at line 261 of file ossl_bn.c.

#define BIGNUM_CMP (   func)
Value:
/* \
* call-seq: \
* bn.##func(bn2) -> integer \
* \
*/ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE other) \
{ \
BIGNUM *bn1, *bn2 = GetBNPtr(other); \
GetBN(self, bn1); \
return INT2FIX(BN_##func(bn1, bn2)); \
}
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
unsigned long VALUE
Definition: ruby.h:88
#define INT2FIX(i)
Definition: ruby.h:225
return
Definition: name2ctype.h:23857
BIGNUM * GetBNPtr(VALUE obj)
Definition: ossl_bn.c:58

Definition at line 634 of file ossl_bn.c.

#define BIGNUM_NUM (   func)
Value:
/* \
* call-seq: \
* bn.##func -> integer \
* \
*/ \
static VALUE \
ossl_bn_##func(VALUE self) \
{ \
BIGNUM *bn; \
GetBN(self, bn); \
return INT2FIX(BN_##func(bn)); \
}
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
unsigned long VALUE
Definition: ruby.h:88
#define INT2FIX(i)
Definition: ruby.h:225
return
Definition: name2ctype.h:23857

Definition at line 600 of file ossl_bn.c.

#define BIGNUM_RAND (   func)
Value:
/* \
* call-seq: \
* BN.##func(bits [, fill [, odd]]) -> aBN \
* \
*/ \
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); \
if (!(result = BN_new())) { \
} \
if (!BN_##func(result, b, top, bottom)) { \
BN_free(result); \
} \
WrapBN(klass, obj, result); \
return obj; \
}
#define NUM2INT(x)
Definition: ruby.h:536
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define Qtrue
Definition: ruby.h:366
int argc
Definition: ruby.c:120
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1415
#define NULL
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
unsigned int top
Definition: nkf.c:3914
return
Definition: name2ctype.h:23857
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319
VALUE eBNError
Definition: ossl_bn.c:37
char ** argv
Definition: ruby.c:121
#define WrapBN(klass, obj, bn)
Definition: ossl_bn.c:14

Definition at line 502 of file ossl_bn.c.

#define BIGNUM_RAND_RANGE (   func)
Value:
/* \
* call-seq: \
* BN.##func(range) -> aBN \
* \
*/ \
static VALUE \
ossl_bn_s_##func##_range(VALUE klass, VALUE range) \
{ \
BIGNUM *bn = GetBNPtr(range), *result; \
VALUE obj; \
if (!(result = BN_new())) { \
} \
if (!BN_##func##_range(result, bn)) { \
BN_free(result); \
} \
WrapBN(klass, obj, result); \
return obj; \
}
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define range(low, item, hi)
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
#define NULL
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
return
Definition: name2ctype.h:23857
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319
BIGNUM * GetBNPtr(VALUE obj)
Definition: ossl_bn.c:58
VALUE eBNError
Definition: ossl_bn.c:37
#define WrapBN(klass, obj, bn)
Definition: ossl_bn.c:14

Definition at line 536 of file ossl_bn.c.

#define BIGNUM_SELF_SHIFT (   func)
Value:
/* \
* call-seq: \
* bn.##func!(bits) -> self \
* \
*/ \
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)) \
return self; \
}
#define NUM2INT(x)
Definition: ruby.h:536
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
#define NULL
unsigned long VALUE
Definition: ruby.h:88
return
Definition: name2ctype.h:23857
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319
VALUE eBNError
Definition: ossl_bn.c:37

Definition at line 482 of file ossl_bn.c.

#define BIGNUM_SHIFT (   func)
Value:
/* \
* call-seq: \
* bn.##func(bits) -> aBN \
* \
*/ \
static VALUE \
ossl_bn_##func(VALUE self, VALUE bits) \
{ \
BIGNUM *bn, *result; \
int b; \
VALUE obj; \
b = NUM2INT(bits); \
GetBN(self, bn); \
if (!(result = BN_new())) { \
} \
if (!BN_##func(result, bn, b)) { \
BN_free(result); \
} \
WrapBN(CLASS_OF(self), obj, result); \
return obj; \
}
#define NUM2INT(x)
Definition: ruby.h:536
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define CLASS_OF(v)
Definition: ruby.h:376
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
#define NULL
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
return
Definition: name2ctype.h:23857
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319
VALUE eBNError
Definition: ossl_bn.c:37
#define WrapBN(klass, obj, bn)
Definition: ossl_bn.c:14

Definition at line 455 of file ossl_bn.c.

#define GetBN (   obj,
  bn 
)
Value:
do { \
Data_Get_Struct((obj), BIGNUM, (bn)); \
if (!(bn)) { \
ossl_raise(rb_eRuntimeError, "BN wasn't initialized!"); \
} \
} while (0)
#define Data_Get_Struct(obj, type, sval)
Definition: ruby.h:835
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
VALUE rb_eRuntimeError
Definition: error.c:466
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319

Definition at line 21 of file ossl_bn.c.

Referenced by BIGNUM_1c(), BIGNUM_3c(), GetBNPtr(), ossl_bn_copy(), ossl_bn_initialize(), ossl_bn_is_prime(), ossl_bn_is_prime_fasttest(), ossl_bn_to_i(), and ossl_bn_to_s().

#define SafeGetBN (   obj,
  bn 
)
Value:
do { \
GetBN((obj), (bn)); \
} while (0)
#define GetBN(obj, bn)
Definition: ossl_bn.c:21
VALUE cBN
Definition: ossl_bn.c:36
#define OSSL_Check_Kind(obj, klass)
Definition: ossl.h:90

Definition at line 28 of file ossl_bn.c.

#define WrapBN (   klass,
  obj,
  bn 
)
Value:
do { \
if (!(bn)) { \
ossl_raise(rb_eRuntimeError, "BN wasn't initialized!"); \
} \
(obj) = Data_Wrap_Struct((klass), 0, BN_clear_free, (bn)); \
} while (0)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
Definition: name2ctype.h:23841
#define Data_Wrap_Struct(klass, mark, free, sval)
Definition: ruby.h:817
VALUE rb_eRuntimeError
Definition: error.c:466
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:319

Definition at line 14 of file ossl_bn.c.

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

Function Documentation

BIGNUM_1c ( sqr  )

Definition at line 303 of file ossl_bn.c.

References CLASS_OF, eBNError, GetBN, GetBNPtr(), NULL, ossl_bn_ctx, ossl_raise(), rb_ary_new3(), and WrapBN.

BIGNUM_3c ( mod_add  )

Definition at line 412 of file ossl_bn.c.

References GetBN, NUM2INT, Qfalse, and Qtrue.

BIGNUM* GetBNPtr ( VALUE  obj)
void Init_ossl_bn ( void  )
static VALUE ossl_bn_alloc ( VALUE  klass)
static

Definition at line 92 of file ossl_bn.c.

References eBNError, NULL, ossl_raise(), and WrapBN.

Referenced by Init_ossl_bn().

static VALUE ossl_bn_coerce ( VALUE  self,
VALUE  other 
)
static
static VALUE ossl_bn_copy ( VALUE  self,
VALUE  other 
)
static

Definition at line 617 of file ossl_bn.c.

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

Referenced by Init_ossl_bn().

static VALUE ossl_bn_eql ( VALUE  self,
VALUE  other 
)
static

Definition at line 651 of file ossl_bn.c.

References INT2FIX, Qfalse, and Qtrue.

Referenced by Init_ossl_bn().

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

Definition at line 668 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().

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

Definition at line 701 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().

VALUE ossl_bn_new ( const BIGNUM *  bn)
static VALUE ossl_bn_s_generate_prime ( int  argc,
VALUE argv,
VALUE  klass 
)
static

Definition at line 571 of file ossl_bn.c.

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

Referenced by Init_ossl_bn().

static VALUE ossl_bn_to_bn ( VALUE  self)
static

Definition at line 237 of file ossl_bn.c.

Referenced by Init_ossl_bn().

static VALUE ossl_bn_to_i ( VALUE  self)
static

Definition at line 219 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().

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

Variable Documentation

VALUE cBN

Definition at line 36 of file ossl_bn.c.

Referenced by GetBNPtr(), Init_ossl_bn(), ossl_bn_coerce(), ossl_bn_initialize(), and ossl_bn_new().

VALUE eBNError
BN_CTX* ossl_bn_ctx

Definition at line 89 of file ossl_bn.c.

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