~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/digest/digest.c

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
  digest.c -
4
4
 
5
 
  $Author: knu $
 
5
  $Author: drbrain $
6
6
  created at: Fri May 25 08:57:27 JST 2001
7
7
 
8
8
  Copyright (C) 1995-2001 Yukihiro Matsumoto
9
9
  Copyright (C) 2001-2006 Akinori MUSHA
10
10
 
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 $
13
13
 
14
14
************************************************/
15
15
 
29
29
 * Document-module: Digest
30
30
 *
31
31
 * This module provides a framework for message digest libraries.
 
32
 *
 
33
 * You may want to look at OpenSSL::Digest as it supports support more
 
34
 * algorithms.
 
35
 *
 
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.
 
40
 *
 
41
 * == Example
 
42
 *
 
43
 *   require 'digest'
 
44
 *
 
45
 *   # Compute a complete digest
 
46
 *   sha256 = Digest::SHA256.new
 
47
 *   digest = sha256.digest message
 
48
 *
 
49
 *   # Compute digest by chunks
 
50
 *   sha256 = Digest::SHA256.new
 
51
 *   sha256.update message1
 
52
 *   sha256 << message2 # << is an alias for update
 
53
 *
 
54
 *   digest = sha256.digest
 
55
 *
 
56
 * == Digest algorithms
 
57
 *
 
58
 * Different digest algorithms (or hash functions) are available :
 
59
 *
 
60
 * HMAC::
 
61
 *   See FIPS PUB 198 The Keyed-Hash Message Authentication Code (HMAC)
 
62
 * RIPEMD-160::
 
63
 *   (as Digest::RMD160) see
 
64
 *   http://homes.esat.kuleuven.be/~bosselae/ripemd160.html
 
65
 * SHA1::
 
66
 *   See FIPS 180 Secure Hash Standard
 
67
 * SHA2 family::
 
68
 *   See FIPS 180 Secure Hash Standard which defines the following algorithms:
 
69
 *   * SHA512
 
70
 *   * SHA384
 
71
 *   * SHA256
 
72
 *
 
73
 * The latest versions of the FIPS publications can be found here:
 
74
 * http://csrc.nist.gov/publications/PubsFIPS.html
 
75
 *
 
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
32
79
 */
33
80
 
34
81
static VALUE
415
462
    return hexencode_str_new(rb_funcall2(klass, id_digest, argc, argv));
416
463
}
417
464
 
 
465
/* :nodoc: */
 
466
static VALUE
 
467
rb_digest_class_init(VALUE self)
 
468
{
 
469
    return self;
 
470
}
 
471
 
418
472
/*
419
473
 * Document-class: Digest::Base
420
474
 *
429
483
    VALUE obj;
430
484
    rb_digest_metadata_t *algo;
431
485
 
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);
435
489
            break;
436
490
        }
437
491
    }
438
492
 
439
 
    if (!p)
 
493
    if (NIL_P(p))
440
494
        rb_raise(rb_eRuntimeError, "Digest::Base cannot be directly inherited in Ruby");
441
495
 
442
496
    Data_Get_Struct(obj, rb_digest_metadata_t, algo);
622
676
     * class Digest::Class
623
677
     */
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);
626
681
 
627
682
    /* class methods */