Class: OpenSSL::PKey::EC::Group
- Inherits:
-
Object
- Object
- OpenSSL::PKey::EC::Group
- Defined in:
- ossl_pkey_ec.c
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#asn1_flag ⇒ Fixnum
See the OpenSSL documentation for EC_GROUP_get_asn1_flag().
-
#asn1_flag=(Fixnum) ⇒ Fixnum
See the OpenSSL documentation for EC_GROUP_set_asn1_flag().
-
#get_cofactor ⇒ Object
See the OpenSSL documentation for EC_GROUP_get_cofactor().
-
#curve_name ⇒ String
See the OpenSSL documentation for EC_GROUP_get_curve_name().
-
#degree ⇒ Fixnum
See the OpenSSL documentation for EC_GROUP_get_degree().
- #==(group2) ⇒ Boolean (also: #==)
-
#generator ⇒ Object
See the OpenSSL documentation for EC_GROUP_get0_generator().
-
#initialize(*args) ⇒ Object
constructor
See the OpenSSL documentation for EC_GROUP_*.
-
#get_order ⇒ Object
See the OpenSSL documentation for EC_GROUP_get_order().
-
#point_conversion_form ⇒ Object
See the OpenSSL documentation for EC_GROUP_get_point_conversion_form().
-
#point_conversion_form=(form) ⇒ Object
See the OpenSSL documentation for EC_GROUP_set_point_conversion_form().
-
#seed ⇒ String?
See the OpenSSL documentation for EC_GROUP_get0_seed().
-
#seed=(seed) ⇒ Object
See the OpenSSL documentation for EC_GROUP_set_seed().
-
#set_generator(generator, order, cofactor) ⇒ self
See the OpenSSL documentation for EC_GROUP_set_generator().
-
#to_der ⇒ String
See the OpenSSL documentation for i2d_ECPKParameters_bio().
-
#to_pem ⇒ String
See the OpenSSL documentation for PEM_write_bio_ECPKParameters().
-
#to_text ⇒ String
See the OpenSSL documentation for ECPKParameters_print().
Constructor Details
#OpenSSL::PKey::EC::Group.new("secp112r1") ⇒ Object #OpenSSL::PKey::EC::Group.new(ec_group) ⇒ Object #OpenSSL::PKey::EC::Group.new(pem_string) ⇒ Object #OpenSSL::PKey::EC::Group.new(der_string) ⇒ Object #OpenSSL::PKey::EC::Group.new(pem_file) ⇒ Object #OpenSSL::PKey::EC::Group.new(der_file) ⇒ Object #OpenSSL::PKey::EC::Group.new(: GFp_simple) ⇒ Object #OpenSSL::PKey::EC::Group.new(: GFp_mult) ⇒ Object #OpenSSL::PKey::EC::Group.new(: GFp_nist) ⇒ Object #OpenSSL::PKey::EC::Group.new(: GF2m_simple) ⇒ Object #OpenSSL::PKey::EC::Group.new(: GFp, bignum_p, bignum_a, bignum_b) ⇒ Object #OpenSSL::PKey::EC::Group.new(: GF2m, bignum_p, bignum_a, bignum_b) ⇒ Object
See the OpenSSL documentation for EC_GROUP_*
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 |
# File 'ossl_pkey_ec.c', line 727 static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self) { VALUE arg1, arg2, arg3, arg4; ossl_ec_group *ec_group; EC_GROUP *group = NULL; Data_Get_Struct(self, ossl_ec_group, ec_group); if (ec_group->group != NULL) rb_raise(rb_eRuntimeError, "EC_GROUP is already initialized"); switch (rb_scan_args(argc, argv, "13", &arg1, &arg2, &arg3, &arg4)) { case 1: if (SYMBOL_P(arg1)) { const EC_METHOD *method = NULL; ID id = SYM2ID(arg1); if (id == s_GFp_simple) { method = EC_GFp_simple_method(); } else if (id == s_GFp_mont) { method = EC_GFp_mont_method(); } else if (id == s_GFp_nist) { method = EC_GFp_nist_method(); } else if (id == s_GF2m_simple) { method = EC_GF2m_simple_method(); } if (method) { if ((group = EC_GROUP_new(method)) == NULL) ossl_raise(eEC_GROUP, "EC_GROUP_new"); } else { rb_raise(rb_eArgError, "unknown symbol, must be :GFp_simple, :GFp_mont, :GFp_nist or :GF2m_simple"); } } else if (rb_obj_is_kind_of(arg1, cEC_GROUP)) { const EC_GROUP *arg1_group; SafeRequire_EC_GROUP(arg1, arg1_group); if ((group = EC_GROUP_dup(arg1_group)) == NULL) ossl_raise(eEC_GROUP, "EC_GROUP_dup"); } else { BIO *in = ossl_obj2bio(arg1); group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL); if (!group) { BIO_reset(in); group = d2i_ECPKParameters_bio(in, NULL); } BIO_free(in); if (!group) { const char *name = STR2CSTR(arg1); int nid = OBJ_sn2nid(name); if (nid == NID_undef) ossl_raise(eEC_GROUP, "unknown curve name (%s)", name); group = EC_GROUP_new_by_curve_name(nid); if (group == NULL) ossl_raise(eEC_GROUP, "unable to create curve (%s)", name); EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE); EC_GROUP_set_point_conversion_form(group, POINT_CONVERSION_UNCOMPRESSED); } } break; case 4: if (SYMBOL_P(arg1)) { ID id = SYM2ID(arg1); EC_GROUP *(*new_curve)(const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *) = NULL; const BIGNUM *p = GetBNPtr(arg2); const BIGNUM *a = GetBNPtr(arg3); const BIGNUM *b = GetBNPtr(arg4); if (id == s_GFp) { new_curve = EC_GROUP_new_curve_GFp; } else if (id == s_GF2m) { new_curve = EC_GROUP_new_curve_GF2m; } else { rb_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m"); } if ((group = new_curve(p, a, b, ossl_bn_ctx)) == NULL) ossl_raise(eEC_GROUP, "EC_GROUP_new_by_GF*"); } else { rb_raise(rb_eArgError, "unknown argument, must be :GFp or :GF2m"); } break; default: rb_raise(rb_eArgError, "wrong number of arguments"); } if (group == NULL) ossl_raise(eEC_GROUP, ""); ec_group->group = group; return self; } |
Instance Method Details
#asn1_flag ⇒ Fixnum
See the OpenSSL documentation for EC_GROUP_get_asn1_flag()
986 987 988 989 990 991 992 993 994 995 996 |
# File 'ossl_pkey_ec.c', line 986 static VALUE ossl_ec_group_get_asn1_flag(VALUE self) { EC_GROUP *group = NULL; int flag; Require_EC_GROUP(self, group); flag = EC_GROUP_get_asn1_flag(group); return INT2FIX(flag); } |
#asn1_flag=(Fixnum) ⇒ Fixnum
See the OpenSSL documentation for EC_GROUP_set_asn1_flag()
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 |
# File 'ossl_pkey_ec.c', line 1003 static VALUE ossl_ec_group_set_asn1_flag(VALUE self, VALUE flag_v) { EC_GROUP *group = NULL; Require_EC_GROUP(self, group); EC_GROUP_set_asn1_flag(group, NUM2INT(flag_v)); return flag_v; } |
#get_cofactor ⇒ Object
See the OpenSSL documentation for EC_GROUP_get_cofactor()
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
# File 'ossl_pkey_ec.c', line 911 static VALUE ossl_ec_group_get_cofactor(VALUE self) { VALUE bn_obj; BIGNUM *bn; EC_GROUP *group = NULL; Require_EC_GROUP(self, group); bn_obj = ossl_bn_new(NULL); bn = GetBNPtr(bn_obj); if (EC_GROUP_get_cofactor(group, bn, ossl_bn_ctx) != 1) ossl_raise(eEC_GROUP, "EC_GROUP_get_cofactor"); return bn_obj; } |
#curve_name ⇒ String
See the OpenSSL documentation for EC_GROUP_get_curve_name()
933 934 935 936 937 938 939 940 941 942 943 944 945 946 |
# File 'ossl_pkey_ec.c', line 933 static VALUE ossl_ec_group_get_curve_name(VALUE self) { EC_GROUP *group = NULL; int nid; Get_EC_GROUP(self, group); if (group == NULL) return Qnil; nid = EC_GROUP_get_curve_name(group); /* BUG: an nid or asn1 object should be returned, maybe. */ return rb_str_new2(OBJ_nid2sn(nid)); } |
#degree ⇒ Fixnum
See the OpenSSL documentation for EC_GROUP_get_degree()
1112 1113 1114 1115 1116 1117 1118 1119 |
# File 'ossl_pkey_ec.c', line 1112 static VALUE ossl_ec_group_get_degree(VALUE self) { EC_GROUP *group = NULL; Require_EC_GROUP(self, group); return INT2NUM(EC_GROUP_get_degree(group)); } |
#==(group2) ⇒ Boolean Also known as: ==
832 833 834 835 836 837 838 839 840 841 842 843 |
# File 'ossl_pkey_ec.c', line 832 static VALUE ossl_ec_group_eql(VALUE a, VALUE b) { EC_GROUP *group1 = NULL, *group2 = NULL; Require_EC_GROUP(a, group1); SafeRequire_EC_GROUP(b, group2); if (EC_GROUP_cmp(group1, group2, ossl_bn_ctx) == 1) return Qfalse; return Qtrue; } |
#generator ⇒ Object
See the OpenSSL documentation for EC_GROUP_get0_generator()
850 851 852 853 854 855 856 857 858 859 860 |
# File 'ossl_pkey_ec.c', line 850 static VALUE ossl_ec_group_get_generator(VALUE self) { VALUE point_obj; EC_GROUP *group = NULL; Require_EC_GROUP(self, group); point_obj = ossl_ec_point_dup(EC_GROUP_get0_generator(group), self); return point_obj; } |
#get_order ⇒ Object
See the OpenSSL documentation for EC_GROUP_get_order()
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 |
# File 'ossl_pkey_ec.c', line 889 static VALUE ossl_ec_group_get_order(VALUE self) { VALUE bn_obj; BIGNUM *bn; EC_GROUP *group = NULL; Require_EC_GROUP(self, group); bn_obj = ossl_bn_new(NULL); bn = GetBNPtr(bn_obj); if (EC_GROUP_get_order(group, bn, ossl_bn_ctx) != 1) ossl_raise(eEC_GROUP, "EC_GROUP_get_order"); return bn_obj; } |
#point_conversion_form ⇒ Object
See the OpenSSL documentation for EC_GROUP_get_point_conversion_form()
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 |
# File 'ossl_pkey_ec.c', line 1019 static VALUE ossl_ec_group_get_point_conversion_form(VALUE self) { EC_GROUP *group = NULL; point_conversion_form_t form; VALUE ret; Require_EC_GROUP(self, group); form = EC_GROUP_get_point_conversion_form(group); switch (form) { case POINT_CONVERSION_UNCOMPRESSED: ret = ID_uncompressed; break; case POINT_CONVERSION_COMPRESSED: ret = ID_compressed; break; case POINT_CONVERSION_HYBRID: ret = ID_hybrid; break; default: rb_raise(eEC_GROUP, "unsupported point conversion form: %d, this module should be updated", form); } return ID2SYM(ret); } |
#point_conversion_form=(form) ⇒ Object
See the OpenSSL documentation for EC_GROUP_set_point_conversion_form()
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 |
# File 'ossl_pkey_ec.c', line 1044 static VALUE ossl_ec_group_set_point_conversion_form(VALUE self, VALUE form_v) { EC_GROUP *group = NULL; point_conversion_form_t form; ID form_id = SYM2ID(form_v); Require_EC_GROUP(self, group); if (form_id == ID_uncompressed) { form = POINT_CONVERSION_UNCOMPRESSED; } else if (form_id == ID_compressed) { form = POINT_CONVERSION_COMPRESSED; } else if (form_id == ID_hybrid) { form = POINT_CONVERSION_HYBRID; } else { rb_raise(rb_eArgError, "form must be :compressed, :uncompressed, or :hybrid"); } EC_GROUP_set_point_conversion_form(group, form); return form_v; } |
#seed ⇒ String?
See the OpenSSL documentation for EC_GROUP_get0_seed()
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 |
# File 'ossl_pkey_ec.c', line 1072 static VALUE ossl_ec_group_get_seed(VALUE self) { EC_GROUP *group = NULL; size_t seed_len; Require_EC_GROUP(self, group); seed_len = EC_GROUP_get_seed_len(group); if (seed_len == 0) return Qnil; return rb_str_new(EC_GROUP_get0_seed(group), seed_len); } |
#seed=(seed) ⇒ Object
See the OpenSSL documentation for EC_GROUP_set_seed()
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
# File 'ossl_pkey_ec.c', line 1092 static VALUE ossl_ec_group_set_seed(VALUE self, VALUE seed) { EC_GROUP *group = NULL; Require_EC_GROUP(self, group); StringValue(seed); if (EC_GROUP_set_seed(group, RSTRING_PTR(seed), RSTRING_LEN(seed)) != RSTRING_LEN(seed)) ossl_raise(eEC_GROUP, "EC_GROUP_set_seed"); return seed; } |
#set_generator(generator, order, cofactor) ⇒ self
See the OpenSSL documentation for EC_GROUP_set_generator()
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 |
# File 'ossl_pkey_ec.c', line 867 static VALUE ossl_ec_group_set_generator(VALUE self, VALUE generator, VALUE order, VALUE cofactor) { EC_GROUP *group = NULL; const EC_POINT *point; const BIGNUM *o, *co; Require_EC_GROUP(self, group); SafeRequire_EC_POINT(generator, point); o = GetBNPtr(order); co = GetBNPtr(cofactor); if (EC_GROUP_set_generator(group, point, o, co) != 1) ossl_raise(eEC_GROUP, "EC_GROUP_set_generator"); return self; } |
#to_der ⇒ String
See the OpenSSL documentation for i2d_ECPKParameters_bio()
1170 1171 1172 1173 |
# File 'ossl_pkey_ec.c', line 1170 static VALUE ossl_ec_group_to_der(VALUE self) { return ossl_ec_group_to_string(self, EXPORT_DER); } |
#to_pem ⇒ String
See the OpenSSL documentation for PEM_write_bio_ECPKParameters()
1160 1161 1162 1163 |
# File 'ossl_pkey_ec.c', line 1160 static VALUE ossl_ec_group_to_pem(VALUE self) { return ossl_ec_group_to_string(self, EXPORT_PEM); } |
#to_text ⇒ String
See the OpenSSL documentation for ECPKParameters_print()
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 |
# File 'ossl_pkey_ec.c', line 1180 static VALUE ossl_ec_group_to_text(VALUE self) { EC_GROUP *group; BIO *out; VALUE str; Require_EC_GROUP(self, group); if (!(out = BIO_new(BIO_s_mem()))) { ossl_raise(eEC_GROUP, "BIO_new(BIO_s_mem())"); } if (!ECPKParameters_print(out, group, 0)) { BIO_free(out); ossl_raise(eEC_GROUP, NULL); } str = ossl_membio2str(out); return str; } |