示例#1
0
/* TLS can call too */
int StoreKeys(CYASSL* ssl, const byte* keyData)
{
    int sz, i = 0;

    if (ssl->specs.cipher_type != aead) {
        sz = ssl->specs.hash_size;
        XMEMCPY(ssl->keys.client_write_MAC_secret,&keyData[i], sz);
        i += sz;
        XMEMCPY(ssl->keys.server_write_MAC_secret,&keyData[i], sz);
        i += sz;
    }
    sz = ssl->specs.key_size;
    XMEMCPY(ssl->keys.client_write_key, &keyData[i], sz);
    i += sz;
    XMEMCPY(ssl->keys.server_write_key, &keyData[i], sz);
    i += sz;

    sz = ssl->specs.iv_size;
    XMEMCPY(ssl->keys.client_write_IV, &keyData[i], sz);
    i += sz;
    XMEMCPY(ssl->keys.server_write_IV, &keyData[i], sz);

    return SetKeys(&ssl->encrypt, &ssl->decrypt, &ssl->keys, &ssl->specs,
                   ssl->options.side, ssl->heap, ssl->rng);
}
示例#2
0
static void create() {
    door::create();
    SetId("north", "door");
    SetShort("north", "a door made from fine oak");
    SetLong("north", "It is a magnificent door marking the entrance to "
            "the fighter class hall.");
    SetLockable("north", 1);
    SetKeys("north", "special_key_id");
    SetId("south", "door");
    SetShort("south", "a door made from fine oak");
    SetLong("south", "It is a magnificent door leading out to the recruitment "
            "area.");
    SetLockable("south", 1);
    SetKeys("south", "special_key_id");
    SetClosed(1);
    SetLocked(0);
}
//*****************************************************************************
//
//! ReadFromUser - Populates the parameters from User
//!
//! \param  uiConfig Configuration Value
//! \param  uiHashLength is the Length of Hash Value
//! \param  uiKey is the Key Used
//! \param  uiDataLength is the Length of Data
//! \param  puiResult is the Result
//!
//! \return pointer to plain text
//!
//*****************************************************************************
unsigned char *
ReadFromUser(unsigned int *uiConfig,unsigned int *uiHashLength,unsigned 
              char **uiKey,unsigned int *uiDataLength,unsigned char **puiResult)
{
    char ucCmdBuffer[520],*pucKeyBuff,*pucMsgBuff;
    unsigned char *uiData;

    //
    // POinting KeyBuffer into appropriate Keys. 
    //
    pucKeyBuff=(char*)&uiHMACKey[0];
    *uiKey=(unsigned char*)&uiHMACKey[0];
    pucMsgBuff=( char*)&puiPlainMsg[0];

    //
    // Set Default Values
    //
    SetKeys();

    //
    // Usage Display
    //
    UsageDisplay();

    //
    // Get the Command
    //
    UART_PRINT("cmd# ");
    GetCmd(ucCmdBuffer,520);
    if(SHAMD5Parser(ucCmdBuffer,uiConfig,uiHashLength))
    {
        if(GetKey(pucKeyBuff))
        {
            uiData=GetMsg(pucMsgBuff,uiDataLength);
            *puiResult=(unsigned char *)malloc(64);
            memset(*puiResult,0,64);
        }
        else
        {
            UART_PRINT("\n\r Invalid Key \n\r");
            return NULL;
        }
    }
    else
    {
        UART_PRINT("\n\r Wrong Input \n\r");
        return NULL;
    }
    return uiData;
}
nsresult
nsUrlClassifierHashCompleter::RekeyRequested()
{
  // Our keys are no longer valid.
  SetKeys(EmptyCString(), EmptyCString());

  // Notify the key manager that we need a new key.  Until we get a
  // new key, gethash requests will be unauthenticated (and therefore
  // uncacheable).
  nsresult rv;
  nsCOMPtr<nsIObserverService> observerService =
    do_GetService("@mozilla.org/observer-service;1", &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = observerService->NotifyObservers(static_cast<nsIUrlClassifierHashCompleter*>(this),
                                        "url-classifier-rekey-requested",
                                        nsnull);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}
示例#5
0
文件: keys.c 项目: GreenLunar/smaFS
/* TLS can call too */
int StoreKeys(SSL* ssl, const byte* keyData)
{
    int sz = ssl->specs.hash_size, i;

    memcpy(ssl->keys.client_write_MAC_secret, keyData, sz);
    i = sz;
    memcpy(ssl->keys.server_write_MAC_secret,&keyData[i], sz);
    i += sz;

    sz = ssl->specs.key_size;
    memcpy(ssl->keys.client_write_key, &keyData[i], sz);
    i += sz;
    memcpy(ssl->keys.server_write_key, &keyData[i], sz);
    i += sz;

    sz = ssl->specs.iv_size;
    memcpy(ssl->keys.client_write_IV, &keyData[i], sz);
    i += sz;
    memcpy(ssl->keys.server_write_IV, &keyData[i], sz);

    return SetKeys(ssl);
}
示例#6
0
文件: keys.c 项目: agoragames/cyassl
/* TLS can call too */
int StoreKeys(SSL* ssl, const byte* keyData)
{
    int sz = ssl->specs.hash_size, i;

    XMEMCPY(ssl->keys.client_write_MAC_secret, keyData, sz);
    i = sz;
    XMEMCPY(ssl->keys.server_write_MAC_secret,&keyData[i], sz);
    i += sz;

    sz = ssl->specs.key_size;
    XMEMCPY(ssl->keys.client_write_key, &keyData[i], sz);
    i += sz;
    XMEMCPY(ssl->keys.server_write_key, &keyData[i], sz);
    i += sz;

    sz = ssl->specs.iv_size;
    XMEMCPY(ssl->keys.client_write_IV, &keyData[i], sz);
    i += sz;
    XMEMCPY(ssl->keys.server_write_IV, &keyData[i], sz);

    return SetKeys(&ssl->encrypt, &ssl->decrypt, &ssl->keys, &ssl->specs,
                   ssl->options.side);
}
示例#7
0
unsigned char*
ReadFromUser(unsigned int *uiConfig,unsigned int *uiKeySize,unsigned char **uiKey,
    unsigned int *uiDataLength,unsigned char **puiResult)
{
    
    char ucCmdBuffer[BUFFER_LEN],*pucKeyBuff,*pucMsgBuff;
    unsigned char *uiData;

    pucMsgBuff=( char*)&pui32AESPlainMsg[0];
    
    //
    // Usage Display
    //
    UsageDisplay();
    
    //
    // Set keys
    //
    SetKeys();
    
    //
    // Get the Command
    //
    UART_PRINT("cmd# ");
    GetCmd(ucCmdBuffer,BUFFER_LEN);

    if(DESParser(ucCmdBuffer,uiConfig,uiKeySize))
    {

     //
     // Get Key Length
     //
     if(*uiKeySize==8)
     {
       //
       // KeyBuff is used when User inputs the Key
       //
       pucKeyBuff=(char*)&uiDESKey[0];
       *uiKey=(unsigned char*)&uiDESKey[0];
       
     }
     else if(*uiKeySize==24)
     {
       pucKeyBuff=( char*)&uiTDESKey[0];
       *uiKey=(unsigned char*)&uiTDESKey[0];
     }
     else
     {
       pucKeyBuff = (char *) malloc(BUFFER_LEN);
     }
     if(GetKey(*uiKeySize,pucKeyBuff))
     {
       uiData=GetMsg(pucMsgBuff,uiDataLength);
       *puiResult=(unsigned char *)malloc(*uiDataLength);
       memset(*puiResult,0,*uiDataLength);
       
     }
     else
     {
       UART_PRINT("\n\r Invalid Key \n\r");
       return NULL;
     }
    }
    else
    {
      return NULL;
    }
    return uiData;

}
示例#8
0
//*****************************************************************************
//
//! ReadFrom User Function
//!
//! This function
//!        1. Gets Input from User
//! \out uiConfig - Configuration Value
//! \out uiKeySize - Key Size
//! \out uiKey - Key Used
//! \out uiDataLength - DataLength
//! \out puiResult - Result
//!
//! \return pointer to Plain Text
//
//*****************************************************************************
unsigned int*
ReadFromUser(unsigned int *uiConfig,unsigned int *uiKeySize,unsigned int **uiKey
             ,unsigned int *uiDataLength,unsigned int **puiResult)
{
    char ucCmdBuffer[520],*pucKeyBuff,*pucMsgBuff;
    unsigned int *uiData;
    pui32AESPlainMsg[0] = '\0';
    pucMsgBuff=( char*)&pui32AESPlainMsg[0];
    
    //
    //Set the default keys.
    //
    SetKeys();
    UsageDisplay();
    UART_PRINT("cmd# ");
    GetCmd(ucCmdBuffer,520);
    if(AESParser(ucCmdBuffer,uiConfig,uiKeySize))
    {
        //
        // Get Key Length
        //
        if(*uiKeySize==AES_CFG_KEY_SIZE_128BIT)
        {
            pucKeyBuff=(char*)&uiKey128[0];
            *uiKey=(unsigned int*)&uiKey128[0];
        }
        else if(*uiKeySize==AES_CFG_KEY_SIZE_192BIT)
        {
            pucKeyBuff=( char*)&uiKey192[0];
            *uiKey=(unsigned int*)&uiKey192[0];
        }
        else if(*uiKeySize==AES_CFG_KEY_SIZE_256BIT)
        {
            pucKeyBuff=( char*)&uiKey256[0];
            *uiKey=(unsigned int*)&uiKey256[0];
        }
        else
        {
            pucKeyBuff = (char *) malloc(BUFFER_LEN);
        }

        if(GetKey(*uiKeySize,pucKeyBuff))
        {
            uiData=GetMsg(pucMsgBuff,uiDataLength);
            if(uiData == 0)
            {
                return NULL;
            }
            *puiResult=(unsigned int *)malloc(*uiDataLength);
            memset(*puiResult,0,*uiDataLength);
        }
        else
        {
            UART_PRINT("\n\r Invalid Key \n\r");
            return NULL;
        }
    }
    else
    {
        return NULL;
    }
    return uiData;
}
int ParseArgs(int argc, char *argv[], user_settings *set)
{
	if (argv == NULL || set == NULL)
		return USR_PTR_PASS_FAIL;

	if (argc < 2) {
		DisplayHelp(argv[0]);
		return USR_HELP;
	}

	// Detecting Help Requried
	for (int i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-help") == 0) {
			DisplayHelp(argv[0]);
			return USR_HELP;
		}
		else if (strcmp(argv[i], "-exthelp") == 0) {
			DisplayExtendedHelp(argv[0]);
			return USR_HELP;
		}
	}

	// Allocating Memory for Content Path Ptrs
	set->common.contentPath = calloc(CIA_MAX_CONTENT, sizeof(char*));
	if (set->common.contentPath == NULL) {
		fprintf(stderr, "[SETTING ERROR] Not Enough Memory\n");
		return USR_MEM_ERROR;
	}

	// Initialise Keys
	InitKeys(&set->common.keys);

	// Setting Defaults
	SetDefaults(set);

	// Parsing Arguments
	int set_result;
	for (int i = 1; i < argc; i += set_result) {
		set_result = SetArgument(argc, i, argv, set);
		if (set_result < 1) {
			fprintf(stderr, "[RESULT] Invalid arguments, see '%s -help'\n", argv[0]);
			return set_result;
		}
	}

	// Checking arguments
	if ((set_result = CheckArgumentCombination(set)) != 0)
		return set_result;

	// Setting Keys
	if ((set_result = SetKeys(&set->common.keys)) != 0)
		return set_result;

	// Generating outpath if required
	if (!set->common.outFileName) {
		char *source_path = NULL;
		if (set->ncch.buildNcch0)
			source_path = set->common.rsfPath;
		else if (set->common.workingFileType == infile_ncsd || set->common.workingFileType == infile_cia || set->common.workingFileType == infile_srl)
			source_path = set->common.workingFilePath;
		else
			source_path = set->common.contentPath[0];
		set->common.outFileName_mallocd = true;
		set->common.outFileName = replace_filextention(source_path, GetOutputExtention(set->common.outFormat));
	}
	return 0;
}
示例#10
0
//*****************************************************************************
//
//! ReadFrom User Function
//!
//! This function
//!		1. Gets Input from User
//! \out uiConfig - Configuration Value
//! \out uiKeySize - Key Size
//! \out uiKey - Key Used
//! \out uiDataLength - DataLength
//! \out puiResult - Result
//!
//! \return pointer to Plain Text
//
//*****************************************************************************
unsigned int*
ReadFromUser(unsigned int *uiConfig,unsigned int *uiKeySize,unsigned int **uiKey
             ,unsigned int *uiDataLength,unsigned int **puiResult)
{

    char ucCmdBuffer[520],*pucKeyBuff,*pucMsgBuff;
    unsigned int *uiData;
    pui32AESPlainMsg[0] = '\0';
    pucMsgBuff=( char*)&pui32AESPlainMsg[0];
    
    //
    //Set the default keys.
    //
    SetKeys();
    UsageDisplay();
    UART_PRINT("cmd# ");
    GetCmd(ucCmdBuffer,520);
    if(AESParser(ucCmdBuffer,uiConfig,uiKeySize))//vrati ti duzinu i mode
    {
     //
     // Get Key Length
     //
     if(*uiKeySize==AES_CFG_KEY_SIZE_128BIT)
     {
       pucKeyBuff=(char*)&uiKey128[0];
       *uiKey=(unsigned int*)&uiKey128[0];
     }
     else if(*uiKeySize==AES_CFG_KEY_SIZE_192BIT)
     {
       pucKeyBuff=( char*)&uiKey192[0];
       *uiKey=(unsigned int*)&uiKey192[0];
     }
     else if(*uiKeySize==AES_CFG_KEY_SIZE_256BIT)
     {
       pucKeyBuff=( char*)&uiKey256[0];
       *uiKey=(unsigned int*)&uiKey256[0];
     }
     else
     {
       pucKeyBuff = (char *) malloc(BUFFER_LEN);//nisi nista odabrao od zeljenih duzina odjebi iz memorije
     }

     if(GetKey(*uiKeySize,pucKeyBuff))//unesem moju rec
     {
       uiData=GetMsg(pucMsgBuff,uiDataLength);//vraca rec koju zelim da kriptujem
       if(uiData == 0)
       {
         return NULL;
       }
       *puiResult=(unsigned int *)malloc(*uiDataLength);
       memset(*puiResult,0,*uiDataLength);
     }
     else
     {
       UART_PRINT("\n\r Invalid Key \n\r");
       return NULL;
     }
    }
    else
    {
      return NULL;
    }
    return uiData;
}
Controls::Controls () {
	SetKeys();
}