Ruby: ext/digest/sha1/sha1init.c Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

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_COMMONDIGEST)
7#include "sha1cc.h"
8#else
9#include "sha1.h"
10#endif
11
12static const rb_digest_metadata_t sha1 = {
13 RUBY_DIGEST_API_VERSION,
14 SHA1_DIGEST_LENGTH,
15 SHA1_BLOCK_LENGTH,
16 sizeof(SHA1_CTX),
17 (rb_digest_hash_init_func_t)SHA1_Init,
18 (rb_digest_hash_update_func_t)SHA1_Update,
19 (rb_digest_hash_finish_func_t)SHA1_Finish,
20};
21
22/*
23 * Document-class: Digest::SHA1 < Digest::Base
24 * A class for calculating message digests using the SHA-1 Secure Hash
25 * Algorithm by NIST (the US' National Institute of Standards and
26 * Technology), described in FIPS PUB 180-1.
27 *
28 * See Digest::Instance for digest API.
29 *
30 * SHA-1 calculates a digest of 160 bits (20 bytes).
31 *
32 * == Examples
33 * require 'digest'
34 *
35 * # Compute a complete digest
36 * Digest::SHA1.hexdigest 'abc' #=> "a9993e36..."
37 *
38 * # Compute digest by chunks
39 * sha1 = Digest::SHA1.new # =>#<Digest::SHA1>
40 * sha1.update "ab"
41 * sha1 << "c" # alias for #update
42 * sha1.hexdigest # => "a9993e36..."
43 *
44 * # Use the same object to compute another digest
45 * sha1.reset
46 * sha1 << "message"
47 * sha1.hexdigest # => "6f9b9af3..."
48 */
49void
50Init_sha1(void)
51{
52 VALUE mDigest, cDigest_Base, cDigest_SHA1;
53
54#if 0
55 mDigest = rb_define_module("Digest"); /* let rdoc know */
56#endif
57 mDigest = rb_digest_namespace();
58 cDigest_Base = rb_path2class("Digest::Base");
59
60 cDigest_SHA1 = rb_define_class_under(mDigest, "SHA1", cDigest_Base);
61
62 rb_iv_set(cDigest_SHA1, "metadata", rb_digest_make_metadata(&sha1));
63}
RUBY_DIGEST_API_VERSION
#define RUBY_DIGEST_API_VERSION
Definition: digest.h:18
rb_digest_hash_update_func_t
void(* rb_digest_hash_update_func_t)(void *, unsigned char *, size_t)
Definition: digest.h:21
rb_digest_hash_init_func_t
int(* rb_digest_hash_init_func_t)(void *)
Definition: digest.h:20
rb_digest_hash_finish_func_t
int(* rb_digest_hash_finish_func_t)(void *, unsigned char *)
Definition: digest.h:22
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:797
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:871
rb_path2class
VALUE rb_path2class(const char *)
Definition: variable.c:287
rb_iv_set
VALUE rb_iv_set(VALUE, const char *, VALUE)
Definition: variable.c:3580
ruby.h
sha1.h
SHA1_BLOCK_LENGTH
#define SHA1_BLOCK_LENGTH
Definition: sha1.h:35
SHA1_DIGEST_LENGTH
#define SHA1_DIGEST_LENGTH
Definition: sha1.h:36
SHA1_Finish
#define SHA1_Finish
Definition: sha1.h:27
SHA1_Update
#define SHA1_Update
Definition: sha1.h:26
SHA1_Init
#define SHA1_Init
Definition: sha1.h:25
sha1cc.h
Init_sha1
void Init_sha1(void)
Definition: sha1init.c:50
SHA1_CTX
Definition: sha1.h:16
rb_digest_metadata_t
Definition: digest.h:24
VALUE
unsigned long VALUE
Definition: value.h:38