Ruby 1.9.2p136(2010-12-25revision30365)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Defines | Functions | Variables

# ext/openssl/ossl_bn.c File Reference

`#include "ossl.h"`
Include dependency graph for ossl_bn.c:

Go to the source code of this file.

## Defines
#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

## Define 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())) {                     \
                ossl_raise(eBNError, NULL);                 \
            }                                               \
            if (!BN_##func(result, bn, ossl_bn_ctx)) {      \
                BN_free(result);                            \
                ossl_raise(eBNError, NULL);                 \
            }                                               \
            WrapBN(CLASS_OF(self), obj, result);            \
            return obj;                                     \
        }

Definition at line 275 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())) {                     \
                ossl_raise(eBNError, NULL);                 \
            }                                               \
            if (!BN_##func(result, bn1, bn2)) {             \
                BN_free(result);                            \
                ossl_raise(eBNError, NULL);                 \
            }                                               \
            WrapBN(CLASS_OF(self), obj, result);            \
            return obj;                                     \
        }

Referenced by BIGNUM_1c().

#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())) {                             \
                ossl_raise(eBNError, NULL);                         \
            }                                                       \
            if (!BN_##func(result, bn1, bn2, ossl_bn_ctx)) {        \
                BN_free(result);                                    \
                ossl_raise(eBNError, NULL);                         \
            }                                                       \
            WrapBN(CLASS_OF(self), obj, result);                    \
            return obj;                                             \
        }

Referenced by BIGNUM_1c().

#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())) {                             \
                ossl_raise(eBNError, NULL);                         \
            }                                                       \
            if (!BN_##func(result, bn1, bn2, bn3, ossl_bn_ctx)) {   \
                BN_free(result);                                    \
                ossl_raise(eBNError, NULL);                         \
            }                                                       \
            WrapBN(CLASS_OF(self), obj, result);                    \
            return obj;                                             \
        }

Definition at line 371 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))) {             \
                ossl_raise(eBNError, NULL);                 \
            }                                               \
            return self;                                    \
        }

#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)) {                            \
                return Qtrue;                               \
            }                                               \
            return Qfalse;                                  \
        }

Definition at line 259 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));            \
        }

Definition at line 588 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));          \
        }

Definition at line 558 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())) {                             \
                ossl_raise(eBNError, NULL);                         \
            }                                                       \
            if (!BN_##func(result, b, top, bottom)) {               \
                BN_free(result);                                    \
                ossl_raise(eBNError, NULL);                         \
            }                                                       \
            WrapBN(klass, obj, result);                             \
            return obj;                                             \
        }

Definition at line 468 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())) {                             \
                ossl_raise(eBNError, NULL);                         \
            }                                                       \
            if (!BN_##func##_range(result, bn)) {                   \
                BN_free(result);                                    \
                ossl_raise(eBNError, NULL);                         \
            }                                                       \
            WrapBN(klass, obj, result);                             \
            return obj;                                             \
        }

Definition at line 498 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))                      \
                    ossl_raise(eBNError, NULL);             \
            return self;                                    \
        }

Definition at line 452 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())) {                     \
                    ossl_raise(eBNError, NULL);             \
            }                                               \
            if (!BN_##func(result, bn, b)) {                \
                    BN_free(result);                        \
                    ossl_raise(eBNError, NULL);             \
            }                                               \
            WrapBN(CLASS_OF(self), obj, result);            \
            return obj;                                     \
        }

Definition at line 429 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)

Definition at line 21 of file ossl_bn.c.

Referenced by BIGNUM_1c(), GetBNPtr(), ossl_bn_initialize(), ossl_bn_to_i(), and ossl_bn_to_s().

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

Value:

    do { \
      OSSL_Check_Kind(obj, cBN); \
      GetBN(obj, bn); \
    } while (0)

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)

Definition at line 14 of file ossl_bn.c.

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

## Function Documentation

BIGNUM_1c | ( | sqr |  | ) |

Definition at line 293 of file ossl_bn.c.

