//Check whether the key exists or not.
int bPlusTree::setkey(int val, bPlusTreeNode *n, int *p, bPlusTreeNode **ch)
{
	int key;
	if (n == NULL)
	{
		*p = val;
		*ch = NULL;
		return 1;
	}
	else
	{
		if (searchnode(val, n, &key))
			cout << endl << "Key value already exists." << endl;
		else if (setkey(val, n->child[key], p, ch))
		{
			if (n->count < MAX)
			{
				fillnode(*p, *ch, n, key);
				return 0;
			}
			else
			{
				split(*p, *ch, n, key, p, ch);
				return 1;
			}
		}
		return 0;
	}
}
Esempio n. 2
0
resetkey()	/* reset the encryption key if needed */

{
	register int s;	/* return status */

	/* turn off the encryption flag */
	cryptflag = FALSE;

	/* if we are in crypt mode */
	if (curbp->b_mode & MDCRYPT) {
		if (curbp->b_key[0] == 0) {
			s = setkey(FALSE, 0);
			if (s != TRUE)
				return(s);
		}

		/* let others know... */
		cryptflag = TRUE;

		/* and set up the key to be used! */
		/* de-encrypt it */
		crypt((char *)NULL, 0);
		crypt(curbp->b_key, strlen(curbp->b_key));

		/* re-encrypt it...seeding it to start */
		crypt((char *)NULL, 0);
		crypt(curbp->b_key, strlen(curbp->b_key));
	}

	return(TRUE);
}
Esempio n. 3
0
void HASH128( unsigned char BN, unsigned char *MSGIN, unsigned char *INIT,
     unsigned char *OUT )
{
    register i, loop ;
    unsigned char X2[16], X1[16], Y[16] ;
    void setkey( unsigned char *key ) ;
    void encrypt( unsigned char *data, unsigned char *output ) ;

    for ( i = 0 ; i < 16 ; i++ )
     X2[i] = INIT[i] ;
    for ( loop = 0 ; loop < BN ; loop++ )
    {
     for ( i = 0 ; i < 16 ; i++ )
         X1[i] = MSGIN[16*loop + i ] ;
     printf( "\n\nH%X      ", loop ) ;
     for ( i = 0 ; i < 16 ; i++ )
         printf( " %02X", X2[i] ) ;
     printf( "\nM%x      ", loop + 1 ) ;
     for ( i = 0 ; i < 16 ; i++ )
         printf( " %02X", X1[i] ) ;

     setkey( X2 ) ;
     
     encrypt( X1, Y ) ;

     printf( "\nH%x      ", loop + 1 ) ;
     for ( i = 0 ; i < 16 ; i++ )
         printf( " %02X", Y[i] ) ;
     for ( i = 0 ; i < 16 ; i++ )
         X2[i] = Y[i] ;
    }
    for ( i = 0 ; i < 16 ; i++ )
     OUT[i] = Y[i] ;
}
Esempio n. 4
0
static void
DesEncrypt( u_char *clear, /* IN  8 octets */
            u_char *key,   /* IN  7 octets */
            u_char *cipher /* OUT 8 octets */)
{
  u_char des_key[8];
  u_char crypt_key[66];
  u_char des_input[66];

  MakeKey(key, des_key);

  Expand(des_key, crypt_key);
  setkey((char*)crypt_key);

#if 0
  CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
             clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
#endif

  Expand(clear, des_input);
  encrypt((char*)des_input, 0);
  Collapse(des_input, cipher);

#if 0
  CHAPDEBUG(LOG_INFO, ("DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
             cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
#endif
}
Esempio n. 5
0
int do_setkey(int nargs, char **args)
{
    struct kbentry kbe;
    kbe.kb_table = strtoul(args[1], 0, 0);
    kbe.kb_index = strtoul(args[2], 0, 0);
    kbe.kb_value = strtoul(args[3], 0, 0);
    return setkey(&kbe);
}
Esempio n. 6
0
int main (int argc, char **argv) {
	unsigned int k0;
	unsigned int k1;
	k0 = strtol(argv[1], NULL, 0);
	k1 = strtol(argv[2], NULL, 0);

	if (setkey(k0,k1) < 0) {
		printf("error\n");
	}
}
Esempio n. 7
0
/**
void  setkey_byBuffer(Buffer key)

アスキー文字(8Byte)を用いて,encrypt関数(DES)の暗号化キーを設定する.
ただし,キーとして有もなものは最初の7Byteである.

@param  key  暗号化のキー
*/
void  setkey_byBuffer(Buffer key)
{
	Buffer deskey; 

	deskey = to_bin64(key); 
	setkey((const char*)deskey.buf);
	free_Buffer(&deskey);

	return;
}
Esempio n. 8
0
bool SymmCipher::setkey(const string* key)
{
    if (key->size() == FILENODEKEYLENGTH || key->size() == FOLDERNODEKEYLENGTH)
    {
        setkey((const byte*)key->data(), (key->size() == FOLDERNODEKEYLENGTH) ? FOLDERNODE : FILENODE);

        return true;
    }

    return false;
}
Esempio n. 9
0
int main(void) {
	// http://man7.org/linux/man-pages/man3/crypt.3.html
	char password[] = "Ab(d3";
	char salt[] = "201802221723";
	char result1[] = "20338EPKt5xtY";
	char result2[] = "$1$Ab(d3$.SgUCw1AqIVAiXBaS6kzU.";
	char result3[] = "$5$Ab(d3$00nkgDrj2dM68IbqFTZPJ.a3mgai49mY.Ezq5ey0xY0";
	char result4[] = "$6$Ab(d3$TB6UIPV7sprvpcQh2esPr2/ye4FTp9lLft8yAj.2x/HcTXPwzGDxdK/tIF10DdVdV9Z2hhc3MaosUBS3fdueZ1";

	// 20338EPKt5xtY
	if (strcmp(result1, crypt(password, salt)) != 0) return -1;

	// $1$Ab(d3$.SgUCw1AqIVAiXBaS6kzU.
	if (strcmp(result2, crypt(password, concat_str((char*) "$1$", password))) != 0) return -2;

	// $5$Ab(d3$00nkgDrj2dM68IbqFTZPJ.a3mgai49mY.Ezq5ey0xY0
	if (strcmp(result3, crypt(password, concat_str((char*) "$5$", password))) != 0) return -3;

	// $6$Ab(d3$TB6UIPV7sprvpcQh2esPr2/ye4FTp9lLft8yAj.2x/HcTXPwzGDxdK/tIF10DdVdV9Z2hhc3MaosUBS3fdueZ1
	if (strcmp(result4, crypt(password, concat_str((char*) "$6$", password))) != 0) return -4;

	// encrypt
	// http://man7.org/linux/man-pages/man3/encrypt.3.html
	char key[64];
	char buf[64];
	char txt[6];
	int i, j;

	for (i = 0; i < 6; i++) {
		for (j = 0; j < 8; j++) {
			buf[i * 8 + j] = password[i] >> j & 1;
		}
	}
	setkey(key);


	encrypt(buf, 0);
	for (i = 0; i < 6; i++) {
		for (j = 0, txt[i] = '\0'; j < 8; j++) {
			txt[i] |= buf[i * 8 + j] << j;
		}
	}

	if (strcmp(password, txt) == 0) return -5;

	encrypt(buf, 1);
	for (i = 0; i < 6; i++) {
		for (j = 0, txt[i] = '\0'; j < 8; j++) {
			txt[i] |= buf[i * 8 + j] << j;
		}
	}

	return (strcmp(password, txt) == 0) ? 0 : -6;
}
Esempio n. 10
0
static void *
mythread(void * arg)
{
  (void) pthread_barrier_wait(&startBarrier);

  setkey(arg);

  return 0;

  /* Exiting the thread will call the key destructor. */
}
Esempio n. 11
0
/**
void  setkey_byBase64(Buffer key)

Base64によってエンコードされた文字列をデコードし,それを encrypt関数(DES)の暗号化キーとして設定する.@n
キー長は通常 8Byte(64bit)だが,有効なものは最初の7Byte(56bit)である.

@param  key	 暗号化のキー
*/
void  setkey_byBase64(Buffer key)
{
	Buffer tmpkey, deskey; 

	tmpkey = decode_base64_Buffer(key);
	deskey = to_bin64(tmpkey); 

	setkey((const char*)deskey.buf);
	free_Buffer(&tmpkey);
	free_Buffer(&deskey);
	return;
}
Esempio n. 12
0
static void *
mythread(void * arg)
{
  while (key == NULL)
    {
	sched_yield();
    }

  setkey(arg);

  return 0;

  /* Exiting the thread will call the key destructor. */
}
Esempio n. 13
0
static TACommandVerdict setkey_cmd(TAThread thread,TAInputStream stream)

{

    char* key;

    int i;

   

    // Prepare

    key=(char*)readPointer(&stream);



    ta_debug_printf("setkey:\n");

    for(i=0;i<64;i++)

        ta_debug_printf("%d ", key[i]);

    ta_debug_printf("\n");



    START_TARGET_OPERATION(thread);

    errno=0;

    setkey(key);

    END_TARGET_OPERATION(thread);

    

    // Response

    writeInt(thread, errno);



    sendResponse(thread);

    

    return taDefaultVerdict;

}
Esempio n. 14
0
void
DesEncrypt(unsigned char *clear, unsigned char *key, unsigned char *cipher)
{
    u_char des_key[8];
    u_char crypt_key[66];
    u_char des_input[66];

    MakeKey(key, des_key);

    Expand(des_key, crypt_key);
    setkey(crypt_key);

    Expand(clear, des_input);
    encrypt(des_input, 0);
    Collapse(des_input, cipher);
}
//Inserts node in the tree.
void bPlusTree::insertNode(int val)
{
	int i;
	bPlusTreeNode *c, *n;
	int flag;
	flag = setkey(val, root, &i, &c);
	if (flag)
	{
		n = new bPlusTreeNode;
		n->count = 1;
		n->value[1] = i;
		n->child[0] = root;
		n->child[1] = c;
		root = n;
	}
}
Esempio n. 16
0
CAST256::CAST256(const std::string & KEY)
    : CAST256()
{
    setkey(KEY);
}
static int async_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
			unsigned int keylen)
{
	return setkey(crypto_ablkcipher_tfm(tfm), key, keylen);
}
Esempio n. 18
0
int
main()
{
  int i;
  int fail = 0;
  pthread_t thread[10];

  for (i = 1; i < 5; i++)
    {
	accesscount[i] = thread_set[i] = thread_destroyed[i] = 0;
      assert(pthread_create(&thread[i], NULL, mythread, (void *)&accesscount[i]) == 0);
    }

  Sleep(2000);

  /*
   * Here we test that existing threads will get a key created
   * for them.
   */
  assert(pthread_key_create(&key, destroy_key) == 0);

  /*
   * Test main thread key.
   */
  accesscount[0] = 0;
  setkey((void *) &accesscount[0]);

  /*
   * Here we test that new threads will get a key created
   * for them.
   */
  for (i = 5; i < 10; i++)
    {
	accesscount[i] = thread_set[i] = thread_destroyed[i] = 0;
      assert(pthread_create(&thread[i], NULL, mythread, (void *)&accesscount[i]) == 0);
    }

  /*
   * Wait for all threads to complete.
   */
  for (i = 1; i < 10; i++)
    {
	int result = 0;

	assert(pthread_join(thread[i], (void **) &result) == 0);
    }

  assert(pthread_key_delete(key) == 0);

  for (i = 1; i < 10; i++)
    {
	/*
	 * The counter is incremented once when the key is set to
	 * a value, and again when the key is destroyed. If the key
	 * doesn't get set for some reason then it will still be
	 * NULL and the destroy function will not be called, and
	 * hence accesscount will not equal 2.
	 */
	if (accesscount[i] != 2)
	  {
	    fail++;
	    fprintf(stderr, "Thread %d key, set = %d, destroyed = %d\n",
			i, thread_set[i], thread_destroyed[i]);
	  }
    }

  fflush(stderr);

  return (fail);
}
Esempio n. 19
0
SymmCipher::SymmCipher(const SymmCipher &ref)
{
    setkey(ref.key);
}
Esempio n. 20
0
SymmCipher::SymmCipher(const byte* key)
{
    setkey(key);
}
Esempio n. 21
0
strategy()
{
	register int			i, allexact;
	struct accessparam		sourceparam, indexparam;
	struct index			itup, rtup;
	struct key			lowikey[MAXKEYS+1], highikey[MAXKEYS+1];
	register struct descriptor	*d;
	extern struct descriptor	Inddes;
	struct descriptor		*openindex();

#	ifdef xOTR1
	if (tTf(31, 0))
		printf("STRATEGY\tSource=%.12s\tNewq = %d\n", Source ? Source->relid : "(none)", Newq);
#	endif

	while (Newq)	/* if Newq=TRUE then compute a new strategy */
			/* NOTE: This while loop is executed only once */
	{
		Scanr = Source;
	
		if (!Scanr)
			return (1);	/* return immediately if there is no source relation */
	
		Fmode = NOKEY;	/* assume a find mode with no key */
	
		if (!Qlist)
			break;	/* if no qualification then you must scan entire rel */
	
		/* copy structure of source relation into sourceparam */
		paramd(Source, &sourceparam);
	
		/* if source is unkeyed and has no sec index then give up */
		if (sourceparam.mode == NOKEY && Source->relindxd <= 0)
			break;

		/* find all simple clauses if any */
		if (!findsimps())
			break;	/* break if there are no simple clauses */
	
		/* Four steps are now performed to try and find a key.
		** First if the relation is hashed then an exact key is search for
		**
		** Second if there are secondary indexes, then a search is made
		** for an exact key. If that fails then a  check is made for
		** a range key. The result of the rangekey check is saved.
		**
		** Third if the relation is an ISAM a check is  made for
		** an exact key or a range key.
		**
		** Fourth if there is a secondary index, then if step two
		** found a key, that key is used.
		**
		**  Lastly, give up and scan the  entire relation
		*/
	
		/* step one. Try to find exact key on primary */
		if (exactkey(&sourceparam, &Lkey_struct))
		{
			Fmode = EXACTKEY;
			break;
		}
	
		/* step two. If there is an index, try to find an exactkey on one of them */
		if (Source->relindxd)
		{
	
			opencatalog("indexes", 0);
			setkey(&Inddes, &itup, Source->relid, IRELIDP);
			setkey(&Inddes, &itup, Source->relowner, IOWNERP);
			if (i = find(&Inddes, EXACTKEY, &Lotid, &Hitid, &itup))
				syserr("strategy:find indexes %d", i);
	
			while (!(i = get(&Inddes, &Lotid, &Hitid, &itup, NXTTUP)))
			{
#				ifdef xOTR1
				if (tTf(31, 3))
					printup(&Inddes, &itup);
#				endif
				if (!bequal(itup.irelidp, Source->relid, MAXNAME) ||
				    !bequal(itup.iownerp, Source->relowner, 2))
					continue;
				parami(&itup, &indexparam);
				if (exactkey(&indexparam, &Lkey_struct))
				{
					Fmode = EXACTKEY;
					d = openindex(itup.irelidi);
					/* temp check for 6.0 index */
					if (d->relindxd == -1)
						ov_err(BADSECINDX);
					Scanr = d;
					break;
				}
				if (Fmode == LRANGEKEY)
					continue;	/* a range key on a s.i. has already been found */
				if (allexact = rangekey(&indexparam, &lowikey, &highikey))
				{
					bmove(&itup, &rtup, sizeof itup);	/* save tuple */
					Fmode = LRANGEKEY;
				}
			}
			if (i < 0)
				syserr("stragery:bad get from index-rel %d", i);
			/* If an exactkey on a secondary index was found, look no more. */
			if (Fmode == EXACTKEY)
				break;
		}
	

		/* step three. Look for a range key on primary */
		if (i = rangekey(&sourceparam, &Lkey_struct, &Hkey_struct))
		{
			if (i < 0)
				Fmode = EXACTKEY;
			else
				Fmode = LRANGEKEY;
			break;
		}
	
		/* last step. If a secondary index range key was found, use it */
		if (Fmode == LRANGEKEY)
		{
			if (allexact < 0)
				Fmode = EXACTKEY;
			d = openindex(rtup.irelidi);
			/* temp check for 6.0 index */
			if (d->relindxd == -1)
				ov_err(BADSECINDX);
			Scanr = d;
			bmove(&lowikey, &Lkey_struct, sizeof lowikey);
			bmove(&highikey, &Hkey_struct, sizeof highikey);
			break;
		}

		/* nothing will work. give up! */
		break;
	
	}

	/* check for Newq = FALSE and no source relation */
	if (!Scanr)
		return (1);
	/*
	** At this point the strategy is determined.
	**
	** If Fmode is EXACTKEY then Lkey_struct contains
	** the pointers to the keys.
	**
	** If Fmode is LRANGEKEY then Lkey_struct contains
	** the pointers to the low keys and Hkey_struct
	** contains pointers to the high keys.
	**
	** If Fmode is NOKEY, then a full scan will be performed
	*/
#	ifdef xOTR1
	if (tTf(31, -1))
		printf("Fmode= %d\n",Fmode);
#	endif

	/* set up the key tuples */
	if (Fmode != NOKEY)
	{
		if (setallkey(&Lkey_struct, Keyl))
			return (0);	/* query false. There is a simple
					** clause which can never be satisfied.
					** These simple clauses can be choosey!
					*/
	}

	if (i = find(Scanr, Fmode, &Lotid, &Hitid, Keyl))
		syserr("strategy:find1 %.12s, %d", Scanr->relid, i);

	if (Fmode == LRANGEKEY)
	{
		setallkey(&Hkey_struct, Keyh);
		if (i = find(Scanr, HRANGEKEY, &Lotid, &Hitid, Keyh))
			syserr("strategy:find2 %.12s, %d", Scanr->relid, i);
	}

#	ifdef xOTR1
	if (tTf(31, 1))
	{
		printf("Lo");
		dumptid(&Lotid);
		printf("Hi");
		dumptid(&Hitid);
	}
#	endif

	return (1);
}
Esempio n. 22
0
char *crypt::crypttext(const char *wort, const char *salt)
   {
   // temporary variables
   char *k;
   int tmp, keybyte;
   int i, j;

   // declare and initialize key
   char key[BS + 2];
   memset(key, 0, BS + 2);

   for (k = key, i = 0; i < BS; i++)
      {
      // get next letter & quit if the end has been reached
      if (!(keybyte = *wort++))
         break;
      k += 7;
      for (j = 0; j < 7; j++, i++)
         {
         *--k = keybyte & 1;
         keybyte >>= 1;
         }
      k += 8;
      }

   setkey(key);
   memset(key, 0, BS + 2);

   static char retkey[14];
   for (k = E, i = 0; i < 2; i++)
      {
      retkey[i] = keybyte = *salt++;
      if (keybyte > 'Z')
         keybyte -= 'a' - 'Z' - 1;
      if (keybyte > '9')
         keybyte -= 'A' - '9' - 1;
      keybyte -= '.';

      for (j = 0; j < 6; j++, keybyte >>= 1, k++)
         {
         if (!(keybyte & 1))
            continue;
         tmp = *k;
         *k = k[24];
         k[24] = tmp;
         }
      }

   for (i = 0; i < 25; i++)
      encrypt(key, 0);

   for (k = key, i = 0; i < 11; i++)
      {
      for (j = keybyte = 0; j < 6; j++)
         {
         keybyte <<= 1;
         keybyte |= *k++;
         }

      keybyte += '.';
      if (keybyte > '9')
         keybyte += 'A' - '9' - 1;
      if (keybyte > 'Z')
         keybyte += 'a' - 'Z' - 1;
      retkey[i + 2] = keybyte;
      }

   retkey[i + 2] = 0;

   if (!retkey[1])
      retkey[1] = *retkey;

   return retkey;
   }
Esempio n. 23
0
File: set.c Progetto: danmedsa/opsys
int main (void) {
	if (setkey(129,512) < 0) {
		printf("error\n");
	}
}
Esempio n. 24
0
int main (void) {
	if (setkey(0,0) < 0) {
		printf("error\n");
	}
}
Esempio n. 25
0
IDEA::IDEA(const std::string & KEY) :
    IDEA()
{
    setkey(KEY);
}
Esempio n. 26
0
DES::DES(const std::string & KEY)
    : DES()
{
    setkey(KEY);
}
Esempio n. 27
0
SymmCipher& SymmCipher::operator=(const SymmCipher& ref)
{
    setkey(ref.key);
    return *this;
}