PageRenderTime 30ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/BulkCiphers.as

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 102 lines | 84 code | 9 blank | 9 comment | 4 complexity | 86925f2e6696668849fa4c5d64a986b4 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * BulkCiphers
  3. *
  4. * An enumeration of bulk ciphers available for TLS, along with their properties,
  5. * with a few convenience methods to go with it.
  6. * Copyright (c) 2007 Henri Torgemane
  7. *
  8. * See LICENSE.txt for full license information.
  9. */
  10. package com.hurlant.crypto.tls {
  11. import com.hurlant.crypto.Crypto;
  12. import flash.utils.ByteArray;
  13. import com.hurlant.crypto.symmetric.ICipher;
  14. import com.hurlant.crypto.symmetric.TLSPad;
  15. import com.hurlant.crypto.symmetric.SSLPad;
  16. public class BulkCiphers {
  17. public static const STREAM_CIPHER:uint = 0;
  18. public static const BLOCK_CIPHER:uint = 1;
  19. public static const NULL:uint = 0;
  20. public static const RC4_40:uint = 1;
  21. public static const RC4_128:uint = 2
  22. public static const RC2_CBC_40:uint = 3; // XXX I don't have that one.
  23. public static const DES_CBC:uint = 4;
  24. public static const DES3_EDE_CBC:uint = 5;
  25. public static const DES40_CBC:uint = 6;
  26. public static const IDEA_CBC:uint = 7; // XXX I don't have that one.
  27. public static const AES_128:uint = 8;
  28. public static const AES_256:uint = 9;
  29. private static const algos:Array =
  30. ['', 'rc4', 'rc4', '', 'des-cbc', '3des-cbc', 'des-cbc', '', 'aes', 'aes'];
  31. private static var _props:Array;
  32. init();
  33. private static function init():void {
  34. _props = [];
  35. _props[NULL] = new BulkCiphers(STREAM_CIPHER, 0, 0, 0, 0, 0);
  36. _props[RC4_40] = new BulkCiphers(STREAM_CIPHER, 5, 16, 40, 0, 0);
  37. _props[RC4_128] = new BulkCiphers(STREAM_CIPHER, 16, 16, 128, 0, 0);
  38. _props[RC2_CBC_40] = new BulkCiphers( BLOCK_CIPHER, 5, 16, 40, 8, 8);
  39. _props[DES_CBC] = new BulkCiphers( BLOCK_CIPHER, 8, 8, 56, 8, 8);
  40. _props[DES3_EDE_CBC] = new BulkCiphers( BLOCK_CIPHER, 24, 24, 168, 8, 8);
  41. _props[DES40_CBC] = new BulkCiphers( BLOCK_CIPHER, 5, 8, 40, 8, 8);
  42. _props[IDEA_CBC] = new BulkCiphers( BLOCK_CIPHER, 16, 16, 128, 8, 8);
  43. _props[AES_128] = new BulkCiphers( BLOCK_CIPHER, 16, 16, 128, 16, 16);
  44. _props[AES_256] = new BulkCiphers( BLOCK_CIPHER, 32, 32, 256, 16, 16);
  45. }
  46. private static function getProp(cipher:uint):BulkCiphers {
  47. var p:BulkCiphers = _props[cipher];
  48. if (p==null) {
  49. throw new Error("Unknown bulk cipher "+cipher.toString(16));
  50. }
  51. return p;
  52. }
  53. public static function getType(cipher:uint):uint {
  54. return getProp(cipher).type;
  55. }
  56. public static function getKeyBytes(cipher:uint):uint {
  57. return getProp(cipher).keyBytes;
  58. }
  59. public static function getExpandedKeyBytes(cipher:uint):uint {
  60. return getProp(cipher).expandedKeyBytes;
  61. }
  62. public static function getEffectiveKeyBits(cipher:uint):uint {
  63. return getProp(cipher).effectiveKeyBits;
  64. }
  65. public static function getIVSize(cipher:uint):uint {
  66. return getProp(cipher).IVSize;
  67. }
  68. public static function getBlockSize(cipher:uint):uint {
  69. return getProp(cipher).blockSize;
  70. }
  71. public static function getCipher(cipher:uint, key:ByteArray, proto:uint):ICipher {
  72. if (proto == TLSSecurityParameters.PROTOCOL_VERSION) {
  73. return Crypto.getCipher(algos[cipher], key, new TLSPad);
  74. } else {
  75. return Crypto.getCipher(algos[cipher], key, new SSLPad);
  76. }
  77. }
  78. private var type:uint;
  79. private var keyBytes:uint;
  80. private var expandedKeyBytes:uint;
  81. private var effectiveKeyBits:uint;
  82. private var IVSize:uint;
  83. private var blockSize:uint;
  84. public function BulkCiphers(t:uint, kb:uint, ekb:uint, fkb:uint, ivs:uint, bs:uint) {
  85. type = t;
  86. keyBytes = kb;
  87. expandedKeyBytes = ekb;
  88. effectiveKeyBits = fkb;
  89. IVSize = ivs;
  90. blockSize = bs;
  91. }
  92. }
  93. }