Sorry..deleted that just before your reply appeared.  On further 
consideration I also realized that although I just got some code to work, I 
shouldn't assume it's a non-issue till the cross-validation you discussed 
was done.  But apologies in advanve if this is a non-issue.

So first, my original post, followed by new code that appears to work:



Threefish-1024 IV specification issue/doumentaion...or bug?

There appears to be a problem setting the longer IV required for
threefish-1024.  My code (modified from code on the wiki) works
for -256 but nothing I've tried works for -1024.

The problem might be in documentation of something specific to
threefish-1024, though it might be related to

threefish.h:
41:   CRYPTOPP_CONSTANT(IV_LENGTH=32)

which is described as NOT_RESYNCHRONIZABLE [though I don't know 
whether this is in the sense pertaining to IV length] and is not 
varied for different cases as the keylength is nearby.

But the benchmark suggests there's a way around this if it's not 
misreporting.

Crypto++ 6.0.0 Benchmarks
Threefish/CTR (1024-bit key)    61    25.2    0.918    1469

Here's what I get with similar code for threefish-256 and 
threefish-1024:

$ ./threefish256try
IV_LENGTH: 32
Algorithm:
  Threefish/CTR
Maximum Key Size:
  128 bytes

Plain Text (12 bytes)
  'Hello World.'

Recovered Text:
  'Hello World.'


$ ./threefish1024try 
IV_LENGTH: 128
terminate called after throwing an instance of 'CryptoPP::InvalidArgument'
  what():  Threefish/CTR: IV length 32 is less than the minimum of 128
Aborted (core dumped)

==============================

code for 1024:

// threefish1024try.cpp
//based on
// 
https://web.archive.org/web/20150315102342/http://www.cryptopp.com/fom-serve/cache/79.html
//2006-Jan-21 11:08am jason entry

// g++ -g3 -O2 -Wall -Wextra  threefish1024try.cpp -o threefish1024try 
-I/usr/local/include/cryptopp -L/usr/local/lib -lcryptopp


#include <iostream>
//#include <iomanip>

// Crypto++ Includes
#include "cryptlib.h"
#include "modes.h"      // xxx_Mode< >
#include "filters.h"    // StringSource and
#include "threefish.h"

#define CIPHER_MODE CTR_Mode
#define CIPHER Threefish

#define BLOCKSIZE 128
#define IV_LENGTH 128

// using namespace CryptoPP;

int main(int argc, char* argv[]) {
    std::cout << "IV_LENGTH: " <<  IV_LENGTH << std::endl; 
    
    CryptoPP::byte key[ CryptoPP::CIPHER::MAX_KEYLENGTH ], 
                    iv[ IV_LENGTH ];

    ::memset( key, 0x01, CryptoPP::CIPHER::MAX_KEYLENGTH );
    ::memset(  iv, 0x01, IV_LENGTH );
    
    // Message M
    std::string PlainText = "Hello World.";

    // Cipher Text Sink
    std::string CipherText;

    // Encryptor
    CryptoPP::CTR_Mode<CryptoPP::Threefish >::Encryption
        Encryptor( key, CryptoPP::CIPHER::MAX_KEYLENGTH, iv );


    // Encryption
    CryptoPP::StringSource( PlainText, true,
        new CryptoPP::StreamTransformationFilter( Encryptor,
            new CryptoPP::StringSink( CipherText )
        ) // StreamTransformationFilter
    ); // StringSource


    ///////////////////////////////////////
    //                DMZ                //
    ///////////////////////////////////////

    // Recovered Text Sink
    std::string RecoveredText;

    // Decryptor
    CryptoPP::CIPHER_MODE<CryptoPP::CIPHER >::Decryption
        Decryptor( key, CryptoPP::CIPHER::MAX_KEYLENGTH, iv );

    // Decryption
    CryptoPP::StringSource( CipherText, true,
        new CryptoPP::StreamTransformationFilter( Decryptor,
            new CryptoPP::StringSink( RecoveredText )
        ) // StreamTransformationFilter
    ); // StringSource

    //////////////////////////////////////////
    //                Output                //
    //////////////////////////////////////////

    std::cout << "Algorithm:" << std::endl;
    std::cout << "  " << Encryptor.AlgorithmName() << std::endl;
    std::cout << "Maximum Key Size:" << std::endl;
    std::cout << "  " << Encryptor.MaxKeyLength() << " bytes" << std::endl;
    std::cout << std::endl;


    std::cout << "Plain Text (" << PlainText.length() << " bytes)" << 
std::endl;
    std::cout << "  '" << PlainText << "'" << std::endl;
    std::cout << std::endl;

    std::cout << "Recovered Text:" << std::endl;
    std::cout << "  '" << RecoveredText << "'" << std::endl;
    std::cout << std::endl;

    return 0;
}



