~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/openssl/ossl_bn.c

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: ossl_bn.c 29794 2010-11-15 11:43:42Z yugui $
 
2
 * $Id: ossl_bn.c 31166 2011-03-24 07:29:21Z naruse $
3
3
 * 'OpenSSL for Ruby' project
4
4
 * Copyright (C) 2001-2002  Technorama team <oss-ruby@technorama.net>
5
5
 * All rights reserved.
12
12
#include "ossl.h"
13
13
 
14
14
#define WrapBN(klass, obj, bn) do { \
15
 
  if (!bn) { \
 
15
  if (!(bn)) { \
16
16
    ossl_raise(rb_eRuntimeError, "BN wasn't initialized!"); \
17
17
  } \
18
 
  obj = Data_Wrap_Struct(klass, 0, BN_clear_free, bn); \
 
18
  (obj) = Data_Wrap_Struct((klass), 0, BN_clear_free, (bn)); \
19
19
} while (0)
20
20
 
21
21
#define GetBN(obj, bn) do { \
22
 
  Data_Get_Struct(obj, BIGNUM, bn); \
23
 
  if (!bn) { \
 
22
  Data_Get_Struct((obj), BIGNUM, (bn)); \
 
23
  if (!(bn)) { \
24
24
    ossl_raise(rb_eRuntimeError, "BN wasn't initialized!"); \
25
25
  } \
26
26
} while (0)
27
27
 
28
28
#define SafeGetBN(obj, bn) do { \
29
 
  OSSL_Check_Kind(obj, cBN); \
30
 
  GetBN(obj, bn); \
 
29
  OSSL_Check_Kind((obj), cBN); \
 
30
  GetBN((obj), (bn)); \
31
31
} while (0)
32
32
 
33
33
/*
70
70
        }
71
71
        WrapBN(cBN, obj, bn); /* Handle potencial mem leaks */
72
72
        break;
 
73
    case T_NIL:
 
74
        break;
73
75
    default:
74
76
        ossl_raise(rb_eTypeError, "Cannot convert into OpenSSL::BN");
75
77
    }
131
133
 
132
134
    switch (base) {
133
135
    case 0:
134
 
        if (!BN_mpi2bn((unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str), bn)) {
 
136
        if (!BN_mpi2bn((unsigned char *)RSTRING_PTR(str), RSTRING_LENINT(str), bn)) {
135
137
            ossl_raise(eBNError, NULL);
136
138
        }
137
139
        break;
138
140
    case 2:
139
 
        if (!BN_bin2bn((unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str), bn)) {
 
141
        if (!BN_bin2bn((unsigned char *)RSTRING_PTR(str), RSTRING_LENINT(str), bn)) {
140
142
            ossl_raise(eBNError, NULL);
141
143
        }
142
144
        break;
196
198
        break;
197
199
    case 10:
198
200
        if (!(buf = BN_bn2dec(bn))) ossl_raise(eBNError, NULL);
199
 
        str = ossl_buf2str(buf, strlen(buf));
 
201
        str = ossl_buf2str(buf, rb_long2int(strlen(buf)));
200
202
        break;
201
203
    case 16:
202
204
        if (!(buf = BN_bn2hex(bn))) ossl_raise(eBNError, NULL);
203
 
        str = ossl_buf2str(buf, strlen(buf));
 
205
        str = ossl_buf2str(buf, rb_long2int(strlen(buf)));
204
206
        break;
205
207
    default:
206
208
        ossl_raise(rb_eArgError, "invalid radix %d", base);
731
733
void
732
734
Init_ossl_bn()
733
735
{
734
 
#if 0 /* let rdoc know about mOSSL */
735
 
    mOSSL = rb_define_module("OpenSSL");
 
736
#if 0
 
737
    mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
736
738
#endif
737
739
 
738
740
    if (!(ossl_bn_ctx = BN_CTX_new())) {