References BIGNUM_2, BIGNUM_2c, eBNError, GetBN, GetBNPtr(), NULL, and ossl_raise().

BIGNUM_3c | ( | mod_add |  | ) |

Definition at line 390 of file ossl_bn.c.

BIGNUM* GetBNPtr | ( | VALUE | obj | ) |

Definition at line 58 of file ossl_bn.c.

References cBN, eBNError, GetBN, NULL, ossl_raise(), rb_eTypeError, rb_obj_is_kind_of(), rb_String(), RTEST, StringValuePtr, T_BIGNUM, T_FIXNUM, TYPE, and WrapBN.

Referenced by BIGNUM_1c(), num_to_asn1integer(), and ossl_dh_compute_key().

void Init_ossl_bn | ( | void |  | ) |

Definition at line 684 of file ossl_bn.c.

Referenced by Init_openssl().

static VALUE ossl_bn_alloc | ( | VALUE | klass | ) | `[static]`

Definition at line 90 of file ossl_bn.c.

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

static VALUE ossl_bn_coerce | ( | VALUE | self,
|  | VALUE | other
| ) |  | `[static]`

Definition at line 241 of file ossl_bn.c.

References cBN, NULL, ossl_bn_to_i(), ossl_bn_to_s(), ossl_raise(), rb_assoc_new(), rb_eTypeError, rb_obj_is_kind_of(), RTEST, T_BIGNUM, T_FIXNUM, T_STRING, and TYPE.

static VALUE ossl_bn_copy | ( | VALUE | self,
|  | VALUE | other
| ) |  | `[static]`

Definition at line 571 of file ossl_bn.c.

static VALUE ossl_bn_eql | ( | VALUE | self,
|  | VALUE | other
| ) |  | `[static]`

Definition at line 601 of file ossl_bn.c.

static VALUE ossl_bn_initialize | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | self
| ) |  | `[static]`

Definition at line 111 of file ossl_bn.c.

References cBN, eBNError, GetBN, NULL, NUM2INT, ossl_raise(), rb_eArgError, rb_obj_is_kind_of(), rb_scan_args(), RSTRING_LEN, RSTRING_PTR, RTEST, and StringValue.

static VALUE ossl_bn_is_prime | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | self
| ) |  | `[static]`

Definition at line 618 of file ossl_bn.c.

static VALUE ossl_bn_is_prime_fasttest | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | self
| ) |  | `[static]`

Definition at line 651 of file ossl_bn.c.

References Qtrue.

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

Definition at line 43 of file ossl_bn.c.

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

Referenced by asn1integer_to_num(), ossl_dh_get_params(), ossl_dsa_get_params(), and ossl_rsa_get_params().

static VALUE ossl_bn_s_generate_prime | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | klass
| ) |  | `[static]`

Definition at line 529 of file ossl_bn.c.

static VALUE ossl_bn_to_bn | ( | VALUE | self | ) | `[static]`

Definition at line 235 of file ossl_bn.c.

static VALUE ossl_bn_to_i | ( | VALUE | self | ) | `[static]`

Definition at line 217 of file ossl_bn.c.

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

Referenced by ossl_bn_coerce().

static VALUE ossl_bn_to_s | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | self
| ) |  | `[static]`

Definition at line 173 of file ossl_bn.c.

References buf, eBNError, GetBN, len, NULL, NUM2INT, ossl_buf2str(), ossl_raise(), rb_eArgError, rb_scan_args(), rb_str_new(), and RSTRING_PTR.

Referenced by ossl_bn_coerce().

## Variable Documentation

VALUE cBN

Definition at line 36 of file ossl_bn.c.

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

VALUE eBNError

Definition at line 37 of file ossl_bn.c.

Referenced by BIGNUM_1c(), GetBNPtr(), ossl_bn_alloc(), ossl_bn_initialize(), ossl_bn_new(), ossl_bn_to_i(), and ossl_bn_to_s().

BN_CTX* ossl_bn_ctx

Definition at line 87 of file ossl_bn.c.