Results 1 to 6 of 6

Thread: Crypto++ How do I use a message authentication code ?

  1. #1
    Join Date
    Jun 2010
    Posts
    102
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Crypto++ How do I use a message authentication code ?

    i want use VMAC in crypto++ lib on QT,i was tried study but i dont find example of it

    can you help me
    can i use Funcition DefaultDecryptorWithMAC ?
    FileSource f(in, true, new DefaultDecryptorWithMAC(passPhrase, new FileSink(out)));

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Crypto++ How do I use a message authentication code ?

    Hi, you can use any C++ library together with Qt (which is just a library itself) so you don't need special examples, any examples you find for crypto++ will be fine.
    Crypto++ should provide something.

    Ginsengelf

  3. #3
    Join Date
    Jun 2010
    Posts
    102
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Crypto++ How do I use a message authentication code ?

    can you help me for VMAC use Crypto++ ?

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crypto++ How do I use a message authentication code ?

    This isn't a Qt question. You need to post to the crypto++ mailing list if you don't understand how to use the library.

  5. #5
    Join Date
    Jun 2010
    Posts
    102
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Crypto++ How do I use a message authentication code ?

    Qt Code:
    1. void VmacFile(const char *hexKey, const char *hexIV, const char *infile, const char *outfile)
    2. {
    3. SecByteBlock keyBlock = HexDecodeString(hexKey);
    4. SecByteBlock iv = HexDecodeString(hexIV);
    5. VMAC<AES,128 > vmacEncryptFile;
    6. vmacEncryptFile.SetKeyWithIV(keyBlock, keyBlock.size(), iv);
    7. CryptoPP::VMAC<CryptoPP::AES, 64> hasher;
    8. //vmacEncryptFile.Resynchronize(pbIV2);
    9. FileSource(infile, true, new IteratedHashBase(vmacEncryptFile, new FileSink(outfile)));
    10. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. #include <vector>
    2. #include "vmac.h"
    3. using namespace std;
    4. void TestVMac( int _num, vector<uint64> *_res )
    5. {
    6. const char key[16] = "somedummykey345";
    7. const byte pattern[100] = {
    8. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    9. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    10. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    11. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    12. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    13. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    14. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    15. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    16. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    17. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    18. if ( sizeof(pattern) < _num )
    19. _num = sizeof(pattern);
    20. const uint64 nonce[2] = { 0x10, 0x0 };
    21. CryptoPP::VMAC<CryptoPP::AES, 64> hasher;
    22. hasher.SetKey( (byte*)key, 16, CryptoPP::MakeParameters
    23. ( CryptoPP::Name::IV(), (const byte*)&nonce, false )
    24. ( CryptoPP::Name::KeySize(), 128 ) );
    25. _res->clear();
    26. for ( size_t i = 1, e = _num; i != e; ++ i )
    27. {
    28. uint64 cv;
    29. hasher.Resynchronize( (const byte*)nonce );
    30. hasher.CalculateDigest( (byte*)&cv, pattern, i );
    31. _res->push_back( cv );
    32. }
    33. }
    34. int main(int argc, char *argv[])
    35. {
    36. QCoreApplication a(argc, argv);
    37. return a.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jun 2010
    Posts
    102
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Crypto++ How do I use a message authentication code ?

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include "vmac.h"
    3. #include <stdlib.h>
    4. #include <stdio.h>
    5. #include <time.h>
    6. #include <string.h>
    7.  
    8. unsigned prime(void)
    9. {
    10. volatile uint64_t i;
    11. volatile uint64_t j=1;
    12. unsigned cnt=0;
    13. volatile clock_t ticks = clock();
    14. do
    15. {
    16. for (i = 0; i < 500000; i++)
    17. {
    18. uint64_t x = get64PE(&j);
    19. j = x * x + (uint64_t)ticks;
    20. }
    21. cnt++;
    22. } while (clock() - ticks < (CLOCKS_PER_SEC / 2));
    23. return cnt; /* cnt is millions of iterations per second */
    24. }
    25.  
    26. int main(int argc, char *argv[])
    27. {
    28. QCoreApplication a(argc, argv);
    29. ALIGN(16) vmac_ctx_t ctx, ctx_aio, ctx_inc1, ctx_inc2;
    30. uint64_t res, tagl;
    31. void *p;
    32. unsigned char *pbData;
    33. ALIGN(4) unsigned char pbKey[] = "abcdefghijklmnop";
    34. ALIGN(4) unsigned char nonce[] = "\0\0\0\0\0\0\0\0bcdefghi";
    35. unsigned int uiVectorLength[] = {0,3,48,300,3000000};
    36. #if (VMAC_TAG_LEN == 64)
    37. ALIGN(4) char *should_be[] = {"2576BE1C56D8B81B","2D376CF5B1813CE5",
    38. "E8421F61D573D298","4492DF6C5CAC1BBE",
    39. "09BA597DD7601113"};
    40. #else
    41. ALIGN(4) char *should_be[] =
    42. { "472766C70F74ED23481D6D7DE4E80DAC",
    43. "4EE815A06A1D71EDD36FC75D51188A42",
    44. "09F2C80C8E1007A0C12FAE19FE4504AE",
    45. "66438817154850C61D8A412164803BCB",
    46. "2B6B02288FFC461B75485DE893C629DC"};
    47. #endif
    48. unsigned speed_lengths[] = {16, 32, 64, 128, 256, 512, 1024, 2048, 4096};
    49. unsigned i, j, *speed_iters;
    50. clock_t ticks;
    51. double cpb;
    52. const unsigned int buf_len = 3 * (1 << 20);
    53. j = prime();
    54. i = sizeof(speed_lengths)/sizeof(speed_lengths[0]);
    55. speed_iters = (unsigned *)malloc(i*sizeof(speed_iters[0]));
    56. speed_iters[i-1] = j * (1 << 12);
    57. while (--i)
    58. {
    59. speed_iters[i-1] = (unsigned)(1.3 * speed_iters[i]);
    60. }
    61. /* Initialize context and message buffer, all 16-byte aligned */
    62. p = malloc(buf_len + 32);
    63. pbData = (unsigned char *)(((size_t)p + 16) & ~((size_t)15));
    64. memset(pbData, 0, buf_len + 16);
    65. vmac_set_key(pbKey, &ctx);
    66. /* Test incremental and all-in-one interfaces for correctness */
    67. vmac_set_key(pbKey, &ctx_aio);
    68. vmac_set_key(pbKey, &ctx_inc1);
    69. vmac_set_key(pbKey, &ctx_inc2);
    70. /* Generate vectors */
    71. for (i = 0; i < sizeof(uiVectorLength)/sizeof(unsigned int); i++)
    72. {
    73. for (j = 0; j < uiVectorLength[i]; j++)
    74. {
    75. pbData[j] = (unsigned char)('a'+j%3);
    76. }
    77. res = vmac(pbData, uiVectorLength[i], nonce, &tagl, &ctx);
    78. #if (VMAC_TAG_LEN == 64)
    79. printf("\'abc\' * %7u: %016llX Should be: %s\n",
    80. uiVectorLength[i]/3,res,should_be[i]);
    81. #else
    82. printf("\'abc\' * %7u: %016llX%016llX\nShould be: %s\n",uiVectorLength[i]/3,res,tagl,should_be[i]);
    83. #endif
    84. }
    85. /* Speed test */
    86. for (i = 0; i < sizeof(speed_lengths)/sizeof(unsigned int); i++)
    87. {
    88. ticks = clock();
    89. for (j = 0; j < speed_iters[i]; j++)
    90. {
    91. #if HASH_ONLY
    92. res = vhash(pbData, speed_lengths[i], &tagl, &ctx);
    93. #else
    94. res = vmac(pbData, speed_lengths[i], nonce, &tagl, &ctx);
    95. nonce[7]++;
    96. #endif
    97. }
    98. ticks = clock() - ticks;
    99. cpb = ((ticks*VMAC_HZ)/((double)CLOCKS_PER_SEC*speed_lengths[i]*speed_iters[i]));
    100. printf("%4u bytes, %2.2f cpb\n", speed_lengths[i], cpb);
    101. }
    102. return a.exec();
    103. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Howto: Qt and RSA crypto
    By jonks in forum Qt Programming
    Replies: 15
    Last Post: 21st April 2010, 15:15
  2. crypto
    By unix7777 in forum Installation and Deployment
    Replies: 0
    Last Post: 24th March 2010, 15:47
  3. Problem in crypto :: RSA
    By erfanonline in forum Qt Programming
    Replies: 3
    Last Post: 21st March 2009, 21:40
  4. Crypto++ and Qt
    By vermarajeev in forum Qt Programming
    Replies: 19
    Last Post: 1st March 2007, 03:41
  5. Crypto++ and Qt3.3.5
    By vermarajeev in forum General Programming
    Replies: 1
    Last Post: 9th February 2007, 07:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.