ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenSSL/OpenSSL/HMAC.pm
Revision: 1.1
Committed: Sat Oct 27 01:53:23 2001 UTC (22 years, 6 months ago) by stefan
Branch: MAIN
CVS Tags: BEFORE_5_8_REGEX_FIX, HEAD
Log Message:
*** empty log message ***

File Contents

# Content
1 package OpenSSL::HMAC;
2
3 =head1 NAME
4
5 OpenSSL::HMAC -- Access to OpenSSL hmac functions
6
7 =head1 SYNOPSIS
8
9 use OpenSSL::HMAC;
10
11 =head1 DESCRIPTION
12
13 Foo/bar.
14
15 =over 4
16
17 =cut
18
19 use OpenSSL;
20
21 our $VERSION = '0.06';
22 use base Exporter;
23 @EXPORT_OK = qw(hmac hmac_hex hmac_base64 new_hmac enum_hmac
24 md4 md5 sha sha1 dss dss1 mdc2 ripemd160 md2
25 md4_hex md5_hex sha_hex sha1_hex dss_hex dss1_hex mdc2_hex ripemd160_hex md2_hex
26 md4_base64 md5_base64 sha_base64 sha1_base64 dss_base64 dss1_base64 mdc2_base64 ripemd160_base64 md2_base64
27 new_md4 new_md5 new_sha new_sha1 new_dss new_dss1 new_mdc2 new_ripemd160 new_md2
28 );
29
30 our %dig_hash_hex;
31 our %dig_hash_base64;
32 our %dig_hash;
33 our %dig_hash_new;
34 our @dignames;
35
36 for (qw(md4 md5 sha sha1 dss dss1 mdc2 ripemd160 md2)) {
37 my $r = '\&OpenSSL::HMAC::';
38 $dig_hash_hex{$_} = eval $r.$_."_hex";
39 $dig_hash_base64{$_} = eval $r.$_."_base64";
40 $dig_hash_new{$_} = eval $r.'new_'.$_;
41 $dig_hash{$_} = eval $r.$_;
42 push @dignames, $_;
43 }
44
45 =back
46
47 =head1 FUNCTIONS
48
49 =over 4
50
51 =item @digs = enum_hmac();
52
53 Returns a list of supported digests for hmac.
54 (sha1, md5, md2, md4, sha, mdc2, ripemd160, dss, dss1)
55
56 =cut
57
58 sub enum_hmac()
59 {
60 @dignames;
61 }
62
63
64 =item $hexhmac = hmac_hex($digname, $key, $string, ...)
65
66 returns $digname hmac over $string hex encoded
67
68
69 =cut
70
71 sub hmac_hex($$;@) {
72 my $f = shift;
73 my $p = shift;
74 $dig_hash_hex{$f}($p, join '', @_)
75 }
76
77 =item $binhmac = hmac($digname, $key, $string, ...)
78
79 returns $digname hmac over $string raw
80
81 =cut
82
83 sub hmac($$;@) {
84 my $f = shift;
85 my $p = shift;
86 $dig_hash{$f}($p, join '', @_)
87 }
88
89 =item $base64_hmac = hmac_base64($digname, $key, $string, ...)
90
91 returns $digname hmac over $string base64 encoded
92
93 =cut
94
95 sub hmac_base64($$;@) {
96 my $f = shift;
97 my $p = shift;
98 $dig_hash_base64{$f}($p, join '', @_)
99 }
100
101 =item $hex_hmac = {hmacname}_hex($key,$string)
102
103 Direct access to low level function.
104
105 =item $raw_hmac = {hmacname}($key,$string)
106
107 Direct access to low level function.
108
109 =item $base64_hmac = {hmacname}_base64($key,$string)
110
111 Direct access to low level function.
112
113 =item $ctx = {hmacname}_new($key)
114
115 Access to classical stream based approach.
116
117 =item $ctx = new_hmac($digname, $key)
118
119 Access to classical stream based approach.
120
121 =cut
122
123 sub new_hmac($$) {
124 $dig_hash_new{$_[0]}($_[1]);
125 }
126
127 =item $ctx->update($string)
128
129 Adds $string to the hmac
130
131 =item $ctx->final
132
133 Returns the hmac raw.
134
135 =item $ctx->final_hex
136
137 Returns the hmac hex encoded.
138
139 =item $ctx->final_base64
140
141 Returns the hmac base64 encoded.
142
143
144 =back
145
146 =head1 SEE ALSO
147
148 L<OpenSSL>, L<OpenSSL::Digest>.
149
150 =head1 AUTHOR
151
152 Stefan Traby <stefan@hello-penguin.com>
153 http://mindterm.plan9.de/
154
155 =cut
156
157 1;