MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / setupSub

Function setupSub

modules/crypt/ssl/ssl_setup.js:46–91  ·  view source on GitHub ↗
(o, cipher)

Source from the content-addressed store, hash-verified

44import Gcm from "gcm";
45
46function setupSub(o, cipher)
47{
48 let enc, h;
49
50 switch (cipher.cipherAlgorithm) {
51 case DES:
52 enc = new BlockCipher("DES", o.key);
53 break;
54 case TDES:
55 enc = new BlockCipher("TDES", o.key);
56 break;
57 case AES:
58 enc = new BlockCipher("AES", o.key);
59 break;
60 case RC4:
61 enc = new StreamCipher("RC4", o.key);
62 break;
63 default:
64 throw new TLSError("SetupCipher: unkown encryption algorithm");
65 }
66 switch (cipher.encryptionMode) {
67 case CBC:
68 case NONE:
69 switch (cipher.hashAlgorithm) {
70 case MD5: h = "MD5"; break;
71 case SHA1: h = "SHA1"; break;
72 case SHA256: h = "SHA256"; break;
73 case SHA384: h = "SHA384"; break;
74 default:
75 throw new TLSError("SetupCipher: unknown hash algorithm");
76 }
77 o.hmac = new HMAC(new Digest(h), o.macSecret);
78 if (cipher.encryptionMode == CBC)
79 o.enc = new Mode("CBC", enc, o.iv); // no padding -- SSL 3.2 requires padding process beyond RFC2630
80 else
81 o.enc = enc;
82 break;
83 case GCM:
84 o.enc = new Gcm(enc);
85 o.nonce = BigInt(1);
86 break;
87 default:
88 o.enc = enc;
89 break;
90 }
91}
92
93function SetupCipher(session, connectionEnd)
94{

Callers 1

SetupCipherFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected