Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_OSSL_PKEY_H_)
00012 #define _OSSL_PKEY_H_
00013
00014 extern VALUE mPKey;
00015 extern VALUE cPKey;
00016 extern VALUE ePKeyError;
00017 extern ID id_private_q;
00018
00019 #define OSSL_PKEY_SET_PRIVATE(obj) rb_iv_set((obj), "private", Qtrue)
00020 #define OSSL_PKEY_SET_PUBLIC(obj) rb_iv_set((obj), "private", Qfalse)
00021 #define OSSL_PKEY_IS_PRIVATE(obj) (rb_iv_get((obj), "private") == Qtrue)
00022
00023 #define WrapPKey(klass, obj, pkey) do { \
00024 if (!pkey) { \
00025 rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!"); \
00026 } \
00027 obj = Data_Wrap_Struct(klass, 0, EVP_PKEY_free, pkey); \
00028 OSSL_PKEY_SET_PUBLIC(obj); \
00029 } while (0)
00030 #define GetPKey(obj, pkey) do {\
00031 Data_Get_Struct(obj, EVP_PKEY, pkey);\
00032 if (!pkey) { \
00033 rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!");\
00034 } \
00035 } while (0)
00036 #define SafeGetPKey(obj, pkey) do { \
00037 OSSL_Check_Kind(obj, cPKey); \
00038 GetPKey(obj, pkey); \
00039 } while (0)
00040
00041 void ossl_generate_cb(int, int, void *);
00042
00043 VALUE ossl_pkey_new(EVP_PKEY *);
00044 VALUE ossl_pkey_new_from_file(VALUE);
00045 EVP_PKEY *GetPKeyPtr(VALUE);
00046 EVP_PKEY *DupPKeyPtr(VALUE);
00047 EVP_PKEY *GetPrivPKeyPtr(VALUE);
00048 EVP_PKEY *DupPrivPKeyPtr(VALUE);
00049 void Init_ossl_pkey(void);
00050
00051
00052
00053
00054 extern VALUE cRSA;
00055 extern VALUE eRSAError;
00056
00057 VALUE ossl_rsa_new(EVP_PKEY *);
00058 void Init_ossl_rsa(void);
00059
00060
00061
00062
00063 extern VALUE cDSA;
00064 extern VALUE eDSAError;
00065
00066 VALUE ossl_dsa_new(EVP_PKEY *);
00067 void Init_ossl_dsa(void);
00068
00069
00070
00071
00072 extern VALUE cDH;
00073 extern VALUE eDHError;
00074 extern DH *OSSL_DEFAULT_DH_512;
00075 extern DH *OSSL_DEFAULT_DH_1024;
00076
00077 VALUE ossl_dh_new(EVP_PKEY *);
00078 void Init_ossl_dh(void);
00079
00080
00081
00082
00083 extern VALUE cEC;
00084 extern VALUE eECError;
00085 extern VALUE cEC_GROUP;
00086 extern VALUE eEC_GROUP;
00087 extern VALUE cEC_POINT;
00088 extern VALUE eEC_POINT;
00089 VALUE ossl_ec_new(EVP_PKEY *);
00090 void Init_ossl_ec(void);
00091
00092
00093 #define OSSL_PKEY_BN(keytype, name) \
00094
00095
00096
00097 \
00098 static VALUE ossl_##keytype##_get_##name(VALUE self) \
00099 { \
00100 EVP_PKEY *pkey; \
00101 BIGNUM *bn; \
00102 \
00103 GetPKey(self, pkey); \
00104 bn = pkey->pkey.keytype->name; \
00105 if (bn == NULL) \
00106 return Qnil; \
00107 return ossl_bn_new(bn); \
00108 } \
00109
00110
00111
00112 \
00113 static VALUE ossl_##keytype##_set_##name(VALUE self, VALUE bignum) \
00114 { \
00115 EVP_PKEY *pkey; \
00116 BIGNUM *bn; \
00117 \
00118 GetPKey(self, pkey); \
00119 if (NIL_P(bignum)) { \
00120 BN_clear_free(pkey->pkey.keytype->name); \
00121 pkey->pkey.keytype->name = NULL; \
00122 return Qnil; \
00123 } \
00124 \
00125 bn = GetBNPtr(bignum); \
00126 if (pkey->pkey.keytype->name == NULL) \
00127 pkey->pkey.keytype->name = BN_new(); \
00128 if (pkey->pkey.keytype->name == NULL) \
00129 ossl_raise(eBNError, NULL); \
00130 if (BN_copy(pkey->pkey.keytype->name, bn) == NULL) \
00131 ossl_raise(eBNError, NULL); \
00132 return bignum; \
00133 }
00134
00135 #define DEF_OSSL_PKEY_BN(class, keytype, name) \
00136 do { \
00137 rb_define_method(class, #name, ossl_##keytype##_get_##name, 0); \
00138 rb_define_method(class, #name "=", ossl_##keytype##_set_##name, 1);\
00139 } while (0)
00140
00141 #endif
00142