|
1 | 1 | # lua-salsa20 |
2 | 2 |
|
3 | | -Salsa20 eStream cipher in Lua. |
4 | | - |
5 | 3 | [](https://travis-ci.org/mrogaski/lua-salsa20) |
6 | 4 |
|
| 5 | +__Salsa20 eStream cipher in Lua.__ |
| 6 | + |
| 7 | +The Salsa20 stream cipher was published by [Daniel J. Bernstein][1] of the University of Illinois at Chicago in 2005 and submitted to the [eSTREAM project][2]. |
| 8 | + |
| 9 | +The algorithm is an efficient and well-designed cipher. As of 2015, there are no effective attacks on this cipher. |
| 10 | + |
| 11 | +## Resources |
| 12 | + |
| 13 | +- [Salsa20 Information][3] |
| 14 | +- [Wikipedia][4] |
| 15 | +- [Salsa20 Usage and Deployment][5] |
| 16 | + |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +All byte sequences are implemented as strings, which are 8-bit clean in Lua. |
| 21 | + |
| 22 | +### generate |
| 23 | + |
| 24 | +```lua |
| 25 | +salsa20.generate(k, v, i, rounds) |
| 26 | +``` |
| 27 | +#### Arguments |
| 28 | + |
| 29 | +<dl> |
| 30 | + <dt>k</dt> |
| 31 | + <dd>A 16-byte or 32-byte sequence representing the secret key.</dd> |
| 32 | + <dt>v</dt> |
| 33 | + <dd>An 8-byte sequence representing the nonce.</dd> |
| 34 | + <dt>i</dt> |
| 35 | + <dd>An 8-byte sequence representing the stream position of the 64-byte block.</dd> |
| 36 | + <dt>rounds (optional)</dt> |
| 37 | + <dd>May be 20 (default), 12, or 8.</dd> |
| 38 | +</dl> |
| 39 | + |
| 40 | +#### Return Value |
| 41 | + |
| 42 | +A 64-byte output block. |
| 43 | + |
| 44 | + |
| 45 | +### encrypt |
| 46 | + |
| 47 | +```lua |
| 48 | +salsa20.encrypt(key, nonce, plaintext, rounds) |
| 49 | +``` |
| 50 | +#### Arguments |
| 51 | + |
| 52 | +<dl> |
| 53 | + <dt>key</dt> |
| 54 | + <dd>A 16-byte or 32-byte sequence representing the secret key.</dd> |
| 55 | + <dt>nonce</dt> |
| 56 | + <dd>An 8-byte sequence representing the nonce.</dd> |
| 57 | + <dt>plaintext</dt> |
| 58 | + <dd>The unencrypted message.</dd> |
| 59 | + <dt>rounds (optional)</dt> |
| 60 | + <dd>May be 20 (default), 12, or 8.</dd> |
| 61 | +</dl> |
| 62 | + |
| 63 | +#### Return Value |
| 64 | + |
| 65 | +The encrypted message. |
| 66 | + |
| 67 | + |
| 68 | +### encrypt_table |
| 69 | + |
| 70 | +```lua |
| 71 | +salsa20.encrypt_table(key, nonce, plaintab, rounds) |
| 72 | +``` |
| 73 | + |
| 74 | +This is a convenience function for encrypting multiple strings while maintaining state. |
| 75 | + |
| 76 | +#### Arguments |
| 77 | + |
| 78 | +<dl> |
| 79 | + <dt>key</dt> |
| 80 | + <dd>A 16-byte or 32-byte sequence representing the secret key.</dd> |
| 81 | + <dt>nonce</dt> |
| 82 | + <dd>An 8-byte sequence representing the nonce.</dd> |
| 83 | + <dt>plaintab</dt> |
| 84 | + <dd>A table containing unencrypted messages.</dd> |
| 85 | + <dt>rounds (optional)</dt> |
| 86 | + <dd>May be 20 (default), 12, or 8.</dd> |
| 87 | +</dl> |
| 88 | + |
| 89 | +#### Return Value |
| 90 | + |
| 91 | +A table containing encrypted messages. |
| 92 | + |
| 93 | + |
| 94 | +### decrypt |
| 95 | + |
| 96 | +```lua |
| 97 | +salsa20.decrypt(key, nonce, ciphertext, rounds) |
| 98 | +``` |
| 99 | +#### Arguments |
| 100 | + |
| 101 | +<dl> |
| 102 | + <dt>key</dt> |
| 103 | + <dd>A 16-byte or 32-byte sequence representing the secret key.</dd> |
| 104 | + <dt>nonce</dt> |
| 105 | + <dd>An 8-byte sequence representing the nonce.</dd> |
| 106 | + <dt>ciphertext</dt> |
| 107 | + <dd>The encrypted message.</dd> |
| 108 | + <dt>rounds (optional)</dt> |
| 109 | + <dd>May be 20 (default), 12, or 8.</dd> |
| 110 | +</dl> |
| 111 | + |
| 112 | +#### Return Value |
| 113 | + |
| 114 | +The unencrypted message. |
| 115 | + |
| 116 | + |
| 117 | +### decrypt_table |
| 118 | + |
| 119 | +```lua |
| 120 | +salsa20.decrypt_table(key, nonce, ciphertab, rounds) |
| 121 | +``` |
| 122 | + |
| 123 | +This is a convenience function for decrypting multiple strings while maintaining state. |
| 124 | + |
| 125 | +#### Arguments |
| 126 | + |
| 127 | +<dl> |
| 128 | + <dt>key</dt> |
| 129 | + <dd>A 16-byte or 32-byte sequence representing the secret key.</dd> |
| 130 | + <dt>nonce</dt> |
| 131 | + <dd>An 8-byte sequence representing the nonce.</dd> |
| 132 | + <dt>ciphertab</dt> |
| 133 | + <dd>A table containing encrypted messages.</dd> |
| 134 | + <dt>rounds (optional)</dt> |
| 135 | + <dd>May be 20 (default), 12, or 8.</dd> |
| 136 | +</dl> |
| 137 | + |
| 138 | +#### Return Value |
| 139 | + |
| 140 | +A table containing unencrypted messages. |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | +[1]: http://cr.yp.to/djb.html |
| 145 | +[2]: http://www.ecrypt.eu.org/stream/salsa20pf.html |
| 146 | +[3]: http://cr.yp.to/snuffle.html |
| 147 | +[4]: https://en.wikipedia.org/wiki/Salsa20 |
| 148 | +[5]: http://ianix.com/pub/salsa20-deployment.html |
0 commit comments