Ruby  2.5.0dev(2017-10-22revision60238)
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 = {
18  sizeof(SHA1_CTX),
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  rb_require("digest");
57 
58 #if 0
59  mDigest = rb_define_module("Digest"); /* let rdoc know */
60 #endif
61  mDigest = rb_path2class("Digest");
62  cDigest_Base = rb_path2class("Digest::Base");
63 
64  cDigest_SHA1 = rb_define_class_under(mDigest, "SHA1", cDigest_Base);
65 
66 #undef RUBY_UNTYPED_DATA_WARNING
67 #define RUBY_UNTYPED_DATA_WARNING 0
68  rb_iv_set(cDigest_SHA1, "metadata",
69  Data_Wrap_Struct(0, 0, 0, (void *)&sha1));
70 }
int SHA1_Init(SHA1_CTX *context)
Definition: sha1.c:202
#define SHA1_CTX
Definition: sha1cc.h:6
int SHA1_Finish(SHA1_CTX *context, uint8_t digest[20])
Definition: sha1.c:248
#define SHA1_DIGEST_LENGTH
Definition: sha1.h:36
VALUE rb_iv_set(VALUE, const char *, VALUE)
Definition: variable.c:3095
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:693
void Init_sha1(void)
Definition: sha1init.c:52
VALUE rb_path2class(const char *)
Definition: variable.c:432
int(* rb_digest_hash_finish_func_t)(void *, unsigned char *)
Definition: digest.h:22
#define SHA1_BLOCK_LENGTH
Definition: sha1.h:35
#define Data_Wrap_Struct(klass, mark, free, sval)
Definition: ruby.h:1142
VALUE rb_require(const char *)
Definition: load.c:1061
#define RUBY_DIGEST_API_VERSION
Definition: digest.h:18
unsigned long VALUE
Definition: ruby.h:85
void(* rb_digest_hash_update_func_t)(void *, unsigned char *, size_t)
Definition: digest.h:21
void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len)
Definition: sha1.c:221
int(* rb_digest_hash_init_func_t)(void *)
Definition: digest.h:20
VALUE rb_define_module(const char *name)
Definition: class.c:768