xrootd
XrdCryptosslRSA.hh
Go to the documentation of this file.
00001 #ifndef __CRYPTO_SSLRSA_H__
00002 #define __CRYPTO_SSLRSA_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                   X r d C r y p t o S s l R S A . h h                      */
00006 /*                                                                            */
00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*   Produced by Gerri Ganis for CERN                                         */
00009 /*                                                                            */
00010 /* This file is part of the XRootD software suite.                            */
00011 /*                                                                            */
00012 /* XRootD is free software: you can redistribute it and/or modify it under    */
00013 /* the terms of the GNU Lesser General Public License as published by the     */
00014 /* Free Software Foundation, either version 3 of the License, or (at your     */
00015 /* option) any later version.                                                 */
00016 /*                                                                            */
00017 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00018 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00019 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00020 /* License for more details.                                                  */
00021 /*                                                                            */
00022 /* You should have received a copy of the GNU Lesser General Public License   */
00023 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00024 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00025 /*                                                                            */
00026 /* The copyright holder's institutional names and contributor's names may not */
00027 /* be used to endorse or promote products derived from this software without  */
00028 /* specific prior written permission of the institution or contributor.       */
00029 /******************************************************************************/
00030 
00031 /* ************************************************************************** */
00032 /*                                                                            */
00033 /* OpenSSL implementation of XrdCryptoRSA                                     */
00034 /*                                                                            */
00035 /* ************************************************************************** */
00036 
00037 #include "XrdCrypto/XrdCryptoRSA.hh"
00038 
00039 #include <openssl/evp.h>
00040 
00041 // ---------------------------------------------------------------------------//
00042 //
00043 // RSA interface
00044 //
00045 // ---------------------------------------------------------------------------//
00046 class XrdCryptosslRSA : public XrdCryptoRSA
00047 {
00048 private:
00049    EVP_PKEY *fEVP;     // The key pair
00050    int       publen;   // Length of export public key
00051    int       prilen;   // Length of export private key
00052 
00053 public:
00054    XrdCryptosslRSA(int bits = XrdCryptoMinRSABits, int exp = XrdCryptoDefRSAExp);
00055    XrdCryptosslRSA(const char *pub, int lpub = 0);
00056    XrdCryptosslRSA(EVP_PKEY *key, bool check = 1);
00057    XrdCryptosslRSA(const XrdCryptosslRSA &r);
00058    virtual ~XrdCryptosslRSA();
00059 
00060    // Access underlying data (in opaque form)
00061    XrdCryptoRSAdata Opaque() { return fEVP; }
00062 
00063    // Dump information
00064    void Dump();
00065 
00066    // Output lengths
00067    int GetOutlen(int lin);   // Length of encrypted buffers
00068    int GetPublen();          // Length of export public key
00069    int GetPrilen();          // Length of export private key
00070 
00071    // Import / Export methods
00072    int ImportPublic(const char *in, int lin);
00073    int ExportPublic(char *out, int lout);
00074    int ImportPrivate(const char *in, int lin);
00075    int ExportPrivate(char *out, int lout);
00076 
00077    // Encryption / Decryption methods
00078    int EncryptPrivate(const char *in, int lin, char *out, int lout);
00079    int DecryptPublic(const char *in, int lin, char *out, int lout);
00080    int EncryptPublic(const char *in, int lin, char *out, int lout);
00081    int DecryptPrivate(const char *in, int lin, char *out, int lout);
00082 };
00083 
00084 #endif