@@ -33,3 +33,43 @@ fn test_from_cipher() {
3333 assert_eq ! ( & buf, & ciphertext) ;
3434 }
3535}
36+
37+ #[ test]
38+ fn compare_to_openssl_with_over_64bit_counter ( ) {
39+ use stream_cipher:: { NewStreamCipher , SyncStreamCipher , SyncStreamCipherSeek } ;
40+ // values from https://github.com/RustCrypto/stream-ciphers/issues/12 poc
41+
42+ let key = [
43+ 13 , 193 , 67 , 14 , 105 , 84 , 246 , 135 , 216 , 216 , 40 , 251 , 26 , 84 , 119 , 223 ,
44+ ] ;
45+ let nonce = [
46+ 26 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
47+ ] ;
48+ let data = [
49+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
50+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
51+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
52+ 255 , 255 , 255 , 255 , 255 , 255 , 7 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
53+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
54+ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 202 , 124 , 216 , 0 ,
55+ ] ;
56+ let openssl = [
57+ 108 , 253 , 73 , 159 , 41 , 43 , 94 , 79 , 15 , 121 , 128 , 186 , 135 , 246 , 194 , 87 , 27 , 222 , 233 , 216 ,
58+ 2 , 74 , 106 , 79 , 70 , 239 , 105 , 93 , 125 , 169 , 59 , 243 , 171 , 225 , 15 , 165 , 102 , 87 , 79 , 1 , 31 ,
59+ 125 , 151 , 72 , 199 , 184 , 71 , 14 , 69 , 200 , 13 , 5 , 171 , 26 , 106 , 86 , 129 , 55 , 254 , 219 , 166 ,
60+ 51 , 34 , 105 , 154 , 166 , 12 , 108 , 239 , 100 , 153 , 125 , 229 , 136 , 86 , 30 , 233 , 149 , 169 , 77 ,
61+ 154 , 25 , 226 , 107 , 205 , 53 , 144 , 233 , 62 , 225 , 237 , 218 , 7 , 246 , 61 , 146 , 31 , 189 , 212 ,
62+ 178 , 104 , 88 ,
63+ ] ;
64+
65+ let mut cipher = Aes128Ctr :: new_var ( & key, & nonce) . unwrap ( ) ;
66+ let mut encrypted = data. to_vec ( ) ;
67+ cipher. apply_keystream ( & mut encrypted) ;
68+
69+ assert_eq ! ( & encrypted[ ..] , & openssl[ ..] ) ;
70+
71+ cipher. seek ( 0 ) ;
72+ cipher. apply_keystream ( & mut encrypted[ ..] ) ;
73+
74+ assert_eq ! ( & encrypted[ ..] , & data[ ..] ) ;
75+ }
0 commit comments