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
|
# File 'ext/cobreak/cobreak_openssl.c', line 23
VALUE ripemd160_hexdigest(VALUE self, VALUE full){
char *str = RSTRING_PTR(full);
int n;
RIPEMD160_CTX c;
unsigned char digest[65];
char *out = (char*)malloc(33);
int length = strlen(str);
RIPEMD160_Init(&c);
while (length > 0) {
if (length > 512) {
RIPEMD160_Update(&c, str, 512);
} else {
RIPEMD160_Update(&c, str, length);
}
length -= 512;
str += 512;
}
RIPEMD160_Final(digest, &c);
for (n = 0; n < RIPEMD160_DIGEST_LENGTH; ++n) {
snprintf(&(out[n*2]), RIPEMD160_DIGEST_LENGTH*2, "%02x", (unsigned int)digest[n]);
}
return rb_str_new2(out);
free(out);
}
|