key commit(xmr_amount amount, key mask) { mask = scalarmultBase(mask); key am = d2h(amount); key bH = scalarmultH(am); addKeys(mask, mask, bH); return mask; }
key commit(xmr_amount amount, const key &mask) { key c = scalarmultBase(mask); key am = d2h(amount); key bH = scalarmultH(am); addKeys(c, c, bH); return c; }
key zeroCommit(xmr_amount amount) { key mask = identity(); mask = scalarmultBase(mask); key am = d2h(amount); key bH = scalarmultH(am); addKeys(mask, mask, bH); return mask; }
//generates a <secret , public> / Pedersen commitment to the amount tuple<ctkey, ctkey> ctskpkGen(xmr_amount amount) { ctkey sk, pk; skpkGen(sk.dest, pk.dest); skpkGen(sk.mask, pk.mask); key am = d2h(amount); key bH = scalarmultH(am); addKeys(pk.mask, pk.mask, bH); return make_tuple(sk, pk); }
static int ibrowse_drv_control(ErlDrvData handle, unsigned int command, char *buf, int bufflen, char **rbuf, int rlen) { State* state = (State *) handle; unsigned int j = 0, i = 0; unsigned int temp = 0, rlen_1 = 0; char* replybuf; fprintf(stderr, "alloc_ptr -> %p\n", state->alloc_ptr); /* if(state->alloc_ptr != NULL) */ /* { */ /* driver_free(state->alloc_ptr); */ /* } */ /* Calculate encoded length. If same as bufflen, it means there is no encoding to do. Do return an empty list */ rlen_1 = calc_encoded_length(buf, bufflen); if(rlen_1 == bufflen) { *rbuf = NULL; state->alloc_ptr = NULL; return 0; } *rbuf = driver_alloc(rlen_1); state->alloc_ptr = *rbuf; fprintf(stderr, "*rbuf -> %p\n", *rbuf); replybuf = *rbuf; for(i=0; i<bufflen; i++) { temp = buf[i]; if( ('a' <= temp && temp <= 'z') || ('A' <= temp && temp <= 'Z') || ('0' <= temp && temp <= '9') || temp == '-' || temp == '_' || temp == '.' ) { replybuf[j++] = temp; /* printf("j -> %d\n", j); */ } else { replybuf[j++] = 37; /* printf("temp -> %d\n", temp); printf("d2h(temp >> 4) -> %d\n", d2h(temp >> 4)); printf("d2h(temp & 15) -> %d\n", d2h(temp & 15)); */ replybuf[j++] = d2h(temp >> 4); replybuf[j++] = d2h(temp & 15); /* printf("j -> %d\n", j); */ } } return rlen_1; }
CVMMemHandle * CVMmemFind(void *addr) { CVMMemPrivateData *privateData = memList; while (privateData != NULL) { if ((CVMAddr)addr >= privateData->dataStart.start && (CVMAddr)addr <= privateData->end) { return d2h(privateData); } else { privateData = privateData->next; } } return NULL; }
void CVMmemDisableWriteNotify(CVMMemHandle *h) { CVMMemPrivateData *c; CVMassert(wnlLock != NULL); CVMmutexLock(wnlLock); c = writeNotifyList; while (c != NULL) { if (d2h(c) == h) { CVMMemPrivateData *region; CVMAddr start = c->dataStart.start; CVMAddr end = c->end; CVMAddr alignedStart = ALIGNED(start); CVMAddr alignedEnd = ALIGNEDNEXT(end); /* Found the region. Unprotect it. */ /* Now traverse the list again to check if part of the * aligned pages (first page and last page) belong to * other regions. */ region = writeNotifyList; while (region != NULL) { if (region->end < start && region->end >= alignedStart) { alignedStart = ALIGNEDNEXT(start); } if (region->dataStart.start > end && region->dataStart.start <= alignedEnd) { alignedEnd = ALIGNED(end); } region = region->next; } /* Unprotect the adjusted aligned region, so the next * write within the range would not cause a signal. */ CVMmprotect((void*)alignedStart, (void*)alignedEnd, CVM_FALSE); CVMmutexUnlock(wnlLock); return; } c = c->nextWriteNotify; } CVMmutexUnlock(wnlLock); }
//generates C =aG + bH from b, a is given.. void genC(key & C, const key & a, xmr_amount amount) { key bH = scalarmultH(d2h(amount)); addKeys1(C, a, bH); }
key zeroCommit(xmr_amount amount) { key am = d2h(amount); key bH = scalarmultH(am); return addKeys(G, bH); }
CVMMemHandle * CVMmemAllocWithMetaData(size_t dataSize, int align, CVMMemType mt, CVMMemFlag mf, size_t metaDataSize) { void *p0; void *p; CVMMemPrivateData *h; CVMMemAllocType allocType; CVMMemHandle **hp = NULL; if (dataSize < 16 * 1024) { if (align > 8) { allocType = CVM_MEM_ALLOC_MEMALIGN, p0 = CVMmemalignAlloc(align, dataSize); if (p0 != NULL && mf == CVM_MEM_CLEAR) { memset(p0, 0, dataSize); p = p0; } } else { size_t n = dataSize + 8; allocType = CVM_MEM_ALLOC_MALLOC; if (mf == CVM_MEM_CLEAR) { p0 = calloc(1, n); } else { p0 = malloc(n); } if (p0 != NULL && (mf & CVM_MEM_FAST_ADDR2HANDLE) != 0) { /* * Speed vs. memory trade-off. We can * waste 8-16 bytes to speedup reverse * lookups. */ p = (char *)p0 + 8; if (((CVMAddr)p & (pagesize-1)) == 0) { p0 = realloc(p, dataSize + 16); if (p0 != NULL) { p = (void *)((char *)p + 8); if (((CVMAddr)p & (pagesize-1)) == 0) { p += 8; } } } hp = (CVMMemHandle **)p - 1; } } } else { allocType = CVM_MEM_ALLOC_MMAP; #if 0 p0 = CVMmapNamedAnonMemory(CVMmemTypeInfo[mt].shortName, align, dataSize); #else p0 = NULL; #endif } if (p0 == NULL) { return NULL; } h = (CVMMemPrivateData *)malloc(sizeof *h + metaDataSize); h->data0 = p0; h->dataStart.data = p; h->type = mt; h->allocType = allocType; if (hp != NULL) { *hp = d2h(h); } return &h->h; }
/* Traverse the private list to find if the address belongs to any * region. Notify the write if necessary. An address may still be * a valid address even there is no corresponding region found, * because we can only protect/unprotect aligned range. The return * value tells if the address is valid. */ CVMBool CVMMemWriteNotify(int pid, CVMUint32 *addr, void*pc) { CVMMemPrivateData *r = writeNotifyList; CVMMemHandle *h = NULL; CVMMemType type; CVMMemMonMode mode; CVMBool isValid = CVM_FALSE; /* First check if it's from the same region where the last * write happened. */ if (lastWriteRegion != NULL && (CVMAddr)addr >= ALIGNED(lastWriteRegion->dataStart.start) && (CVMAddr)addr <= ALIGNEDNEXT(lastWriteRegion->end)) { isValid = CVM_TRUE; if ((CVMAddr)addr >= lastWriteRegion->dataStart.start && (CVMAddr)addr <= lastWriteRegion->end) { h = d2h(lastWriteRegion); goto found_region; } } while (r != NULL) { if ((CVMAddr)addr >= ALIGNED(r->dataStart.start) && (CVMAddr)addr <= ALIGNEDNEXT(r->end)) { /* The address is a valid address */ isValid = CVM_TRUE; /* Is the address belong to any write notify region */ if ((CVMAddr)addr >= r->dataStart.start && (CVMAddr)addr <= r->end) { h = d2h(r); lastWriteRegion = r; goto found_region; } } r = r->nextWriteNotify; } return isValid; found_region: CVMassert(h != NULL); type = CVMmemGetType(h); mode = CVMmemGetMonitorMode(h); if (type != -1 && (mode == CVM_MEM_MON_FIRST_WRITE || mode == CVM_MEM_MON_ALL_WRITES)) { CVMBool isFirstWrite = markDirtyPage(addr, h); if (mode == CVM_MEM_MON_ALL_WRITES || (mode == CVM_MEM_MON_FIRST_WRITE && isFirstWrite)) { if (type < CVM_MEM_NUM_TYPES) { CVMmemType[type].writeNotify(pid, addr, pc, h); } else { /* it's a custom type. Look at CVMcustomMemType table. */ CVMcustomMemType[type - CVM_MEM_NUM_TYPES]. writeNotify( pid, addr, pc, h); } } } return isValid; }