ts_Sha2.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 
00024 #include <icl_core_crypt/Sha2.h>
00025 
00026 #include <boost/test/unit_test.hpp>
00027 
00028 using ::icl_core::crypt::Sha224;
00029 using ::icl_core::crypt::Sha256;
00030 using ::icl_core::crypt::Sha384;
00031 using ::icl_core::crypt::Sha512;
00032 
00033 BOOST_AUTO_TEST_SUITE(ts_Sha2)
00034 
00035 //----------------------------------------------------------------------
00036 // Empty strings
00037 //----------------------------------------------------------------------
00038 
00039 BOOST_AUTO_TEST_CASE(EmptyStringDigestSha224)
00040 {
00041   Sha224 sha;
00042   sha.finalize();
00043   BOOST_CHECK_EQUAL(sha.getHexDigest(), "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f");
00044 }
00045 
00046 BOOST_AUTO_TEST_CASE(EmptyStringDigestSha256)
00047 {
00048   Sha256 sha;
00049   sha.finalize();
00050   BOOST_CHECK_EQUAL(sha.getHexDigest(), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
00051 }
00052 
00053 BOOST_AUTO_TEST_CASE(EmptyStringDigestSha384)
00054 {
00055   Sha384 sha;
00056   sha.finalize();
00057   BOOST_CHECK_EQUAL(sha.getHexDigest(), "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b");
00058 }
00059 
00060 BOOST_AUTO_TEST_CASE(EmptyStringDigestSha512)
00061 {
00062   Sha512 sha;
00063   sha.finalize();
00064   BOOST_CHECK_EQUAL(sha.getHexDigest(), "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
00065 }
00066 
00067 //----------------------------------------------------------------------
00068 // The quick brown fox
00069 //----------------------------------------------------------------------
00070 
00071 const char *teststring1 = "The quick brown fox jumps over the lazy dog";
00072 const char *teststring2 = "The quick brown fox jumps over the lazy dog.";
00073 
00074 BOOST_AUTO_TEST_CASE(SimpleStringDigestSha224)
00075 {
00076   Sha224 sha;
00077   sha.process(teststring1);
00078   sha.finalize();
00079   BOOST_CHECK_EQUAL(sha.getHexDigest(), "730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525");
00080   sha.clear();
00081   sha.process(teststring2);
00082   sha.finalize();
00083   BOOST_CHECK_EQUAL(sha.getHexDigest(), "619cba8e8e05826e9b8c519c0a5c68f4fb653e8a3d8aa04bb2c8cd4c");
00084 }
00085 
00086 BOOST_AUTO_TEST_CASE(SimpleStringDigestSha256)
00087 {
00088   Sha256 sha;
00089   sha.process(teststring1);
00090   sha.finalize();
00091   BOOST_CHECK_EQUAL(sha.getHexDigest(), "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592");
00092   sha.clear();
00093   sha.process(teststring2);
00094   sha.finalize();
00095   BOOST_CHECK_EQUAL(sha.getHexDigest(), "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c");
00096 }
00097 
00098 BOOST_AUTO_TEST_CASE(SimpleStringDigestSha384)
00099 {
00100   Sha384 sha;
00101   sha.process(teststring1);
00102   sha.finalize();
00103   BOOST_CHECK_EQUAL(sha.getHexDigest(), "ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1");
00104   sha.clear();
00105   sha.process(teststring2);
00106   sha.finalize();
00107   BOOST_CHECK_EQUAL(sha.getHexDigest(), "ed892481d8272ca6df370bf706e4d7bc1b5739fa2177aae6c50e946678718fc67a7af2819a021c2fc34e91bdb63409d7");
00108 }
00109 
00110 BOOST_AUTO_TEST_CASE(SimpleStringDigestSha512)
00111 {
00112   Sha512 sha;
00113   sha.process(teststring1);
00114   sha.finalize();
00115   BOOST_CHECK_EQUAL(sha.getHexDigest(), "07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6");
00116   sha.clear();
00117   sha.process(teststring2);
00118   sha.finalize();
00119   BOOST_CHECK_EQUAL(sha.getHexDigest(), "91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed");
00120 }
00121 
00122 //----------------------------------------------------------------------
00123 // Longer string consisting of more than one message block
00124 //----------------------------------------------------------------------
00125 
00126 const char *longstring =
00127   "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam "
00128   "lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam "
00129   "viverra nec consectetur ante hendrerit. Donec et mollis "
00130   "dolor. Praesent et diam eget libero egestas mattis sit amet vitae "
00131   "augue. Nam tincidunt congue enim, ut porta lorem lacinia "
00132   "consectetur. Donec ut libero sed arcu vehicula ultricies a non "
00133   "tortor. Lorem ipsum dolor sit amet, consectetur adipiscing "
00134   "elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper "
00135   "sed, adipiscing id dolor. Pellentesque auctor nisi id magna "
00136   "consequat sagittis. Curabitur dapibus enim sit amet elit pharetra "
00137   "tincidunt feugiat nisl imperdiet. Ut convallis libero in urna "
00138   "ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam "
00139   "pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et "
00140   "magnis dis parturient montes, nascetur ridiculus mus. In rutrum "
00141   "accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in "
00142   "est.\n"
00143   "Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut "
00144   "tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper "
00145   "ultricies. Curabitur ornare, ligula semper consectetur sagittis, "
00146   "nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, "
00147   "odio nec pretium volutpat, arcu ante placerat erat, non tristique "
00148   "elit urna et turpis. Quisque mi metus, ornare sit amet fermentum "
00149   "et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut "
00150   "dolor diam, elementum et vestibulum eu, porttitor vel "
00151   "elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et "
00152   "erat faucibus nunc euismod ultricies ut id justo. Nullam cursus "
00153   "suscipit nisi, et ultrices justo sodales nec. Fusce venenatis "
00154   "facilisis lectus ac semper. Aliquam at massa ipsum. Quisque "
00155   "bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, "
00156   "mi eu aliquam tincidunt, purus velit laoreet tortor, viverra "
00157   "pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis "
00158   "nisi dui.\n";
00159 
00160 BOOST_AUTO_TEST_CASE(LongStringDigestSha224)
00161 {
00162   Sha224 sha;
00163   sha.process(longstring);
00164   sha.finalize();
00165   BOOST_CHECK_EQUAL(sha.getHexDigest(), "9319b8ec0551910b30009ba504103bbdbb1e02ed8e9247320e01dccf");
00166 }
00167 
00168 BOOST_AUTO_TEST_CASE(LongStringDigestSha256)
00169 {
00170   Sha256 sha;
00171   sha.process(longstring);
00172   sha.finalize();
00173   BOOST_CHECK_EQUAL(sha.getHexDigest(), "93ba6b27717ba945b8f43e9ad1d44dc02123b13f9000eb4b25b8a153422b6677");
00174 }
00175 
00176 BOOST_AUTO_TEST_CASE(LongStringDigestSha384)
00177 {
00178   Sha384 sha;
00179   sha.process(longstring);
00180   sha.finalize();
00181   BOOST_CHECK_EQUAL(sha.getHexDigest(), "866e65e74170721a59ced427e884d1e25a1d62862387af2004d30549e3e05a34875283c2d1fd2aa13989fff8b6ecad9f");
00182 }
00183 
00184 BOOST_AUTO_TEST_CASE(LongStringDigestSha512)
00185 {
00186   Sha512 sha;
00187   sha.process(longstring);
00188   sha.finalize();
00189   BOOST_CHECK_EQUAL(sha.getHexDigest(), "aff2b51a8c5555603914381005f6f46bec85793610e89cf9a3517ff3b9e98c7e5e1a636f0b46b1288478d30ec83c434d5e07f86ca6ed8507a9a8b03d63d1f5c7");
00190 }
00191 
00192 //----------------------------------------------------------------------
00193 // String ending exactly one byte before the padding boundary
00194 //----------------------------------------------------------------------
00195 
00196 const char *padstring256_440bit = "....:....|....:....|....:....|....:....|....:....|....:";
00197 const char *padstring512_888bit = "....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|.";
00198 
00199 BOOST_AUTO_TEST_CASE(Pad440Sha224)
00200 {
00201   Sha224 sha;
00202   sha.process(padstring256_440bit);
00203   sha.finalize();
00204   BOOST_CHECK_EQUAL(sha.getHexDigest(), "a526362dae0b4aa0fdd4966ed84d51f6ab3dbff574f75613e8f21ba2");
00205 }
00206 
00207 BOOST_AUTO_TEST_CASE(Pad440Sha256)
00208 {
00209   Sha256 sha;
00210   sha.process(padstring256_440bit);
00211   sha.finalize();
00212   BOOST_CHECK_EQUAL(sha.getHexDigest(), "d0c06dbf5fec4c438d6cacf1113435e7e504ed45c04efb5cb70776f1d391e4d9");
00213 }
00214 
00215 BOOST_AUTO_TEST_CASE(Pad888Sha384)
00216 {
00217   Sha384 sha;
00218   sha.process(padstring512_888bit);
00219   sha.finalize();
00220   BOOST_CHECK_EQUAL(sha.getHexDigest(), "ac807c831aa023556137b6aeaf0b1ec33ff24c99a858ffe97a1926dfd99f3f4cb81b0afd61ff29f01ea5f8851a22ee28");
00221 }
00222 
00223 BOOST_AUTO_TEST_CASE(Pad888Sha512)
00224 {
00225   Sha512 sha;
00226   sha.process(padstring512_888bit);
00227   sha.finalize();
00228   BOOST_CHECK_EQUAL(sha.getHexDigest(), "d3818ef0619071407cab75933bee598cf8b26976d3c51cade7bd86ebc951e5ce53cd18d3784f152bb2536622c6538331f42c2f44f811dd9a75ae345ec7dd060e");
00229 }
00230 
00231 //----------------------------------------------------------------------
00232 // String ending exactly on the padding boundary
00233 //----------------------------------------------------------------------
00234 
00235 const char *padstring256_448bit = "....:....|....:....|....:....|....:....|....:....|....:.";
00236 const char *padstring512_896bit = "....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|..";
00237 
00238 BOOST_AUTO_TEST_CASE(Pad448Sha224)
00239 {
00240   Sha224 sha;
00241   sha.process(padstring256_448bit);
00242   sha.finalize();
00243   BOOST_CHECK_EQUAL(sha.getHexDigest(), "a95081d421a9576d6507b21bab994a139dab99241cc70a1bc4db8763");
00244 }
00245 
00246 BOOST_AUTO_TEST_CASE(Pad448Sha256)
00247 {
00248   Sha256 sha;
00249   sha.process(padstring256_448bit);
00250   sha.finalize();
00251   BOOST_CHECK_EQUAL(sha.getHexDigest(), "5f237fc93336874639ea7fe7a2f55e58b954946f90ab3254f6a93ad33562279f");
00252 }
00253 
00254 BOOST_AUTO_TEST_CASE(Pad896Sha384)
00255 {
00256   Sha384 sha;
00257   sha.process(padstring512_896bit);
00258   sha.finalize();
00259   BOOST_CHECK_EQUAL(sha.getHexDigest(), "c2343fcfe20cedf0ff1314b03002d710d963928687bcc29ca66ed4891bc8ccecb9601771fa8119241f756a7d55b4117b");
00260 }
00261 
00262 BOOST_AUTO_TEST_CASE(Pad896Sha512)
00263 {
00264   Sha512 sha;
00265   sha.process(padstring512_896bit);
00266   sha.finalize();
00267   BOOST_CHECK_EQUAL(sha.getHexDigest(), "ada0d27f302ed4fec585ee259b0590454e159d023befd97782c6fad093284463bc0c366acfed361359d6f63de07291e8039abbe0366c89ee4ad3d67e244fdd04");
00268 }
00269 
00270 //----------------------------------------------------------------------
00271 // String ending exactly one byte after the padding boundary
00272 //----------------------------------------------------------------------
00273 
00274 const char *padstring256_456bit = "....:....|....:....|....:....|....:....|....:....|....:..";
00275 const char *padstring512_904bit = "....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|....:....|...";
00276 
00277 BOOST_AUTO_TEST_CASE(Pad456Sha224)
00278 {
00279   Sha224 sha;
00280   sha.process(padstring256_456bit);
00281   sha.finalize();
00282   BOOST_CHECK_EQUAL(sha.getHexDigest(), "d6c17098edf2463cd98f9f97c58fca8a881d0e83802193c81742129a");
00283 }
00284 
00285 BOOST_AUTO_TEST_CASE(Pad456Sha256)
00286 {
00287   Sha256 sha;
00288   sha.process(padstring256_456bit);
00289   sha.finalize();
00290   BOOST_CHECK_EQUAL(sha.getHexDigest(), "a1d509b8f4d8fac578e40b57273c8d665e2716fe2446b32e25d2d10eb218bd0e");
00291 }
00292 
00293 BOOST_AUTO_TEST_CASE(Pad904Sha384)
00294 {
00295   Sha384 sha;
00296   sha.process(padstring512_904bit);
00297   sha.finalize();
00298   BOOST_CHECK_EQUAL(sha.getHexDigest(), "392bc91f4da2a2f545f19a911fcf5072c8fa7a8909ed1ee9175d17af587f213a02c3a0acf8ee6868129b383c70bb2cc6");
00299 }
00300 
00301 BOOST_AUTO_TEST_CASE(Pad904Sha512)
00302 {
00303   Sha512 sha;
00304   sha.process(padstring512_904bit);
00305   sha.finalize();
00306   BOOST_CHECK_EQUAL(sha.getHexDigest(), "73ce0c347018a80cb9781cc0eb302e43b35384db671c512f31c369c89e2b4ad6ea1cfe59abcc3698b7c7bc01c776e67e804f93823730244a9620d6526baee3da");
00307 }
00308 
00309 BOOST_AUTO_TEST_SUITE_END()


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:19