ObjFW  Check-in [d28c998082]

Overview
Comment:Add class OFHash as a superclass for OFMD5Hash and OFSHA1Hash.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d28c998082ef2cbf198dc0ef2aa6611090bac42660da21901071c226820c8571
User & Date: js on 2010-04-17 16:01:18
Other Links: manifest | tags
Context
2010-04-17
16:09
Give the methods in OFNumber better names. check-in: 2517f18272 user: js tags: trunk
16:01
Add class OFHash as a superclass for OFMD5Hash and OFSHA1Hash. check-in: d28c998082 user: js tags: trunk
15:56
Make applying a table a private method. check-in: baeb7b379a user: js tags: trunk
Changes

Modified src/OFHashes.h from [38b83da8c3] to [816f280e14].

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
















53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

#define OF_MD5_DIGEST_SIZE  16
#define OF_SHA1_DIGEST_SIZE 20

extern int _OFHashing_reference;

/**
 * \brief A class which provides functions to create an MD5 hash.
 */
@interface OFMD5Hash: OFObject
{
	uint32_t buf[4];
	uint32_t bits[2];
	uint8_t	 in[64];

	BOOL	 calculated;
}

/**
 * \return A new autoreleased MD5 Hash
 */
+ md5Hash;

/**
 * Adds a buffer to the hash to be calculated.
 *
 * \param buf The buffer which should be included into calculation.
 * \param size The size of the buffer
 */
- (void)updateWithBuffer: (const char*)buf
		  ofSize: (size_t)size;

/**
 * \return A buffer containing the hash (OF_MD5_DIGEST_SIZE = 16 bytes).
 *	   The buffer is part of object's memory pool.
 */
- (uint8_t*)digest;
@end

















/**
 * \brief A class which provides functions to create an SHA1 hash.
 */
@interface OFSHA1Hash: OFObject
{
	uint32_t state[5];
	uint64_t count;
	char	 buffer[64];
	uint8_t	 digest[OF_SHA1_DIGEST_SIZE];

	BOOL	 calculated;
}

/**
 * \return A new autoreleased SHA1 Hash
 */
+ sha1Hash;

/**
 * Adds a buffer to the hash to be calculated.
 *
 * \param buf The buffer which should be included into calculation.
 * \param size The size of the buffer
 */
- (void)updateWithBuffer: (const char*)buf
		  ofSize: (size_t)size;

/**
 * \return A buffer containing the hash (OF_SHA1_DIGEST_SIZE = 20 bytes).
 *	   The buffer is part of object's memory pool.
 */
- (uint8_t*)digest;
@end

/**
 * The OFString (OFHashing) category provides methods to calculate hashes for
 * strings.
 */
@interface OFString (OFHashing)







|

|

<
<
<
<



<
<
<
<
<



|






|
|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|





<
<






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







14
15
16
17
18
19
20
21
22
23
24




25
26
27





28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68


69
70
71
72
73
74















75
76
77
78
79
80
81

#define OF_MD5_DIGEST_SIZE  16
#define OF_SHA1_DIGEST_SIZE 20

extern int _OFHashing_reference;

/**
 * \brief A base class for classes providing hash functions.
 */
@interface OFHash: OFObject
{




	BOOL	 calculated;
}






/**
 * Adds a buffer to the hash to be calculated.
 *
 * \param buf The buffer which should be included into the calculation.
 * \param size The size of the buffer
 */
- (void)updateWithBuffer: (const char*)buf
		  ofSize: (size_t)size;

/**
 * \return A buffer containing the hash. The size of the buffer is depending
 *	   on the hash used. The buffer is part of object's memory pool.
 */
- (uint8_t*)digest;
@end

/**
 * \brief A class which provides functions to create an MD5 hash.
 */
@interface OFMD5Hash: OFHash
{
	uint32_t buf[4];
	uint32_t bits[2];
	uint8_t	 in[64];
}

/**
 * \return A new autoreleased MD5 Hash
 */
+ md5Hash;
@end

/**
 * \brief A class which provides functions to create an SHA1 hash.
 */
@interface OFSHA1Hash: OFHash
{
	uint32_t state[5];
	uint64_t count;
	char	 buffer[64];
	uint8_t	 digest[OF_SHA1_DIGEST_SIZE];


}

/**
 * \return A new autoreleased SHA1 Hash
 */
+ sha1Hash;















@end

/**
 * The OFString (OFHashing) category provides methods to calculate hashes for
 * strings.
 */
@interface OFString (OFHashing)

Modified src/OFHashes.m from [a97ba49f22] to [4ade11c8e1].

15
16
17
18
19
20
21















22
23
24
25
26
27
28

#import "OFHashes.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "macros.h"

int _OFHashing_reference;
















/*
 * MD5
 */

/* The four MD5 core functions - F1 is optimized somewhat */
#define F1(x, y, z) (z ^ (x & (y ^ z)))







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#import "OFHashes.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "macros.h"

int _OFHashing_reference;

@implementation OFHash
- (void)updateWithBuffer: (const char*)buffer
		  ofSize: (size_t)size
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (uint8_t*)digest
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}
@end

/*
 * MD5
 */

/* The four MD5 core functions - F1 is optimized somewhat */
#define F1(x, y, z) (z ^ (x & (y ^ z)))