Ejemplo n.º 1
0
void DIV32(reg_t r1, reg_t r2, reg_t r3, reg_t scratch)
{
  MOV32(scratch, r2); 
  MOVIM32(r1, 0);

  EQ32(scratch+4, r3, R_ZERO);
  if (REG32(scratch+4))
  {
    goto _end;
  }

  
  GTE32(scratch+4, scratch, r3, scratch+8);
  GT32(scratch+8, scratch, R_ZERO);
  LAND32(scratch+12, scratch+4, scratch+8);
  while (REG32(scratch+12))
  {
    INC32(r1);
    SUB32(scratch, scratch, r3);
    GTE32(scratch+4, scratch, r3, scratch+8);
    GT32(scratch+8, scratch, R_ZERO);
    LAND32(scratch+12, scratch+4, scratch+8);
  } 

_end:
  return;
}
Ejemplo n.º 2
0
static void
ctr32_encrypt_blocks_inplace(const unsigned char *in, unsigned char *out,
			     size_t blocks, const AES_KEY *key,
			     const unsigned char ivec[16])
{
	unsigned i;
	uint8_t ctr[16];
	uint8_t tmp[16];

	memcpy(ctr, ivec, 16);

	for (i=0;i<blocks;i++) {
		aes_v8_encrypt(ctr, tmp, key);
		memxor3(out, tmp, in, 16);

		out += 16;
		in += 16;
		INC32(ctr);
	}
}
Ejemplo n.º 3
0
static void
ctr32_encrypt_blocks(const unsigned char *in, unsigned char *out,
		     size_t blocks, const AES_KEY *key,
		     const unsigned char ivec[16])
{
	unsigned i;
	uint8_t ctr[16];

	if (in == out)
		return ctr32_encrypt_blocks_inplace(in, out, blocks, key, ivec);

	memcpy(ctr, ivec, 16);

	for (i=0;i<blocks;i++) {
		aes_v8_encrypt(ctr, out, key);
		memxor(out, in, 16);

		out += 16;
		in += 16;
		INC32(ctr);
	}
}
Ejemplo n.º 4
0
/* SSL 2.0 imlementation for SSL_read/SSL_peek -
 * This routine will return 0 to len bytes, decrypted etc if required.
 */
