Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-08 10:33:32

0001 #ifndef __CRYPTO_RSA_H__
0002 #define __CRYPTO_RSA_H__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                       X r d C r y p t o R S A . h h                        */
0006 /*                                                                            */
0007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*   Produced by Gerri Ganis for CERN                                         */
0009 /*                                                                            */
0010 /* This file is part of the XRootD software suite.                            */
0011 /*                                                                            */
0012 /* XRootD is free software: you can redistribute it and/or modify it under    */
0013 /* the terms of the GNU Lesser General Public License as published by the     */
0014 /* Free Software Foundation, either version 3 of the License, or (at your     */
0015 /* option) any later version.                                                 */
0016 /*                                                                            */
0017 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0018 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0019 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0020 /* License for more details.                                                  */
0021 /*                                                                            */
0022 /* You should have received a copy of the GNU Lesser General Public License   */
0023 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0024 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0025 /*                                                                            */
0026 /* The copyright holder's institutional names and contributor's names may not */
0027 /* be used to endorse or promote products derived from this software without  */
0028 /* specific prior written permission of the institution or contributor.       */
0029 /******************************************************************************/
0030 
0031 /* ************************************************************************** */
0032 /*                                                                            */
0033 /* Abstract interface for RSA PKI functionality.                              */
0034 /* Allows to plug-in modules based on different crypto implementation         */
0035 /* (OpenSSL, Botan, ...)                                                      */
0036 /*                                                                            */
0037 /* ************************************************************************** */
0038 
0039 #include "XrdSut/XrdSutBucket.hh"
0040 #include "XrdOuc/XrdOucString.hh"
0041 #include "XrdCrypto/XrdCryptoAux.hh"
0042 
0043 typedef void * XrdCryptoRSAdata;
0044 
0045 // ---------------------------------------------------------------------------//
0046 //
0047 // RSA interface
0048 //
0049 // ---------------------------------------------------------------------------//
0050 class XrdCryptoRSA
0051 {
0052 public:
0053    XrdCryptoRSA() { status = kInvalid; }
0054    virtual ~XrdCryptoRSA() {}
0055 
0056    // Status
0057    enum ERSAStatus { kInvalid = 0, kPublic = 1, kComplete = 2};
0058    ERSAStatus  status;
0059    const char *Status(ERSAStatus t = kInvalid) const
0060                  { return ((t == kInvalid) ? cstatus[status] : cstatus[t]); }
0061 
0062    // Access underlying data (in opaque form)
0063    virtual XrdCryptoRSAdata Opaque();
0064 
0065    // Dump information
0066    virtual void Dump();
0067 
0068    // Validity
0069    bool IsValid() { return (status != kInvalid); }
0070 
0071    // Output lengths
0072    virtual int GetOutlen(int lin);   // Length of encrypted buffers
0073    virtual int GetPublen();          // Length of export public key
0074    virtual int GetPrilen();          // Length of export private key
0075 
0076    // Import / Export methods
0077    virtual int ImportPublic(const char *in, int lin);
0078    virtual int ExportPublic(char *out, int lout);
0079    int ExportPublic(XrdOucString &exp);
0080    virtual int ImportPrivate(const char *in, int lin);
0081    virtual int ExportPrivate(char *out, int lout);
0082    int ExportPrivate(XrdOucString &exp);
0083 
0084    // Encryption / Decryption methods
0085    virtual int EncryptPrivate(const char *in, int lin, char *out, int lout);
0086    virtual int DecryptPublic(const char *in, int lin, char *out, int lout);
0087    virtual int EncryptPublic(const char *in, int lin, char *out, int lout);
0088    virtual int DecryptPrivate(const char *in, int lin, char *out, int lout);
0089    int EncryptPrivate(XrdSutBucket &buck);
0090    int DecryptPublic (XrdSutBucket &buck);
0091    int EncryptPublic (XrdSutBucket &buck);
0092    int DecryptPrivate(XrdSutBucket &buck);
0093 
0094 private:
0095    static const char *cstatus[3];  // Names of status
0096 };
0097 
0098 #endif