示例#1
0
Datum taia_lt_pg(PG_FUNCTION_ARGS) {
  void *p1 = PG_GETARG_POINTER(0);
  void *p2 = PG_GETARG_POINTER(1);
  taia_t t1;
  taia_t t2;
  
  taia_unpack(&t1, p1);
  taia_unpack(&t2, p2);
  
  PG_RETURN_BOOL(taia_cmp(&t1, &t2) == -1);
}
示例#2
0
int sv_stat_load(sv_stat_t *svst, char *path) {
  int r;
  struct stat st;
  char status[SUPERVISE_STATUS_SIZE];
  int status_fd;
  uint32_t tmp;
  
  /* stat() path and check that it's actually a file and the correct size. */
  r = stat(path, &st);
  if (r)
    return r;
  if (!S_ISREG(st.st_mode) || (st.st_size != SUPERVISE_STATUS_SIZE))
    return ESVINVALSTAT;
    
  /* Open path and load its contents into the status byte array. */
  status_fd = open_read(path);
  if (status_fd == -1)
    return ESVOPENSTAT;
  r = read(status_fd, status, SUPERVISE_STATUS_SIZE);
  close(status_fd);
  if (r == -1)
    return ESVREADSTAT;
    
  /* taia_unpack will read the pid as the attoseconds, so set it to zero after
   * reading it. */
  taia_unpack(&svst->timestamp, status);
  svst->timestamp.atto = 0;
  tmp = be32toh(((uint32_t *)status)[3]);
  svst->pid = tmp;
  svst->paused = status[16];
  svst->mode = status[17];
  
  return 0;
}
示例#3
0
unsigned int taia_scan (char const *s, struct taia *a)
{
  char pack[TAIA_PACK] ;
  register unsigned int r = ucharn_scan(s, pack, TAIA_PACK) ;
  if (r) taia_unpack(pack, a) ;
  return r ;
}
示例#4
0
int main() {
  char buf[TAI64NA_ENCODE_SIZE];
  taia_t t = TAIA_INIT;
  taia_t u = TAIA_INIT;
  char pt[TAIA_PACK_SIZE];
  char pu[TAIA_PACK_SIZE];
  
  t.sec = UINT64_MAX;
  t.nano = UINT32_MAX;
  t.atto = UINT32_MAX;
  
  int i;
  for (i = 0; i <= 32; i++) {
    taia_pack(pt, &t);
    tai64na_encode(buf, pt);
    tai64na_decode(pu, buf);
    taia_unpack(&u, pu);
    
    if (taia_cmp(&t, &u) != 0)
      return 1;
      
    t.sec >>= 2;
    t.nano >>= 1;
    t.atto >>= 1;
  }
  
  t.sec = UINT64_MAX;
  t.nano = UINT32_MAX;
  t.atto = UINT32_MAX;
  
  for (i = 0; i <= 32; i++) {
    taia_pack(pt, &t);
    tai64na_encode(buf, pt);
    tai64na_decode(pu, buf);
    taia_unpack(&u, pu);
    
    if (taia_cmp(&t, &u) != 0)
      return 1;
    t.sec <<= 2;
    t.nano <<= 1;
    t.atto <<= 1;
  }
  
  return 0;
}
示例#5
0
VALUE Taia_decode(VALUE self, VALUE encode) {
  char pack[TAIA_PACK_SIZE];
  taia_t *t;
  
  if (strlen(RSTRING_PTR(encode)) != TAI64N_ENCODE_SIZE)
    rb_raise(rb_eArgError, "Input must be an encoded TAI64N value");
    
  Data_Get_Struct(self, taia_t, t);
  tai64n_decode(pack, RSTRING_PTR(encode));
  taia_unpack(t, pack);
}
示例#6
0
ssize_t curve25519_decode(struct curve25519_struct *c, struct curve25519_proto *p,
			  unsigned char *chipertext, size_t size,
			  unsigned char **plaintext, struct taia *arrival_taia)
{
	int ret;
	ssize_t done = size;
	struct taia packet_taia, __arrival_taia;

	spinlock_lock(&c->dec_lock);

	if (unlikely(size > c->dec_buf_size)) {
		spinlock_unlock(&c->dec_lock);
		return -ENOMEM;
	}

	if (unlikely(size < crypto_box_boxzerobytes + NONCE_LENGTH)) {
		spinlock_unlock(&c->dec_lock);
		return 0;
	}
	if (arrival_taia == NULL) {
		taia_now(&__arrival_taia);
		arrival_taia = &__arrival_taia;
	}

	taia_unpack(chipertext + crypto_box_boxzerobytes - NONCE_LENGTH,
		    &packet_taia);
        if (is_good_taia(arrival_taia, &packet_taia) == 0) {
		/* Ignoring packet */
		spinlock_unlock(&c->dec_lock);
		syslog(LOG_ERR, "Bad packet time! Dropping connection!\n");
		return 0;
	}

	memcpy(p->dnonce + NONCE_OFFSET,
	       chipertext + crypto_box_boxzerobytes - NONCE_LENGTH,
	       NONCE_LENGTH);

	memset(c->dec_buf, 0, c->dec_buf_size);

	ret = crypto_box_open_afternm(c->dec_buf, chipertext, size,
				      p->dnonce, p->key);
	if (unlikely(ret)) {
		spinlock_unlock(&c->dec_lock);
		return -EIO;
	}

	(*plaintext) = c->dec_buf;

	spinlock_unlock(&c->dec_lock);

	return done;
}