Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

93 řádky
1.6 KiB

  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package rc2
  5. import (
  6. "bytes"
  7. "encoding/hex"
  8. "testing"
  9. )
  10. func TestEncryptDecrypt(t *testing.T) {
  11. // TODO(dgryski): add the rest of the test vectors from the RFC
  12. var tests = []struct {
  13. key string
  14. plain string
  15. cipher string
  16. t1 int
  17. }{
  18. {
  19. "0000000000000000",
  20. "0000000000000000",
  21. "ebb773f993278eff",
  22. 63,
  23. },
  24. {
  25. "ffffffffffffffff",
  26. "ffffffffffffffff",
  27. "278b27e42e2f0d49",
  28. 64,
  29. },
  30. {
  31. "3000000000000000",
  32. "1000000000000001",
  33. "30649edf9be7d2c2",
  34. 64,
  35. },
  36. {
  37. "88",
  38. "0000000000000000",
  39. "61a8a244adacccf0",
  40. 64,
  41. },
  42. {
  43. "88bca90e90875a",
  44. "0000000000000000",
  45. "6ccf4308974c267f",
  46. 64,
  47. },
  48. {
  49. "88bca90e90875a7f0f79c384627bafb2",
  50. "0000000000000000",
  51. "1a807d272bbe5db1",
  52. 64,
  53. },
  54. {
  55. "88bca90e90875a7f0f79c384627bafb2",
  56. "0000000000000000",
  57. "2269552ab0f85ca6",
  58. 128,
  59. },
  60. {
  61. "88bca90e90875a7f0f79c384627bafb216f80a6f85920584c42fceb0be255daf1e",
  62. "0000000000000000",
  63. "5b78d3a43dfff1f1",
  64. 129,
  65. },
  66. }
  67. for _, tt := range tests {
  68. k, _ := hex.DecodeString(tt.key)
  69. p, _ := hex.DecodeString(tt.plain)
  70. c, _ := hex.DecodeString(tt.cipher)
  71. b, _ := New(k, tt.t1)
  72. var dst [8]byte
  73. b.Encrypt(dst[:], p)
  74. if !bytes.Equal(dst[:], c) {
  75. t.Errorf("encrypt failed: got % 2x wanted % 2x\n", dst, c)
  76. }
  77. b.Decrypt(dst[:], c)
  78. if !bytes.Equal(dst[:], p) {
  79. t.Errorf("decrypt failed: got % 2x wanted % 2x\n", dst, p)
  80. }
  81. }
  82. }