本文整理匯總了Golang中C.ulonglong函數的典型用法代碼示例。如果您正苦於以下問題:Golang ulonglong函數的具體用法?Golang ulonglong怎麽用?Golang ulonglong使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ulonglong函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Download
func (v *VirStorageVol) Download(stream *VirStream, offset, length uint64, flags uint32) error {
if C.virStorageVolDownload(v.ptr, stream.ptr, C.ulonglong(offset),
C.ulonglong(length), C.uint(flags)) == -1 {
return GetLastError()
}
return nil
}
示例2: CryptoSignFucky
// sign data with secret key sk
// return detached sig
// this uses crypto_sign instead pf crypto_sign_detached
func CryptoSignFucky(msg, sk []byte) []byte {
msgbuff := NewBuffer(msg)
defer msgbuff.Free()
skbuff := NewBuffer(sk)
defer skbuff.Free()
if skbuff.size != C.crypto_sign_bytes() {
log.Println("nacl.CryptoSign() invalid secret key size", len(sk))
return nil
}
// allocate the signed message buffer
sig := malloc(C.crypto_sign_bytes() + msgbuff.size)
defer sig.Free()
// compute signature
siglen := C.ulonglong(0)
res := C.crypto_sign(sig.uchar(), &siglen, msgbuff.uchar(), C.ulonglong(msgbuff.size), skbuff.uchar())
if res == 0 {
// return copy of signature inside the signed message
offset := int(C.crypto_sign_bytes())
return sig.Bytes()[:offset]
}
// failure to sign
log.Println("nacl.CryptoSign() failed")
return nil
}
示例3: StorageVolUpload
func StorageVolUpload(vol VirStorageVol, s VirStream, offset uint64, length uint64) error {
result := C.virStorageVolUpload(vol.ptr, s.ptr, C.ulonglong(offset), C.ulonglong(length), 0)
if result < 0 {
return errors.New(GetLastError())
}
return nil
}
示例4: Seal
func (ctx *natrAEAD) Seal(dst, nonce, plaintext, data []byte) []byte {
out := make([]byte, len(plaintext)+_AEADOverheadBytes)
rv := C.crypto_aead_chacha20poly1305_encrypt(g2cbt(out), nil,
g2cbt(plaintext), C.ulonglong(len(plaintext)), g2cbt(data), C.ulonglong(len(data)),
nil, g2cbt(nonce), g2cbt(ctx.key[:]))
if rv != 0 {
panic("crypto_secretbox_easy returned non-zero")
}
return append(dst, out...)
}
示例5: Open
func (ctx *natrAEAD) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
out := make([]byte, len(ciphertext)-_AEADOverheadBytes)
rv := C.crypto_aead_chacha20poly1305_decrypt(g2cbt(out), nil, nil,
g2cbt(ciphertext), C.ulonglong(len(ciphertext)), g2cbt(data), C.ulonglong(len(data)),
g2cbt(nonce), g2cbt(ctx.key[:]))
if rv != 0 {
return nil, errors.New("MAC error")
}
return append(dst, out...), nil
}
示例6: lowerWindow
func lowerWindow(c1 chan string, cycles int64) {
C.init_perfcounters(1, 0)
timeStart := C.ulonglong(C.get_cyclecount())
for {
timeElapsed := C.ulonglong(C.get_cyclecount()) - timeStart
if timeElapsed > C.ulonglong(cycles) {
c1 <- "ENTER WINDOW\n"
break
}
}
}
示例7: big2scalar
func big2scalar(out *[4]C.ulonglong, in *big.Int) error {
b := in.Bits()
if len(b) > 8 {
return fmt.Errorf("big.Int needs %d words, cannot be converted to scalar_t", len(b))
}
max := len(b) >> 1
for i := 0; i < max; i++ {
out[i] = C.ulonglong(b[i<<1]) | (C.ulonglong(b[i<<1+1]) << 32)
}
if len(b)&0x1 == 1 {
out[max] = C.ulonglong(b[len(b)-1])
}
return nil
}
示例8: ReadMsgpackFrame
//export ReadMsgpackFrame
//
// ReadMsgpackFrame reads the msgpack frame at byteOffset in rawStream, decodes the
// 2-5 bytes of a msgpack binary array (either bin8, bin16, or bin32), and returns
// and the decoded-into-R object and the next byteOffset to use.
//
func ReadMsgpackFrame(rawStream C.SEXP, byteOffset C.SEXP) C.SEXP {
var start int
if C.TYPEOF(byteOffset) == C.REALSXP {
start = int(C.get_real_elt(byteOffset, 0))
} else if C.TYPEOF(byteOffset) == C.INTSXP {
start = int(C.get_int_elt(byteOffset, 0))
} else {
C.ReportErrorToR_NoReturn(C.CString("read.msgpack.frame(x, byteOffset) requires byteOffset to be a numeric byte-offset number."))
}
// rawStream must be a RAWSXP
if C.TYPEOF(rawStream) != C.RAWSXP {
C.ReportErrorToR_NoReturn(C.CString("read.msgpack.frame(x, byteOffset) requires x be a RAW vector of bytes."))
}
n := int(C.Rf_xlength(rawStream))
if n == 0 {
return C.R_NilValue
}
if start >= n {
C.ReportErrorToR_NoReturn(C.CString(fmt.Sprintf("read.msgpack.frame(x, byteOffset) error: byteOffset(%d) is beyond the length of x (x has len %d).", start, n)))
}
var decoder [5]byte
C.memcpy(unsafe.Pointer(&decoder[0]), unsafe.Pointer(C.get_raw_elt_ptr(rawStream, C.ulonglong(start))), C.size_t(5))
headerSz, _, totalSz, err := DecodeMsgpackBinArrayHeader(decoder[:])
if err != nil {
C.ReportErrorToR_NoReturn(C.CString(fmt.Sprintf("ReadMsgpackFrame error trying to decode msgpack frame: %s", err)))
}
if start+totalSz > n {
C.ReportErrorToR_NoReturn(C.CString(fmt.Sprintf("read.msgpack.frame(x, byteOffset) error: byteOffset(%d) plus the frames size(%d) goes beyond the length of x (x has len %d).", start, totalSz, n)))
}
bytes := make([]byte, totalSz)
C.memcpy(unsafe.Pointer(&bytes[0]), unsafe.Pointer(C.get_raw_elt_ptr(rawStream, C.ulonglong(start))), C.size_t(totalSz))
rObject := decodeMsgpackToR(bytes[headerSz:])
C.Rf_protect(rObject)
returnList := C.allocVector(C.VECSXP, C.R_xlen_t(2))
C.Rf_protect(returnList)
C.SET_VECTOR_ELT(returnList, C.R_xlen_t(0), C.Rf_ScalarReal(C.double(float64(start+totalSz))))
C.SET_VECTOR_ELT(returnList, C.R_xlen_t(1), rObject)
C.Rf_unprotect_ptr(rObject)
C.Rf_unprotect_ptr(returnList)
return returnList
}
示例9: CryptoVerify
// verify a signed message
func CryptoVerify(smsg, pk []byte) bool {
smsg_buff := NewBuffer(smsg)
defer smsg_buff.Free()
pk_buff := NewBuffer(pk)
defer pk_buff.Free()
if pk_buff.size != C.crypto_sign_publickeybytes() {
return false
}
mlen := C.ulonglong(0)
msg := malloc(C.size_t(len(smsg)))
defer msg.Free()
smlen := C.ulonglong(smsg_buff.size)
return C.crypto_sign_open(msg.uchar(), &mlen, smsg_buff.uchar(), smlen, pk_buff.uchar()) != -1
}
示例10: waitTimer
func waitTimer(cycles int64, f *os.File) int {
// init counters:
C.init_perfcounters(1, 0)
//fmt.Printf("cyles to wait: %d\n", cycles)
timeStart := C.ulonglong(C.get_cyclecount())
timeElapsed := C.ulonglong(0)
for {
timeElapsed = C.ulonglong(C.get_cyclecount()) - timeStart
if timeElapsed > C.ulonglong(cycles) {
writeMessage(f, fmt.Sprintf("%27s", "COMPLETE"))
break
}
}
return int(timeElapsed)
}
示例11: CryptoBox
// encrypts a message to a user given their public key is known
// returns an encrypted box
func CryptoBox(msg, nounce, pk, sk []byte) []byte {
msgbuff := NewBuffer(msg)
defer msgbuff.Free()
// check sizes
if len(pk) != int(C.crypto_box_publickeybytes()) {
log.Println("len(pk) != crypto_box_publickey_bytes")
return nil
}
if len(sk) != int(C.crypto_box_secretkeybytes()) {
log.Println("len(sk) != crypto_box_secretkey_bytes")
return nil
}
if len(nounce) != int(C.crypto_box_macbytes()) {
log.Println("len(nounce) != crypto_box_macbytes()")
return nil
}
pkbuff := NewBuffer(pk)
defer pkbuff.Free()
skbuff := NewBuffer(sk)
defer skbuff.Free()
nouncebuff := NewBuffer(nounce)
defer nouncebuff.Free()
resultbuff := malloc(msgbuff.size + nouncebuff.size)
defer resultbuff.Free()
res := C.crypto_box_easy(resultbuff.uchar(), msgbuff.uchar(), C.ulonglong(msgbuff.size), nouncebuff.uchar(), pkbuff.uchar(), skbuff.uchar())
if res != 0 {
log.Println("crypto_box_easy failed:", res)
return nil
}
return resultbuff.Bytes()
}
示例12: New
// New returns a new Pigosat instance, ready to have literals added to it. The
// error return value need only be checked if the OutputFile option is non-nil.
func New(options *Options) (*Pigosat, error) {
// PicoSAT * picosat_init (void);
p := C.picosat_init()
if options != nil {
// void picosat_set_propagation_limit (PicoSAT *, unsigned long long limit);
C.picosat_set_propagation_limit(p, C.ulonglong(options.PropagationLimit))
if options.OutputFile != nil {
cfile, err := cfdopen(options.OutputFile, "a")
if err != nil {
C.picosat_reset(p)
return nil, &os.PathError{Op: "fdopen",
Path: options.OutputFile.Name(), Err: err}
}
// void picosat_set_output (PicoSAT *, FILE *);
C.picosat_set_output(p, cfile)
}
// void picosat_set_verbosity (PicoSAT *, int new_verbosity_level);
C.picosat_set_verbosity(p, C.int(options.Verbosity))
if options.Prefix != "" {
// void picosat_set_prefix (PicoSAT *, const char *);
prefix := C.CString(options.Prefix)
defer C.free(unsafe.Pointer(prefix))
C.picosat_set_prefix(p, prefix)
}
if options.MeasureAllCalls {
// void picosat_measure_all_calls (PicoSAT *);
C.picosat_measure_all_calls(p)
}
}
pgo := &Pigosat{p: p, lock: sync.RWMutex{}}
runtime.SetFinalizer(pgo, (*Pigosat).delete)
return pgo, nil
}
示例13: Random
func Random(n int) []byte {
buf := make([]byte, n)
C.randombytes(array(buf), C.ulonglong(n))
return buf
}
示例14: CryptoBoxOpen
// open an encrypted box
func CryptoBoxOpen(box, nounce, sk, pk []byte) ([]byte, error) {
boxbuff := NewBuffer(box)
defer boxbuff.Free()
// check sizes
if len(pk) != int(C.crypto_box_publickeybytes()) {
err := errors.New("len(pk) != crypto_box_publickey_bytes")
return nil, err
}
if len(sk) != int(C.crypto_box_secretkeybytes()) {
err := errors.New("len(sk) != crypto_box_secretkey_bytes")
return nil, err
}
if len(nounce) != int(C.crypto_box_macbytes()) {
err := errors.New("len(nounce) != crypto_box_macbytes()")
return nil, err
}
pkbuff := NewBuffer(pk)
defer pkbuff.Free()
skbuff := NewBuffer(sk)
defer skbuff.Free()
nouncebuff := NewBuffer(nounce)
defer nouncebuff.Free()
resultbuff := malloc(boxbuff.size - nouncebuff.size)
defer resultbuff.Free()
// decrypt
res := C.crypto_box_open_easy(resultbuff.uchar(), boxbuff.uchar(), C.ulonglong(boxbuff.size), nouncebuff.uchar(), pkbuff.uchar(), skbuff.uchar())
if res != 0 {
return nil, errors.New("crypto_box_open_easy failed")
}
// return result
return resultbuff.Bytes(), nil
}
示例15: Hash
func Hash(message []byte) []byte {
hash := make([]byte, HashSize)
C.crypto_hash(array(hash), array(message), C.ulonglong(len(message)))
return hash
}