source: Dev/trunk/src/client/dojox/encoding/digests/SHA224.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 1.7 KB
Line 
1define(["./_sha-32"], function(sha32){
2        //      The 224-bit implementation of SHA-2
3        var hash = [
4                0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
5                0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
6        ];
7
8        var SHA224 = function(/* String */data, /* sha32.outputTypes? */outputType){
9                var out = outputType || sha32.outputTypes.Base64;
10                data = sha32.stringToUtf8(data);
11                var wa = sha32.digest(sha32.toWord(data), data.length * 8, hash, 224);
12                switch(out){
13                        case sha32.outputTypes.Raw: {
14                                return wa;
15                        }
16                        case sha32.outputTypes.Hex: {
17                                return sha32.toHex(wa);
18                        }
19                        case sha32.outputTypes.String: {
20                                return sha32._toString(wa);
21                        }
22                        default: {
23                                return sha32.toBase64(wa);
24                        }
25                }
26        };
27
28        SHA224._hmac = function(/* String */data, /* String */key, /* sha32.outputTypes? */outputType){
29                var out = outputType || sha32.outputTypes.Base64;
30                data = sha32.stringToUtf8(data);
31                key = sha32.stringToUtf8(key);
32
33                //      prepare the key
34                var wa = sha32.toWord(key);
35                if(wa.length > 16){
36                        wa = sha32.digest(wa, key.length * 8, hash, 224);
37                }
38
39                //      set up the pads
40                var ipad = new Array(16), opad = new Array(16);
41                for(var i=0; i<16; i++){
42                        ipad[i] = wa[i] ^ 0x36363636;
43                        opad[i] = wa[i] ^ 0x5c5c5c5c;
44                }
45
46                //      make the final digest
47                var r1 = sha32.digest(ipad.concat(sha32.toWord(data)), 512 + data.length * 8, hash, 224);
48                var r2 = sha32.digest(opad.concat(r1), 512 + 160, hash, 224);
49
50                //      return the output.
51                switch(out){
52                        case sha32.outputTypes.Raw: {
53                                return wa;
54                        }
55                        case sha32.outputTypes.Hex: {
56                                return sha32.toHex(wa);
57                        }
58                        case sha32.outputTypes.String: {
59                                return sha32._toString(wa);
60                        }
61                        default: {
62                                return sha32.toBase64(wa);
63                        }
64                }
65        };
66
67        return SHA224;
68});
Note: See TracBrowser for help on using the repository browser.