RevpropTable::RevpropTable(jobject jrevpropTable) { m_revpropTable = jrevpropTable; if (jrevpropTable != NULL) { static jmethodID keySet = 0, toArray = 0, get = 0; JNIEnv *env = JNIUtil::getEnv(); jclass mapClazz = env->FindClass("java/util/Map"); if (keySet == 0) { keySet = env->GetMethodID(mapClazz, "keySet", "()Ljava/util/Set;"); if (JNIUtil::isExceptionThrown()) return; } jobject jkeySet = env->CallObjectMethod(jrevpropTable, keySet); if (JNIUtil::isExceptionThrown()) return; if (get == 0) { get = env->GetMethodID(mapClazz, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); if (JNIUtil::isExceptionThrown()) return; } Array keyArray(jkeySet); std::vector<jobject> keys = keyArray.vector(); for (std::vector<jobject>::const_iterator it = keys.begin(); it < keys.end(); ++it) { JNIStringHolder propname((jstring)*it); if (JNIUtil::isExceptionThrown()) return; jobject jpropval = env->CallObjectMethod(jrevpropTable, get, *it); if (JNIUtil::isExceptionThrown()) return; JNIStringHolder propval((jstring)jpropval); if (JNIUtil::isExceptionThrown()) return; m_revprops[std::string((const char *)propname)] = std::string((const char *)propval); JNIUtil::getEnv()->DeleteLocalRef(jpropval); } JNIUtil::getEnv()->DeleteLocalRef(jkeySet); } }
extern "C" void CMIOInitPreferencesOnce() { // this code only executes once CACFArray keyArray( CFPreferencesCopyKeyList(CFSTR("com.apple.cmio"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost), true ); if ( keyArray.GetCFArray() ) sCMIOPrefsCache = CFPreferencesCopyMultiple( keyArray.GetCFArray(), CFSTR("com.apple.cmio"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost); #if !USE_DTRACE_LOGGING if ( sCMIOPrefsCache ) { CACFDictionary(sCMIOPrefsCache, false).GetBool(CFSTR("Debug"), sCMIODebug); } #endif }
//funzione principale unsigned initAesCuda(std::string myKeyFile, unsigned char myKeyBuffer[], const unsigned int myKeyBitsSize, std::string myInputFile, char inputArray[], const unsigned inputArraySize){ path inputPath(myInputFile.c_str()); path keyPath(myKeyFile.c_str()); if ( !exists(keyPath) ) throw std::string("file "+keyPath.string()+" doesn't exist"); if ( !exists(inputPath) ) throw std::string("file "+inputPath.string()+" doesn't exist"); if ( myKeyBitsSize!=256 && myKeyBitsSize!=128) throw std::string("cannot use a key dimension different from 256 or 128"); if ( !myKeyBuffer ) throw std::string("key array not allocated"); if ( !inputArray ) throw std::string("input array not allocated"); boost::intmax_t inputFileSize = getFileSize(inputPath); boost::intmax_t keyFileSize = getFileSize(keyPath); if ( keyFileSize==0 ) throw std::string("cannot use an empty input file"); if ( inputFileSize==0 ) throw std::string("cannot use an empty key file"); if ( inputFileSize > inputArraySize - 1 && MODE) throw std::string("cannot encrypt a file bigger than 34.603.007 bytes"); if ( inputFileSize > inputArraySize && !MODE) throw std::string("cannot decrypt a file bigger than 33MB"); //legge l'input readFromFileNotForm(inputPath, inputArray, inputFileSize); std::vector<unsigned> keyArray(myKeyBitsSize/8); unsigned ekSize = (myKeyBitsSize != 256) ? 176 : 240; std::vector<unsigned> expKeyArray(ekSize); std::vector<unsigned> invExpKeyArray(ekSize); //legge la chiave readFromFileForm(keyPath, keyArray); std::cout << "\n###############################################################\n\n"; std::cout << "AES - CUDA by Svetlin Manavski)\n\n"; std::cout << "AES " << myKeyBitsSize << " is running...." << std::endl << std::endl; std::cout << "Input file size: " << inputFileSize << " Bytes" << std::endl << std::endl; std::cout << "Key: "; for (unsigned cnt=0; cnt<keyArray.size(); ++cnt) std::cout << std::hex << keyArray[cnt]; if (MODE){ //ENCRYPTION MODE //PADDING MANAGEMENT FOLLOWING THE PKCS STANDARD unsigned mod16 = inputFileSize % 16; unsigned div16 = inputFileSize / 16; unsigned padElem; if ( mod16 != 0 ) padElem = 16 - mod16; else padElem = 16; for (unsigned cnt = 0; cnt < padElem; ++cnt) inputArray[div16*16 + mod16 + cnt] = padElem; inputFileSize = inputFileSize + padElem; //IN THE ENCRYPTION MODE I NEED THE EXPANDED KEY expFunc(keyArray, expKeyArray); for (unsigned cnt=0; cnt<expKeyArray.size(); ++cnt){ unsigned val = expKeyArray[cnt]; unsigned char *pc = reinterpret_cast<unsigned char *>(&val); myKeyBuffer[cnt] = *(pc); } } else { //DECRYPTION MODE //IN THE ENCRYPTION MODE I NEED THE INVERSE EXPANDED KEY expFunc(keyArray, expKeyArray); invExpFunc(expKeyArray, invExpKeyArray); for (unsigned cnt=0; cnt<invExpKeyArray.size(); ++cnt){ unsigned val = invExpKeyArray[cnt]; unsigned char *pc = reinterpret_cast<unsigned char *>(&val); myKeyBuffer[cnt] = *(pc); } } std::cout << std::endl; return inputFileSize; }
PropertyTable::PropertyTable(jobject jrevpropTable, bool bytearray_values) { m_revpropTable = jrevpropTable; if (jrevpropTable != NULL) { static jmethodID keySet = 0, get = 0; JNIEnv *env = JNIUtil::getEnv(); jclass mapClazz = env->FindClass("java/util/Map"); if (keySet == 0) { keySet = env->GetMethodID(mapClazz, "keySet", "()Ljava/util/Set;"); if (JNIUtil::isExceptionThrown()) return; } jobject jkeySet = env->CallObjectMethod(jrevpropTable, keySet); if (JNIUtil::isExceptionThrown()) return; if (get == 0) { get = env->GetMethodID(mapClazz, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); if (JNIUtil::isExceptionThrown()) return; } Array keyArray(jkeySet); std::vector<jobject> keys = keyArray.vector(); for (std::vector<jobject>::const_iterator it = keys.begin(); it < keys.end(); ++it) { JNIStringHolder propname((jstring)*it); if (JNIUtil::isExceptionThrown()) return; jobject jpropval = env->CallObjectMethod(jrevpropTable, get, *it); if (JNIUtil::isExceptionThrown()) return; std::string pv; if (bytearray_values) { JNIByteArray propval((jbyteArray)jpropval); if (JNIUtil::isExceptionThrown()) return; if (!propval.isNull()) pv = std::string( reinterpret_cast<const char*>(propval.getBytes()), propval.getLength()); } else { JNIStringHolder propval((jstring)jpropval); if (JNIUtil::isExceptionThrown()) return; if (NULL != static_cast<const char *>(propval)) pv = static_cast<const char *>(propval); } m_revprops[std::string(static_cast<const char *>(propname))] = pv; JNIUtil::getEnv()->DeleteLocalRef(jpropval); } JNIUtil::getEnv()->DeleteLocalRef(jkeySet); } }