Example #1
0
/*!
 * Encrypt what's in a slot on the SCC
 *
 * @brief    Encrypt what's in a slot on the SCC
 *
 * @param    user_ctx
 * @param    ownerid
 * @param    slot
 * @param    key_length
 * @param    black_data
 *
 * @return    A return code of type #fsl_shw_return_t.
 */
fsl_shw_return_t do_scc_slot_encrypt(fsl_shw_uco_t * user_ctx,
				     uint64_t ownerid,
				     uint32_t slot,
				     uint32_t key_length, uint8_t * black_data)
{
	scc_return_t scc_code;

	user_ctx = NULL;	/* for unused-param warning */
	scc_code = scc_encrypt_slot(ownerid, slot, key_length, black_data);
	return (scc_code == SCC_RET_OK) ? FSL_RETURN_OK_S : FSL_RETURN_ERROR_S;
}
fsl_shw_return_t
keystore_slot_encrypt(fsl_shw_uco_t *user_ctx, fsl_shw_kso_t *keystore,
		      uint64_t owner_id, uint32_t slot, uint32_t length,
		      uint8_t *destination)
{

#ifdef FSL_HAVE_SCC2
	LOCK_INCLUDES;
	fsl_shw_return_t retval = FSL_RETURN_ERROR_S;
	uint32_t slot_length;
	uint32_t IV[4];
	uint32_t * iv_ptr = (uint32_t *) & (owner_id);

	/* Build the IV */
	IV[0] = iv_ptr[0];
	IV[1] = iv_ptr[1];
	IV[2] = 0;
	IV[3] = 0;
	ACQUIRE_LOCK;

	/* Ensure that the data will fit in the key slot */
	slot_length =
	    keystore->slot_get_slot_size(keystore->user_data, slot);
	if (length > slot_length) {
		goto out;
	}

	  /* Call scc encrypt function to encrypt the data. */
	    retval = do_scc_encrypt_region(user_ctx,
					   (void *)keystore->
					   slot_get_base(keystore->user_data,
							 slot),
					   keystore->slot_get_offset(keystore->
								      user_data,
								      slot),
					   length, destination, IV,
					   FSL_SHW_CYPHER_MODE_CBC);
	goto out;
out:RELEASE_LOCK;
	return retval;

#else
	scc_return_t retval;
	retval = scc_encrypt_slot(owner_id, slot, length, destination);
	if (retval == SCC_RET_OK)
		return FSL_RETURN_OK_S;
	return FSL_RETURN_ERROR_S;

#endif	/* FSL_HAVE_SCC2 */
}