예제 #1
0
TSPICALL
Tspi_DAA_IssueSetup(TSS_HDAA       hDAA,			// in
		    UINT32         issuerBaseNameLength,	// in
		    BYTE*          issuerBaseName,		// in
		    UINT32         numberPlatformAttributes,	// in
		    UINT32         numberIssuerAttributes,	// in
		    TSS_HDAA_DATA* keyPair,			// out (TSS_KEY_PAIR)
		    TSS_HDAA_DATA* publicKeyProof)		// out (TSS_DAA_PK_PROOF)
{
	TSS_RESULT result;
	KEY_PAIR_WITH_PROOF_internal *key_proof;
	TSS_DAA_KEY_PAIR *tss_daa_key_pair;
	TSS_HCONTEXT hContext;
#ifdef TSS_DEBUG
	int before = mallinfo().uordblks;
#endif

	LogDebug( "TSPI_DAA_IssueSetup hDAA=%d  ",hDAA);
	// TODO: lock access to _hContext
	if ((result = obj_daa_get_tsp_context(hDAA, &hContext)))
		return result;
	result = generate_key_pair(numberIssuerAttributes,
						numberPlatformAttributes,
						issuerBaseNameLength,
						issuerBaseName,
						&key_proof);
	if (result != TSS_SUCCESS)
		return result;
	LogDebug("TSPI_DAA_IssueSetup convert internal structure to public allocated using tspi_alloc");
	LogDebug("key_proof->proof->length_challenge=%d  key_proof->proof->length_response=%d",
			key_proof->proof->length_challenge, key_proof->proof->length_response);
	// prepare out parameters
	*publicKeyProof = i_2_e_TSS_DAA_PK_PROOF( key_proof->proof, &tss_alloc, hContext);

	tss_daa_key_pair = (TSS_DAA_KEY_PAIR *)tss_alloc( sizeof(TSS_DAA_KEY_PAIR), hContext);
	if (tss_daa_key_pair == NULL) {
		LogError("malloc of %d bytes failed", sizeof(TSS_DAA_KEY_PAIR));
		result = TSPERR(TSS_E_OUTOFMEMORY);
		goto close;
	}
	tss_daa_key_pair->private_key = i_2_e_TSS_DAA_PRIVATE_KEY( key_proof->private_key,
								&tss_alloc,
								hContext);
	tss_daa_key_pair->public_key = i_2_e_TSS_DAA_PK( key_proof->pk,
							&tss_alloc,
							hContext);
	*keyPair = (TSS_HKEY)tss_daa_key_pair;
close:
	bi_flush_memory();

	LogDebug("TSPI_DAA_IssueSetup ALLOC DELTA:%d", mallinfo().uordblks-before);
	LogDebug( "TSPI_DAA_IssueSetup end return=%d ",result);
	return result;
}
예제 #2
0
TSS_RESULT
Tspi_DAA_Issuer_GenerateKey(TSS_HDAA_ISSUER_KEY hIssuerKey,           // in
			    UINT32              issuerBaseNameLength, // in
			    BYTE*               issuerBaseName)       // in
{
	TSS_RESULT result;
	KEY_PAIR_WITH_PROOF_internal *key_proof;
	TSS_DAA_KEY_PAIR *tss_daa_key_pair;
	TSS_HCONTEXT tspContext;
	UINT32 numberPlatformAttributes, numberIssuerAttributes;
#ifdef TSS_DEBUG
	int before = mallinfo().uordblks;
#endif

	if ((result = obj_daaissuerkey_get_tsp_context(hIssuerKey, &tspContext)))
		return result;

	if ((result = obj_daaissuerkey_get_attribs(hIssuerKey, &numberIssuerAttributes,
						   &numberPlatformAttributes)))
		return result;

	if ((result = generate_key_pair(numberIssuerAttributes, numberPlatformAttributes,
					issuerBaseNameLength, issuerBaseName, &key_proof)))
		return result;

	LogDebugFn("convert internal structure to public allocated using tspi_alloc");
	LogDebug("key_proof->proof->length_challenge=%d  key_proof->proof->length_response=%d",
		 key_proof->proof->length_challenge, key_proof->proof->length_response);

	// prepare out parameters
	*publicKeyProof = i_2_e_TSS_DAA_PK_PROOF( key_proof->proof, &tss_alloc, tspContext);

	tss_daa_key_pair = (TSS_DAA_KEY_PAIR *)tss_alloc( sizeof(TSS_DAA_KEY_PAIR), tspContext);
	if (tss_daa_key_pair == NULL) {
		LogError("malloc of %d bytes failed", sizeof(TSS_DAA_KEY_PAIR));
		result = TSPERR(TSS_E_OUTOFMEMORY);
		goto close;
	}
	tss_daa_key_pair->private_key = i_2_e_TSS_DAA_PRIVATE_KEY( key_proof->private_key,
								&tss_alloc,
								tspContext);
	tss_daa_key_pair->public_key = i_2_e_TSS_DAA_PK( key_proof->pk,
							&tss_alloc,
							tspContext);
	*keyPair = (TSS_HKEY)tss_daa_key_pair;
close:
	bi_flush_memory();

	LogDebug("TSPI_DAA_IssueSetup ALLOC DELTA:%d", mallinfo().uordblks-before);
	LogDebug( "TSPI_DAA_IssueSetup end return=%d ",result);
	return result;
}
예제 #3
0
static void
initialize(const u_char *seed, int server, int ossh_key_fix)
{
	u_char client_to_server_key[OBFUSCATE_KEY_LENGTH];
	u_char server_to_client_key[OBFUSCATE_KEY_LENGTH];
	
	generate_key_pair(seed, client_to_server_key, server_to_client_key, ossh_key_fix);

	if(server)
		set_keys(client_to_server_key, server_to_client_key);
	else
		set_keys(server_to_client_key, client_to_server_key);
}
예제 #4
0
key_agreement::key_agreement(
  size_t private_key_bytes
  )
{
  generate_key_pair(private_key_bytes);
}
예제 #5
0
int main(int argc, char* argv[])
{
	// Program parameters
	unsigned long bit_size = DEFAULT_BITSIZE;
	unsigned long num_attribs = 0;
	unsigned long counter = 0;
	time_t expiry = std::time(NULL);
	std::string pub_key_filename;
	std::string priv_key_filename;
	std::string base_URI = DEFAULT_BASE_URI;
	int c = 0;
	
	// Add a year to expiry and round it down to 1 day
	struct tm* now = localtime(&expiry);
	now->tm_year = now->tm_year + 1;
	now->tm_hour = 0;
	now->tm_min = 0;
	now->tm_sec = 0;
	expiry = mktime(now);

	while ((c = getopt(argc, argv, "a:n:c:d:p:P:u:hv")) != -1)
	{
		switch (c)
		{
		case 'h':
			usage();
			return 0;
		case 'v':
			version();
			return 0;
		case 'a':
			num_attribs = strtoul(optarg, NULL, 10);
			break;
		case 'n':
			bit_size = strtoul(optarg, NULL, 10);
			break;
		case 'c':
			counter = strtoul(optarg, NULL, 10);
			break;
		case 'd':
			expiry = strtoul(optarg, NULL, 10);
			break;
		case 'p':
			pub_key_filename = std::string(optarg);
			break;
		case 'P':
			priv_key_filename = std::string(optarg);
			break;
		case 'u':
			base_URI = std::string(optarg);
			break;
		}
	}
	
	if (num_attribs <= 0)
	{
		fprintf(stderr, "Missing argument -a; please specify a number of attributes\n");
		
		return -1;
	}
	
	FILE* pub_key_file = stdout;
	FILE* priv_key_file = stdout;
	
	if (!pub_key_filename.empty())
	{
		pub_key_file = fopen(pub_key_filename.c_str(), "w");
		
		if (pub_key_file == NULL)
		{
			fprintf(stderr, "Failed to open %s for writing\n", pub_key_filename.c_str());
			
			return -1;
		}
		
		printf("Writing public key to %s\n", pub_key_filename.c_str());
	}
	
	if (!priv_key_filename.empty())
	{
		priv_key_file = fopen(priv_key_filename.c_str(), "w");
		
		if (priv_key_file == NULL)
		{
			fprintf(stderr, "Failed to open %s for writing\n", priv_key_filename.c_str());
			
			return -1;
		}
		
		printf("Writing private key to %s\n", priv_key_filename.c_str());
	}
	
	generate_key_pair(pub_key_file, priv_key_file, base_URI, num_attribs, bit_size, counter, expiry);
	
	if (!pub_key_filename.empty()) fclose(pub_key_file);
	if (!priv_key_filename.empty()) fclose(priv_key_file);
	
	return 0;
}