// INITIALIZE THE DEVICE LIST WITH THE DISKS AVAILABLE FOR USE void DialogNewPool::setDevices(QList<vdev_t> *disks) { QList<vdev_t>::const_iterator it=disks->constBegin(); while(it!=disks->constEnd()) { // DETERMINE IF THE DEVICE IS AVAILABLE if((*it).Partitions.count()!=0) { // DISK IS NOT AVAILABLE, CHECK PARTITIONS RECURSIVELY setDevices((QList<vdev_t> *)&((*it).Partitions)); } else { if((*it).PartType=="freebsd-zfs" && (*it).InPool.isEmpty()) { // THIS IS AN EMPTY ZFS PARTITION QTreeWidgetItem *item=new QTreeWidgetItem(ui->vdevList); QString sz; sz=" ("+printBytes((*it).Size)+")"; item->setText(0,(*it).Name+sz+"\n[freebsd-zfs]"); item->setText(1," "); item->setData(0,Qt::UserRole,(*it).Name); item->setIcon(0,QIcon(":/icons/kdf.png")); item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); item->setCheckState(1,Qt::Unchecked); } else { if((*it).PartType.isEmpty() && (*it).InPool.isEmpty() && (*it).Size!=0) { // THIS IS AN EMPTY DISK QTreeWidgetItem *item=new QTreeWidgetItem(ui->vdevList); QString sz; sz=" ("+printBytes((*it).Size)+")"; if(!(*it).PartType.isEmpty()) { sz+=" [" + (*it).PartType + "]"; } sz+="\n"; item->setText(0,(*it).Name + sz + (*it).Description); item->setText(1," "); item->setData(0,Qt::UserRole,(*it).Name); item->setIcon(0,QIcon(":/icons/drive-harddisk.png")); item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); item->setCheckState(1,Qt::Unchecked); } } } ++it; } Vdevcount=0; }
int readTextureList() { printInt(14); printInt(2); printBytes("\xFF\xFF\xFF\xFF", 4); int beginningOffset = ftell(output); openBracket(); int numTextures = readInt("*TEXTURE_COUNT"); printInt(numTextures); int i; for (i = 0; i < numTextures; i++) { readTexture(); } closeBracket(); int endOffset = ftell(output); int size = endOffset - beginningOffset; fseek(output, beginningOffset - 4, 0); printInt(size); fseek(output, endOffset, 0); return numTextures; }
UErrorCode convsample_02() { printf("\n\n==============================================\n" "Sample 02: C: simple Unicode -> koi8-r conversion\n"); // **************************** START SAMPLE ******************* // "cat<cat>OK" UChar source[] = { 0x041C, 0x043E, 0x0441, 0x043A, 0x0432, 0x0430, 0x0021, 0x0000 }; char target[100]; UErrorCode status = U_ZERO_ERROR; UConverter *conv; int32_t len; // set up the converter conv = ucnv_open("koi8-r", &status); assert(U_SUCCESS(status)); // convert to koi8-r len = ucnv_fromUChars(conv, target, 100, source, -1, &status); assert(U_SUCCESS(status)); // close the converter ucnv_close(conv); // ***************************** END SAMPLE ******************** // Print it out printUChars("src", source); printf("\n"); printBytes("targ", target, len); return U_ZERO_ERROR; }
UErrorCode convsample_12() { printf("\n\n==============================================\n" "Sample 12: C: simple sjis -> unicode conversion\n"); // **************************** START SAMPLE ******************* char source[] = { 0x63, 0x61, 0x74, (char)0x94, 0x4C, (char)0x82, 0x6E, (char)0x82, 0x6A, 0x00 }; UChar target[100]; UErrorCode status = U_ZERO_ERROR; UConverter *conv; int32_t len; // set up the converter conv = ucnv_open("shift_jis", &status); assert(U_SUCCESS(status)); // convert to Unicode // Note: we can use strlen, we know it's an 8 bit null terminated codepage target[6] = 0xFDCA; len = ucnv_toUChars(conv, target, 100, source, strlen(source), &status); U_ASSERT(status); // close the converter ucnv_close(conv); // ***************************** END SAMPLE ******************** // Print it out printBytes("src", source, strlen(source) ); printf("\n"); printUChars("targ", target, len); return U_ZERO_ERROR; }
void getPublicKeyRaw(ecc_key_t *pubkeyraw, char *inFile) { EVP_PKEY* pkey; EC_KEY *key; const EC_GROUP *ecgrp; const EC_POINT *ecpoint; BIGNUM *pubkeyBN; unsigned char pubkeyData[1 + 2*EC_COORDBYTES]; FILE *fp = fopen( inFile, "r"); pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL); assert(pkey); key = EVP_PKEY_get1_EC_KEY(pkey); assert(key); ecgrp = EC_KEY_get0_group(key); assert(ecgrp); ecpoint = EC_KEY_get0_public_key(key); assert(ecpoint); pubkeyBN = EC_POINT_point2bn(ecgrp, ecpoint, POINT_CONVERSION_UNCOMPRESSED, NULL, NULL); BN_bn2bin(pubkeyBN, pubkeyData); if (debug) printBytes((char *)"pubkey (RAW) = ", &pubkeyData[1], sizeof(pubkeyData) - 1, 32); memcpy(*pubkeyraw, &pubkeyData[1], sizeof(ecc_key_t)); EC_KEY_free(key); EVP_PKEY_free(pkey); fclose(fp); return; }
/** * MixColumns * * The MixColumns function is the trickiest to implement efficiently since it * contains a lot of expensive operations if implemented literally as stated * in FIPS-197. * * Considerable experimentation, trial, error and literature search lead to * the present form. A fuller discussion and the sources used are cited in the * body of the function. * */ void MixColumns(void *pText) { // The sub bytes operation is as follows (see 5.1.3 in the FIPS-197 document): // // s'_0,c = ({02} * s_0,c ) XOR ({03} * s_1,c ) XOR s_2,c XOR s_3,c // s'_1,c = s_0,c XOR ({02} * s_1,c ) XOR ({03} * s_2,c ) XOR s_3,c // s'_2,c = s_0,c XOR s_1,c XOR ({02} * s_2,c ) XOR ({03} * s_3,c ) ′ // s'_3,c = ({03} * s_0,c ) XOR s_1,c XOR s_2,c XOR ({02} * s_3,c ) // // The * operation is here multiplication in the AES (Rijndael) finite field. See section // 4.2.1 in FIPS-197 on the multiplication and the xtime function. // A much clearer description can be found in // http://www.usenix.org/event/cardis02/full_papers/valverde/valverde_html/node12.html // // The xtime function is as follows: // xtime(a) = a<<1 if x7==0 (the eight bit is 0) // xtime(a) = a<<1 XOR Ox1 if x7==1 // see also: // * http://en.wikipedia.org/wiki/Rijndael_mix_columns // * http://en.wikipedia.org/wiki/Rijndael_Galois_field // * http://www.usenix.org/event/cardis02/full_papers/valverde/valverde_html/node12.html byte_ard *pState = (byte_ard *)pText; byte_ard a, s0; int c; for(c = 0; c < 4; c++) { // This algorithm is adapted from the paper // "Efficient AES Implementations for ARM Based Platforms" by Atasu, Breveglieri and Macchetti (2004) // Note: This is in essence identical to the code from Daemen and Rijmen (sec. 5.1). // // temp[0] = xtime(pState[0][c] ^ pState[1][c]) ^ pState[1][c] ^ pState[2][c] ^ pState[3][c]; // temp[1] = xtime(pState[1][c] ^ pState[2][c]) ^ pState[2][c] ^ pState[3][c] ^ pState[0][c]; // temp[2] = xtime(pState[2][c] ^ pState[3][c]) ^ pState[3][c] ^ pState[0][c] ^ pState[1][c]; // temp[3] = xtime(pstate[3][c] ^ pstate[0][c]) ^ pState[0][c] ^ pState[1][c] ^ pState[2][c]; // // The code below is a variation of the pseudocode in the document by Daemen and Rijmen (sec. 5.1) // and allows us to dispense with the temporary variable: a single initial XOR A of all four // states is computed. Then, temporary variables can be avoided by XORing A with the xtime calculation // and the target field itself. This self-XOR nullifies the corresponding term from A, avoiding // the temporary variable. The use of the a variable also saves quite a few XORs. // This is reimplemented as follows: a = state(pState,0,c) ^ state(pState,1,c) ^ state(pState,2,c) ^ state(pState,3,c); s0 = state(pState,0,c); // This is the only temporary variable needed state(pState,0,c) ^= xtime((state(pState,0,c) ^ state(pState,1,c))) ^ a; state(pState,1,c) ^= xtime((state(pState,1,c) ^ state(pState,2,c))) ^ a; state(pState,2,c) ^= xtime((state(pState,2,c) ^ state(pState,3,c))) ^ a; state(pState,3,c) ^= xtime((state(pState,3,c) ^ s0)) ^ a; // Here, we need to use a temp, since the contents of s0c have been modified } // FIXME -- Use non-arduino-specific debug #ifdef verbose_debug Serial.println("State after mixColumns:"); printBytes((unsigned char*)pText,16,16); #endif } // MixColumns()
void DeleteCommonTicketMode::OnRightsIdSelected() { tin::ui::ViewManager& manager = tin::ui::ViewManager::Instance(); ConsoleOptionsView* prevView; RightsIdOptionValue* optionValue; if (!(prevView = dynamic_cast<ConsoleOptionsView*>(manager.GetCurrentView()))) { throw std::runtime_error("View must be a ConsoleOptionsView!"); } if (!(optionValue = dynamic_cast<RightsIdOptionValue*>(prevView->GetSelectedOptionValue()))) { throw std::runtime_error("Option value must be a RightsIdOptionValue"); } RightsId rightsId = optionValue->rightsId; // Push a blank view auto view = std::make_unique<tin::ui::ConsoleView>(); manager.PushView(std::move(view)); LOG_DEBUG("RightsId to delete: \n"); printBytes(nxlinkout, rightsId.c, sizeof(RightsId), true); ASSERT_OK(esDeleteTicket(&rightsId, sizeof(RightsId)), "Failed to delete common ticket"); printf("Deleted common ticket successfully!\n\nPress (B) to return.\n"); prevView->GetSelectedEntry()->selectType = ConsoleEntrySelectType::SELECT_INACTIVE; }
byte PN532::getCommandResponse(byte * resp, const long & wmillis) { if (!IRQ_wait(wmillis)) { #ifdef PN532DEBUG Serial.println("IRQ wail expired."); Serial.print("Couldn't wait "); Serial.println(wmillis); #endif return 0; } comm_status = REQUEST_RECEIVE; byte count = receivepacket(); #ifdef PN532COMM Serial.print("CommandResp. >> "); printBytes(packet, count); Serial.println('\n'); #endif //#undef PN532DEBUG if (!(packet[0] == 0xd5 && packet[1] == (last_command + 1))) { #ifdef PN532DEBUG Serial.println("Missmatch with the last command."); #endif comm_status = RESP_COMMAND_MISSMATCH; return 0; } comm_status = RESP_RECEIVED; count -= 2; memmove(resp, packet + 2, count); return count; }
byte PN532::InListPassiveTarget(const byte maxtg, const byte brty, byte * data, const byte length) { // byte inidatalen = 0; packet[0] = COMMAND_InListPassiveTarget; packet[1] = maxtg; // max 1 cards at once (we can set this to 2 later) packet[2] = brty; if (length > 0) { memcpy(packet + 3, data, length); } #ifdef PN532COMM Serial.print("InListPassiveTarget << "); printBytes(packet, length + 3); Serial.println(); #endif sendpacket(3 + length); last_command = COMMAND_InListPassiveTarget; comm_status = COMMAND_ISSUED; if (!checkACKframe()) { comm_status = ACK_NOT_RECEIVED; return 0; } #ifdef PN532COMM Serial.println("ACKed."); #endif comm_status = ACK_FRAME_RECEIVED; return 1; }
void InvMixColumns(void *pText) { byte_ard *pState = (byte_ard *)pText; byte_ard s0, s1, s2, s3; int c; for (c = 0; c < 4; c++) { s0 = state(pState,0,c); // S_0,0 s1 = state(pState,1,c); // S_1,0 s2 = state(pState,2,c); // S_2,0 s3 = state(pState,3,c); // S_3,0 // * is multiplication is GF(2^8) // s'_0,c = (0x0e * s0) xor (0x0b * s1) xor (0x0d * s2) xor (0x09 * s3) state(pState,0,c) = (eight(s0)^four(s0)^xtime(s0)) ^ (eight(s1)^xtime(s1)^s1) ^ (eight(s2)^four(s2)^s2) ^ (eight(s3) ^ s3); // s'_1,c = (0x09 * s0) xor (0x0e * s1) xor (0x0b * s2) xor (0x0d * s3) state(pState,1,c) = (eight(s0)^s0) ^ (eight(s1)^four(s1)^xtime(s1)) ^ (eight(s2)^xtime(s2)^s2) ^ (eight(s3)^four(s3)^s3); // s'_2,c = (0x0d * s0) xor (0x09 * s1) xor (0x0e * s2) xor (0x0b * s3) state(pState,2,c) = (eight(s0)^four(s0)^s0) ^ (eight(s1)^s1) ^ (eight(s2)^four(s2)^xtime(s2)) ^ (eight(s3)^xtime(s3)^s3); // s'_3,c = (0x0b * s0) xor (0x0d * s1) xor (0x09 * s2) xor (0x0e * s3) state(pState,3,c) = (eight(s0)^xtime(s0)^s0) ^ (eight(s1)^four(s1)^s1) ^ (eight(s2)^s2) ^ (eight(s3)^four(s3)^xtime(s3)); } // arduino specific debug #ifdef verbose_debig Serial.println("state after InvMixColumns(): "); printBytes((unsigned char*)pText, 16, 16); #endif } // InvMixColumns()
int GetKsocketSendBuf (char path[NG_PATHSIZ]) { struct ng_ksocket_sockopt *sockopt_resp = malloc(sizeof(struct ng_ksocket_sockopt) + sizeof(int)); struct ng_ksocket_sockopt *sk; struct ng_mesg *resp; memset(sockopt_resp, 0, sizeof(struct ng_ksocket_sockopt) + sizeof(int)); sockopt_resp->level = SOL_SOCKET; sockopt_resp->name = SO_SNDBUF; if ( NgSendMsg(csock, path, NGM_KSOCKET_COOKIE, NGM_KSOCKET_GETOPT, sockopt_resp, sizeof(*sockopt_resp)) == -1 ) { printf("Error while trying to get sockopt from %s - %s\n", path, strerror(errno)); return 1; } if ( NgAllocRecvMsg(csock, &resp, 0 ) < 0 ) { fprintf(stderr, "Error while trying to get message from getsockopt: %s\n", strerror(errno)); return 1; } sk = (struct ng_ksocket_sockopt *)resp->data; int option = *((int *)sk->value); printBytes(sk, resp->header.arglen); printf("SO_SNDBUF = %d\n", option); free(sockopt_resp); free(resp); return 1; }
/** * Initializes the temperature sensor. * This method is called when the sensor is first created and also any time the sensor reports it's disconnected. * If the result is TEMP_SENSOR_DISCONNECTED then subsequent calls to read() will also return TEMP_SENSOR_DISCONNECTED. * Clients should attempt to re-initialize the sensor by calling init() again. */ bool OneWireTempSensor::init(){ // save address and pinNr for log messages char addressString[17]; printBytes(sensorAddress, 8, addressString); uint8_t pinNr = oneWire->pinNr(); bool success = false; if (sensor==NULL) { sensor = new DallasTemperature(oneWire); if (sensor==NULL) { logErrorString(ERROR_SRAM_SENSOR, addressString); } } logDebug("init onewire sensor"); // This quickly tests if the sensor is connected and initializes the reset detection. // During the main TempControl loop, we don't want to spend many seconds // scanning each sensor since this brings things to a halt. if (sensor && sensor->initConnection(sensorAddress) && requestConversion()) { logDebug("init onewire sensor - wait for conversion"); waitForConversion(); temperature temp = readAndConstrainTemp(); DEBUG_ONLY(logInfoIntStringTemp(INFO_TEMP_SENSOR_INITIALIZED, pinNr, addressString, temp)); success = temp!=DEVICE_DISCONNECTED && requestConversion(); } setConnected(success); logDebug("init onewire sensor complete %d", success); return success; }
void pprint(LSPMessage& msg) { printf("LSPMessage\n{connid: %d, seqnum: %d, payload.len: %u\n", msg.connid, msg.seqnum, msg.payload.len); printBytes(msg.payload.data, msg.payload.len); printf("}\n"); }
byte PN532::mifare_ReadBlock(uint8_t blockNumber, uint8_t * data) { #ifdef MIFAREDEBUG Serial.print("Try to read 16 bytes from block "); Serial.println(blockNumber); #endif // Access the Target 1 after polling by InList or AutoPoll // Authentication must be succeeded so the uid (and its length) is // stored in target.UID /* Send the command */ if (!InDataExchange(1, MIFARE_CMD_READ, blockNumber, packet, 0)) { #ifdef MIFAREDEBUG Serial.println("Failed to receive ACK for read command"); #endif } byte c = getCommandResponse(packet); if (! c) { #ifdef MIFAREDEBUG Serial.println("Unexpected response"); printBytes(packet, 26); Serial.println(); #endif return 0; } //#define MIFAREDEBUG #ifdef MIFAREDEBUG Serial.print("Packet "); printBytes(packet, c); Serial.println(); #endif if (packet[0] != 0) { // error. return 0; } memcpy(data, packet + 1, 16); #ifdef MIFAREDEBUG Serial.print("data "); Serial.println(blockNumber); printBytes(data, 16); Serial.println(); #endif //#undef MIFAREDEBUG return 16; }
/** * AddRoundKey * * Adds a key from the schedule (for the specified round) to the current state. * Loop unrolled for a bit of performance gain * The key is XOR-ed to the state */ void AddRoundKey(void *pText, const u_int32_ard *pKeys, int round) { int roundOffset=round*4; u_int32_ard *pState = (u_int32_ard *)pText; pState[0] ^= pKeys[roundOffset]; pState[1] ^= pKeys[roundOffset+1]; pState[2] ^= pKeys[roundOffset+2]; pState[3] ^= pKeys[roundOffset+3]; // FIXME -- use non-arduino-specific debug code #ifdef verbose_debug Serial.print("Adding round key at round:"); Serial.println(round); printBytes((unsigned char*)(pKeys+4*round),16); Serial.println("State after:"); printBytes((unsigned char*)pText,16,16); #endif }
/** * KeyExpansion() * * Implements the AES key expansion algorithm. * Note: only supports 128 bit keys and 10 rounds. * See FIPS-197 and http://en.wikipedia.org/wiki/Rijndael_key_schedule on the algorithm. * The Rcon table used in the algorithm copied from (but not verified!) the wikipedia * article. * key is the ecryption key, whereas keys are the derived expansion keys. */ void KeyExpansion(const void *key, void *keys) { memcpy(keys,key,16); // Copy the first key #ifdef verbose_debug Serial.println("Starting key expansion"); Serial.println("Initial key:"); printBytes((byte_ard *)key,16,16); #endif byte_ard *ckeys = (byte_ard*)keys; int r=1; // The Rcon counter for(int i=16; i<176; i+=4) { // The SubWord and RotWord methods described in Section 5.2 of FIPS-197 are // replaced here by their inlined equivalents. The algorithm is also simplifyed // by not supporting the longer key lengths. Several steps are combined to be // able to compute keys in-place without temporary variables. if (i % 16 == 0) // Dividable by 16, the first key { // Copy the previous four bytes with rotate. // Apply the AES Sbox to the four bytes of the key only. // Multiply the first byte with the Rcon. ckeys[i] = ckeys[i-16] ^ getSboxValue(ckeys[i-3]) ^ getRconValue(r++); ckeys[i+1] = ckeys[i-15] ^ getSboxValue(ckeys[i-2]); ckeys[i+2] = ckeys[i-14] ^ getSboxValue(ckeys[i-1]); ckeys[i+3] = ckeys[i-13] ^ getSboxValue(ckeys[i-4]); } else { // Straight copy and rotate of the previous key bytes. ckeys[i] = ckeys[i-16] ^ ckeys[i-4]; ckeys[i+1] = ckeys[i-15] ^ ckeys[i-3]; ckeys[i+2] = ckeys[i-14] ^ ckeys[i-2]; ckeys[i+3] = ckeys[i-13] ^ ckeys[i-1]; } } #ifdef verbose_debug printBytes((byte_ard*)keys,160,16); #endif }
byte PN532::receivepacket() { chksum = 0; byte i; byte n = 0; Wire.requestFrom((int) i2c_addr, BUFFER_LENGTH); receive(); for (i = 0; i < 6; i++) { packet[i] = receive(); } // preamble if (memcmp(packet, "\x00\x00\xff", 3) != 0 || ((packet[3] + packet[4]) & 0xff) != 0 ) { #ifdef PN532DEBUG Serial.println("received illigale preamble."); #endif comm_status = WRONG_PREAMBLE; return 0; } n = packet[3]; if (((packet[3] + packet[4]) & 0xff) != 0x00) { comm_status = WRONG_PREAMBLE; return 0; } // Wire.requestFrom((int) i2c_addr, (int) n); for (; i < n + 5 + 2; i++) { packet[i] = receive(); } #ifdef PN532DEBUG Serial.print("receivepacket Len = "); Serial.print(n, DEC); Serial.print(", "); printBytes(packet, n + 7); Serial.println(); Serial.print("xsum: "); Serial.print(chksum, HEX); Serial.println(); #endif if (chksum != 0) { comm_status = CHECKSUMERROR; #ifdef PN532DEBUG Serial.println("!!! Checksum error !!!"); return 0; #endif } if (packet[6 + n] != 0) { #ifdef PN532DEBUG Serial.println("termination 0x00 error"); #endif comm_status = WRONG_POSTAMBLE; return 0; } memmove(packet, packet + 5, n); return n; }
IOReturn org_litio_OzoneStrikeBattle::newReportDescriptor(IOMemoryDescriptor** descriptor) const { // TODO: Define new device descriptor struct for the keyboard. // Assigning current descriptor. IOLog("OzoneStrike::%s[%p] - Setting HID report descriptor.\n", getName(), this); OSData *reportDescriptor = OSData::withBytes(Ozone::HIDReportDescriptor, sizeof(Ozone::HIDReportDescriptor)); OSData *reportDescriptorNew = OSDynamicCast(OSData, getProperty("ReportDescriptorOverride")); if (reportDescriptor == NULL) { IOLog("OzoneStrike::%s[%p] - reportDescriptor OSData not set.\n", getName(), this); return kIOReturnNoResources; } printBytes(reportDescriptorNew); printBytes(reportDescriptor); IOLog("OzoneStrike::%s[%p] - reportDescriptor OSData set (size: %d, data: %s).\n", getName(), this, reportDescriptor->getLength(), reportDescriptor->getBytesNoCopy()); //OSData *reportDescriptor = OSDynamicCast(OSData, Ozone::HIDReportDescriptor); IOBufferMemoryDescriptor *bufferDescriptor = IOBufferMemoryDescriptor::withBytes(reportDescriptor->getBytesNoCopy(), reportDescriptor->getLength(), kIODirectionOutIn); //IOBufferMemoryDescriptor *bufferDescriptor = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task, // 0, // sizeof(Ozone::HIDReportDescriptor)); /* if (bufferDescriptor == NULL) { return kIOReturnNoResources; } bufferDescriptor->writeBytes(0, Ozone::HIDReportDescriptor,sizeof(Ozone::HIDReportDescriptor)); */ if (bufferDescriptor) { *descriptor = bufferDescriptor; return kIOReturnSuccess; } else { bufferDescriptor->release(); *descriptor = NULL; return kIOReturnNoMemory; } //return IOUSBHostHIDDevice::newReportDescriptor(descriptor); }
void OneWireTempSensor::setConnected(bool connected) { if (this->connected == connected) return; // state is stays the same char addressString[17]; printBytes(sensorAddress, 8, addressString); this->connected = connected; if (connected) { logInfoIntString(INFO_TEMP_SENSOR_CONNECTED, this->oneWire->pinNr(), addressString); } else { logWarningIntString(WARNING_TEMP_SENSOR_DISCONNECTED, this->oneWire->pinNr(), addressString); } }
UErrorCode convsample_13() { printf("\n\n==============================================\n" "Sample 13: C: simple Big5 -> unicode conversion, char at a time\n"); const char sourceChars[] = { 0x7a, 0x68, 0x3d, (char)0xa4, (char)0xa4, (char)0xa4, (char)0xe5, (char)0x2e }; // const char sourceChars[] = { 0x7a, 0x68, 0x3d, 0xe4, 0xb8, 0xad, 0xe6, 0x96, 0x87, 0x2e }; const char *source, *sourceLimit; UChar32 target; UErrorCode status = U_ZERO_ERROR; UConverter *conv = NULL; int32_t srcCount=0; int32_t dstCount=0; srcCount = sizeof(sourceChars); conv = ucnv_open("Big5", &status); U_ASSERT(status); source = sourceChars; sourceLimit = sourceChars + sizeof(sourceChars); // **************************** START SAMPLE ******************* printBytes("src",source,sourceLimit-source); while(source < sourceLimit) { puts(""); target = ucnv_getNextUChar (conv, &source, sourceLimit, &status); // printBytes("src",source,sourceLimit-source); U_ASSERT(status); printUChar(target); dstCount++; } // ************************** END SAMPLE ************************* printf("src=%d bytes, dst=%d uchars\n", srcCount, dstCount); ucnv_close(conv); return U_ZERO_ERROR; }
/** * EncryptBlock * * Encrypt a single block, stored in the buffer text. The buffer MUST be 16 * bytes in length! * pKeys stores a complete key schedule for the round. * The algorithm, call order and function names, follows the reference of * FIPS-197, section 5.1. * * The encryption loop can be unrolled or left as is by using the * unroll_encrypt_loop define. * * The encrypted data is returned in the text buffer. * * Note: Only 10 rounds and 128 bit keys are supported in this implementation. */ void EncryptBlock(void *pBlock, const u_int32_ard *pKeys) { // FIXME -- Use non-arduino-specific debug #ifdef verbose_debug Serial.println("\n\nStarting encrypt, plaintext is"); printBytes((byte_ard*)pBlock,16,16); #endif // XOR the first key to the first state AddRoundKey(pBlock, pKeys, 0); #if defined(unroll_encrypt_loop) ntransform(pBlock, pKeys, 1); ntransform(pBlock, pKeys, 2); ntransform(pBlock, pKeys, 3); ntransform(pBlock, pKeys, 4); ntransform(pBlock, pKeys, 5); ntransform(pBlock, pKeys, 6); ntransform(pBlock, pKeys, 7); ntransform(pBlock, pKeys, 8); ntransform(pBlock, pKeys, 9); #else int round; for (round=1; round<ROUNDS; round++) { // Fixme: Use non-arduino-specific debug #ifdef verbose_debug Serial.print("Encryption round "); Serial.println(round); #endif SubAndShift(pBlock); MixColumns(pBlock); AddRoundKey(pBlock, pKeys, round); } #endif // Fixme: Use non-arduino-specific debug #ifdef verbose_debug Serial.println("Encryption round 10"); #endif // Now, do the final round of encryption SubAndShift(pBlock); AddRoundKey(pBlock, pKeys, 10); // add the last round key from the schedule } //EncryptBlock()
void getSigRaw(ecc_signature_t *sigraw, char *inFile) { ECDSA_SIG* signature; int fdin; struct stat s; void *infile; unsigned char outbuf[2*EC_COORDBYTES]; int r, rlen, roff, slen, soff; const BIGNUM *sr, *ss; fdin = open(inFile, O_RDONLY); assert(fdin > 0); r = fstat(fdin, &s); assert(r==0); infile = mmap(NULL, s.st_size, PROT_READ, MAP_PRIVATE, fdin, 0); assert(infile); signature = d2i_ECDSA_SIG(NULL, (const unsigned char **) &infile, 7 + 2*EC_COORDBYTES); memset(&outbuf, 0, sizeof(outbuf)); #if OPENSSL_VERSION_NUMBER >= 0x10100000L ECDSA_SIG_get0(signature, &sr, &ss); #else sr = signature->r; ss = signature->s; #endif rlen = BN_num_bytes(sr); roff = 66 - rlen; BN_bn2bin(sr, &outbuf[roff]); slen = BN_num_bytes(ss); soff = 66 + (66 - slen); BN_bn2bin(sr, &outbuf[soff]); if (debug) printBytes((char *)"sig (RAW) = ", outbuf, sizeof(outbuf), 32); memcpy(*sigraw, outbuf, 2*EC_COORDBYTES); ECDSA_SIG_free(signature); close(fdin); return; }
// InvSubAndShift() // // Implements the inverse of the AES operations SubBytes and ShiftRows. // Applies the inverted SBox to the bytes while and shifts the // rows backwards. void InvSubAndShift(void *pText) { byte_ard *pState = (byte_ard*)pText; byte_ard temp; // Loop unrolled for a bit of performance gain // The first row isnt rotataed, only isboxed state(pState,0,0) = getISboxValue(state(pState,0,0)); state(pState,0,1) = getISboxValue(state(pState,0,1)); state(pState,0,2) = getISboxValue(state(pState,0,2)); state(pState,0,3) = getISboxValue(state(pState,0,3)); // Second row is shifted one byte to the left temp = state(pState,1,3); state(pState,1,3) = getISboxValue(state(pState,1,2)); state(pState,1,2) = getISboxValue(state(pState,1,1)); state(pState,1,1) = getISboxValue(state(pState,1,0)); state(pState,1,0) = getISboxValue(temp); // Third row is shifted two bytes to the left temp = state(pState,2,2); state(pState,2,2) = getISboxValue(state(pState,2,0)); state(pState,2,0) = getISboxValue(temp); temp = state(pState,2,1); state(pState,2,1) = getISboxValue(state(pState,2,3)); state(pState,2,3) = getISboxValue(temp); // The fourth row is shifted three bytes to the left temp = state(pState,3,0); state(pState,3,0) = getISboxValue(state(pState,3,1)); state(pState,3,1) = getISboxValue(state(pState,3,2)); state(pState,3,2) = getISboxValue(state(pState,3,3)); state(pState,3,3) = getISboxValue(temp); // FIXME -- Use non-arduino-specific debug #ifdef verbose_debug Serial.println("State after subAndShift:"); printBytes((unsigned char *)pText,16,16); #endif } // InvSubAndShift()
/** * Initializes the temperature sensor. * This method is called when the sensor is first created and also any time the sensor reports it's disconnected. * If the result is TEMP_SENSOR_DISCONNECTED then subsequent calls to read() will also return TEMP_SENSOR_DISCONNECTED. * Clients should attempt to re-initialize the sensor by calling init() again. */ bool OneWireTempSensor::init() { // save address and pinNr for log messages char addressString[17]; printBytes(sensorAddress, 8, addressString); #if BREWPI_DEBUG uint8_t pinNr = oneWire->pinNr(); #endif bool success = false; if (sensor == NULL) { sensor = new DallasTemperature(oneWire); if (sensor == NULL) { logErrorString(ERROR_SRAM_SENSOR, addressString); } } logDebug("init onewire sensor"); // This quickly tests if the sensor is connected and initializes the reset detection if necessary. if (sensor){ // If this is the first conversion after power on, the device will return DEVICE_DISCONNECTED_RAW // Because HIGH_ALARM_TEMP will be copied from EEPROM int16_t temp = sensor->getTempRaw(sensorAddress); if(temp == DEVICE_DISCONNECTED_RAW){ // Device was just powered on and should be initialized if(sensor->initConnection(sensorAddress)){ requestConversion(); waitForConversion(); temp = sensor->getTempRaw(sensorAddress); } } DEBUG_ONLY(logInfoIntStringTemp(INFO_TEMP_SENSOR_INITIALIZED, pinNr, addressString, temp)); success = temp != DEVICE_DISCONNECTED_RAW; if(success){ requestConversion(); // piggyback request for a new conversion } } setConnected(success); logDebug("init onewire sensor complete %d", success); return success; }
//|================================ Int main =========================================== int main () { int pid = fork(); // fork start if(pid == 0){ // pid always starts at 0 SHELLCODE(); // launch void SHELLCODE // this is to represent a scenario where you bind to a good program // you always want your shellcode to run first }else if(pid > 0){ // pid will always be greater than 0 after the 1st process // this argument will always be satisfied printBytes(); // launch printBYTES // pretend that this is the one the victim thinks he is only using } return 0; // satisfy int main system("exit"); // keeps our shellcode a daemon }
byte PN532::InDataExchange(const byte Tg, const byte * data, const byte length) { // Prepare the authentication command // packet[0] = COMMAND_InDataExchange; /* Data Exchange Header */ packet[1] = Tg; /* target number */ memcpy(packet + 2, data, length); #ifdef MIFAREDEBUG printBytes(packet, length+2); Serial.println(); #endif sendpacket(length + 2); comm_status = COMMAND_ISSUED; last_command = COMMAND_InDataExchange; if (!(checkACKframe())) { comm_status = ACK_NOT_RECEIVED; return 0; } comm_status = ACK_FRAME_RECEIVED; return 1; }
//|============================== Int main ================================ int main () { // IMPORTANT> replace CODEX the "unsigned char" variable below // > This needs to be done twice (for string count + code to use) int pid = fork(); // fork start if(pid == 0){ // pid always starts at 0 SHELLCODE(); // launch void SHELLCODE // this is to represent a scenario where you bind to a good program // you always want your shellcode to run first }else if(pid > 0){ // pid will always be greater than 0 after the 1st process // this argument will always be satisfied printBytes(); // launch printBYTES // pretend that this is the one the victim thinks he is only using } return 0; // satisfy int main system("exit"); // keeps our shellcode a daemon }
/** * SubAndShift * * Implementation of the AES subBytes and shiftRows operations. * * The AES sbox is applied to each byte as the shift is performed * Loop unrolled for a bit of preformance gain. * * See: FIPS-197. * See: http://en.wikipedia.org/wiki/Rijndael_S-box */ void SubAndShift(void *pText) { byte_ard *pState = (byte_ard*)pText; byte_ard temp; // Only sbox for first row state(pState,0,0) = getSboxValue(state(pState,0,0)); state(pState,0,1) = getSboxValue(state(pState,0,1)); state(pState,0,2) = getSboxValue(state(pState,0,2)); state(pState,0,3) = getSboxValue(state(pState,0,3)); // Shift and sbox the second row temp=state(pState,1,0); state(pState,1,0)=getSboxValue(state(pState,1,1)); state(pState,1,1)=getSboxValue(state(pState,1,2)); state(pState,1,2)=getSboxValue(state(pState,1,3)); state(pState,1,3)=getSboxValue(temp); // Shift and sbox the third row temp = state(pState,2,0); state(pState,2,0)=getSboxValue(state(pState,2,2)); state(pState,2,2)=getSboxValue(temp); temp = state(pState,2,1); state(pState,2,1)=getSboxValue(state(pState,2,3)); state(pState,2,3)=getSboxValue(temp); // Shift and sbox the fourth row temp = state(pState,3,3); state(pState,3,3) = getSboxValue(state(pState,3,2)); state(pState,3,2) = getSboxValue(state(pState,3,1)); state(pState,3,1) = getSboxValue(state(pState,3,0)); state(pState,3,0) = getSboxValue(temp); // FIXME -- Use non-arduino-specific debug #ifdef verbose_debug Serial.println("State after subAndShift:"); printBytes((unsigned char *)pText,16,16); #endif } // SubAndShift
int readMaterialList() { printInt(7); printInt(2); //Placeholder for length printBytes("\xFF\xFF\xFF\xFF", 4); int beginningOffset = ftell(output); openBracket(); int matCount = readInt("*MATERIAL_COUNT"); printInt(matCount); int i; for (i = 0; i < matCount; i++) { readMaterial(); } closeBracket(); int endOffset = ftell(output); int size = endOffset - beginningOffset; fseek(output, beginningOffset - 4, 0); printInt(size); fseek(output, endOffset, 0); return matCount; }
void writeHdr(void *hdr, const char *outFile, int hdr_type) { int fdout; int r, hdr_sz=0; const char *lead; unsigned char md[SHA512_DIGEST_LENGTH]; fdout = open(outFile, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(fdout > 0); switch (hdr_type) { case PREFIX_HDR: hdr_sz = sizeof(ROM_prefix_header_raw); break; case SOFTWARE_HDR: hdr_sz = sizeof(ROM_sw_header_raw); break; } r = write(fdout, (const void *)hdr, hdr_sz); assert(r > 0); if (debug) { if (hdr_type == PREFIX_HDR) lead = "PR hdr hash = "; else lead = "SW hdr hash = "; SHA512(hdr, r, md); printBytes((char *)lead, md, sizeof(md), 32); } close(fdout); return; }