Last active
April 7, 2016 12:06
-
-
Save JoeAlamo/b225e7c7736c34424e42f88b63ebb8e4 to your computer and use it in GitHub Desktop.
Revisions
-
JoeAlamo revised this gist
Apr 7, 2016 . 1 changed file with 19 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,36 @@ <?php // vectors $key = pack('H*', '1C9240A5EB55D38AF333888604F6B5F0473917C1402B80099DCA5CBC207075C0'); $nonce = pack('H*', '0102030405060708'); $additionalData = pack('H*', 'F33388860000000000004E91'); $plaintext = pack('H*', '496E7465726E65742D4472616674732061726520647261667420646F63756D656E74732076616C696420666F722061206D6178696D756D206F6620736978206D6F6E74687320616E64206D617920626520757064617465642C207265706C616365642C206F72206F62736F6C65746564206279206F7468657220646F63756D656E747320617420616E792074696D652E20497420697320696E617070726F70726961746520746F2075736520496E7465726E65742D447261667473206173207265666572656E6365206D6174657269616C206F7220746F2063697465207468656D206F74686572207468616E206173202FE2809C776F726B20696E2070726F67726573732E2FE2809D'); $plaintextLen = mb_strlen($plaintext, '8bit'); $expectedTag = pack('H*', 'EEAD9D67890CBB22392336FEA1851F38'); $ciphertext = \Sodium\crypto_aead_chacha20poly1305_encrypt($plaintext, $additionalData, $nonce, $key); $actualTag = substr($ciphertext, $plaintextLen, 16); echo '<pre>'; echo "KEY:\n"; echo bin2hex($key); echo "\nPLAINTEXT:\n"; echo bin2hex($plaintext); echo "\nADDITIONAL DATA:\n"; echo bin2hex($additionalData); echo "\nNONCE:\n"; echo bin2hex($nonce); echo "\nEXPECTED TAG:\n"; echo bin2hex($expectedTag); echo "\nCIPHERTEXT:\n"; echo bin2hex($ciphertext); echo "\nACTUAL TAG:\n"; echo bin2hex($actualTag); echo '</pre>'; -
JoeAlamo created this gist
Apr 6, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ <?php // vectors $key = base64_decode('HJJApetV04rzM4iGBPa18Ec5F8FAK4AJncpcvCBwdcA='); $nonce = base64_decode('AQIDBAUGBwg='); $additionalData = base64_decode('8zOIhgAAAAAAAE6R'); $plaintext = base64_decode('SW50ZXJuZXQtRHJhZnRzIGFyZSBkcmFmdCBkb2N1bWVudHMgdmFsaWQgZm9yIGEgbWF4aW11bSBvZiBzaXggbW9udGhzIGFuZCBtYXkgYmUgdXBkYXRlZCwgcmVwbGFjZWQsIG9yIG9ic29sZXRlZCBieSBvdGhlciBkb2N1bWVudHMgYXQgYW55IHRpbWUuIEl0IGlzIGluYXBwcm9wcmlhdGUgdG8gdXNlIEludGVybmV0LURyYWZ0cyBhcyByZWZlcmVuY2UgbWF0ZXJpYWwgb3IgdG8gY2l0ZSB0aGVtIG90aGVyIHRoYW4gYXMgL+KAnHdvcmsgaW4gcHJvZ3Jlc3MuL+KAnQ=='); $ciphertext = \Sodium\crypto_aead_chacha20poly1305_encrypt($plaintext, $additionalData, $nonce, $key); echo "KEY:\n"; echo bin2hex($key); echo "\nPLAINTEXT:\n"; echo $plaintext; echo "\nADDITIONAL DATA:\n"; echo bin2hex($additionalData); echo "\nNONCE:\n"; echo bin2hex($nonce); echo "\nCIPHERTEXT:\n"; echo bin2hex($ciphertext);