int main(void) { uint8_t k[32] = {0}; for (int i = 0; i < 32; i++) { k[i] = 0; // (uint8_t)i; } uint8_t nc[32] = {0}; for (int i = 0; i < 24; i++) { nc[i] = 0; //(uint8_t)(255 - i); } printf("k = "); hexprint(k, 32); printf("\nn = "); hexprint(nc, 24); uint32_t ks[120] = {0}; Rijndael_k32b32_expandkey(ks, k); uint8_t* E = valloc(1024*32); if (E == NULL) { abort(); } memset(E, 0, 1024*32); Rijndael_b32_ecb(ks, E, nc); // Rijndael_k32b32_encrypt_x1(ks, E, nc); // Rijndael_k32b32_ctr(ks, E, E, nc, 1); printf("\nE = "); hexprint(E, 32);//1024*32); printf("\nnc= "); hexprint(nc, 32); free(E); }
//------------------------------------------------------------------------------ int compare_buffer(const uint8_t *buffer, const uint32_t length_buffer, const uint8_t *pattern, const uint32_t length_pattern) //------------------------------------------------------------------------------ { int i; if (length_buffer != length_pattern) { printf("Length mismatch, expecting %d bytes, got %d bytes\n", length_pattern, length_buffer); hexprint(buffer, length_buffer); return -1; } for (i = 0; i < length_buffer; i++) { if (pattern[i] != buffer[i]) { printf("Expecting:\n"); hexprint(pattern, length_pattern); printf("Received:\n"); hexprint(buffer, length_buffer); printf("Mismatch fount in byte %d\nExpecting 0x%02x, got 0x%02x\n", i, pattern[i], buffer[i]); return -1; } } return 0; }
static isoprint (struct sockaddr_iso *siso, char *bp) { int didone = 0; if (siso -> siso_plen) { hexprint (bp, siso -> siso_plen, PSEL (siso), "'", "'H"); bp += strlen (bp); *bp++ = '/'; didone++; } if (siso -> siso_slen || didone) { hexprint (bp, siso -> siso_slen, SSEL (siso), "'", "'H"); bp += strlen (bp); *bp++ = '/'; didone++; } if (siso -> siso_tlen || didone) { hexprint (bp, siso -> siso_tlen, TSEL (siso), "'", "'H"); bp += strlen (bp); *bp++ = '/'; didone++; } hexprint (bp, siso -> siso_nlen, siso -> siso_data, "NS+", ""); }
static void print_bitval(FILE *f, const struct msrbits *mb, const struct msr val) { uint8_t i; struct msr tmp, mask = MSR1(1); const struct msrbitvalues *mbv = mb->bitval; while (mbv->text && !msr_eq(mbv->value, val)) mbv++; switch (mb->present) { case PRESENT_BIN: mask = msr_shl(mask, mb->size - 1); for (i = 0; i < mb->size; i++) { memcpy(&tmp, &val, sizeof(val)); msr_and(&tmp, mask); fprintf(f, "%d", (tmp.hi || tmp.lo) ? 1 : 0); mask = msr_shr(mask, 1); } break; case PRESENT_DEC: fprintf(f, "%d", val.lo); break; case PRESENT_OCT: fprintf(f, "0%o", val.lo); break; case PRESENT_HEX: hexprint(f, val, mb->size); break; case PRESENT_HEXDEC: hexprint(f, val, mb->size); fprintf(f, " %d", val.lo); break; } if (mbv->text) fprintf(f, ": %s", mbv->text); fprintf(f, "\n"); }
watchdog_interrupt(void) { #ifdef CONTIKI_TARGET_SKY #if PRINT_STACK_ON_REBOOT uint8_t dummy; static uint8_t *ptr; static int i; ptr = &dummy; printstring("Watchdog reset"); printstring("\nStack at $"); hexprint(((int)ptr) >> 8); hexprint(((int)ptr) & 0xff); printstring(":\n"); for(i = 0; i < 64; ++i) { hexprint(ptr[i]); printchar(' '); if((i & 0x0f) == 0x0f) { printchar('\n'); } } printchar('\n'); #endif /* PRINT_STACK_ON_REBOOT */ #endif /* CONTIKI_TARGET_SKY */ watchdog_reboot(); }
void doit (void) { char digest[20]; int err; /* XXX: We need this to fix secure memory. */ gnutls_global_init (); err = _gnutls_hmac_fast (GNUTLS_MAC_MD5, "keykeykey", 9, "abcdefgh", 8, digest); if (err < 0) fail ("_gnutls_hmac_fast(MD5) failed: %d\n", err); else { if (memcmp (digest, "\x3c\xb0\x9d\x83\x28\x01\xef\xc0" "\x7b\xb3\xaf\x42\x69\xe5\x93\x9a", 16) == 0) success ("_gnutls_hmac_fast(MD5) OK\n"); else { hexprint (digest, 16); fail ("_gnutls_hmac_fast(MD5) failure\n"); } } err = _gnutls_hmac_fast (GNUTLS_MAC_SHA1, "keykeykey", 9, "abcdefgh", 8, digest); if (err < 0) fail ("_gnutls_hmac_fast(SHA1) failed: %d\n", err); else { if (memcmp (digest, "\x58\x93\x7a\x58\xfe\xea\x82\xf8" "\x0e\x64\x62\x01\x40\x2b\x2c\xed\x5d\x54\xc1\xfa", 20) == 0) success ("_gnutls_hmac_fast(SHA1) OK\n"); else { hexprint (digest, 20); fail ("_gnutls_hmac_fast(SHA1) failure\n"); } } err = _gnutls_pbkdf2_sha1 ("password", 8, "salt", 4, 4711, digest, 16); if (err < 0) fail ("_gnutls_pkcs5_pbkdf2_sha1() failed: %d\n", err); else { if (memcmp (digest, "\x09\xb7\x85\x57\xdd\xf6\x07\x15" "\x1c\x52\x34\xde\xba\x5c\xdc\x59", 16) == 0) success ("_gnutls_pkcs5_pbkdf2_sha1() OK\n"); else { hexprint (digest, 16); fail ("_gnutls_pkcs5_pbkdf2_sha1() failure\n"); } } gnutls_global_deinit (); }
void doit (void) { char *out; size_t i; for (i = 0; i < sizeof (nfkc) / sizeof (nfkc[0]); i++) { if (debug) printf ("NFKC entry %ld\n", i); out = stringprep_utf8_nfkc_normalize (nfkc[i].in, (ssize_t) strlen (nfkc[i].in)); if (out == NULL) { fail ("NFKC entry %ld failed fatally\n", i); continue; } if (debug) { uint32_t *t; size_t len; printf ("in:\n"); escapeprint (nfkc[i].in, strlen (nfkc[i].in)); hexprint (nfkc[i].in, strlen (nfkc[i].in)); binprint (nfkc[i].in, strlen (nfkc[i].in)); printf ("out:\n"); escapeprint (out, strlen (out)); hexprint (out, strlen (out)); binprint (out, strlen (out)); t = stringprep_utf8_to_ucs4 (out, -1, &len); if (t) { ucs4print (t, len); free (t); } printf ("expected out:\n"); escapeprint (nfkc[i].out, strlen (nfkc[i].out)); hexprint (nfkc[i].out, strlen (nfkc[i].out)); binprint (nfkc[i].out, strlen (nfkc[i].out)); } if (strlen (nfkc[i].out) != strlen (out) || memcmp (nfkc[i].out, out, strlen (out)) != 0) { fail ("NFKC entry %ld failed\n", i); if (debug) printf ("ERROR\n"); } else if (debug) printf ("OK\n"); free (out); } }
void disp_label() { unsigned char serialbuf[26]; union REGS regs; struct SREGS sregs; /* First set the dta to be fcb so information returned is put there. */ regs.x.ax = 0x1a00; regs.x.dx = (unsigned)fcb; /* needs NEAR POINTER */ intdos(®s, ®s); /* Now try to find the volume label. */ fcb[fcbDRIVE] = *Drive-'A'+1; regs.x.ax = 0x1100; regs.x.dx = (unsigned)fcb; /* needs NEAR POINTER */ intdos(®s, ®s); if (regs.h.al) { myprintf("Volume in drive ",0); myprintf(Drive,1); myprintf(" has no label\r\n",0); } /* end if. */ else { NoLabel = 0; fcb[ENDNAME] = '\0'; myprintf("Volume in drive ",0); myprintf(Drive,1); myprintf(" is ",0); myprintf(&fcb[NAME],0); myprintf("\r\n",0); } /* end else. */ /* Now print out the volume serial number, if it exists. */ segread(&sregs); regs.x.ax = 0x6900; regs.h.bl = *Drive-'A'+1; regs.x.dx = (unsigned)serialbuf; /* needs NEAR POINTER */ intdosx(®s, ®s, &sregs); if (!regs.x.cflag) { myprintf("Volume serial number is ",0); hexprint(serialbuf[5]); hexprint(serialbuf[4]); myprintf("-",0); hexprint(serialbuf[3]); hexprint(serialbuf[2]); myprintf("\r\n",0); } /* end if. */ } /* end disp_label. */
static int sha512_monte_carlo_core ( const char *seed, const char *checks[100] ) { struct sha512_ctx_t sha; sha512_init(&sha); unsigned char md0[64],md1[64],md2[64]; int ret = hexdecode(md0,seed,64); if (ret) { youfail(); printf(" SHA-512 NIST Monte Carlo validation seed hex decode failure.\n"); return -1; } int i,j; memcpy(md1,md0,sizeof(md1)); memcpy(md2,md0,sizeof(md1)); for (j=0; j<100; j++) { for (i=3; i<1003; i++) { sha512_update(&sha,md0,sizeof(md0)); sha512_update(&sha,md1,sizeof(md1)); sha512_update(&sha,md2,sizeof(md2)); memcpy(md0,md1,sizeof(md1)); memcpy(md1,md2,sizeof(md1)); sha512_final(&sha,md2); } ret = hexdecode(md0,checks[j],64); if (ret) { youfail(); printf(" SHA-512 NIST Monte Carlo validation hex decode failure at iteration %d\n", j); return -1; } else if (memcmp(md0,md2,sizeof(md2))) { youfail(); printf(" SHA-512 NIST Monte Carlo validation failure at iteration %d\n", j); hexprint(" Expected", md0, 64); hexprint(" But got ", md2, 64); return j+1; } memcpy(md0,md2,sizeof(md1)); memcpy(md1,md2,sizeof(md1)); } return 0; }
static void server_finished_callback (gnutls_session_t session, const void *finished, size_t len) { success ("server finished (length %d)\n", len); hexprint (finished, len); }
static ssize_t client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) { size_t newlen = to_server_len + len; char *tmp; if (debug) { success ("client_push len %d has %d\n", (int) len, (int) to_server_len); hexprint (data, len); } tmp = realloc (to_server, newlen); if (!tmp) { fail ("Memory allocation failure...\n"); exit (1); } to_server = tmp; memcpy (to_server + to_server_len, data, len); to_server_len = newlen; return len; }
static int send_msg(struct nlmsghdr *nlh) { struct sockaddr_nl nladdr; void *buf = (void *)nlh; int r, len = nlh->nlmsg_len; memset(&nladdr, 0, sizeof(nladdr)); nladdr.nl_family = AF_NETLINK; do { if (hexdump) { printf("SENT A MESSAGE: %d\n", len); hexprint((char *)nlh, nlh->nlmsg_len); } r = sendto(nl_sd, buf, len, 0, (struct sockaddr *)&nladdr, sizeof(nladdr)); } while (r < 0 && errno == EINTR); if (r < 0) { printf("SEND FAILED: %d\n", r); return 1; } else return 0; }
int main(int argc, char **argv) { int8_t *p; uint8_t c; unsigned int key, len, autoboot = 1, dispmenu = 1; // Initialize UART uart_init(); while(1){ /* loop forever until u-boot gets booted or the board is reset */ if(dispmenu){ uart_putstr("\n1: Upload program to RAM\r\n"); // uart_putstr("2: Upload u-boot to Dataflash\r\n"); // uart_putstr("3: Upload Kernel to Dataflash\r\n"); // uart_putstr("4: Start u-boot\r\n"); // uart_putstr("5: Upload Filesystem image\r\n"); // uart_putstr("6: Memory test\r\n"); dispmenu = 0; } key = uart_getchar(); autoboot = 0; if(key == '1'){ len = rxmodem((unsigned char *)0x800); uart_putstr("Received "); hexprint(len); uart_putstr(" bytes\r\n"); // jump(0x1000); dispmenu = 1; } else{ uart_putstr("Invalid input\r\n"); dispmenu = 1; } } }
void doit (void) { MD5_CTX c; unsigned char md[MD5_DIGEST_LENGTH]; if (global_init () != 0) fail ("global_init\n"); if (!gnutls_check_version (GNUTLS_VERSION)) success ("gnutls_check_version ERROR\n"); MD5_Init (&c); MD5_Update (&c, "abc", 3); MD5_Final (&(md[0]), &c); if (memcmp (md, "\x90\x01\x50\x98\x3c\xd2\x4f\xb0" "\xd6\x96\x3f\x7d\x28\xe1\x7f\x72", sizeof (md)) != 0) { hexprint (md, sizeof (md)); fail ("MD5 failure\n"); } else if (debug) success ("MD5 OK\n"); gnutls_global_deinit (); }
int write_seriport(struct gwseriport *s,char *buf,int len) { if(s){ hexprint("seriport send",buf,len); return write(s->fd,buf,len); } return -1; }
static int drbg_hmac_reseed(DRBG_CTX *dctx, const unsigned char *ent, size_t ent_len, const unsigned char *adin, size_t adin_len) { if (!drbg_hmac_update(dctx, ent, ent_len, adin, adin_len, NULL, 0)) return 0; #ifdef HMAC_DRBG_TRACE { DRBG_HMAC_CTX *hmac = &dctx->d.hmac; fprintf(stderr, "K+V after reseed:\n"); hexprint(stderr, hmac->K, hmac->blocklength); hexprint(stderr, hmac->V, hmac->blocklength); } #endif return 1; }
int kmain (void) { struct xmitimerval req = {{0, 200000}, {0, 0}}; struct xmtimespec st, et; int count = 0; long tm; long baud = 156000; int ret; ret = serial_device_init(my_Console_ttyS, baud); set_timer(&req, 0); install_event_handler(0, timer_handler); unmask_event(0); enable_events_flag(); //rt_serial_write(string, 30); while (1) { suspend_domain (0, 0); do { ret = rt_serial_read(string, 1024); if(ret > 0) { count ++; if(count == 1) get_time(&st); else if(count == 100) { get_time(&et); write_scr("\n\n", 2); tm = et.tv_sec-st.tv_sec; hexprint(tm); hexprint(et.tv_nsec); hexprint(st.tv_nsec); count = 0; } } } while(ret > 0); } return 0; }
int main(int argc, char *argv[]) { log_verbose(); get_env(); check(argv); hexprint(argv[1]); return 0; }
static void client_finished_callback (gnutls_session_t session, const void *finished, size_t len) { if (debug) { success ("client finished (length %d)\n", (int) len); hexprint (finished, len); } }
static int drbg_hmac_instantiate(DRBG_CTX *dctx, const unsigned char *ent, size_t ent_len, const unsigned char *nonce, size_t nonce_len, const unsigned char *pstr, size_t pstr_len) { DRBG_HMAC_CTX *hmac = &dctx->d.hmac; memset(hmac->K, 0, dctx->blocklength); memset(hmac->V, 1, dctx->blocklength); if (!drbg_hmac_update(dctx, ent, ent_len, nonce, nonce_len, pstr, pstr_len)) return 0; #ifdef HMAC_DRBG_TRACE fprintf(stderr, "K+V after instantiate:\n"); hexprint(stderr, hmac->K, hmac->blocklength); hexprint(stderr, hmac->V, hmac->blocklength); #endif return 1; }
int main(int argc, char* argv[]) { if(argc == 1){ fputs("error\n",stderr); exit(1); } hexprint(argv[1]); return 0; }
static struct nlmsghdr *get_msg(void) { struct nlmsghdr *nlh; int len; nlh = (struct nlmsghdr *)malloc(MAX_MSG_SIZE); if (NULL==nlh) return NULL; memset(nlh, 0, MAX_MSG_SIZE); len = recv(nl_sd, (void *)nlh, MAX_MSG_SIZE, 0); if (len < 0) { printf("RECEIVE FAILED with %d", errno); free(nlh); return NULL; } if (!(NLMSG_OK(nlh, (unsigned int)len))) { printf("RECEIVE FAILED, message too long\n"); free(nlh); return NULL; } if (nlh->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA(nlh); printf("RECEIVE FAILED with msg error %i (pid %d): %s\n", err->error, nlh->nlmsg_pid, strerror(err->error * -1)); if (hexdump && len > 0) hexprint((char *)nlh, len); free(nlh); return NULL; } if (hexdump) { printf("RECEIVED A MESSAGE: %d\n", len); hexprint((char *)nlh, nlh->nlmsg_len); } return nlh; }
int main(int argc, char* argv[]) { unsigned long dwResult = 0; unsigned char plainText[BUFFERLENGTH]; unsigned char cipher[BUFFERLENGTH]; unsigned char random[17]; unsigned char encryptrandom[33]; // clear text memset(plainText, 0, BUFFERLENGTH); memcpy(plainText, "select * from t0a12 where", BUFFERLENGTH); // test encrypt printf("Begin encrypt in TDES_ECB mode...\n"); memset(cipher, 0, BUFFERLENGTH); crypto(0, plainText, cipher); printf("Success!\nThe cipher:"); hexprint(stdout, cipher, BUFFERLENGTH); // test decrypt printf("Begin decrypt in TDES_ECB mode...\n"); memset(plainText, 0, BUFFERLENGTH); crypto(1, cipher, plainText); printf("Success!\nThe plainText:"); hexprint(stdout, plainText, BUFFERLENGTH); printf("%s",plainText); // test encryptrand memset(random, 0, 17); memset(encryptrandom, 0, 33); memcpy(random, "FCVK3MP6B0d8TezE", 16); encryptrand(random, encryptrandom); hexprint(stdout, random, 16); printf("\n%s\n", encryptrandom); return dwResult; }
static int amr_codec_decoder(const struct PluginCodec_Definition * codec, void * context, const void * from, unsigned * fromLen, void * to, unsigned * toLen, unsigned int * flag) { // unsigned int mode; if( *fromLen < 1 ) return 0; /* // get the AMR mode from the first nibble of the frame mode = *(char *)from & 0xF; // check that the input is long enough for the decoder if( *fromLen != bytes_per_frame[mode] ) { fprintf(stderr,"AMR codec: packet size %u doesn't match expected %u for mode %u\n", *fromLen,bytes_per_frame[mode], mode ); return 0; } */ Decoder_Interface_Decode( context, (void *)from, (short *)to, 0 ); #if 0 fprintf(stderr,"Decoded AMR frame ["); hexprint(from,*fromLen); fprintf(stderr,"]\nResult: ["); hexprint(to,40); fprintf(stderr,"...]\n"); #endif // return the number of decoded bytes to the caller *toLen = 160*sizeof(short); return 1; }
/* idx == -1 indicates main key * otherwise the subkey. */ static void print_key_fingerprint (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert) { char fpr[128]; size_t fpr_size = sizeof (fpr); int err; err = gnutls_openpgp_crt_get_fingerprint (cert, fpr, &fpr_size); if (err < 0) addf (str, "error: get_fingerprint: %s\n", gnutls_strerror (err)); else { adds (str, _("\tFingerprint (hex): ")); hexprint (str, fpr, fpr_size); addf (str, "\n"); } }
char *ft_xitoa(long unsigned int n, char c) { char *str; size_t i; i = len_str(n); str = ft_strnew(i); if (str) { if (!n) str[0] = '0'; while (n) { str[--i] = hexprint(n, c); n = n / 16; } } return (str); }
static void seriportHandler(aeEventLoop *el,int fd,void *privdata,int mask) { struct gwseriport *s = privdata; int nread = buffer_read_append(s->recvbuf,fd); if(nread == -1){ if(errno == EAGAIN){ return; }else{ fprintf(stdout,"Read from seriport: %s\n",strerror(errno)); gwseriport_release(s); return; } }else if(nread == 0){ fprintf(stdout,"Seriport closed\n"); gwseriport_release(s); return; } char buf[512] = {0}; int r; struct sensor_data *sd; while((r=buffer_read_slip(s->recvbuf,buf,sizeof(buf))) >= 0){ if(r == 0) continue; hexprint("read seriport",buf,r); sd = slip_to_sensor_data(buf,r); if(sd != NULL){ sensor_data_debug(sd); snprintf(s->transfer_media,sizeof(s->transfer_media),"%s",sd->transfer_type); sdlist_check_push(server.global_sensor_data,sd); json_server_broadcast(sd); gw_cloud_broadcast(sd); sensor_data_release(sd); }else{ fprintf(stderr,"slip_to_sensor_data return NULL\n"); } } }
/* idx == -1 indicates main key * otherwise the subkey. */ static void print_key_id (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert, int idx) { gnutls_openpgp_keyid_t id; int err; if (idx < 0) err = gnutls_openpgp_crt_get_key_id (cert, id); else err = gnutls_openpgp_crt_get_subkey_id (cert, idx, id); if (err < 0) addf (str, "error: get_key_id: %s\n", gnutls_strerror (err)); else { adds (str, _("\tID (hex): ")); hexprint (str, id, sizeof (id)); addf (str, "\n"); } }
std::ostream& operator << ( std::ostream& stream, const flowgraph::node* n ) { stream << tobinary( (void*) n ) << " : "; if( n -> ins ) stream << * ( n -> ins ); else stream << " "; stream << " [ "; for( std::list< flowgraph::node* > :: const_iterator p = n -> succ. begin( ); p != n -> succ. end( ); ++ p ) { if( p != ( n -> succ. begin( ))) stream << ", "; stream << tobinary( (void*) *p ); } stream << " ]"; #if 0 stream << ", back[ "; for( std::list< flowgraph::node* > :: const_iterator p = n -> pred. begin( ); p != n -> pred. end( ); ++ p ) { if( p != ( n -> pred. begin( ))) stream << ", "; hexprint( stream, (void*) *p ); } stream << " ]"; #endif return stream; }
static void decode(const char *test_name, const gnutls_datum_t *raw, const gnutls_datum_t *id, const gnutls_datum_t *b, unsigned idx, int res) { int ret; psk_ext_parser_st p; psk_ext_iter_st iter; struct psk_st psk; gnutls_datum_t binder; unsigned found = 0; unsigned i, j; ret = _gnutls13_psk_ext_parser_init(&p, raw->data, raw->size); if (ret < 0) { if (res == ret) /* expected */ return; fail("%s: _gnutls13_psk_ext_parser_init: %d/%s\n", test_name, ret, gnutls_strerror(ret)); exit(1); } _gnutls13_psk_ext_iter_init(&iter, &p); for (i = 0; ; i++) { ret = _gnutls13_psk_ext_iter_next_identity(&iter, &psk); if (ret < 0) { if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) break; if (res == ret) /* expected */ return; } if (i == idx) { if (psk.identity.size == id->size && memcmp(psk.identity.data, id->data, id->size) == 0) { if (debug) success("%s: found id\n", test_name); found = 1; break; } else { fail("%s: did not found identity on index %d\n", test_name, idx); } } } if (found == 0) fail("%s: did not found identity!\n", test_name); _gnutls13_psk_ext_iter_init(&iter, &p); for (j = 0; j <= i; j++) { ret = _gnutls13_psk_ext_iter_next_binder(&iter, &binder); if (ret < 0) { if (res == ret) /* expected */ return; fail("%s: could not extract binder: %s\n", test_name, gnutls_strerror(ret)); } } if (debug) success("%s: found binder\n", test_name); if (binder.size != b->size || memcmp(binder.data, b->data, b->size) != 0) { hexprint(binder.data, binder.size); fail("%s: did not match binder on index %d\n", test_name, idx); } return; }