void mask_generation(uint8_t *seed, size_t seed_len, uint8_t *data, size_t data_len) { sha1_ctx_t ctx; uint8_t mask[SHA1_DIGEST_LENGTH]; uint32_t i, len, counter = 0; while (data_len > 0) { sha1_init(&ctx); sha1_update(&ctx, seed, seed_len); sha1_update(&ctx, (uint8_t*)&counter, 4); sha1_final(&ctx, mask); counter = CPU_TO_BE32(BE32_TO_CPU(counter) + 1); len = (data_len < SHA1_DIGEST_LENGTH) ? data_len : SHA1_DIGEST_LENGTH; for (i = 0; i < len; i++) *data++ ^= mask[i]; data_len -= len; } }
static int au_write_stream_close(bstreamhandle h) { uint32_t sz; str_errno = 0; sz = lseek(h->bstr_fd, 0L, SEEK_END); sz -= PRE_DEF_AU_HDR_LEN; sz = CPU_TO_BE32(sz); if (lseek(h->bstr_fd, 8L, SEEK_SET) < 0) return (1); if (write(h->bstr_fd, &sz, 4) < 0) return (1); (void) close(h->bstr_fd); free(h); return (0); }
bool uhi_msc_scsi_read_10(uint8_t lun, uint32_t addr, uint8_t *ram, uint8_t nb_sector, uhi_msc_scsi_callback_t callback) { uint32_t addrTmp = addr; uint32_t *pBlockLen = (uint32_t *) &uhi_msc_lun_sel->capacity.pLogicalBlockLength[0]; if (!uhi_msc_select_lun(lun)) return false; uhi_msc_scsi_callback = callback; // Prepare specific value of CBW packet uhi_msc_cbw.dCBWDataTransferLength = (*pBlockLen) * nb_sector; uhi_msc_cbw.bmCBWFlags = MSD_CBW_DEVICE_TO_HOST; uhi_msc_cbw.bCBWCBLength = 10; memset(uhi_msc_cbw.pCommand, 0, sizeof(uhi_msc_cbw.pCommand)); /**pCommand++ = SBC_WRITE10; memcpy(pCommand, &addr, sizeof(addr));*/ // CBWCB0 - Operation Code uhi_msc_cbw.pCommand[0] = SBC_READ_10; // CBWCB1 - RDPROTECT, DPO, FUA, Obsolete (0x00) (done by previous memset()) addrTmp = CPU_TO_BE32(addr); // CBWCB2 to 5 - Logical Block Address (BE16) memcpy(&uhi_msc_cbw.pCommand[2], &addrTmp, sizeof(addr)); // CBWCW6 - Reserved (0x00) (done by previous memset()) // CBWCW7 to 8 - Transfer Length // uhi_msc_cbw.pCommand[7] = 0x00; // MSB (done by previous memset()) uhi_msc_cbw.pCommand[8] = nb_sector; // LSB // CBWCW9 - Control (0x00) (done by previous memset()) uhi_msc_scsi(uhi_msc_scsi_read_10_done, ram); return true; }
#include <ccan/crypto/ripemd160/ripemd160.h> /* Include the C files directly. */ #include <ccan/crypto/ripemd160/ripemd160.c> #include <ccan/tap/tap.h> /* Test vectors. */ struct test { const char *test; size_t repetitions; beint32_t result[5]; }; /* Test vectors from: http://homes.esat.kuleuven.be/~bosselae/ripemd160.html */ static struct test tests[] = { { "", 1, { CPU_TO_BE32(0x9c1185a5), CPU_TO_BE32(0xc5e9fc54), CPU_TO_BE32(0x61280897), CPU_TO_BE32(0x7ee8f548), CPU_TO_BE32(0xb2258d31) } }, { "abc", 1, { CPU_TO_BE32(0x8eb208f7), CPU_TO_BE32(0xe05d987a), CPU_TO_BE32(0x9b044a8e), CPU_TO_BE32(0x98c6b087), CPU_TO_BE32(0xf15a0bfc) } }, { "message digest", 1, { CPU_TO_BE32(0x5d0689ef), CPU_TO_BE32(0x49d2fae5), CPU_TO_BE32(0x72b881b1), CPU_TO_BE32(0x23a85ffa), CPU_TO_BE32(0x21595f36) } }, { "abcdefghijklmnopqrstuvwxyz", 1, { CPU_TO_BE32(0xf71c2710), CPU_TO_BE32(0x9c692c1b), CPU_TO_BE32(0x56bbdceb), CPU_TO_BE32(0x5b9d2865), CPU_TO_BE32(0xb3708dbc) } }, { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
arising out of or in connection with the use or performance of this software. */ /** \file * * Bluetooth RFCOMM service SDP table definitions, to register the RFCOMM service with the SDP service. */ #include "RFCOMMServiceTable.h" /** Serial Port Profile attribute, listing the unique service handle of the Serial Port service * within the device. This handle can then be requested by the SDP client in future transactions * in lieu of a search UUID list. */ static const SDP_Item32Bit_t PROGMEM SerialPort_Attribute_ServiceHandle = SDP_ITEM32BIT(SDP_DATATYPE_UnsignedInt, CPU_TO_BE32(0x00010000)); /** Serial Port Profile attribute, listing the implemented Service Class UUIDs of the Serial Port service * within the device. This list indicates all the class UUIDs that apply to the Serial Port service, so that * a SDP client can search by a generalized class rather than a specific UUID to determine supported services. */ static const struct { SDP_ItemSequence8Bit_t UUIDList_Header; struct { SDP_ItemUUID_t SerialPortUUID; } UUIDList; } ATTR_PACKED PROGMEM SerialPort_Attribute_ServiceClassIDs = { SDP_ITEMSEQUENCE8BIT(sizeof(SerialPort_Attribute_ServiceClassIDs.UUIDList)),
#include <ccan/crypto/sha256/sha256.h> /* Include the C files directly. */ #include <ccan/crypto/sha256/sha256.c> #include <ccan/tap/tap.h> #include <stdio.h> /* This is the test introduced for SHA-3, which checks for 33-bit overflow: "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno" 16777216 times. */ static uint32_t expected[] = { CPU_TO_BE32(0x50e72a0e), CPU_TO_BE32(0x26442fe2), CPU_TO_BE32(0x552dc393), CPU_TO_BE32(0x8ac58658), CPU_TO_BE32(0x228c0cbf), CPU_TO_BE32(0xb1d2ca87), CPU_TO_BE32(0x2ae43526), CPU_TO_BE32(0x6fcd055e) }; /* Produced by actually running the code on x86. */ static const struct sha256_ctx after_16M_by_64 = { #ifdef CCAN_CRYPTO_SHA256_USE_OPENSSL { { LE32_TO_CPU(0x515e3215), LE32_TO_CPU(0x592f4ae0), LE32_TO_CPU(0xd407a8fc), LE32_TO_CPU(0x1fad409b), LE32_TO_CPU(0x51fa46cc), LE32_TO_CPU(0xea528ae5), LE32_TO_CPU(0x5fa58ebb), LE32_TO_CPU(0x8be97931) }, 0x0, 0x2, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0x0, 0x20 } #else { LE32_TO_CPU(0x515e3215), LE32_TO_CPU(0x592f4ae0), LE32_TO_CPU(0xd407a8fc), LE32_TO_CPU(0x1fad409b), LE32_TO_CPU(0x51fa46cc), LE32_TO_CPU(0xea528ae5),
TPM_RESULT TPM_GetCapability(TPM_CAPABILITY_AREA capArea, UINT32 subCapSize, BYTE *subCap, UINT32 *respSize, BYTE **resp) { info("TPM_GetCapability() (not fully implemented yet)"); switch (capArea) { case TPM_CAP_ORD: debug("[TPM_CAP_ORD]"); return cap_ord(subCapSize, subCap, respSize, resp); case TPM_CAP_ALG: debug("[TPM_CAP_ALG]"); return cap_alg(subCapSize, subCap, respSize, resp); case TPM_CAP_PID: debug("[TPM_CAP_PID]"); return cap_pid(subCapSize, subCap, respSize, resp); case TPM_CAP_FLAG: debug("[TPM_CAP_FLAG]"); return cap_flag(subCapSize, subCap, respSize, resp); case TPM_CAP_PROPERTY: debug("[TPM_CAP_PROPERTY]"); return cap_property(subCapSize, subCap, respSize, resp); case TPM_CAP_VERSION: debug("[TPM_CAP_VERSION]"); return cap_version(respSize, resp); case TPM_CAP_KEY_HANDLE: debug("[TPM_CAP_KEY_HANDLE]"); subCapSize = CPU_TO_BE32(TPM_RT_KEY); return cap_handle(4, (BYTE*)&subCapSize, respSize, resp); case TPM_CAP_CHECK_LOADED: debug("[TPM_CAP_CHECK_LOADED]"); return cap_loaded(subCapSize, subCap, respSize, resp); case TPM_CAP_SYM_MODE: debug("[TPM_CAP_SYM_MODE]"); /* TODO: TPM_CAP_SYM_MODE */ return TPM_FAIL; case TPM_CAP_KEY_STATUS: debug("[TPM_CAP_KEY_STATUS]"); /* TODO: TPM_CAP_KEY_STATUS */ return TPM_FAIL; case TPM_CAP_NV_LIST: debug("[TPM_CAP_NV_LIST]"); /* TODO: TPM_CAP_NV_LIST */ return TPM_FAIL; case TPM_CAP_MFR: debug("[TPM_CAP_MFR]"); return cap_mfr(respSize, resp); case TPM_CAP_NV_INDEX: debug("[TPM_CAP_NV_INDEX]"); /* TODO: TPM_CAP_NV_INDEX */ return TPM_FAIL; case TPM_CAP_TRANS_ALG: debug("[TPM_CAP_TRANS_ALG]"); /* TODO: TPM_CAP_TRANS_ALG */ return TPM_FAIL; case TPM_CAP_HANDLE: debug("[TPM_CAP_HANDLE]"); return cap_handle(subCapSize, subCap, respSize, resp); case TPM_CAP_TRANS_ES: debug("[TPM_CAP_TRANS_ES]"); /* TODO: TPM_CAP_TRANS_ES */ return TPM_FAIL; case TPM_CAP_AUTH_ENCRYPT: debug("[TPM_CAP_AUTH_ENCRYPT]"); return cap_auth_encrypt(subCapSize, subCap, respSize, resp); case TPM_CAP_SELECT_SIZE: debug("[TPM_CAP_SELECT_SIZE]"); /* TODO: TPM_CAP_SELECT_SIZE */ return TPM_FAIL; case TPM_CAP_VERSION_VAL: debug("[TPM_CAP_VERSION_VAL]"); return cap_version_val(respSize, resp); default: return TPM_BAD_MODE; } }