6
6
created at: Fri May 25 08:57:27 JST 2001
8
8
Copyright (C) 1995-2001 Yukihiro Matsumoto
9
9
Copyright (C) 2001-2006 Akinori MUSHA
11
11
$RoughId: digest.c,v 1.16 2001/07/13 15:38:27 knu Exp $
12
$Id: digest.c 26339 2010-01-17 19:12:10Z knu $
12
$Id: digest.c 32951 2011-08-12 17:26:00Z drbrain $
14
14
************************************************/
29
29
* Document-module: Digest
31
31
* This module provides a framework for message digest libraries.
33
* You may want to look at OpenSSL::Digest as it supports support more
36
* A cryptographic hash function is a procedure that takes data and return a
37
* fixed bit string : the hash value, also known as _digest_. Hash functions
38
* are also called one-way functions, it is easy to compute a digest from
39
* a message, but it is infeasible to generate a message from a digest.
45
* # Compute a complete digest
46
* sha256 = Digest::SHA256.new
47
* digest = sha256.digest message
49
* # Compute digest by chunks
50
* sha256 = Digest::SHA256.new
51
* sha256.update message1
52
* sha256 << message2 # << is an alias for update
54
* digest = sha256.digest
56
* == Digest algorithms
58
* Different digest algorithms (or hash functions) are available :
61
* See FIPS PUB 198 The Keyed-Hash Message Authentication Code (HMAC)
63
* (as Digest::RMD160) see
64
* http://homes.esat.kuleuven.be/~bosselae/ripemd160.html
66
* See FIPS 180 Secure Hash Standard
68
* See FIPS 180 Secure Hash Standard which defines the following algorithms:
73
* The latest versions of the FIPS publications can be found here:
74
* http://csrc.nist.gov/publications/PubsFIPS.html
76
* Additionally Digest::BubbleBabble encodes a digest as a sequence of
77
* consonants and vowels which is more recognizable and comparable than a
78
* hexadecimal digest. See http://en.wikipedia.org/wiki/Bubblebabble
415
462
return hexencode_str_new(rb_funcall2(klass, id_digest, argc, argv));
467
rb_digest_class_init(VALUE self)
419
473
* Document-class: Digest::Base
430
484
rb_digest_metadata_t *algo;
432
for (p = klass; p; p = RCLASS_SUPER(p)) {
486
for (p = klass; !NIL_P(p); p = rb_class_superclass(p)) {
433
487
if (rb_ivar_defined(p, id_metadata)) {
434
488
obj = rb_ivar_get(p, id_metadata);
440
494
rb_raise(rb_eRuntimeError, "Digest::Base cannot be directly inherited in Ruby");
442
496
Data_Get_Struct(obj, rb_digest_metadata_t, algo);
622
676
* class Digest::Class
624
678
rb_cDigest_Class = rb_define_class_under(rb_mDigest, "Class", rb_cObject);
679
rb_define_method(rb_cDigest_Class, "initialize", rb_digest_class_init, 0);
625
680
rb_include_module(rb_cDigest_Class, rb_mDigest_Instance);
627
682
/* class methods */