static int ssl2_read_internal(SSL *s, void *buf, int len, int peek)
	{
	int n;
	unsigned char mac[MAX_MAC_SIZE];
	unsigned char *p;
	int i;
	int mac_size;

 ssl2_read_again:
	if (SSL_in_init(s) && !s->in_handshake)
		{
		n=s->handshake_func(s);
		if (n < 0) return(n);
		if (n == 0)
			{
			SSLerr(SSL_F_SSL2_READ_INTERNAL,SSL_R_SSL_HANDSHAKE_FAILURE);
			return(-1);
			}
		}

	clear_sys_error();
	s->rwstate=SSL_NOTHING;
	if (len <= 0) return(len);

	if (s->s2->ract_data_length != 0) /* read from buffer */
		{
		if (len > s->s2->ract_data_length)
			n=s->s2->ract_data_length;
		else
			n=len;

		memcpy(buf,s->s2->ract_data,(unsigned int)n);
		if (!peek)
			{
			s->s2->ract_data_length-=n;
			s->s2->ract_data+=n;
			if (s->s2->ract_data_length == 0)
				s->rstate=SSL_ST_READ_HEADER;
			}

		return(n);
		}

	/* s->s2->ract_data_length == 0
	 * 
	 * Fill the buffer, then goto ssl2_read_again.
	 */

	if (s->rstate == SSL_ST_READ_HEADER)
		{
		if (s->first_packet)
			{
			n=read_n(s,5,SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER+2,0);
			if (n <= 0) return(n); /* error or non-blocking */
			s->first_packet=0;
			p=s->packet;
			if (!((p[0] & 0x80) && (
				(p[2] == SSL2_MT_CLIENT_HELLO) ||
				(p[2] == SSL2_MT_SERVER_HELLO))))
				{
				SSLerr(SSL_F_SSL2_READ_INTERNAL,SSL_R_NON_SSLV2_INITIAL_PACKET);
				return(-1);
				}
			}
		else
			{
			n=read_n(s,2,SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER+2,0);
			if (n <= 0) return(n); /* error or non-blocking */
			}
		/* part read stuff */

		s->rstate=SSL_ST_READ_BODY;
		p=s->packet;
		/* Do header */
		/*s->s2->padding=0;*/
		s->s2->escape=0;
		s->s2->rlength=(((unsigned int)p[0])<<8)|((unsigned int)p[1]);
		if ((p[0] & TWO_BYTE_BIT))		/* Two byte header? */
			{
			s->s2->three_byte_header=0;
			s->s2->rlength&=TWO_BYTE_MASK;	
			}
		else
			{
			s->s2->three_byte_header=1;
			s->s2->rlength&=THREE_BYTE_MASK;

			/* security >s2->escape */
			s->s2->escape=((p[0] & SEC_ESC_BIT))?1:0;
			}
		}

	if (s->rstate == SSL_ST_READ_BODY)
		{
		n=s->s2->rlength+2+s->s2->three_byte_header;
		if (n > (int)s->packet_length)
			{
			n-=s->packet_length;
			i=read_n(s,(unsigned int)n,(unsigned int)n,1);
			if (i <= 0) return(i); /* ERROR */
			}

		p= &(s->packet[2]);
		s->rstate=SSL_ST_READ_HEADER;
		if (s->s2->three_byte_header)
			s->s2->padding= *(p++);
		else	s->s2->padding=0;

		/* Data portion */
		if (s->s2->clear_text)
			{
			mac_size = 0;
			s->s2->mac_data=p;
			s->s2->ract_data=p;
			if (s->s2->padding)
				{
				SSLerr(SSL_F_SSL2_READ_INTERNAL,SSL_R_ILLEGAL_PADDING);
				return(-1);
				}
			}
		else
			{
			mac_size=EVP_MD_CTX_size(s->read_hash);
			if (mac_size < 0)
				return -1;
			OPENSSL_assert(mac_size <= MAX_MAC_SIZE);
			s->s2->mac_data=p;
			s->s2->ract_data= &p[mac_size];
			if (s->s2->padding + mac_size > s->s2->rlength)
				{
				SSLerr(SSL_F_SSL2_READ_INTERNAL,SSL_R_ILLEGAL_PADDING);
				return(-1);
				}
			}

		s->s2->ract_data_length=s->s2->rlength;
		/* added a check for length > max_size in case
		 * encryption was not turned on yet due to an error */
		if ((!s->s2->clear_text) &&
			(s->s2->rlength >= (unsigned int)mac_size))
			{
			ssl2_enc(s,0);
			s->s2->ract_data_length-=mac_size;
			ssl2_mac(s,mac,0);
			s->s2->ract_data_length-=s->s2->padding;
			if (	(CRYPTO_memcmp(mac,s->s2->mac_data,mac_size) != 0) ||
				(s->s2->rlength%EVP_CIPHER_CTX_block_size(s->enc_read_ctx) != 0))
				{
				SSLerr(SSL_F_SSL2_READ_INTERNAL,SSL_R_BAD_MAC_DECODE);
				return(-1);
				}
			}
		INC32(s->s2->read_sequence); /* expect next number */
		/* s->s2->ract_data is now available for processing */

		/* Possibly the packet that we just read had 0 actual data bytes.
		 * (SSLeay/OpenSSL itself never sends such packets; see ssl2_write.)
		 * In this case, returning 0 would be interpreted by the caller
		 * as indicating EOF, so it's not a good idea.  Instead, we just
		 * continue reading; thus ssl2_read_internal may have to process
		 * multiple packets before it can return.
		 *
		 * [Note that using select() for blocking sockets *never* guarantees
		 * that the next SSL_read will not block -- the available
		 * data may contain incomplete packets, and except for SSL 2,
		 * renegotiation can confuse things even more.] */

		goto ssl2_read_again; /* This should really be
		                       * "return ssl2_read(s,buf,len)",
		                       * but that would allow for
		                       * denial-of-service attacks if a
		                       * C compiler is used that does not
		                       * recognize end-recursion. */
		}
	else
		{
		SSLerr(SSL_F_SSL2_READ_INTERNAL,SSL_R_BAD_STATE);
			return(-1);
		}
	}
