aboutsummaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2021-05-25 19:34:36 +0900
committerGitHub <noreply@github.com>2021-05-25 19:34:36 +0900
commit0ac1a4e11faf36fed9a4a06ffdead5f5a34d9d44 (patch)
treeba9eb673bb83c07f1fc511a20d01b31ef6927d08 /ext
parent809646ecaf9f1a64a6361efb31d17907b2093a55 (diff)
parent1e565eba89524d8b05f2560e84e48d09ac3fa1ab (diff)
downloadruby-openssl-0ac1a4e11faf36fed9a4a06ffdead5f5a34d9d44.tar.gz
Merge pull request #417 from mame/add-BN_set_flags
Add OpenSSL::BN#set_flags and #get_flags
Diffstat (limited to 'ext')
-rw-r--r--ext/openssl/ossl_bn.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c
index 02530789..8d0f63a9 100644
--- a/ext/openssl/ossl_bn.c
+++ b/ext/openssl/ossl_bn.c
@@ -1191,6 +1191,42 @@ ossl_bn_is_prime_fasttest(int argc, VALUE *argv, VALUE self)
}
/*
+ * call-seq:
+ * bn.get_flags(flags) => flags
+ *
+ * Returns the flags on the BN object.
+ * The argument is used as a bit mask.
+ *
+ * === Parameters
+ * * _flags_ - integer
+ */
+static VALUE
+ossl_bn_get_flags(VALUE self, VALUE arg)
+{
+ BIGNUM *bn;
+ GetBN(self, bn);
+
+ return INT2NUM(BN_get_flags(bn, NUM2INT(arg)));
+}
+
+/*
+ * call-seq:
+ * bn.set_flags(flags) => nil
+ *
+ * Enables the flags on the BN object.
+ * Currently, the flags argument can contain zero of OpenSSL::BN::CONSTTIME.
+ */
+static VALUE
+ossl_bn_set_flags(VALUE self, VALUE arg)
+{
+ BIGNUM *bn;
+ GetBN(self, bn);
+
+ BN_set_flags(bn, NUM2INT(arg));
+ return Qnil;
+}
+
+/*
* INIT
* (NOTE: ordering of methods is the same as in 'man bn')
*/
@@ -1289,6 +1325,23 @@ Init_ossl_bn(void)
/* lshift1 - DON'T IMPL. */
/* rshift1 - DON'T IMPL. */
+ rb_define_method(cBN, "get_flags", ossl_bn_get_flags, 1);
+ rb_define_method(cBN, "set_flags", ossl_bn_set_flags, 1);
+
+#ifdef BN_FLG_CONSTTIME
+ rb_define_const(cBN, "CONSTTIME", INT2NUM(BN_FLG_CONSTTIME));
+#endif
+ /* BN_FLG_MALLOCED and BN_FLG_STATIC_DATA seems for C programming.
+ * Allowing them leads to memory leak.
+ * So, for now, they are not exported
+#ifdef BN_FLG_MALLOCED
+ rb_define_const(cBN, "MALLOCED", INT2NUM(BN_FLG_MALLOCED));
+#endif
+#ifdef BN_FLG_STATIC_DATA
+ rb_define_const(cBN, "STATIC_DATA", INT2NUM(BN_FLG_STATIC_DATA));
+#endif
+ */
+
/*
* bn2bin
* bin2bn