pax_global_header00006660000000000000000000000064122773566510014530gustar00rootroot0000000000000052 comment=a641ef84761a06fefb9ce2f08f4907bb8adf6489 gnustep-gscrypt-r31301/000075500000000000000000000000001227735665100150775ustar00rootroot00000000000000gnustep-gscrypt-r31301/.gear/000075500000000000000000000000001227735665100160735ustar00rootroot00000000000000gnustep-gscrypt-r31301/.gear/gscrypt.spec000064400000000000000000000033441227735665100204460ustar00rootroot00000000000000%set_verify_elf_method unresolved=strict Name: gnustep-gscrypt Version: r31301 Release: alt2.git20100910 Summary: GNUstep GSCrypt Library License: GPLv3 Group: Graphical desktop/GNUstep Url: https://github.com/gnustep/gnustep-gscrypt Packager: Eugeny A. Rostovtsev (REAL) # https://github.com/gnustep/gnustep-gscrypt.git Source: %name-%version.tar BuildPreReq: clang-devel gnustep-make-devel libgnustep-objc2-devel /proc BuildPreReq: gnustep-gui-devel BuildPreReq: libgmp-devel libgnutls-devel libgcrypt-devel BuildPreReq: libxslt-devel libffi-devel libicu-devel zlib-devel BuildPreReq: libpam0-devel %description GNUstep GSCrypt Library. %package -n lib%name Summary: GNUstep GSCrypt Library Group: System/Libraries %description -n lib%name GNUstep GSCrypt Library. %package -n lib%name-devel Summary: Development files of GNUstep GSCrypt Library Group: Development/Objective-C Provides: %name-devel = %EVR Requires: lib%name = %EVR %description -n lib%name-devel GNUstep GSCrypt Library. This package contains development files of GNUstep GSCrypt Library. %prep %setup mkdir gscrypt cp *.h gscrypt/ %build . %_datadir/GNUstep/Makefiles/GNUstep.sh %make_build \ messages=yes \ debug=yes \ strip=no \ shared=yes \ CONFIG_SYSTEM_LIBS='-lpam -lgnustep-base -lobjc2' %install . %_datadir/GNUstep/Makefiles/GNUstep.sh %makeinstall_std GNUSTEP_INSTALLATION_DOMAIN=SYSTEM %files -n lib%name %doc ChangeLog %_libdir/*.so.* %files -n lib%name-devel %_includedir/* %_libdir/*.so %changelog * Fri Feb 14 2014 Eugeny A. Rostovtsev (REAL) r31301-alt2.git20100910 - Built with clang * Sat Jan 25 2014 Eugeny A. Rostovtsev (REAL) r31301-alt1.git20100910 - Initial build for Sisyphus gnustep-gscrypt-r31301/.gear/rules000064400000000000000000000001141227735665100171440ustar00rootroot00000000000000spec: .gear/gscrypt.spec tar: . name=@name@-@version@ base=@name@-@version@ gnustep-gscrypt-r31301/ChangeLog000064400000000000000000000014741227735665100166570ustar00rootroot000000000000002007-02-18 Nicola Pero * Makefile.preamble (ADDITIONAL_LIB_DIRS): Removed obscure (and obsolete) -L$(GNUSTEP_SYSTEM_ROOT)/lib flag. (ADDITIONAL_LDFLAGS): Removed ifeq which would do the same thing in both cases. 2006-10-09 Nicola Pero * GNUmakefile: Do not set GNUSTEP_INSTALLATION_DIR and GNUSTEP_MAKEFILES. 2003-01-19 Manuel Guesdon * GSCryptBase.m: Fixed Bug in HexStringToData 2002-11-25 Richard Frith-Macdonald Remove reference to obsolete extensions library 2000-04-01 Manuel Guesdon * Added GSPam.h/m: PAM Support * GNUmakefile: Added GSPam * Makefile.pramble: Added -lpam 2000-03-31 Manuel Guesdon * Initial Version gnustep-gscrypt-r31301/GNUmakefile000064400000000000000000000042521227735665100171540ustar00rootroot00000000000000# GNUmakefila # # Copyright (C) 2000 Free Software Foundation, Inc. # # Written by: Manuel Guesdon # # This file is part of the GNUstep GSCrypt Library. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ifeq ($(GNUSTEP_MAKEFILES),) GNUSTEP_MAKEFILES := $(shell gnustep-config --variable=GNUSTEP_MAKEFILES 2>/dev/null) ifeq ($(GNUSTEP_MAKEFILES),) $(warning ) $(warning Unable to obtain GNUSTEP_MAKEFILES setting from gnustep-config!) $(warning Perhaps gnustep-make is not properly installed,) $(warning so gnustep-config is not in your PATH.) $(warning ) $(warning Your PATH is currently $(PATH)) $(warning ) endif endif ifeq ($(GNUSTEP_MAKEFILES),) $(error You need to set GNUSTEP_MAKEFILES before compiling!) endif include $(GNUSTEP_MAKEFILES)/common.make #include ../../Version #include ../../config.mak srcdir = . PACKAGE_NAME = gscrypt # The library to be compiled LIBRARY_NAME=libgscrypt # The Objective-C source files to be compiled libgscrypt_OBJC_FILES = \ GSCryptBase.m \ GSMD5.m \ GSRC4.m \ GSPam.m \ libgscrypt_HEADER_FILES = \ GSCryptCommon.h \ GSCryptBase.h \ GSMD5.h \ GSRC4.h \ GSPam.h \ SRCS = $(LIBRARY_NAME:=.m) HDRS = $(LIBRARY_NAME:=.h) libgscrypt_HEADER_FILES_DIR = . libgscrypt_HEADER_FILES_INSTALL_DIR = /$(GNUSTEP_FND_DIR)/gscrypt #DIST_FILES = $(SRCS) $(HDRS) GNUmakefile Makefile.postamble Makefile.preamble -include Makefile.preamble -include GNUmakefile.local include $(GNUSTEP_MAKEFILES)/library.make -include Makefile.postamble gnustep-gscrypt-r31301/GSCryptBase.h000064400000000000000000000073761227735665100174130ustar00rootroot00000000000000/* GSCryptBase.h - GSCrypt Copyright (C) 2000 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Mar 2000 This file is part of the GNUstep GSCrypt Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ // $Id$ #ifndef _GSCryptBase_h__ #define _GSCryptBase_h__ #include //==================================================================== @protocol GSCryptBlockTransforming -(NSData*)processBlock:(NSData*)blockData_; -(UINT)blockSize; @end //==================================================================== @interface NSObject (GSBlockTransform) // -(NSData*)processBufferForBlock:(NSData*)dataIn_; @end //==================================================================== @protocol GSCrypting -(id)initWithKey:(NSData*)key; +(UINT)keyMinSize; +(UINT)keyMaxSize; +(UINT)blockSize; -(NSData*)crypt:(NSData*)dataIn_; -(NSData*)decrypt:(NSData*)dataIn_; @end //==================================================================== @interface NSObject (GSCrypt) // +(UINT)calculDstSizeWithSrcSize:(UINT)sourceSize_ blockSize:(UINT)blockSize_; +(UINT)dstSizeWithSrcSize:(UINT)sourceSize_; @end //==================================================================== @interface GSHashObject: NSObject { // protected NSData* digest; BOOL done; } -(void)updateWithData:(NSData*)data_; //subClassResponsability -(void)updateWithString:(NSString*)string_ usingEncoding:(NSStringEncoding)encoding_; -(UINT)digestSize; +(UINT)digestSize; //subClassResponsability -(NSData*)digest; -(void)calculateDigest; +(NSData*)digestOfData:(NSData*)data_; +(NSData*)digestOfString:(NSString*)string_ usingEncoding:(NSStringEncoding)encoding_; @end //==================================================================== @protocol GSByteStreaming -(BYTE)streamByte; @end //==================================================================== @interface NSObject (GSRandomNbGen) // // calls -streamByte and returns the parity of the byte -(int)bit; // get a random 32 bit word in the range min to max, inclusive -(UINT32)longBetween:(UINT32)min_ and:(UINT32)max_; -(UINT16)shortBetween:(UINT16)min_ and:(UINT16)max_; // calls -streamByte length_ times -(NSData*)blockOfLength:(UINT16)length_; @end //==================================================================== @protocol GSStreamCyphering -(BYTE)cypherByte:(BYTE)input_; @end //==================================================================== @interface NSObject (GSStreamCypher) // -(NSData*)cypherBuffer:(NSData*)data_; @end //==================================================================== UINT16 BytePrecision(UINT32 value); UINT16 BitPrecision(UINT32 value); UINT32 CropValueToBitsNb(UINT32 value,UINT16 bitsNb); void Swap_(void* a,int sizeOfa,void* b,int sizeOfb); #define Swap(a,b); Swap_((void*)&a,sizeof(a),(void*)&b,sizeof(b)); #ifdef DEBUG BOOL TestEndianess(); #endif NSString* DataToHexString(NSData* data); NSData* HexStringToData(NSString* _string); #endif //_GSCryptBase_h__ gnustep-gscrypt-r31301/GSCryptBase.m000064400000000000000000000240531227735665100174070ustar00rootroot00000000000000/* GSCryptBase.m - GSCrypt Copyright (C) 2000-2003 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Mar 2000 This file is part of the GNUstep GSCrypt Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ static const char rcsId[]="$Id$"; #include //==================================================================== @implementation NSObject (GSBlockTransform)// //-------------------------------------------------------------------- -(NSData*)processBufferForBlock:(NSData*)dataIn_ { NSMutableData* dataOut=[NSMutableData data]; UINT blockSize=[(NSObject*)self blockSize]; UINT dataInSize=[dataIn_ length]; UINT blockNb= dataInSize/blockSize; UINT modSize= dataInSize%blockSize; UINT blockN = blockNb; IMP impAppendData=OBJ_METHOD_FOR_SEL(dataOut,appendData:); IMP impProcessBlock=OBJ_METHOD_FOR_SEL((NSObject*)self,processBlock:); IMP impSubdataWithRange=OBJ_METHOD_FOR_SEL(dataIn_,impSubdataWithRange:); for(blockN=0;blockN0) { NSMutableData* dataInTmp=[[impSubdataWithRange(dataIn_,@selector(subdataWithRange:), NSMakeRange(blockNb*blockSize,modSize)) mutableCopy] autorelease]; [dataInTmp increaseLengthBy:blockSize-modSize]; impAppendData(dataOut,@selector(appendData:), impProcessBlock(self,@selector(processBlock:), dataInTmp)); }; return [NSData dataWithData:dataOut]; }; @end //==================================================================== @implementation NSObject (GSCrypt) // //-------------------------------------------------------------------- +(UINT)calculDstSizeWithSrcSize:(UINT)sourceSize_ blockSize:(UINT)blockSize_ { if ((sourceSize_%blockSize_)!=0) sourceSize_=((sourceSize_/blockSize_)+1)*blockSize_; return sourceSize_; }; //-------------------------------------------------------------------- +(UINT)dstSizeWithSrcSize:(UINT)sourceSize_ { return [self calculDstSizeWithSrcSize:sourceSize_ blockSize:[self blockSize]]; }; @end //==================================================================== @implementation GSHashObject //-------------------------------------------------------------------- -(void)updateWithData:(NSData*)data_ { [self subclassResponsibility:_cmd]; }; //-------------------------------------------------------------------- -(void)updateWithString:(NSString*)string_ usingEncoding:(NSStringEncoding)encoding_ { [self updateWithData:[string_ dataUsingEncoding:encoding_]]; }; //-------------------------------------------------------------------- -(UINT)digestSize { return [[self class] digestSize]; }; //-------------------------------------------------------------------- +(UINT)digestSize { return (UINT)[self subclassResponsibility:_cmd]; }; //-------------------------------------------------------------------- -(NSData*)digest { if (!done) [self calculateDigest]; NSAssert(done,@"Not caclulated"); return [[digest copy] autorelease]; }; //-------------------------------------------------------------------- -(void)calculateDigest { NSAssert(!done,@"Already caclulated"); done=YES; }; //-------------------------------------------------------------------- +(NSData*)digestOfData:(NSData*)data_ { NSData* _digest=nil; GSHashObject* hashObject=[self new]; [hashObject updateWithData:data_]; _digest=[hashObject digest]; DESTROY(hashObject); return _digest; }; //-------------------------------------------------------------------- +(NSData*)digestOfString:(NSString*)string_ usingEncoding:(NSStringEncoding)encoding_ { return [self digestOfData:[string_ dataUsingEncoding:encoding_]]; }; @end #ifdef DEBUG BOOL TestEndianess() { BOOL fOk; /* #ifdef __BIG_ENDIAN #ifdef __LITTLE_ENDIAN #pragma message ("Error: __BIG_ENDIAN && __LITTLE_ENDIAN defined !!!") #endif #else #ifndef __LITTLE_ENDIAN #pragma message ("Error: __BIG_ENDIAN && __LITTLE_ENDIAN not defined !!!") #endif #endif */ NSLog(@"Testing Endianess..."); if (*(UINT32 *)"\x01\x00\x00\x00" == 1L) { #ifdef __LITTLE_ENDIAN NSLog(@"PASSED: "); fOk = YES; #else NSCAssert(NO,"FAILED"); fOk = NO; #endif NSLog(@"Your machine is little endian."); } else if (*(UINT32*)"\x01\x00\x00\x00" == 0x01000000L) { #ifndef __LITTLE_ENDIAN NSLog(@"PASSED: "); fOk = YES; #else NSCAssert(NO,@"Endianess Test Failed"); NSLog(@"FAILED: "); fOk = NO; #endif NSLog(@"Your machine is big endian."); } else { NSCAssert(NO,@"Endianess Test Failed"); NSLog(@"FAILED: Your machine is neither big endian nor little endian."); fOk = NO; }; return fOk; }; #endif //==================================================================== @implementation NSObject (GSRandomNbGen) // // calls -byte and returns the parity of the random BYTE -(int)bit { int n = 0; int x = [(NSObject*)self streamByte]; if (x) do n++; while (0 != (x = x&(x-1))); return (n % 2); }; //--------------------------------------------------------------------- // get a random 32 bit word in the range min to max, inclusive -(UINT32)longBetween:(UINT32)min_ and:(UINT32)max_ { UINT32 range = max_-min_; const UINT16 maxBytes = BytePrecision(range); const UINT16 maxBits = BitPrecision(range); UINT32 value=0; do { int i; value = 0; for (i=0; i*)self streamByte]; value = CropValueToBitsNb(value, maxBits); } while (value > range); return value+min_; }; //--------------------------------------------------------------------- -(UINT16)shortBetween:(UINT16)min_ and:(UINT16)max_ { return (UINT16)[self longBetween:min_ and:max_]; }; //--------------------------------------------------------------------- // calls -streamByte length_ times -(NSData*)blockOfLength:(UINT16)length_ { NSMutableData* data=[NSMutableData dataWithLength:length_]; BYTE* dataBytes=(BYTE*)[data mutableBytes]; IMP impStreamByte=OBJ_METHOD_FOR_SEL(self,streamByte); while (length_--) *dataBytes++ = (BYTE)(impStreamByte((NSObject*)self,@selector(streamByte))); return [NSData dataWithData:data]; }; @end //==================================================================== @implementation NSObject (GSStreamCypher) // -(NSData*)cypherBuffer:(NSData*)data_ { unsigned int dataLength=[data_ length]; const BYTE* inDataBytes=(BYTE*)[data_ bytes]; NSMutableData* data=[NSMutableData dataWithLength:dataLength]; BYTE* outDataBytes=(BYTE*)[data mutableBytes]; IMP impCypherByte=OBJ_METHOD_FOR_SEL(self,cypherByte:); while(dataLength--) *outDataBytes++ = (BYTE)(impCypherByte((NSObject*)self,@selector(cypherByte:),*inDataBytes++)); return [NSData dataWithData:data]; }; @end //-------------------------------------------------------------------- UINT16 BytePrecision(UINT32 value) { UINT16 i=0; for (i=sizeof(value);i;--i) if (value >> (i-1)*8) break; return i; }; //-------------------------------------------------------------------- UINT16 BitPrecision(UINT32 value) { UINT16 i=0; for (i=8*sizeof(value);i;i--) if (value >> (i-1)) break; return i; }; //-------------------------------------------------------------------- UINT32 CropValueToBitsNb(UINT32 value,UINT16 bitsNb) { return (value & ((1L << bitsNb) - 1)); }; void Swap_(void* a,int sizeOfa,void* b,int sizeOfb) { BYTE temp[sizeOfa]; NSCAssert2(sizeOfa==sizeOfb,@"Different Size: %d %d",sizeOfa,sizeOfb); memcpy(temp,a,sizeOfa); memcpy(a,b,sizeOfa); memcpy(b,temp,sizeOfa); }; //-------------------------------------------------------------------- NSString* DataToHexString(NSData* data) { unsigned int size=[data length]; if (size) { const unsigned char* pData=(const unsigned char*)[data bytes]; if (pData) { NSMutableString* string=[[NSMutableString new] autorelease]; int i=0; for(i=0;i0) { const char* pString=(const char*)[[_string uppercaseString]cString]; if (pString) { NSMutableData* data=[NSMutableData dataWithLength:size/2]; unsigned char* pData=(unsigned char*)[data bytes]; int i=0; for(i=0;i='0' && pString[i*2]<='9') pData[i]=(pString[i*2]-'0') << 4; else if (pString[i*2]>='A' && pString[i*2]<='F') pData[i]=(pString[i*2]-'A'+10) << 4; else { NSCAssert(NO,@"Bad hex String"); }; if (pString[i*2+1]>='0' && pString[i*2+1]<='9') pData[i]=pData[i]|(pString[i*2+1]-'0'); else if (pString[i*2+1]>='A' && pString[i*2+1]<='F') pData[i]=pData[i]|(pString[i*2+1]-'A'+10); else { NSCAssert(NO,@"Bad hex String"); }; }; return data; }; }; return nil; }; gnustep-gscrypt-r31301/GSCryptCommon.h000064400000000000000000000031601227735665100177540ustar00rootroot00000000000000/* GSCryptCommon.h - GSCrypt Copyright (C) 2000 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Mar 2000 This file is part of the GNUstep GSCrypt Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ // $Id$ #ifndef _GSCryptCommon_h__ #define _GSCryptCommon_h__ #include #include #include #include #include #include #include #ifndef BYTE_DEFINED typedef unsigned char BYTE; #define BYTE_DEFINED #endif #ifndef UINTs_DEFINED typedef unsigned int UINT; typedef unsigned char UINT8; typedef unsigned short UINT16; typedef unsigned int UINT32; #define UINTs_DEFINED #endif #include #define OBJ_METHOD_FOR_SEL(_obj, _sel) [(NSObject*)_obj methodForSelector:@selector(_sel)] #endif // _GSCryptCommon_h__ gnustep-gscrypt-r31301/GSMD5.h000064400000000000000000000024761227735665100161000ustar00rootroot00000000000000/* GSMD5.h - GSCrypt: Class GSMD5 Copyright (C) 2000 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Mar 2000 This file is part of the GNUstep GSCrypt Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ // $Id$ #ifndef _GSMD5_h__ #define _GSMD5_h__ #include @interface GSMD5: GSHashObject { // protected: UINT32 ctxBuf[4]; UINT32 ctxBits[2]; BYTE ctxIn[64]; } -(id)init; -(void)updateWithData:(NSData*)data_; -(void)calculateDigest; +(UINT)digestSize; //Non Public -(void)transform; #ifdef DEBUG +(BOOL)debugTest; #endif @end #endif // _GSMD5_h__ gnustep-gscrypt-r31301/GSMD5.m000064400000000000000000000260751227735665100161060ustar00rootroot00000000000000/* GSMD5.m - GSCrypt: Class GSMD5 Copyright (C) 2000 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Mar 2000 This file is part of the GNUstep GSCrypt Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ // $Id$ #include #define MD5__DIGEST_SIZE 16 //-------------------------------------------------------------------- #ifdef __LITTLE_ENDIAN #define MD5_ByteReverse(buff,size) {} // Nothing #else void MD5_ByteReverse(BYTE* buff,UINT16 size); // size in Machine Word { if (size>0) { UINT32 dwTemp; do { dwTemp = (UINT32) ( ((unsigned)buff[3] << 8 | buff[2]) << 16 ) | ( (unsigned)buff[1] << 8 | buff[0] ); *(UINT32*)buff = dwTemp; buff+=4; } while (--size); }; }; #endif //__LITTLE_ENDIAN @implementation GSMD5 //--------------------------------------------------------------------------------------- // Start MD5 accumulation. Set bit count to 0 and buffer to mysterious initialization constants. -(id)init { if ((self=[super init])) { ctxBuf[0] = 0x67452301; ctxBuf[1] = 0xefcdab89; ctxBuf[2] = 0x98badcfe; ctxBuf[3] = 0x10325476; ctxBits[0] = 0; ctxBits[1] = 0; memset(ctxIn,0,64); }; return self; }; //-------------------------------------------------------------------- // Update context to reflect the concatenation of another buffer full of bytes. -(void)updateWithData:(NSData*)data_ { UINT dataSize=0; const BYTE* dataBytes=NULL; UINT32 temp=0; IMP impTransform=OBJ_METHOD_FOR_SEL(self,transform); NSAssert(!done,@"Already Calculated"); dataSize=[data_ length]; dataBytes=[data_ bytes]; // Update bitcount temp=ctxBits[0]; ctxBits[0] = temp + ((UINT32) dataSize << 3); if (ctxBits[0]> 29; temp = (temp >> 3) & 0x3f; // Bytes already in shsInfo->data // Handle any leading odd-sized chunks if (temp) { BYTE* buff =(BYTE*)ctxIn+temp; temp = 64 - temp; if (dataSize < temp) { memcpy(buff,dataBytes,dataSize); return; }; memcpy(buff,dataBytes,temp); MD5_ByteReverse(ctxIn,16); impTransform(self,@selector(transform)); dataBytes+=temp; dataSize-=temp; }; // Process data in 64-byte chunks while (dataSize >= 64) { memcpy(ctxIn,dataBytes,64); MD5_ByteReverse(ctxIn, 16); impTransform(self,@selector(transform)); dataBytes += 64; dataSize -= 64; }; // Handle any remaining bytes of data. memcpy(ctxIn,dataBytes,dataSize); }; //-------------------------------------------------------------------- // Final wrapup - pad to 64-byte boundary with the bit pattern 1 0* (64-bit count of bits processed, MSB-first) -(void)calculateDigest { UINT16 count=0; BYTE* buff=NULL; NSData* _digest=nil; [super calculateDigest]; count=(UINT16)((ctxBits[0] >> 3) & 0x3F); // Compute number of bytes mod 64 // Set the first char of padding to 0x80. This is safe since there is always at least one byte free buff=ctxIn + count; *buff++ = 0x80; count = 64 - 1 - count; // Bytes of padding needed to make 64 bytes // Pad out to 56 mod 64 if (count<8) { // Two lots of padding: Pad the first block to 64 bytes memset(buff, 0, count); MD5_ByteReverse(ctxIn, 16); [self transform]; // Now fill the next block with 56 bytes memset(ctxIn, 0, 56); } else { memset(buff, 0, count - 8); // Pad block to 56 bytes }; MD5_ByteReverse(ctxIn, 14); // Append length in bits and transform ((UINT32 *)ctxIn)[14] = ctxBits[0]; ((UINT32 *)ctxIn)[15] = ctxBits[1]; [self transform]; MD5_ByteReverse((BYTE*)ctxBuf, 4); _digest=[NSData dataWithBytes:ctxBuf length:[self digestSize]]; ASSIGN(digest,_digest); }; //-------------------------------------------------------------------- // The four core functions - CMD5_F1 is optimized somewhat // #define CMD5_F1(x, y, z) (x & y | ~x & z) #define CMD5_F1(x, y, z) (z ^ (x & (y ^ z))) #define CMD5_F2(x, y, z) CMD5_F1(z, x, y) #define CMD5_F3(x, y, z) (x ^ y ^ z) #define CMD5_F4(x, y, z) (y ^ (x | ~z)) // This is the central step in the MD5 algorithm. #define CMD5_STEP(f, w, x, y, z, data, s) ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) // The core of the MD5 algorithm, this alters an existing MD5 hash to reflect the addition of 16 longwords of new data. // Update blocks the data and converts bytes into longwords for this routine. -(void)transform { UINT32* dwCtxIn=(UINT32*)ctxIn; UINT32 a = ctxBuf[0]; UINT32 b = ctxBuf[1]; UINT32 c = ctxBuf[2]; UINT32 d = ctxBuf[3]; CMD5_STEP(CMD5_F1, a, b, c, d, dwCtxIn[0] + 0xd76aa478, 7); CMD5_STEP(CMD5_F1, d, a, b, c, dwCtxIn[1] + 0xe8c7b756, 12); CMD5_STEP(CMD5_F1, c, d, a, b, dwCtxIn[2] + 0x242070db, 17); CMD5_STEP(CMD5_F1, b, c, d, a, dwCtxIn[3] + 0xc1bdceee, 22); CMD5_STEP(CMD5_F1, a, b, c, d, dwCtxIn[4] + 0xf57c0faf, 7); CMD5_STEP(CMD5_F1, d, a, b, c, dwCtxIn[5] + 0x4787c62a, 12); CMD5_STEP(CMD5_F1, c, d, a, b, dwCtxIn[6] + 0xa8304613, 17); CMD5_STEP(CMD5_F1, b, c, d, a, dwCtxIn[7] + 0xfd469501, 22); CMD5_STEP(CMD5_F1, a, b, c, d, dwCtxIn[8] + 0x698098d8, 7); CMD5_STEP(CMD5_F1, d, a, b, c, dwCtxIn[9] + 0x8b44f7af, 12); CMD5_STEP(CMD5_F1, c, d, a, b, dwCtxIn[10] + 0xffff5bb1, 17); CMD5_STEP(CMD5_F1, b, c, d, a, dwCtxIn[11] + 0x895cd7be, 22); CMD5_STEP(CMD5_F1, a, b, c, d, dwCtxIn[12] + 0x6b901122, 7); CMD5_STEP(CMD5_F1, d, a, b, c, dwCtxIn[13] + 0xfd987193, 12); CMD5_STEP(CMD5_F1, c, d, a, b, dwCtxIn[14] + 0xa679438e, 17); CMD5_STEP(CMD5_F1, b, c, d, a, dwCtxIn[15] + 0x49b40821, 22); CMD5_STEP(CMD5_F2, a, b, c, d, dwCtxIn[1] + 0xf61e2562, 5); CMD5_STEP(CMD5_F2, d, a, b, c, dwCtxIn[6] + 0xc040b340, 9); CMD5_STEP(CMD5_F2, c, d, a, b, dwCtxIn[11] + 0x265e5a51, 14); CMD5_STEP(CMD5_F2, b, c, d, a, dwCtxIn[0] + 0xe9b6c7aa, 20); CMD5_STEP(CMD5_F2, a, b, c, d, dwCtxIn[5] + 0xd62f105d, 5); CMD5_STEP(CMD5_F2, d, a, b, c, dwCtxIn[10] + 0x02441453, 9); CMD5_STEP(CMD5_F2, c, d, a, b, dwCtxIn[15] + 0xd8a1e681, 14); CMD5_STEP(CMD5_F2, b, c, d, a, dwCtxIn[4] + 0xe7d3fbc8, 20); CMD5_STEP(CMD5_F2, a, b, c, d, dwCtxIn[9] + 0x21e1cde6, 5); CMD5_STEP(CMD5_F2, d, a, b, c, dwCtxIn[14] + 0xc33707d6, 9); CMD5_STEP(CMD5_F2, c, d, a, b, dwCtxIn[3] + 0xf4d50d87, 14); CMD5_STEP(CMD5_F2, b, c, d, a, dwCtxIn[8] + 0x455a14ed, 20); CMD5_STEP(CMD5_F2, a, b, c, d, dwCtxIn[13] + 0xa9e3e905, 5); CMD5_STEP(CMD5_F2, d, a, b, c, dwCtxIn[2] + 0xfcefa3f8, 9); CMD5_STEP(CMD5_F2, c, d, a, b, dwCtxIn[7] + 0x676f02d9, 14); CMD5_STEP(CMD5_F2, b, c, d, a, dwCtxIn[12] + 0x8d2a4c8a, 20); CMD5_STEP(CMD5_F3, a, b, c, d, dwCtxIn[5] + 0xfffa3942, 4); CMD5_STEP(CMD5_F3, d, a, b, c, dwCtxIn[8] + 0x8771f681, 11); CMD5_STEP(CMD5_F3, c, d, a, b, dwCtxIn[11] + 0x6d9d6122, 16); CMD5_STEP(CMD5_F3, b, c, d, a, dwCtxIn[14] + 0xfde5380c, 23); CMD5_STEP(CMD5_F3, a, b, c, d, dwCtxIn[1] + 0xa4beea44, 4); CMD5_STEP(CMD5_F3, d, a, b, c, dwCtxIn[4] + 0x4bdecfa9, 11); CMD5_STEP(CMD5_F3, c, d, a, b, dwCtxIn[7] + 0xf6bb4b60, 16); CMD5_STEP(CMD5_F3, b, c, d, a, dwCtxIn[10] + 0xbebfbc70, 23); CMD5_STEP(CMD5_F3, a, b, c, d, dwCtxIn[13] + 0x289b7ec6, 4); CMD5_STEP(CMD5_F3, d, a, b, c, dwCtxIn[0] + 0xeaa127fa, 11); CMD5_STEP(CMD5_F3, c, d, a, b, dwCtxIn[3] + 0xd4ef3085, 16); CMD5_STEP(CMD5_F3, b, c, d, a, dwCtxIn[6] + 0x04881d05, 23); CMD5_STEP(CMD5_F3, a, b, c, d, dwCtxIn[9] + 0xd9d4d039, 4); CMD5_STEP(CMD5_F3, d, a, b, c, dwCtxIn[12] + 0xe6db99e5, 11); CMD5_STEP(CMD5_F3, c, d, a, b, dwCtxIn[15] + 0x1fa27cf8, 16); CMD5_STEP(CMD5_F3, b, c, d, a, dwCtxIn[2] + 0xc4ac5665, 23); CMD5_STEP(CMD5_F4, a, b, c, d, dwCtxIn[0] + 0xf4292244, 6); CMD5_STEP(CMD5_F4, d, a, b, c, dwCtxIn[7] + 0x432aff97, 10); CMD5_STEP(CMD5_F4, c, d, a, b, dwCtxIn[14] + 0xab9423a7, 15); CMD5_STEP(CMD5_F4, b, c, d, a, dwCtxIn[5] + 0xfc93a039, 21); CMD5_STEP(CMD5_F4, a, b, c, d, dwCtxIn[12] + 0x655b59c3, 6); CMD5_STEP(CMD5_F4, d, a, b, c, dwCtxIn[3] + 0x8f0ccc92, 10); CMD5_STEP(CMD5_F4, c, d, a, b, dwCtxIn[10] + 0xffeff47d, 15); CMD5_STEP(CMD5_F4, b, c, d, a, dwCtxIn[1] + 0x85845dd1, 21); CMD5_STEP(CMD5_F4, a, b, c, d, dwCtxIn[8] + 0x6fa87e4f, 6); CMD5_STEP(CMD5_F4, d, a, b, c, dwCtxIn[15] + 0xfe2ce6e0, 10); CMD5_STEP(CMD5_F4, c, d, a, b, dwCtxIn[6] + 0xa3014314, 15); CMD5_STEP(CMD5_F4, b, c, d, a, dwCtxIn[13] + 0x4e0811a1, 21); CMD5_STEP(CMD5_F4, a, b, c, d, dwCtxIn[4] + 0xf7537e82, 6); CMD5_STEP(CMD5_F4, d, a, b, c, dwCtxIn[11] + 0xbd3af235, 10); CMD5_STEP(CMD5_F4, c, d, a, b, dwCtxIn[2] + 0x2ad7d2bb, 15); CMD5_STEP(CMD5_F4, b, c, d, a, dwCtxIn[9] + 0xeb86d391, 21); ctxBuf[0] += a; ctxBuf[1] += b; ctxBuf[2] += c; ctxBuf[3] += d; }; //-------------------------------------------------------------------- +(UINT)digestSize { return MD5__DIGEST_SIZE; }; #ifdef DEBUG //-------------------------------------------------------------------- +(BOOL)debugTest { BOOL ok=YES; GSMD5* md5=nil; NSArray* tests=[NSArray arrayWithObjects:@"", @"a", @"abc", @"message digest", @"abcdefghijklmnopqrstuvwxyz", @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", @"12345678901234567890123456789012345678901234567890123456789012345678901234567890", nil]; NSArray* results=[NSArray arrayWithObjects:@"D41D8CD98F00B204E9800998ECF8427E", // "" @"0CC175B9C0F1B6A831C399E269772661", // "a" @"900150983CD24FB0D6963F7D28E17F72", // "abc" @"F96B697D7CB7938D525A2F31AAF161D0", // "message digest" @"C3FCD3D76192E4007DFB496CCA67E13B", // "abcdefghijklmnopqrstuvwxyz" @"D174AB98D277D9F5A5611C2C9F419D9F", // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" @"57EDF4A22BE3C955AC49DA2E2107B67A", // "12345678901234567890123456789012345678901234567890123456789012345678901234567890" nil]; NSString* result=nil; int i=0; NSLog(@"MD5 Test..."); TestEndianess(); for(i=0;i<[tests count];i++) { BOOL failed=NO; md5=[[GSMD5 new]autorelease]; [md5 updateWithString:[tests objectAtIndex:i] usingEncoding:NSASCIIStringEncoding]; result=[DataToHexString([md5 digest])uppercaseString]; failed=![result isEqualToString:[results objectAtIndex:i]]; if (failed) { NSLog(@"i=%d result=%@ instead of %@",i,result,[results objectAtIndex:i]); } else { NSLog(@"MD5 Test %d PASSED",i); }; }; NSLog(@"MD5 Tests %s",(ok ? "PASSED" : "FAILED")); NSAssert(ok,@"MD5 Tests Failed"); return ok; }; #endif @end gnustep-gscrypt-r31301/GSPam.h000064400000000000000000000046311227735665100162230ustar00rootroot00000000000000/* GSPam.h - GSCrypt: Class GSPam Copyright (C) 2000 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Feb 2000 This file is part of the GNUstep GSCrypt Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ //$Id$ #ifndef _GSPam_h__ #define _GSPam_h__ #include #include #include //==================================================================== @interface GSPam: NSObject { pam_handle_t* _pamHandle; struct pam_conv _pamConv; int _lastStatus; NSString* _lastErrorMessage; NSString* _serviceName; NSString* _user; NSString* _password; }; +(id)pam; +(id)pamWithServiceName:(NSString*)serviceName; +(id)pamWithServiceName:(NSString*)serviceName user:(NSString*)user password:(NSString*)password; -(id)init; -(id)initWithServiceName:(NSString*)serviceName; -(id)initWithServiceName:(NSString*)serviceName user:(NSString*)user password:(NSString*)password; -(void)dealloc; -(void)assignLastErrorMessage; -(int)processMessages:(const struct pam_message**)messages withMessagesNb:(int)numMessages withResponse:(struct pam_response*)responses; -(void)setServiceName:(NSString*)serviceName; -(void)setUser:(NSString*)user; -(void)setPassword:(NSString*)password; -(NSString*)serviceName; -(NSString*)user; -(NSString*)password; -(int)status; -(NSString*)errorMessage; -(BOOL)start; -(BOOL)end; -(BOOL)endWithStatus:(int)status; -(BOOL)authenticateWithFlag:(int)flag silent:(BOOL)silentFlag; -(BOOL)accountManagementWithFlag:(int)flag silent:(BOOL)silentFlag; -(BOOL)openSessionSilently:(BOOL)silentFlag; -(BOOL)closeSessionSilently:(BOOL)silentFlag; @end #endif //_GSPam_h__ gnustep-gscrypt-r31301/GSPam.m000064400000000000000000000224751227735665100162360ustar00rootroot00000000000000/* GSPam.m - GSCrypt: Class GSPam Copyright (C) 2000 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Feb 2000 This file is part of the GNUstep GSCrypt Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ //$Id$ #include //==================================================================== static int pam_exchange(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) { int retStatus=PAM_SUCCESS; struct pam_response* response=NULL; response = malloc(sizeof(struct pam_response)*num_msg); if(response == (struct pam_response *)0) retStatus=PAM_CONV_ERR; else { int i=0; memset((void*)response,0,sizeof(struct pam_response)*num_msg); for(i=0;imsg_style); response[i].resp_retcode = PAM_SUCCESS; switch(msg[i]->msg_style) { case PAM_PROMPT_ECHO_ON: case PAM_PROMPT_ECHO_OFF: case PAM_TEXT_INFO: case PAM_ERROR_MSG: //Handled by object ! break; case PAM_BINARY_PROMPT: // Must be an error of some sort... free(response); retStatus=PAM_CONV_ERR; NSCAssert(NO,@"Unattended PAM message Style PAM_BINARY_PROMPT"); break; default: // Must be an error of some sort... free(response); retStatus=PAM_CONV_ERR; NSCAssert1(NO,@"Unattended PAM message Style %d",msg[i]->msg_style); break; }; }; *resp=response; retStatus=[((GSPam*)appdata_ptr) processMessages:msg withMessagesNb:num_msg withResponse:response]; }; return retStatus; }; //==================================================================== @implementation GSPam //-------------------------------------------------------------------- +(id)pam { return [[self new]autorelease]; }; //-------------------------------------------------------------------- +(id)pamWithServiceName:(NSString*)serviceName { return [[[self alloc]initWithServiceName:serviceName] autorelease]; }; //-------------------------------------------------------------------- +(id)pamWithServiceName:(NSString*)serviceName user:(NSString*)user password:(NSString*)password { return [[[self alloc]initWithServiceName:serviceName user:user password:password] autorelease]; }; //-------------------------------------------------------------------- -(id)init { if ((self=[super init])) { memset(&_pamConv,0,sizeof(_pamConv)); _pamConv.conv=&pam_exchange; _pamConv.appdata_ptr=(void*)self; }; return self; }; //-------------------------------------------------------------------- -(id)initWithServiceName:(NSString*)serviceName { if ((self=[self init])) { [self setServiceName:serviceName]; }; return self; }; //-------------------------------------------------------------------- -(id)initWithServiceName:(NSString*)serviceName user:(NSString*)user password:(NSString*)password { if ((self=[self initWithServiceName:serviceName])) { [self setUser:user]; [self setPassword:password]; }; return self; }; //-------------------------------------------------------------------- -(void)dealloc { // GSWLogC("Dealloc GSPam"); [self endWithStatus:-1]; DESTROY(_serviceName); DESTROY(_user); DESTROY(_password); DESTROY(_lastErrorMessage); // GSWLogC("Dealloc GSPam Super"); [super dealloc]; // GSWLogC("End Dealloc GSPam"); }; //-------------------------------------------------------------------- -(void)assignLastErrorMessage { DESTROY(_lastErrorMessage); if (_lastStatus!=PAM_SUCCESS) { ASSIGN(_lastErrorMessage,[NSString stringWithCString:pam_strerror(_pamHandle,_lastStatus)]); }; }; //-------------------------------------------------------------------- -(int)processMessages:(const struct pam_message**)messages withMessagesNb:(int)numMessages withResponse:(struct pam_response*)responses { int retStatus=PAM_SUCCESS; int i=0; for(i=0;imsg_style) { case PAM_PROMPT_ECHO_ON: NSDebugMLog(@"PAM Message #%d: PAM_PROMPT_ECHO_ON return: %@",i,[self user]); responses[i].resp=strdup([[self user] cString]); NSDebugMLog(@"==>%s",responses[i]); // PAM frees resp break; case PAM_PROMPT_ECHO_OFF: NSDebugMLog(@"PAM Message #%d: PAM_PROMPT_ECHO_OFF return: %@",i,[self password]); responses[i].resp=strdup([[self password] cString]); NSDebugMLog(@"==>%s",responses[i]); // PAM frees resp break; case PAM_TEXT_INFO: case PAM_ERROR_MSG: NSLog(@"PAM Ignore Message: %s",messages[i]->msg); // ignore it, but pam still wants a NULL response... responses[i].resp = NULL; NSDebugMLog(@"==>%s",responses[i]); break; default: NSAssert1(NO,@"Unknown PAM message Style: %d",(int)messages[i]->msg_style); retStatus=PAM_CONV_ERR; break; }; }; return retStatus; }; //-------------------------------------------------------------------- -(void)setServiceName:(NSString*)serviceName { ASSIGN(_serviceName,serviceName); }; //-------------------------------------------------------------------- -(void)setUser:(NSString*)user { ASSIGN(_user,user); }; //-------------------------------------------------------------------- -(void)setPassword:(NSString*)password { ASSIGN(_password,password); }; //-------------------------------------------------------------------- -(NSString*)serviceName { return _serviceName; }; //-------------------------------------------------------------------- -(NSString*)user { return _user; }; //-------------------------------------------------------------------- -(NSString*)password { return _password; }; //-------------------------------------------------------------------- -(int)status { return _lastStatus; }; //-------------------------------------------------------------------- -(NSString*)errorMessage { return _lastErrorMessage; }; //-------------------------------------------------------------------- -(BOOL)start { _lastStatus=PAM_SUCCESS; if (_pamHandle) { [self endWithStatus:-1]; }; NSLog(@"PAM start: serviceName: [%@] user: [%@]",[self serviceName],[self user]); _lastStatus=pam_start([[self serviceName] cString], [[self user] cString], &_pamConv, &_pamHandle); [self assignLastErrorMessage]; return (_lastStatus==PAM_SUCCESS); }; //-------------------------------------------------------------------- -(BOOL)end { return [self endWithStatus:PAM_SUCCESS]; } //-------------------------------------------------------------------- -(BOOL)endWithStatus:(int)status { _lastStatus=PAM_SUCCESS; if (_pamHandle) { _lastStatus=pam_end(_pamHandle,status); _pamHandle=NULL; }; [self assignLastErrorMessage]; return (_lastStatus==PAM_SUCCESS); }; //-------------------------------------------------------------------- /* PAM_DISALLOW_NULL_AUTHTOK Instruct the authentication modules to return PAM_AUTH_ERR if the user does not have a registered authorization token---it is set to NULL in the system database. */ -(BOOL)authenticateWithFlag:(int)flag silent:(BOOL)silentFlag { _lastStatus=PAM_SUCCESS; if (silentFlag) flag|=PAM_SILENT; NSLog(@"PAM pam_authenticate: serviceName: [%@] user: [%@] lastStatus=%d", [self serviceName], [self user], _lastStatus); _lastStatus=pam_authenticate(_pamHandle,flag); NSLog(@"PAM pam_authenticate: lastStatus=%d", _lastStatus); [self assignLastErrorMessage]; return (_lastStatus==PAM_SUCCESS); }; //-------------------------------------------------------------------- /* PAM_DISALLOW_NULL_AUTHTOK Instruct the authentication modules to return PAM_AUTH_ERR if the user does not have a registered authorization token---it is set to NULL in the system database. */ -(BOOL)accountManagementWithFlag:(int)flag silent:(BOOL)silentFlag { _lastStatus=PAM_SUCCESS; if (silentFlag) flag|=PAM_SILENT; _lastStatus=pam_acct_mgmt(_pamHandle,flag); [self assignLastErrorMessage]; return (_lastStatus==PAM_SUCCESS); }; //-------------------------------------------------------------------- -(BOOL)openSessionSilently:(BOOL)silentFlag { int flag=0; _lastStatus=PAM_SUCCESS; if (silentFlag) flag|=PAM_SILENT; _lastStatus=pam_open_session(_pamHandle,flag); [self assignLastErrorMessage]; return (_lastStatus==PAM_SUCCESS); }; //-------------------------------------------------------------------- -(BOOL)closeSessionSilently:(BOOL)silentFlag { int flag=0; _lastStatus=PAM_SUCCESS; if (silentFlag) flag|=PAM_SILENT; _lastStatus=pam_close_session(_pamHandle,flag); [self assignLastErrorMessage]; return (_lastStatus==PAM_SUCCESS); }; @end gnustep-gscrypt-r31301/GSRC4.h000064400000000000000000000031251227735665100160730ustar00rootroot00000000000000/* GSRC4.h - GSCrypt: Class GSRC4 Copyright (C) 2000 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Mar 2000 This file is part of the GNUstep GSCrypt Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ // $Id$ #ifndef _GSRC4_h__ #define _GSRC4_h__ #include @interface GSRC4: NSObject { // protected: NSMutableData* state; BYTE x; BYTE y; BOOL m_fInit; }; +(id)rc4WithKey:(NSData*)key; -(id)init; -(id)initWithKey:(NSData*)key;//GSCrypting -(BYTE)streamByte; //GSByteStreaming -(BYTE)cypherByte:(BYTE)input_;//GSStreamCyphering -(NSData*)crypt:(NSData*)dataIn_;//GSCrypting -(NSData*)decrypt:(NSData*)dataIn_;//GSCrypting +(UINT)keyMinSize;//GSCrypting +(UINT)keyMaxSize;//GSCrypting +(UINT)blockSize;//GSCrypting #ifdef DEBUG +(BOOL)debugTest; #endif @end #endif // _GSRC4_h__ gnustep-gscrypt-r31301/GSRC4.m000064400000000000000000000272231227735665100161050ustar00rootroot00000000000000/* GSRC4.m - GSCrypt: Class GSRC4 Copyright (C) 2000 Free Software Foundation, Inc. Written by: Manuel Guesdon Date: Mar 2000 This file is part of the GNUstep GSCrypt Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ // $Id$ #include @implementation GSRC4 //-------------------------------------------------------------------- +(id)rc4WithKey:(NSData*)key { return [[[self alloc]initWithKey:key]autorelease]; }; //-------------------------------------------------------------------- -(id)init { if ((self=[super init])) { }; return self; }; //-------------------------------------------------------------------- -(id)initWithKey:(NSData*)key { NSAssert([key length]>0,@"No Key or empty key"); if ((self=[self init])) { BYTE* stateBytes=NULL; UINT16 counter=0; short keyLength=[key length]; const BYTE* keyBytes=[key bytes]; BYTE index1 = 0; BYTE index2 = 0; ASSIGN(state,[NSMutableData dataWithLength:256]); stateBytes=[state mutableBytes]; NSLog(@"Key Length=%d",keyLength); for (counter=0;counter<256;counter++) stateBytes[counter]=(BYTE)counter; x = 0; y = 0; for (counter=0;counter<256;counter++) { NSAssert(index1 # Date: Mar 2000 # # This file is part of the GNUstep GSCrypt Library. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # ==================================================================== # Project specific makefile rules # # Uncomment the targets you want. # The double colons (::) are important, do not make them single colons # otherwise the normal makefile rules will not be performed. # ==================================================================== # Things to do before compiling # before-all:: # Things to do after compiling # after-all:: # Things to do before installing # before-install:: # Things to do after installing # after-install:: # Things to do before uninstalling # before-uninstall:: # Things to do after uninstalling # after-uninstall:: # Things to do before cleaning # before-clean:: # Things to do after cleaning # after-clean:: # Things to do before distcleaning # before-distclean:: # Things to do after distcleaning # after-distclean:: # Things to do before checking # before-check:: # Things to do after checking # after-check:: regenerate: copy-dist: $(DIST_FILES) gnustep-gscrypt-r31301/Makefile.preamble000064400000000000000000000036401227735665100203300ustar00rootroot00000000000000# Makefile.preamble # # Copyright (C) 2000 Free Software Foundation, Inc. # # Written by: Manuel Guesdon # Date: Mar 2000 # # This file is part of the GNUstep GSCrypt Library. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ==================================================================== # Project specific makefile variables, and additional # # Do not put any Makefile rules in this file, instead they should # be put into Makefile.postamble. # ==================================================================== # # Flags dealing with compiling and linking # # Additional flags to pass to the preprocessor ADDITIONAL_CPPFLAGS = # Additional flags to pass to the Objective-C compiler ADDITIONAL_OBJCFLAGS = # Additional flags to pass to the C compiler ADDITIONAL_CFLAGS = # Additional include directories the compiler should search ADDITIONAL_INCLUDE_DIRS = -I../ # Additional LDFLAGS to pass to the linker ADDITIONAL_LDFLAGS = -lpam # Additional library directories the linker should search ADDITIONAL_LIB_DIRS = -L../src/$(GNUSTEP_OBJ_DIR) # # Flags dealing with installing and uninstalling # # Additional directories to be created during installation ADDITIONAL_INSTALL_DIRS =