2001-07-14 00:06:14 +04:00
|
|
|
/************************************************
|
|
|
|
|
2006-10-11 09:15:15 +04:00
|
|
|
digest.h - header file for ruby digest modules
|
2001-07-14 00:06:14 +04:00
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Fri May 25 08:54:56 JST 2001
|
|
|
|
|
|
|
|
|
2006-10-11 09:15:15 +04:00
|
|
|
Copyright (C) 2001-2006 Akinori MUSHA
|
2001-07-14 00:06:14 +04:00
|
|
|
|
|
|
|
$RoughId: digest.h,v 1.3 2001/07/13 15:38:27 knu Exp $
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
|
|
#include "ruby.h"
|
|
|
|
|
2014-07-15 18:58:53 +04:00
|
|
|
#define RUBY_DIGEST_API_VERSION 3
|
2006-10-20 16:48:35 +04:00
|
|
|
|
2014-07-15 18:58:53 +04:00
|
|
|
typedef int (*rb_digest_hash_init_func_t)(void *);
|
2006-10-20 16:48:35 +04:00
|
|
|
typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t);
|
2014-07-15 18:58:53 +04:00
|
|
|
typedef int (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
|
2001-07-14 00:06:14 +04:00
|
|
|
|
|
|
|
typedef struct {
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-14 03:23:18 +04:00
|
|
|
int api_version;
|
2001-07-14 00:06:14 +04:00
|
|
|
size_t digest_len;
|
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c:
Introduce API versioning.
* ext/digest/digest.c, ext/digest/digest.h,
ext/digest/md5/md5init.c, ext/digest/rmd160/rmd160init.c,
ext/digest/sha1/sha1init.c, ext/digest/sha2/sha2init.c: Remove
the constants DIGEST_LENGTH and BLOCK_LENGTH and turn them into
instance methods digest_length() and block_length(). Class
methods with the same names are also provided, which take extra
parameters for a digest method.
* ext/digest/lib/digest/hmac.rb: Completely redesign the API which
is similar to Perl's, now that Digest classes can take hashing
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-10-14 03:23:18 +04:00
|
|
|
size_t block_len;
|
2001-07-14 00:06:14 +04:00
|
|
|
size_t ctx_size;
|
2006-10-20 16:48:35 +04:00
|
|
|
rb_digest_hash_init_func_t init_func;
|
|
|
|
rb_digest_hash_update_func_t update_func;
|
|
|
|
rb_digest_hash_finish_func_t finish_func;
|
|
|
|
} rb_digest_metadata_t;
|
2015-02-11 05:09:23 +03:00
|
|
|
|
|
|
|
#define DEFINE_UPDATE_FUNC_FOR_UINT(name) \
|
|
|
|
void \
|
|
|
|
rb_digest_##name##_update(void *ctx, unsigned char *ptr, size_t size) \
|
|
|
|
{ \
|
|
|
|
const unsigned int stride = 16384; \
|
|
|
|
\
|
|
|
|
for (; size > stride; size -= stride, ptr += stride) { \
|
|
|
|
name##_Update(ctx, ptr, stride); \
|
|
|
|
} \
|
|
|
|
if (size > 0) name##_Update(ctx, ptr, size); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_FINISH_FUNC_FROM_FINAL(name) \
|
|
|
|
int \
|
|
|
|
rb_digest_##name##_finish(void *ctx, unsigned char *ptr) \
|
|
|
|
{ \
|
|
|
|
return name##_Final(ptr, ctx); \
|
|
|
|
}
|