// triangle tests TEUCHOS_UNIT_TEST(tSTK_IO, fields) { RCP<STK_Interface> mesh = buildMesh(8,8); std::map<std::string,Teuchos::RCP<std::vector<std::size_t> > > localIds; buildLocalIds(*mesh,localIds); FieldContainer vert0, vert1; out << "get vertices" << std::endl; mesh->getElementVertices(*localIds["eblock-0_0"],vert0); mesh->getElementVertices(*localIds["eblock-1_0"],vert1); FieldContainer ublock0, tblock0, tblock1; ublock0.resize(localIds["eblock-0_0"]->size(),4); tblock0.resize(localIds["eblock-0_0"]->size(),4); tblock1.resize(localIds["eblock-1_0"]->size(),4); out << "assigning" << std::endl; assignBlock(ublock0,vert0,xval); assignBlock(tblock0,vert0,yval); assignBlock(tblock1,vert1,block2); mesh->setSolutionFieldData("u","eblock-0_0",*localIds["eblock-0_0"],ublock0); mesh->setSolutionFieldData("T","eblock-0_0",*localIds["eblock-0_0"],tblock0); mesh->setSolutionFieldData("T","eblock-1_0",*localIds["eblock-1_0"],tblock1); out << "write to exodus" << std::endl; mesh->writeToExodus("output.exo"); }
void WaspAES::CBCEncrypt(uint8_t *original_data,uint16_t size, uint8_t *InitialVector,uint16_t keySize){ /////////////////////////// // In CBC mode the message is divided into blocks of 16 bytes, to 1 block // Applied to the XOR and calculated its block cipher with block // Encryption XOR obtained is applied to the second data block in clear // And the result is encrypted with AES given, the result will be the 2nd block // Encryption, so on. // // This function is: // 1 - separated data block of 16 bytes, // 2 - XOR operation is performed with the IV / block precesor // 3 - was called to the encryption function // 4 - Once all blocks are encrypted will join // 5 - forms the encrypted message and returns // /////////////////////////// uint8_t IV[16]; uint8_t Plain_text[16]; uint8_t Previous_block[16]; uint16_t index,index2; index = 0; index2 = 0; //Assign Initial Vector to IV variable assignBlock(IV,InitialVector); while(index<size){ // Encrypt for (int i =0; i<16;i++){ Plain_text[i]= original_data[index]; index++; } if (index == 16){ XOR(Plain_text,IV,block_data); }else { XOR(Plain_text,Previous_block,block_data); } switch(keySize){ case 128: aes128_enc(block_data, &ctx128); break; case 192: aes192_enc(block_data, &ctx192); break; case 256: aes256_enc(block_data, &ctx256); break; } assignBlock(Previous_block,block_data); for (int i = 0; i<16;i++){ original_data[index2] = block_data[i]; index2++; } } }
/* * CBCEncrypt - Encrypt message using CBC mode * * In CBC mode the message is divided into blocks of 16 bytes, to 1 block * Applied to the XOR and calculated its block cipher with block * Encryption XOR obtained is applied to the second data block in clear * And the result is encrypted with AES given, the result will be the 2nd block * Encryption, so on. * * This function is: * 1 - separated data block of 16 bytes, * 2 - XOR operation is performed with the IV / block precesor * 3 - was called to the encryption function * 4 - Once all blocks are encrypted will join * 5 - forms the encrypted message and returns * */ void WaspAES::CBCEncrypt( uint8_t *original_data, uint16_t size, uint8_t *InitialVector, uint16_t keySize) { uint8_t IV[16]; uint8_t Plain_text[16]; uint8_t Previous_block[16]; uint16_t index,index2; index = 0; index2 = 0; //Assign Initial Vector to IV variable assignBlock(IV,InitialVector); while( index < size ) { // Copy 16B block for (int i =0; i<16 ; i++) { Plain_text[i] = original_data[index]; index++; } // Perform XOR with corresponding IV block if ( index == 16) { // the first time the XOR is done with the Original IV XOR( Plain_text, IV, block_data); } else { // the rest of the times, the XOR is done with // the previous encrypted block XOR( Plain_text, Previous_block, block_data); } switch(keySize) { case 128: aes128_enc(block_data, &ctx128); break; case 192: aes192_enc(block_data, &ctx192); break; case 256: aes256_enc(block_data, &ctx256); break; } assignBlock( Previous_block, block_data); for (int i = 0; i<16;i++) { original_data[index2] = block_data[i]; index2++; } } }
TEUCHOS_UNIT_TEST(tSTK_IO, exodus_factory_transient_fields) { STK_ExodusReaderFactory factory("meshes/basic.gen"); RCP<STK_Interface> mesh = factory.buildUncommitedMesh(MPI_COMM_WORLD); mesh->addSolutionField("u","block_1"); mesh->addSolutionField("T","block_1"); mesh->addSolutionField("T","block_2"); factory.completeMeshConstruction(*mesh,MPI_COMM_WORLD); std::map<std::string,Teuchos::RCP<std::vector<std::size_t> > > localIds; buildLocalIds(*mesh,localIds); FieldContainer vert0, vert1; out << "get vertices" << std::endl; mesh->getElementVertices(*localIds["block_1"],vert0); mesh->getElementVertices(*localIds["block_2"],vert1); FieldContainer ublock0, tblock0, tblock1; ublock0.resize(localIds["block_1"]->size(),4); tblock0.resize(localIds["block_1"]->size(),4); tblock1.resize(localIds["block_2"]->size(),4); mesh->setupTransientExodusFile("transient_exo.exo"); out << "assigning 4.5" << std::endl; { assignBlock(ublock0,vert0,6.0); assignBlock(tblock0,vert0,7.0); assignBlock(tblock1,vert1,8.0); mesh->setSolutionFieldData("u","block_1",*localIds["block_1"],ublock0); mesh->setSolutionFieldData("T","block_1",*localIds["block_1"],tblock0); mesh->setSolutionFieldData("T","block_2",*localIds["block_2"],tblock1); } out << "write to exodus: 4.5" << std::endl; mesh->writeToExodus(4.5); }
TEUCHOS_UNIT_TEST(tSTK_IO, transient_fields) { RCP<STK_Interface> mesh = buildMesh(20,20); std::map<std::string,Teuchos::RCP<std::vector<std::size_t> > > localIds; buildLocalIds(*mesh,localIds); FieldContainer vert0, vert1; out << "get vertices" << std::endl; mesh->getElementVertices(*localIds["eblock-0_0"],vert0); mesh->getElementVertices(*localIds["eblock-1_0"],vert1); FieldContainer ublock0, tblock0, tblock1; ublock0.resize(localIds["eblock-0_0"]->size(),4); tblock0.resize(localIds["eblock-0_0"]->size(),4); tblock1.resize(localIds["eblock-1_0"]->size(),4); mesh->setupTransientExodusFile("transient.exo"); out << "assigning 3.0" << std::endl; { assignBlock(ublock0,vert0,1.0); assignBlock(tblock0,vert0,2.0); assignBlock(tblock1,vert1,3.0); mesh->setSolutionFieldData("u","eblock-0_0",*localIds["eblock-0_0"],ublock0); mesh->setSolutionFieldData("T","eblock-0_0",*localIds["eblock-0_0"],tblock0); mesh->setSolutionFieldData("T","eblock-1_0",*localIds["eblock-1_0"],tblock1); } out << "write to exodus: 3.0" << std::endl; mesh->writeToExodus(3.0); TEST_EQUALITY(mesh->getCurrentStateTime(),3.0); out << "assigning 4.5" << std::endl; { assignBlock(ublock0,vert0,6.0); assignBlock(tblock0,vert0,7.0); assignBlock(tblock1,vert1,8.0); mesh->setSolutionFieldData("u","eblock-0_0",*localIds["eblock-0_0"],ublock0); mesh->setSolutionFieldData("T","eblock-0_0",*localIds["eblock-0_0"],tblock0); mesh->setSolutionFieldData("T","eblock-1_0",*localIds["eblock-1_0"],tblock1); } out << "write to exodus: 4.5" << std::endl; mesh->writeToExodus(4.5); TEST_EQUALITY(mesh->getCurrentStateTime(),4.5); STK_ExodusReaderFactory factory("transient.exo",2); RCP<STK_Interface> mesh_read = factory.buildMesh(MPI_COMM_WORLD); TEST_EQUALITY(mesh_read->getInitialStateTime(),4.5); TEST_EQUALITY(mesh_read->getCurrentStateTime(),0.0); // writeToExodus has not yet been called }