==============================
==============================

Result for new code:
$ ./threefish1024try2IV_LENGTH: 128
Algorithm:
  Threefish/CTR
Maximum Key Size:
  128 bytes

Plain Text (12 bytes)
  'Hello World.'

Recovered Text:
  'Hello World.'


==============================

new code:

// threefish1024try2.cpp
//based on
// 
https://web.archive.org/web/20150315102342/http://www.cryptopp.com/fom-serve/cache/79.html
//2006-Jan-21 11:08am jason entry

// g++ -g3 -O2 -Wall -Wextra  threefish1024try2.cpp -o threefish1024try2 
-I/usr/local/include/cryptopp -L/usr/local/lib -lcryptopp


#include <iostream>
//#include <iomanip>

// Crypto++ Includes
#include "cryptlib.h"
#include "modes.h"      // xxx_Mode< >
#include "filters.h"    // StringSource and
#include "threefish.h"

#define CIPHER_MODE CTR_Mode
#define CIPHER Threefish

#define BLOCKSIZE 128
#define KEY_LENGTH 128
#define IV_LENGTH 128

// using namespace CryptoPP;

int main(int argc, char* argv[]) {
    std::cout << "IV_LENGTH: " <<  IV_LENGTH << std::endl; 
    
    CryptoPP::byte key[ CryptoPP::CIPHER::MAX_KEYLENGTH ], 
                    iv[ IV_LENGTH ];

    ::memset( key, 0x01, CryptoPP::CIPHER::MAX_KEYLENGTH );
    ::memset(  iv, 0x01, IV_LENGTH );
    
    // Message M
    std::string PlainText = "Hello World.";

    // Cipher Text Sink
    std::string CipherText;

    // Encryptor
    CryptoPP::CTR_Mode<CryptoPP::Threefish >::Encryption
        Encryptor; //( key, CryptoPP::CIPHER::MAX_KEYLENGTH, iv, IV_LENGTH 
);

    Encryptor.SetKeyWithIV(key, KEY_LENGTH, iv, IV_LENGTH);
//     Encryptor.SetKeyWithIV(key, key.size(), iv, iv.size());

    // Encryption
    CryptoPP::StringSource( PlainText, true,
        new CryptoPP::StreamTransformationFilter( Encryptor,
            new CryptoPP::StringSink( CipherText )
        ) // StreamTransformationFilter
    ); // StringSource


    ///////////////////////////////////////
    //                DMZ                //
    ///////////////////////////////////////

    // Recovered Text Sink
    std::string RecoveredText;

    // Decryptor
    CryptoPP::CIPHER_MODE<CryptoPP::CIPHER >::Decryption
        Decryptor;//( key, CryptoPP::CIPHER::MAX_KEYLENGTH, iv, IV_LENGTH );
    
    Decryptor.SetKeyWithIV(key, KEY_LENGTH, iv, IV_LENGTH);

    // Decryption
    CryptoPP::StringSource( CipherText, true,
        new CryptoPP::StreamTransformationFilter( Decryptor,
            new CryptoPP::StringSink( RecoveredText )
        ) // StreamTransformationFilter
    ); // StringSource

    //////////////////////////////////////////
    //                Output                //
    //////////////////////////////////////////

    std::cout << "Algorithm:" << std::endl;
    std::cout << "  " << Encryptor.AlgorithmName() << std::endl;
    std::cout << "Maximum Key Size:" << std::endl;
    std::cout << "  " << Encryptor.MaxKeyLength() << " bytes" << std::endl;
    std::cout << std::endl;


    std::cout << "Plain Text (" << PlainText.length() << " bytes)" << 
std::endl;
    std::cout << "  '" << PlainText << "'" << std::endl;
    std::cout << std::endl;

    std::cout << "Recovered Text:" << std::endl;
    std::cout << "  '" << RecoveredText << "'" << std::endl;
    std::cout << std::endl;

    return 0;
}








-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to cryptopp-users-unsubscr...@googlegroups.com.
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to