Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
SPDX-License-Identifier: BSD-3-Clause-Clear

# Qualcomm Crypto (qcom_crypto) Functionality Test Script
# Overview

The qcom_crypto test script validates the basic functionality of cryptographic operations using the kcapi tool. It ensures that encryption, decryption, and HMAC-SHA256 operations are correctly executed and verified against expected outputs.

## Features

- Environment Initialization: Robustly locates and sources the init_env file from the directory hierarchy.
- Dependency Check: Verifies the presence of required tools like kcapi.
- Crypto Validation: Performs AES-CBC encryption/decryption and HMAC-SHA256 operations.
- Automated Result Logging: Outputs test results to a .res file for automated result collection.
- Modular Integration: Designed to work within a larger test framework using functestlib.sh.

## Prerequisites

Ensure the following components are present on the target device:

- `kcapi` (Kernel Crypto tool) Available in /usr/bin
- `libkcapi.so.1` (Kernel Crypto library) Available in /usr/lib

## Directory Structure
```
Runner/
├── suites/
│ ├── Kernel/
│ │ ├── FunctionalArea/
│ │ │ ├── baseport/
│ │ │ │ ├── qcom_crypto/
│ │ │ │ │ ├── run.sh
```
## Usage

1. Copy repo to Target Device: Use scp to transfer the scripts from the host to the target device. The scripts should be copied to the ```/<user-defined-location>``` directory on the target device.

2. Verify Transfer: Ensure that the repo have been successfully copied to the ```/<user-defined-location>``` directory on the target device.

3. Run Scripts: Navigate to the ```/<user-defined-location>``` directory on the target device and execute the scripts as needed.

---
Quick Example
```
git clone <this-repo>
cd <this-repo>
scp -r common Runner user@target_device_ip:/<user-defined-location>
ssh user@target_device_ip
cd /<user-defined-location>/Runner && ./run-test.sh qcom_crypto

Sample output:
sh-5.2# ./run-test.sh qcom_crypto
[Executing test case: qcom_crypto] 1970-01-01 05:44:18 -
[INFO] 1970-01-01 05:44:18 - -----------------------------------------------------------------------------------------
[INFO] 1970-01-01 05:44:18 - -------------------Starting qcom_crypto Testcase----------------------------
[INFO] 1970-01-01 05:44:18 - === Test Initialization ===
[INFO] 1970-01-01 05:44:18 - Checking if dependency binary is available
[INFO] 1970-01-01 05:44:18 - Running encryption test
[INFO] 1970-01-01 05:44:18 - Encryption test passed
[INFO] 1970-01-01 05:44:18 - Running decryption test
[INFO] 1970-01-01 05:44:18 - Decryption test passed
[INFO] 1970-01-01 05:44:18 - Running HMAC-SHA256 test
[INFO] 1970-01-01 05:44:18 - HMAC-SHA256 test passed
[PASS] 1970-01-01 05:44:18 - qcom_crypto : All tests passed
[PASS] 1970-01-01 05:44:18 - qcom_crypto passed

[INFO] 1970-01-01 05:44:18 - ========== Test Summary ==========
PASSED:
qcom_crypto

FAILED:
None

SKIPPED:
None
[INFO] 1970-01-01 05:44:18 - ==================================
```
4. Results will be available in the `/<user-defined-location>/Runner/suites/Kernel/FunctionalArea/baseport/qcom_crypto/` directory.

## Notes

- It uses kcapi to validate AES-CBC encryption/decryption and HMAC-SHA256 hashing.
- If any test fails, the script logs the expected vs actual output and exits with a failure code.
116 changes: 116 additions & 0 deletions Runner/suites/Kernel/FunctionalArea/baseport/qcom_crypto/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/sh

# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear

# Robustly find and source init_env
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"
while [ "$SEARCH" != "/" ]; do
if [ -f "$SEARCH/init_env" ]; then
INIT_ENV="$SEARCH/init_env"
break
fi
SEARCH=$(dirname "$SEARCH")
done

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
exit 1
fi

# Only source if not already loaded (idempotent)
if [ -z "$__INIT_ENV_LOADED" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
fi
# Always source functestlib.sh, using $TOOLS exported by init_env
# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

TESTNAME="qcom_crypto"
test_path=$(find_test_case_by_name "$TESTNAME")
cd "$test_path" || exit 1
res_file="./$TESTNAME.res"

log_info "-----------------------------------------------------------------------------------------"
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
log_info "=== Test Initialization ==="

log_info "Checking if dependency binary is available"
check_dependencies kcapi

# Initialize test status
TEST_PASSED=true

# Encryption Test
log_info "Running encryption test"
ENCRYPT_OUTPUT=$(kcapi -x 1 -e -c "cbc(aes)" \
-k 8d7dd9b0170ce0b5f2f8e1aa768e01e91da8bfc67fd486d081b28254c99eb423 \
-i 7fbc02ebf5b93322329df9bfccb635af \
-p 48981da18e4bb9ef7e2e3162d16b1910 2>&1)

EXPECTED_ENCRYPT="8b19050f66582cb7f7e4b6c873819b71"

if [ "$ENCRYPT_OUTPUT" != "$EXPECTED_ENCRYPT" ]; then
log_fail "$TESTNAME : Encryption test failed"
log_info "Expected: $EXPECTED_ENCRYPT"
log_info "Got : $ENCRYPT_OUTPUT"
TEST_PASSED=false
else
log_pass "Encryption test passed"
fi

# Decryption Test
log_info "Running decryption test"
DECRYPT_OUTPUT=$(kcapi -x 1 -c "cbc(aes)" \
-k 3023b2418ea59a841757dcf07881b3a8def1c97b659a4dad \
-i 95aa5b68130be6fcf5cabe7d9f898a41 \
-q c313c6b50145b69a77b33404cb422598 2>&1)

EXPECTED_DECRYPT="836de0065f9d6f6a3dd2c53cd17e33a5"

if [ "$DECRYPT_OUTPUT" != "$EXPECTED_DECRYPT" ]; then
log_fail "$TESTNAME : Decryption test failed"
log_info "Expected: $EXPECTED_DECRYPT"
log_info "Got : $DECRYPT_OUTPUT"
TEST_PASSED=false
else
log_pass "Decryption test passed"
fi

# HMAC-SHA256 Test
log_info "Running HMAC-SHA256 test"
HMAC_OUTPUT=$(kcapi -x 12 -c "hmac(sha256)" \
-k 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b \
-i 000102030405060708090a0b0c \
-p f0f1f2f3f4f5f6f7f8f9 \
-b 42 2>&1)

EXPECTED_HMAC="3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865"

if [ "$HMAC_OUTPUT" != "$EXPECTED_HMAC" ]; then
log_fail "$TESTNAME : HMAC-SHA256 test failed"
log_info "Expected: $EXPECTED_HMAC"
log_info "Got : $HMAC_OUTPUT"
TEST_PASSED=false
else
log_pass "HMAC-SHA256 test passed"
fi

# Final Result
if [ "$TEST_PASSED" = true ]; then
log_pass "$TESTNAME : All tests passed"
echo "$TESTNAME PASS" > "$res_file"
exit 0
else
log_fail "$TESTNAME : One or more tests failed"
echo "$TESTNAME FAIL" > "$res_file"
exit 1
fi

log_info "-------------------Completed $TESTNAME Testcase----------------------------"



Loading