void sharecalc() { char buf[1024]; if(np<n){ fprintf(stderr,"Could not read enough shares, unable to compute.\n"); exit(1); } /*calculate*/ /*printf("Key-Matrix:\n");printm(kmatrix); printf("Hash-Matrix:\n");printm(hmatrix);*/ solve(kmatrix); solve(hmatrix); /*output result*/ str2bin(key,mpz_get_str(buf,16,kmatrix[0][n]),16); str2bin(hashv,mpz_get_str(buf,16,hmatrix[0][n]),16); /*printf("Using key: %s\n",key_prints(0,key)); printf("Expected Hash: %s\n",key_prints(0,hashv));*/ /*printf("Key-Matrix:\n");printm(kmatrix); printf("Hash-Matrix:\n");printm(hmatrix);*/ }
static int handleTgtResp(isess_t *sess, pdu_t *pp) { isc_opt_t *op = sess->op; char *np, *rp, *d1, *d2; int res, l1, l2; res = -1; if(((np = getkeyval("CHAP_N=", pp)) == NULL) || ((rp = getkeyval("CHAP_R=", pp)) == NULL)) goto out; if(strcmp(np, op->tgtChapName? op->tgtChapName: op->initiatorName) != 0) { fprintf(stderr, "%s does not match\n", np); goto out; } l1 = str2bin(op->tgtChapDigest, &d1); l2 = str2bin(rp, &d2); debug(3, "l1=%d '%s' l2=%d '%s'", l1, op->tgtChapDigest, l2, rp); if(l1 == l2 && memcmp(d1, d2, l1) == 0) res = 0; if(l1) free(d1); if(l2) free(d2); out: free(op->tgtChapDigest); op->tgtChapDigest = NULL; debug(3, "res=%d", res); return res; }
static int chapSHA1(char id, char *cp, char *chapSecret, unsigned char *digest) { SHA1_CTX ctx; char *tmp; int len; debug_called(3); SHA1_Init(&ctx); SHA1_Update(&ctx, &id, 1); if((len = str2bin(chapSecret, &tmp)) == 0) { // print error return -1; } SHA1_Update(&ctx, tmp, len); free(tmp); if((len = str2bin(cp, &tmp)) == 0) { // print error return -1; } SHA1_Update(&ctx, tmp, len); free(tmp); SHA1_Final(digest, &ctx); return 0; }
void target(char *s) { unsigned char *p; if(s == NULL) return; p = get_alignmem(1024); if(p == NULL) return; memset(p, 0xcc, 1024); if(str2bin(s, p+1, 64) == -1) return; if(ptrace(PTRACE_TRACEME, 0, NULL, NULL) == -1) return; // initialize __asm("xorl %eax, %eax"); __asm("xorl %ecx, %ecx"); __asm("xorl %edx, %edx"); __asm("xorl %ebx, %ebx"); __asm("xorl %esi, %esi"); __asm("xorl %edi, %edi"); // goto there ((void (*)())p)(); }
/** * * read public or private key in PEM format * * ifile : name of file to write PEM encoded key * pemType : type of key being saved * rsa : RSA object with public and private keys * */ LPVOID rsa_read_pem(const char* ifile, PDWORD binLen) { FILE *in; struct stat st; LPVOID pem = NULL, bin = NULL; stat(ifile, &st); if (st.st_size == 0) return NULL; // open PEM file in = fopen(ifile, "rb"); if (in != NULL) { // allocate memory for data pem = xmalloc(st.st_size + 1); if (pem != NULL) { // read data fread(pem, sizeof(char), st.st_size, in); bin = str2bin(pem, strlen(pem), CRYPT_STRING_BASE64HEADER, binLen); xfree(pem); } fclose(in); } return bin; }
main(int cc, char **vv) { char *p, *ap, *ip, *cp, *chapSecret, *digest; int len; #if 0 ap = "5"; chapSecret = "0xa5aff013dd839b1edd31ee73a1df0b1b"; // chapSecret = "abcdefghijklmnop"; len = str2bin(chapSecret, &cp); puke(chapSecret, cp, len); ip = "238"; cp = "0xbd456029"; if((digest = chapDigest(ap, ip, cp, chapSecret)) != NULL) { len = str2bin(digest, &cp); puke(digest, cp, len); } #else printf("%d] %s\n", 24, genChallenge("0X", 24)); #endif }
static void test_normal_str2bin() { char* s = "00090A0F"; uint8_t b[] = {0x00,0x09,0x0A,0x0F}; uint8_t buffer[MAX_BUFFER_SIZE]; int32_t ret; size_t i; memset(buffer,0,sizeof(buffer)); ret = str2bin(s,strlen(s),buffer,sizeof(buffer)); CU_ASSERT_EQUAL(ret,SUCCESS); for(i = 0;i < ARRAY_SIZE(b);i++) { CU_ASSERT_EQUAL(b[i],buffer[i]); } }
static void encode_password(const str_t password, const char verify_code[VERIFY_LEN], const uchar bits[BITS_LEN], uchar out[MD5_DIGEST_LENGTH << 1]) { str_t password_bin = str2bin(password); uchar md5_src_1[MD5_DIGEST_LENGTH + BITS_LEN] = {0}; uchar md5_src_2[(MD5_DIGEST_LENGTH << 1) + VERIFY_LEN] = {0}; uchar md5_src[MD5_DIGEST_LENGTH << 1] = {0}; size_t i; memcpy(md5_src_1, password_bin.ptr, MD5_DIGEST_LENGTH); memcpy(md5_src_1 + MD5_DIGEST_LENGTH, bits, BITS_LEN); str_free(password_bin); md5_str(md5_src_1, MD5_DIGEST_LENGTH + BITS_LEN, md5_src); memcpy(md5_src_2, md5_src, MD5_DIGEST_LENGTH << 1); for (i = 0; i < VERIFY_LEN; ++i) { md5_src_2[(MD5_DIGEST_LENGTH << 1) + i] = toupper(verify_code[i]); } md5_str(md5_src_2, (MD5_DIGEST_LENGTH << 1) + VERIFY_LEN, out); }
int push_send(PushServer* apns, const char *device_token, const char* alert, const char* custom, int badge) { APNS_Payload* payload = NULL; APNS_Item* item; uint32_t id; char* message; if (device_token == NULL) { LM_ERR("Cannot start push, device token is NULL\n"); return -1; } if (alert == NULL) { LM_ERR("Cannot start push, alert is NULL\n"); return -1; } LM_DBG("token %s\n", device_token); APNS_Notification* notification = create_notification(); if (notification == NULL) { LM_ERR("Cannot create notification\n"); return -1; } payload = calloc(1, sizeof(APNS_Payload)); if (payload == NULL) { LM_ERR("Cannot create payload\n"); destroy_notification(notification); return -1; } payload->alert = strdup(alert); payload->custom_param = (custom == NULL) ? NULL : strdup(custom); payload->badge = badge; item = create_item(payload, PUSH_MAX_PRIO); if (item == NULL) { LM_ERR("Cannot create item\n"); destroy_notification(notification); destroy_payload(payload); return -1; } str2bin(device_token, item->token); id = item->identifier = get_notification_id(); if (-1 == notification_add_item(notification, item)) { LM_ERR("Cannot add item, return....\n"); destroy_notification(notification); destroy_payload(payload); return -1; } LM_DBG("item successfuly added, make a message\n"); message = make_push_msg(notification); if (message == NULL) { LM_DBG("make_push_msg failed, destroy it\n"); destroy_notification(notification); LM_DBG("Return -1\n"); return -1; } { char *buf; bin2str(message, notification->length, &buf); LM_DBG("Sending data to apns: [%s], length %d\n", buf, notification->length); free(buf); } if (-1 == send_push_data(apns, message, notification->length)) { LM_ERR("Push sending failed\n"); } LM_DBG("OK\n"); // free(message); add_push_to_queue(id, message, notification->length); LM_DBG("Destroy\n"); destroy_notification(notification); LM_DBG("Success\n"); return 1; }