|
32 | 32 | extern "C" { |
33 | 33 | #endif |
34 | 34 |
|
35 | | -#define CC_DIGEST_DEPRECATION_WARNING \ |
36 | | - "This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger)." |
37 | | - |
38 | | -/* |
39 | | - * For compatibility with legacy implementations, the *Init(), *Update(), |
40 | | - * and *Final() functions declared here *always* return a value of 1 (one). |
41 | | - * This corresponds to "success" in the similar openssl implementations. |
42 | | - * There are no errors of any kind which can be, or are, reported here, |
43 | | - * so you can safely ignore the return values of all of these functions |
44 | | - * if you are implementing new code. |
45 | | - * |
46 | | - * The one-shot functions (CC_MD2(), CC_SHA1(), etc.) perform digest |
47 | | - * calculation and place the result in the caller-supplied buffer |
48 | | - * indicated by the md parameter. They return the md parameter. |
49 | | - * Unlike the opensssl counterparts, these one-shot functions require |
50 | | - * a non-NULL md pointer. Passing in NULL for the md parameter |
51 | | - * results in a NULL return and no digest calculation. |
52 | | - */ |
53 | | - |
54 | 35 | typedef uint32_t CC_LONG; /* 32 bit unsigned integer */ |
55 | 36 | typedef uint64_t CC_LONG64; /* 64 bit unsigned integer */ |
56 | 37 |
|
57 | | -/*** MD2 ***/ |
58 | | - |
59 | | -#define CC_MD2_DIGEST_LENGTH 16 /* digest length in bytes */ |
60 | | -#define CC_MD2_BLOCK_BYTES 64 /* block size in bytes */ |
61 | | -#define CC_MD2_BLOCK_LONG (CC_MD2_BLOCK_BYTES / sizeof(CC_LONG)) |
62 | | - |
63 | | -typedef struct CC_MD2state_st |
64 | | -{ |
65 | | - int num; |
66 | | - unsigned char data[CC_MD2_DIGEST_LENGTH]; |
67 | | - CC_LONG cksm[CC_MD2_BLOCK_LONG]; |
68 | | - CC_LONG state[CC_MD2_BLOCK_LONG]; |
69 | | -} CC_MD2_CTX; |
70 | | - |
71 | | -extern int CC_MD2_Init(CC_MD2_CTX *c) |
72 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
73 | | - |
74 | | -extern int CC_MD2_Update(CC_MD2_CTX *c, const void *data, CC_LONG len) |
75 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
76 | | - |
77 | | -extern int CC_MD2_Final(unsigned char *md, CC_MD2_CTX *c) |
78 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
79 | | - |
80 | | -extern unsigned char *CC_MD2(const void *data, CC_LONG len, unsigned char *md) |
81 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
82 | | - |
83 | | -/*** MD4 ***/ |
84 | | - |
85 | | -#define CC_MD4_DIGEST_LENGTH 16 /* digest length in bytes */ |
86 | | -#define CC_MD4_BLOCK_BYTES 64 /* block size in bytes */ |
87 | | -#define CC_MD4_BLOCK_LONG (CC_MD4_BLOCK_BYTES / sizeof(CC_LONG)) |
88 | | - |
89 | | -typedef struct CC_MD4state_st |
90 | | -{ |
91 | | - CC_LONG A,B,C,D; |
92 | | - CC_LONG Nl,Nh; |
93 | | - CC_LONG data[CC_MD4_BLOCK_LONG]; |
94 | | - uint32_t num; |
95 | | -} CC_MD4_CTX; |
96 | | - |
97 | | -extern int CC_MD4_Init(CC_MD4_CTX *c) |
98 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
99 | | - |
100 | | -extern int CC_MD4_Update(CC_MD4_CTX *c, const void *data, CC_LONG len) |
101 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
102 | | - |
103 | | -extern int CC_MD4_Final(unsigned char *md, CC_MD4_CTX *c) |
104 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
105 | | - |
106 | | -extern unsigned char *CC_MD4(const void *data, CC_LONG len, unsigned char *md) |
107 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
108 | | - |
109 | | - |
110 | | -/*** MD5 ***/ |
111 | | - |
112 | | -#define CC_MD5_DIGEST_LENGTH 16 /* digest length in bytes */ |
113 | | -#define CC_MD5_BLOCK_BYTES 64 /* block size in bytes */ |
114 | | -#define CC_MD5_BLOCK_LONG (CC_MD5_BLOCK_BYTES / sizeof(CC_LONG)) |
115 | | - |
116 | | -typedef struct CC_MD5state_st |
117 | | -{ |
118 | | - CC_LONG A,B,C,D; |
119 | | - CC_LONG Nl,Nh; |
120 | | - CC_LONG data[CC_MD5_BLOCK_LONG]; |
121 | | - int num; |
122 | | -} CC_MD5_CTX; |
123 | | - |
124 | | -extern int CC_MD5_Init(CC_MD5_CTX *c) |
125 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
126 | | - |
127 | | -extern int CC_MD5_Update(CC_MD5_CTX *c, const void *data, CC_LONG len) |
128 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
129 | | - |
130 | | -extern int CC_MD5_Final(unsigned char *md, CC_MD5_CTX *c) |
131 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
132 | | - |
133 | | -extern unsigned char *CC_MD5(const void *data, CC_LONG len, unsigned char *md) |
134 | | -API_DEPRECATED(CC_DIGEST_DEPRECATION_WARNING, macos(10.4, 10.15), ios(2.0, 13.0)); |
135 | | - |
136 | | -/*** SHA1 ***/ |
137 | | - |
138 | | -#define CC_SHA1_DIGEST_LENGTH 20 /* digest length in bytes */ |
139 | | -#define CC_SHA1_BLOCK_BYTES 64 /* block size in bytes */ |
140 | | -#define CC_SHA1_BLOCK_LONG (CC_SHA1_BLOCK_BYTES / sizeof(CC_LONG)) |
141 | | - |
142 | | -typedef struct CC_SHA1state_st |
143 | | -{ |
144 | | - CC_LONG h0,h1,h2,h3,h4; |
145 | | - CC_LONG Nl,Nh; |
146 | | - CC_LONG data[CC_SHA1_BLOCK_LONG]; |
147 | | - int num; |
148 | | -} CC_SHA1_CTX; |
149 | | - |
150 | | -extern int CC_SHA1_Init(CC_SHA1_CTX *c); |
151 | | - |
152 | | -extern int CC_SHA1_Update(CC_SHA1_CTX *c, const void *data, CC_LONG len); |
153 | | - |
154 | | -extern int CC_SHA1_Final(unsigned char *md, CC_SHA1_CTX *c); |
155 | | - |
156 | | -extern unsigned char *CC_SHA1(const void *data, CC_LONG len, unsigned char *md); |
157 | | - |
158 | 38 | /*** SHA224 ***/ |
159 | 39 | #define CC_SHA224_DIGEST_LENGTH 28 /* digest length in bytes */ |
160 | 40 | #define CC_SHA224_BLOCK_BYTES 64 /* block size in bytes */ |
@@ -258,26 +138,6 @@ + (void)performSelector:(SEL)aSelector onMainThreadOnObject:(nullable id)targetO |
258 | 138 | }]; |
259 | 139 | } |
260 | 140 |
|
261 | | -+ (NSString*)hashUsingSha1:(NSString*)string { |
262 | | - const char *cstr = [string UTF8String]; |
263 | | - uint8_t digest[CC_SHA1_DIGEST_LENGTH]; |
264 | | - CC_SHA1(cstr, (CC_LONG)strlen(cstr), digest); |
265 | | - NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; |
266 | | - for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) |
267 | | - [output appendFormat:@"%02x", digest[i]]; |
268 | | - return output; |
269 | | -} |
270 | | - |
271 | | -+ (NSString*)hashUsingMD5:(NSString*)string { |
272 | | - const char *cstr = [string UTF8String]; |
273 | | - uint8_t digest[CC_MD5_DIGEST_LENGTH]; |
274 | | - CC_MD5(cstr, (CC_LONG)strlen(cstr), digest); |
275 | | - NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; |
276 | | - for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) |
277 | | - [output appendFormat:@"%02x", digest[i]]; |
278 | | - return output; |
279 | | -} |
280 | | - |
281 | 141 | + (NSString*)trimURLSpacing:(NSString*)url { |
282 | 142 | if (!url || [url isEqual:[NSNull null]]) { |
283 | 143 | return nil; |
|
0 commit comments