[BACK]Return to ntlrsa.h CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_ntl / crypt / rsa

Annotation of OpenXM/src/ox_ntl/crypt/rsa/ntlrsa.h, Revision 1.1

1.1     ! iwane       1: /* $OpenXM$ */
        !             2:
        !             3: #ifndef __NTL_RSA_H__
        !             4: #define __NTL_RSA_H__
        !             5:
        !             6: #include <NTL/ZZ.h>
        !             7:
        !             8: /***************************************************
        !             9:  * NtlRsa.
        !            10:  ***************************************************/
        !            11: class NtlRsa {
        !            12: // Member
        !            13: private:
        !            14:        ZZ mod;         // n = p*q : modulus
        !            15:        ZZ privateKey;  // d : private exponent
        !            16:        ZZ publicKey;   // e : public exponent
        !            17:        int k;          // length of modulus in octets
        !            18:
        !            19: public:
        !            20:        static const int OCTET_SIZE = 256;
        !            21:        static const int PS_MIN     = 8;
        !            22:        static const ZZ  dummy;
        !            23:
        !            24:        enum {
        !            25:                PADDING_PRIVATE0 = 0x00,
        !            26:                PADDING_PRIVATE  = 0x01,
        !            27:                PADDING_PUBLIC   = 0x02,
        !            28:        };
        !            29:
        !            30:
        !            31:
        !            32: // constructor
        !            33: public:
        !            34:        NtlRsa(void);
        !            35:        NtlRsa(int seed, int bit);
        !            36:        NtlRsa(ZZ &mod, ZZ &publicKey, ZZ &privateKey);
        !            37:        NtlRsa(ZZ &mod, ZZ &publicKey);
        !            38:        virtual ~NtlRsa() { }
        !            39:
        !            40: // member access
        !            41: public:
        !            42:        inline ZZ getPublicKey() const {
        !            43:                return (publicKey);
        !            44:        };
        !            45:        inline ZZ getPrivateKey() const {
        !            46:                return (privateKey);
        !            47:        };
        !            48:        inline ZZ getMod() const {
        !            49:                return (mod);
        !            50:        };
        !            51:        inline int getModLen() const {
        !            52:                return (k);
        !            53:        };
        !            54:        inline void setKeys(const ZZ &n, const ZZ &e, const ZZ &d) {
        !            55:                mod = n;
        !            56:                publicKey = e;
        !            57:                privateKey = d;
        !            58:                k = getBlockSize(mod);
        !            59:        };
        !            60:
        !            61:        inline void setKeys(const ZZ &n, const ZZ &e) { // dont know private key
        !            62:                setKeys(n, e, dummy);
        !            63:        };
        !            64:
        !            65:
        !            66: // method
        !            67: private:
        !            68:        int getBlockSize(const ZZ &);
        !            69:
        !            70:        void keygen(int seed, int bit, ZZ &, ZZ &, ZZ &);
        !            71:
        !            72:        int     encrypt(unsigned char *, const unsigned char *, int size, int, const ZZ &, const ZZ &, int) const;
        !            73:        int     decrypt(unsigned char *, const unsigned char *, int, const ZZ &, const ZZ &, int) const;
        !            74:
        !            75: public:
        !            76:        void keygen(int seed, int bit);
        !            77:        void keygen(const char *seed_str, int bit);
        !            78:
        !            79:        int     encryptByPublicKey(unsigned char *, const char *) const;
        !            80:        int     encryptByPublicKey(unsigned char *, const unsigned char *, int len) const;
        !            81:        int     encryptByPrivateKey(unsigned char *, const char *) const;
        !            82:        int     encryptByPrivateKey(unsigned char *, const unsigned char *, int len) const;
        !            83:
        !            84:        int     decryptByPublicKey(unsigned char *, const unsigned char *) const;
        !            85:        int     decryptByPrivateKey(unsigned char *, const unsigned char *) const;
        !            86:
        !            87:
        !            88: /// friend operator.
        !            89:
        !            90:        friend ostream & operator << (ostream &o, const NtlRsa &rsa);
        !            91:
        !            92: };
        !            93:
        !            94: #endif /* __NTL_RSA_H__ */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>