XrdCryptolocalFactory.cc

Go to the documentation of this file.
00001 // $Id: XrdCryptolocalFactory.cc 30949 2009-11-02 16:37:58Z ganis $
00002 
00003 const char *XrdCryptolocalFactoryCVSID = "$Id: XrdCryptolocalFactory.cc 30949 2009-11-02 16:37:58Z ganis $";
00004 /******************************************************************************/
00005 /*                                                                            */
00006 /*          X r d C r y p t o L o c a l F a c t o r y . c c                   */
00007 /*                                                                            */
00008 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00009 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00010 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00011 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00012 /******************************************************************************/
00013 
00014 /* ************************************************************************** */
00015 /*                                                                            */
00016 /* Implementation of the local crypto factory                                 */
00017 /*                                                                            */
00018 /* ************************************************************************** */
00019 
00020 #include <XrdCrypto/PC1.hh>
00021 #include <XrdCrypto/XrdCryptolocalCipher.hh>
00022 #include <XrdCrypto/XrdCryptolocalFactory.hh>
00023 #include <XrdCrypto/XrdCryptoTrace.hh>
00024 
00025 #include <string.h>
00026 #include <stdlib.h>
00027 #include <errno.h>
00028 
00029 //____________________________________________________________________________
00030 static int XrdCryptolocalKDFunLen()
00031 {
00032    // Length of buffer needed by XrdCryptolocalKDFun
00033 
00034    return (2*kPC1LENGTH + 1);
00035 }
00036 //____________________________________________________________________________
00037 static int XrdCryptolocalKDFun(const char *pass, int plen,
00038                                const char *salt, int slen,
00039                                char *key, int)
00040 {
00041    // Wrapper to the PSC (Pukall Stream Cipher) Hash Function, returning 
00042    // a 256-bits hash (http://membres.lycos.fr/pc1/).
00043    // Max length for pass and salt is 32 bytes (256 bits).
00044    // Additional bytes are ignored.
00045    // The output is a null-terminated human readable 64-byte string (65 bytes).
00046    // The caller is responsible to allocate enough space to contain it.
00047    // The length of the output string is returned or -1 in case of problems.
00048    // The author sets the number of iterations to 63254; this will be 
00049    // the default.
00050    // It can be specified at the beginning of the salt using a construct
00051    // like this: salt = "$$<number_of_iterations>$<effective_salt>"
00052 
00053    // Defaults
00054    char *realsalt = (char *)salt;
00055    int realslen = slen;
00056    int it = 63254;
00057    //
00058    // Extract iteration number from salt, if any
00059    char *ibeg = (char *)memchr(salt+1,'$',slen-1);
00060    if (ibeg) {
00061       char *del = 0;
00062       int newit = strtol(ibeg+1, &del, 10);
00063       if (newit > 0 && del[0] == '$' && errno != ERANGE) {
00064          // found iteration number
00065          it = newit;
00066          realsalt = del+1;
00067          realslen = slen - (int)(realsalt-salt);
00068       }
00069    }
00070 
00071    //
00072    // Calculate one-way hash
00073    return PC1HashFun(pass, plen, realsalt, realslen, it, key);
00074 }
00075 
00076 //______________________________________________________________________________
00077 XrdCryptolocalFactory::XrdCryptolocalFactory() : 
00078                        XrdCryptoFactory("local",XrdCryptolocalFactoryID)
00079 {
00080    // Constructor:
00081 }
00082 
00083 //______________________________________________________________________________
00084 void XrdCryptolocalFactory::SetTrace(kXR_int32 trace)
00085 {
00086    // Set trace flags according to 'trace'
00087 
00088    if (cryptoTrace) {
00089       // Set debug mask
00090       cryptoTrace->What = 0;
00091       // Low level only
00092       if ((trace & cryptoTRACE_Notify))
00093          cryptoTrace->What |= cryptoTRACE_Notify;
00094       // Medium level
00095       if ((trace & cryptoTRACE_Debug))
00096          cryptoTrace->What |= (cryptoTRACE_Notify | cryptoTRACE_Debug);
00097       // High level
00098       if ((trace & cryptoTRACE_Dump))
00099          cryptoTrace->What |= cryptoTRACE_ALL;
00100    }
00101 }
00102 
00103 //______________________________________________________________________________
00104 XrdCryptoKDFunLen_t XrdCryptolocalFactory::KDFunLen()
00105 {
00106    // Return an instance of an implementation of the local KD fun length.
00107 
00108    return &XrdCryptolocalKDFunLen;
00109 }
00110 
00111 //______________________________________________________________________________
00112 XrdCryptoKDFun_t XrdCryptolocalFactory::KDFun()
00113 {
00114    // Return an instance of an implementation of the local KD function.
00115 
00116    return &XrdCryptolocalKDFun;
00117 }
00118 
00119 //______________________________________________________________________________
00120 XrdCryptoCipher *XrdCryptolocalFactory::Cipher(const char *t, int l)
00121 {
00122    // Return an instance of a local implementation of XrdCryptoCipher.
00123 
00124    XrdCryptoCipher *cip = new XrdCryptolocalCipher(t,l);
00125    if (cip) {
00126       if (cip->IsValid())
00127          return cip;
00128       else
00129          delete cip;
00130    }
00131    return (XrdCryptoCipher *)0;
00132 }
00133 
00134 //______________________________________________________________________________
00135 XrdCryptoCipher *XrdCryptolocalFactory::Cipher(const char *t, int l,
00136                                                const char *k, int, const char *)
00137 {
00138    // Return an instance of a local implementation of XrdCryptoCipher.
00139 
00140    XrdCryptoCipher *cip = new XrdCryptolocalCipher(t,l,k);
00141    if (cip) {
00142       if (cip->IsValid())
00143          return cip;
00144       else
00145          delete cip;
00146    }
00147    return (XrdCryptoCipher *)0;
00148 }
00149 
00150 //______________________________________________________________________________
00151 XrdCryptoCipher *XrdCryptolocalFactory::Cipher(XrdSutBucket *b)
00152 {
00153    // Return an instance of a local implementation of XrdCryptoCipher.
00154 
00155    XrdCryptoCipher *cip = new XrdCryptolocalCipher(b);
00156    if (cip) {
00157       if (cip->IsValid())
00158          return cip;
00159       else
00160          delete cip;
00161    }
00162    return (XrdCryptoCipher *)0;
00163 }
00164 
00165 //______________________________________________________________________________
00166 XrdCryptoCipher *XrdCryptolocalFactory::Cipher(int b, char *p,
00167                                                int l, const char *t)
00168 {
00169    // Return an instance of a local implementation of XrdCryptoCipher.
00170 
00171    XrdCryptoCipher *cip = new XrdCryptolocalCipher(b,p,l,t);
00172    if (cip) {
00173       if (cip->IsValid())
00174          return cip;
00175       else
00176          delete cip;
00177    }
00178    return (XrdCryptoCipher *)0;
00179 }
00180 
00181 //______________________________________________________________________________
00182 XrdCryptoCipher *XrdCryptolocalFactory::Cipher(const XrdCryptoCipher &c)
00183 {
00184    // Return an instance of a local implementation of XrdCryptoCipher.
00185 
00186    XrdCryptoCipher *cip = new XrdCryptolocalCipher(*((XrdCryptolocalCipher *)&c));
00187    if (cip) {
00188       if (cip->IsValid())
00189          return cip;
00190       else
00191          delete cip;
00192    }
00193    return (XrdCryptoCipher *)0;
00194 }
00195 
00196 //______________________________________________________________________________
00197 XrdCryptoMsgDigest *XrdCryptolocalFactory::MsgDigest(const char *)
00198 {
00199    // Return an instance of a local implementation of XrdCryptoMsgDigest.
00200 
00201    ABSTRACTMETHOD("XrdCryptoFactory::MsgDigest");
00202    return 0;
00203 }
00204 
00205 //______________________________________________________________________________
00206 XrdCryptoRSA *XrdCryptolocalFactory::RSA(int bits, int exp)
00207 {
00208    // Return an instance of a local implementation of XrdCryptoRSA.
00209 
00210    ABSTRACTMETHOD("XrdCryptoFactory::RSA");
00211    return (XrdCryptoRSA *)0;
00212 }
00213 
00214 //______________________________________________________________________________
00215 XrdCryptoRSA *XrdCryptolocalFactory::RSA(const char *pub, int lpub)
00216 {
00217    // Return an instance of a local implementation of XrdCryptoRSA.
00218 
00219    ABSTRACTMETHOD("XrdCryptoFactory::RSA");
00220    return (XrdCryptoRSA *)0;
00221 }
00222 
00223 //______________________________________________________________________________
00224 XrdCryptoRSA *XrdCryptolocalFactory::RSA(const XrdCryptoRSA &r)
00225 {
00226    // Return an instance of a local implementation of XrdCryptoRSA.
00227 
00228    ABSTRACTMETHOD("XrdCryptoFactory::RSA");
00229    return (XrdCryptoRSA *)0;
00230 }

Generated on Tue Jul 5 14:46:33 2011 for ROOT_528-00b_version by  doxygen 1.5.1