Ejemplo n.º 5
0
int main(void)
{
  int ret = 0;

  INIT_MACHINE();

  reg_t numCount    = 1;
  reg_t upCount     = 2;
  reg_t lowCount    = 3;
  reg_t specialCount  = 4;
  reg_t otherCount  = 5;
  reg_t spaceCount  = 6;

  MOVIM8(numCount, 0);
  MOVIM8(spaceCount, 0);
  MOVIM8(upCount, 0);
  MOVIM8(lowCount, 0);
  MOVIM8(specialCount, 0);
  MOVIM8(otherCount, 0);

  reg_t numString = 7;
  reg_t upString = 9;
  reg_t lowString = 11;
  reg_t spaceString = 13;
  reg_t specialString = 15;
  reg_t otherString = 17;
  reg_t newlineString = 19;

  MOVIM16(numString, ADDR(0));
  MOVIM16(spaceString, ADDR(16));
  MOVIM16(upString, ADDR(32));
  MOVIM16(lowString, ADDR(48));
  MOVIM16(specialString, ADDR(64));
  MOVIM16(otherString, ADDR(80));
  MOVIM16(newlineString, ADDR(96));


  reg_t i = 21;

  //                                  123456789012
  insertString(numString,     "numbers  = ", i);
  insertString(spaceString,   "spaces   = ", i);
  insertString(upString,      "uppers   = ", i);
  insertString(lowString,     "lowers   = ", i);
  insertString(specialString, "special  = ", i);
  insertString(otherString,   "other    = ", i);

  //endl
  MOVIM8(REG16(newlineString), '\n');
  MOVIM32(REG16(newlineString) + 1, 0);

  ret = getChar(i);
  while (ret != (-1))
  {
    if (isUpLetter(i, i+1))
    {
      INC8(upCount);
    }
    else if (isLowLetter(i, i+1))
    {
      INC8(lowCount);
    }
    else if (isNumber(i, i+1))
    {
      INC8(numCount);
    }
    else if (isSpace(i, i+1))
    {
#ifdef PATCHED
      INC8(spaceCount);
#else
      INC32(spaceCount);
#endif
    }
    else if (isSpecial(i, i+1))
    {
      INC8(specialCount);
    }
    else
    {
      INC8(otherCount);
    }
    printChar(i);
    ret = getChar(i);
  }

  printString(numString, i, i+4);
  printReg8(numCount, i);
  printString(newlineString, i, i+4);

  printString(upString, i, i+4);
  printReg8(upCount, i);
  printString(newlineString, i, i+4);

  printString(lowString, i, i+4);
  printReg8(lowCount, i);
  printString(newlineString, i, i+4);

  printString(spaceString, i, i+4);
  printReg8(spaceCount, i);
  printString(newlineString, i, i+4);

  printString(specialString, i, i+4);
  printReg8(specialCount, i);
  printString(newlineString, i, i+4);

  printString(otherString, i, i+4);
  printReg8(otherCount, i);
  printString(newlineString, i, i+4);

  return (0);
}
Ejemplo n.º 6
0
unsigned int fattr_size(const struct nfs_fattr_set *attr)
{
	uint64_t bitmap = attr->bitmap;
	unsigned int total = 0;

	if (bitmap & (1ULL << FATTR4_SUPPORTED_ATTRS)) {
		INCMAP(fattr_supported_mask);
	}
	if (bitmap & (1ULL << FATTR4_TYPE)) {
		INC32(attr->type);
	}
	if (bitmap & (1ULL << FATTR4_FH_EXPIRE_TYPE)) {
		INC32(attr->fh_expire_type);
	}
	if (bitmap & (1ULL << FATTR4_CHANGE)) {
		INC64(attr->change);
	}
	if (bitmap & (1ULL << FATTR4_SIZE)) {
		INC64(attr->size);
	}
	if (bitmap & (1ULL << FATTR4_LINK_SUPPORT)) {
		INC32(attr->link_support ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_SYMLINK_SUPPORT)) {
		INC32(attr->symlink_support ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_NAMED_ATTR)) {
		INC32(attr->named_attr ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_FSID)) {
		INC64(attr->fsid.major);
		INC64(attr->fsid.minor);
	}
	if (bitmap & (1ULL << FATTR4_UNIQUE_HANDLES)) {
		INC32(attr->unique_handles ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_LEASE_TIME)) {
		INC32(attr->lease_time);
	}
	if (bitmap & (1ULL << FATTR4_RDATTR_ERROR)) {
		INC32(attr->rdattr_error);
	}

#if 0 /* FIXME */
	if (bitmap & (1ULL << FATTR4_ACL)) {
		encode_acl(&attr->acl, writes, wr);
	}
#endif

	if (bitmap & (1ULL << FATTR4_ACLSUPPORT)) {
		INC32(attr->aclsupport);
	}
	if (bitmap & (1ULL << FATTR4_ARCHIVE)) {
		INC32(attr->archive ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_CANSETTIME)) {
		INC32(attr->cansettime ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_CASE_INSENSITIVE)) {
		INC32(attr->case_insensitive ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_CASE_PRESERVING)) {
		INC32(attr->case_preserving ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_CHOWN_RESTRICTED)) {
		INC32(attr->chown_restricted ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_FILEHANDLE)) {
		INC32(sizeof(struct nfs_fh));
		INC64(attr->filehandle);
	}
	if (bitmap & (1ULL << FATTR4_FILEID)) {
		INC64(attr->fileid);
	}
	if (bitmap & (1ULL << FATTR4_FILES_AVAIL)) {
		INC64(attr->files_avail);
	}
	if (bitmap & (1ULL << FATTR4_FILES_FREE)) {
		INC64(attr->files_free);
	}
	if (bitmap & (1ULL << FATTR4_FILES_TOTAL)) {
		INC64(attr->files_total);
	}
	if (bitmap & (1ULL << FATTR4_FS_LOCATIONS)) {
		INC32(1);
		INCSTR("/");		/* fs_root */
		INC32(1);		/* location len */
		INC32(1);		/* location[0].server len */
		INCSTR(my_hostname);	/* location[0].server[0] */
		INC32(1);
		INCSTR("/");		/* location[0].rootpath */
	}
	if (bitmap & (1ULL << FATTR4_HIDDEN)) {
		INC32(attr->hidden ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_HOMOGENEOUS)) {
		INC32(attr->homogeneous ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_MAXFILESIZE)) {
		INC64(attr->maxfilesize);
	}
	if (bitmap & (1ULL << FATTR4_MAXLINK)) {
		INC32(attr->maxlink);
	}
	if (bitmap & (1ULL << FATTR4_MAXNAME)) {
		INC32(attr->maxname);
	}
	if (bitmap & (1ULL << FATTR4_MAXREAD)) {
		INC64(attr->maxread);
	}
	if (bitmap & (1ULL << FATTR4_MAXWRITE)) {
		INC64(attr->maxwrite);
	}
	if ((bitmap & (1ULL << FATTR4_MIMETYPE)) && (attr->mimetype.len)) {
		INCBUF(&attr->mimetype);
	}
	if (bitmap & (1ULL << FATTR4_MODE)) {
		INC32(attr->mode);
	}
	if (bitmap & (1ULL << FATTR4_NO_TRUNC)) {
		INC32(attr->no_trunc ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_NUMLINKS)) {
		INC32(attr->numlinks);
	}
	if ((bitmap & (1ULL << FATTR4_OWNER)) && (attr->owner.len)) {
		INCBUF(&attr->owner);
	}
	if ((bitmap & (1ULL << FATTR4_OWNER_GROUP)) && (attr->owner_group.len)){
		INCBUF(&attr->owner_group);
	}
	if (bitmap & (1ULL << FATTR4_QUOTA_AVAIL_HARD)) {
		INC64(attr->quota_avail_hard);
	}
	if (bitmap & (1ULL << FATTR4_QUOTA_AVAIL_SOFT)) {
		INC64(attr->quota_avail_soft);
	}
	if (bitmap & (1ULL << FATTR4_QUOTA_USED)) {
		INC64(attr->quota_used);
	}
	if (bitmap & (1ULL << FATTR4_RAWDEV)) {
		/* FIXME: correct order of these two dwords? */
		INC32(attr->rawdev.specdata1);
		INC32(attr->rawdev.specdata2);
	}
	if (bitmap & (1ULL << FATTR4_SPACE_AVAIL)) {
		INC64(attr->space_avail);
	}
	if (bitmap & (1ULL << FATTR4_SPACE_FREE)) {
		INC64(attr->space_free);
	}
	if (bitmap & (1ULL << FATTR4_SPACE_TOTAL)) {
		INC64(attr->space_total);
	}
	if (bitmap & (1ULL << FATTR4_SPACE_USED)) {
		INC64(attr->space_used);
	}
	if (bitmap & (1ULL << FATTR4_SYSTEM)) {
		INC32(attr->system ? 1 : 0);
	}
	if (bitmap & (1ULL << FATTR4_TIME_ACCESS)) {
		INC64(attr->time_access.seconds);
		INC32(attr->time_access.nseconds);
	}
	if (bitmap & (1ULL << FATTR4_TIME_BACKUP)) {
		INC64(attr->time_backup.seconds);
		INC32(attr->time_backup.nseconds);
	}
	if (bitmap & (1ULL << FATTR4_TIME_CREATE)) {
		INC64(attr->time_create.seconds);
		INC32(attr->time_create.nseconds);
	}
	if (bitmap & (1ULL << FATTR4_TIME_DELTA)) {
		INC64(attr->time_delta.seconds);
		INC32(attr->time_delta.nseconds);
	}
	if (bitmap & (1ULL << FATTR4_TIME_METADATA)) {
		INC64(attr->time_metadata.seconds);
		INC32(attr->time_metadata.nseconds);
	}
	if (bitmap & (1ULL << FATTR4_TIME_MODIFY)) {
		INC64(attr->time_modify.seconds);
		INC32(attr->time_modify.nseconds);
	}
	if (bitmap & (1ULL << FATTR4_MOUNTED_ON_FILEID)) {
		INC64(attr->mounted_on_fileid);
	}

	return total;
}