Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

sha1init.c
Go to the documentation of this file.
1 /* $RoughId: sha1init.c,v 1.2 2001/07/13 19:49:10 knu Exp $ */
2 /* $Id$ */
3
4 #include <ruby/ruby.h>
5 #include "../digest.h"
6 #if defined(SHA1_USE_OPENSSL)
7 #include "sha1ossl.h"
8 #elif defined(SHA1_USE_COMMONDIGEST)
9 #include "sha1cc.h"
10 #else
11 #include "sha1.h"
12 #endif
13
14 static const rb_digest_metadata_t sha1 = {
15 RUBY_DIGEST_API_VERSION,
16 SHA1_DIGEST_LENGTH,
17 SHA1_BLOCK_LENGTH,
18 sizeof(SHA1_CTX),
19 (rb_digest_hash_init_func_t)SHA1_Init,
20 (rb_digest_hash_update_func_t)SHA1_Update,
21 (rb_digest_hash_finish_func_t)SHA1_Finish,
22 };
23
24 /*
25 * Document-class: Digest::SHA1 < Digest::Base
26 * A class for calculating message digests using the SHA-1 Secure Hash
27 * Algorithm by NIST (the US' National Institute of Standards and
28 * Technology), described in FIPS PUB 180-1.
29 *
30 * See Digest::Instance for digest API.
31 *
32 * SHA-1 calculates a digest of 160 bits (20 bytes).
33 *
34 * == Examples
35 * require 'digest'
36 *
37 * # Compute a complete digest
38 * Digest::SHA1.hexdigest 'abc' #=> "a9993e36..."
39 *
40 * # Compute digest by chunks
41 * sha1 = Digest::SHA1.new # =>#<Digest::SHA1>
42 * sha1.update "ab"
43 * sha1 << "c" # alias for #update
44 * sha1.hexdigest # => "a9993e36..."
45 *
46 * # Use the same object to compute another digest
47 * sha1.reset
48 * sha1 << "message"
49 * sha1.hexdigest # => "6f9b9af3..."
50 */
51 void
52 Init_sha1(void)
53 {
54 VALUE mDigest, cDigest_Base, cDigest_SHA1;
55
56 #if 0
57 mDigest = rb_define_module("Digest"); /* let rdoc know */
58 #endif
59 mDigest = rb_digest_namespace();
60 cDigest_Base = rb_path2class("Digest::Base");
61
62 cDigest_SHA1 = rb_define_class_under(mDigest, "SHA1", cDigest_Base);
63
64 #undef RUBY_UNTYPED_DATA_WARNING
65 #define RUBY_UNTYPED_DATA_WARNING 0
66 rb_iv_set(cDigest_SHA1, "metadata",
67 Data_Wrap_Struct(0, 0, 0, (void *)&sha1));
68 }
SHA1_DIGEST_LENGTH
#define SHA1_DIGEST_LENGTH
Definition: sha1.h:36
rb_digest_hash_finish_func_t
int(* rb_digest_hash_finish_func_t)(void *, unsigned char *)
Definition: digest.h:22
sha1.h
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:772
Data_Wrap_Struct
#define Data_Wrap_Struct(klass, mark, free, sval)
Definition: ruby.h:1211
sha1cc.h
ruby.h
RUBY_DIGEST_API_VERSION
#define RUBY_DIGEST_API_VERSION
Definition: digest.h:18
SHA1_CTX
#define SHA1_CTX
Definition: sha1cc.h:6
rb_digest_metadata_t
Definition: digest.h:24
SHA1_Finish
int SHA1_Finish(SHA1_CTX *context, uint8_t digest[20])
Definition: sha1.c:248
sha1ossl.h
Init_sha1
void Init_sha1(void)
Definition: sha1init.c:52
rb_digest_hash_init_func_t
int(* rb_digest_hash_init_func_t)(void *)
Definition: digest.h:20
rb_path2class
VALUE rb_path2class(const char *)
Definition: variable.c:268
rb_define_class_under
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:698
SHA1_Init
int SHA1_Init(SHA1_CTX *context)
Definition: sha1.c:202
rb_digest_hash_update_func_t
void(* rb_digest_hash_update_func_t)(void *, unsigned char *, size_t)
Definition: digest.h:21
SHA1_BLOCK_LENGTH
#define SHA1_BLOCK_LENGTH
Definition: sha1.h:35
SHA1_Update
void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len)
Definition: sha1.c:221
rb_iv_set
VALUE rb_iv_set(VALUE, const char *, VALUE)
Definition: variable.c:3307