From c196d4c3b4566d7ac9ec73ee61d9e5e97b32f38c Mon Sep 17 00:00:00 2001 From: red-robby Date: Tue, 31 Jan 2023 00:35:22 -0800 Subject: [PATCH 01/14] Params.hpp -- swap macros with constexpr values; add ; use std:: for all standard types; remove unneeded constructor --- sdk/include/host/Params.hpp | 70 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/sdk/include/host/Params.hpp b/sdk/include/host/Params.hpp index a7043ada7..ae3b026b6 100644 --- a/sdk/include/host/Params.hpp +++ b/sdk/include/host/Params.hpp @@ -4,61 +4,61 @@ //------------------------------------------------------------------------------ #pragma once +#include #include +namespace detail { +namespace defaults { +constexpr std::uint64_t untrusted_size = 8192; // 8 KB #if __riscv_xlen == 64 -#define DEFAULT_FREEMEM_SIZE 1024 * 1024 // 1 MB -#define DEFAULT_UNTRUSTED_PTR 0xffffffff80000000 -#define DEFAULT_STACK_SIZE 1024 * 16 // 16k -#define DEFAULT_STACK_START 0x0000000040000000 +constexpr std::uint64_t freemem_size = 1024 * 1024; // 1 MB +constexpr std::uint64_t stack_size = 1024 * 16; // 16k +constexpr std::uint64_t stack_start = 0x0000000040000000; +constexpr std::uint64_t untrusted_ptr = 0xffffffff80000000; #elif __riscv_xlen == 32 -#define DEFAULT_FREEMEM_SIZE 1024 * 512 // 512 KiB -#define DEFAULT_UNTRUSTED_PTR 0x80000000 -#define DEFAULT_STACK_SIZE 1024 * 8 // 3 KiB -#define DEFAULT_STACK_START 0x40000000 -#else // for x86 tests -#define DEFAULT_FREEMEM_SIZE 1024 * 1024 // 1 MB -#define DEFAULT_UNTRUSTED_PTR 0xffffffff80000000 -#define DEFAULT_STACK_SIZE 1024 * 16 // 16k -#define DEFAULT_STACK_START 0x0000000040000000 +constexpr std::uint64_t freemem_size = 1024 * 512; // 512 KiB +constexpr std::uint64_t stack_size = 1024 * 8; // 3 KiB +constexpr std::uint64_t stack_start = 0x40000000; +constexpr std::uint64_t untrusted_ptr = 0x80000000; +#else +constexpr std::uint64_t freemem_size = 1024 * 1024; // 1 MB +constexpr std::uint64_t stack_size = 1024 * 16; // 16k +constexpr std::uint64_t stack_start = 0x0000000040000000; +constexpr std::uint64_t untrusted_ptr = 0xffffffff80000000; #endif - -#define DEFAULT_UNTRUSTED_SIZE 8192 // 8 KB +} // namespace defaults +} // namespace detail /* parameters for enclave creation */ namespace Keystone { class Params { public: - Params() { - simulated = false; - untrusted = DEFAULT_UNTRUSTED_PTR; - untrusted_size = DEFAULT_UNTRUSTED_SIZE; - freemem_size = DEFAULT_FREEMEM_SIZE; - } - void setSimulated(bool _simulated) { simulated = _simulated; } - void setEnclaveEntry(uint64_t) { + + void setEnclaveEntry(std::uint64_t) { printf("WARN: setEnclaveEntry() is deprecated.\n"); } - void setUntrustedMem(uint64_t ptr, uint64_t size) { + + void setUntrustedMem(std::uint64_t ptr, std::uint64_t size) { untrusted = ptr; untrusted_size = size; } - void setFreeMemSize(uint64_t size) { freemem_size = size; } + + void setFreeMemSize(std::uint64_t size) { freemem_size = size; } bool isSimulated() { return simulated; } - uintptr_t getUntrustedMem() { return untrusted; } - uintptr_t getUntrustedSize() { return untrusted_size; } - uintptr_t getUntrustedEnd() { return untrusted + untrusted_size; } - uintptr_t getFreeMemSize() { return freemem_size; } + std::uintptr_t getUntrustedMem() { return untrusted; } + std::uintptr_t getUntrustedSize() { return untrusted_size; } + std::uintptr_t getUntrustedEnd() { return untrusted + untrusted_size; } + std::uintptr_t getFreeMemSize() { return freemem_size; } private: - bool simulated; - uint64_t runtime_entry; - uint64_t enclave_entry; - uint64_t untrusted; - uint64_t untrusted_size; - uint64_t freemem_size; + bool simulated{false}; + std::uint64_t runtime_entry; + std::uint64_t enclave_entry; + std::uint64_t untrusted{detail::defaults::untrusted_ptr}; + std::uint64_t untrusted_size{detail::defaults::untrusted_size}; + std::uint64_t freemem_size{detail::defaults::freemem_size}; }; } // namespace Keystone From 339ca74f05ff3ed13d3ccb3f918114dce8bf38f5 Mon Sep 17 00:00:00 2001 From: red-robby Date: Tue, 31 Jan 2023 00:41:51 -0800 Subject: [PATCH 02/14] Params.hpp -- add const/noexcept to member functions as appropriate --- sdk/include/host/Params.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/include/host/Params.hpp b/sdk/include/host/Params.hpp index ae3b026b6..140ec8ed6 100644 --- a/sdk/include/host/Params.hpp +++ b/sdk/include/host/Params.hpp @@ -34,23 +34,23 @@ namespace Keystone { class Params { public: - void setSimulated(bool _simulated) { simulated = _simulated; } + void setSimulated(bool _simulated) noexcept { simulated = _simulated; } void setEnclaveEntry(std::uint64_t) { printf("WARN: setEnclaveEntry() is deprecated.\n"); } - void setUntrustedMem(std::uint64_t ptr, std::uint64_t size) { + void setUntrustedMem(std::uint64_t ptr, std::uint64_t size) noexcept { untrusted = ptr; untrusted_size = size; } - void setFreeMemSize(std::uint64_t size) { freemem_size = size; } - bool isSimulated() { return simulated; } - std::uintptr_t getUntrustedMem() { return untrusted; } - std::uintptr_t getUntrustedSize() { return untrusted_size; } - std::uintptr_t getUntrustedEnd() { return untrusted + untrusted_size; } - std::uintptr_t getFreeMemSize() { return freemem_size; } + void setFreeMemSize(std::uint64_t size) noexcept { freemem_size = size; } + bool isSimulated() const noexcept { return simulated; } + std::uintptr_t getUntrustedMem() const noexcept { return untrusted; } + std::uintptr_t getUntrustedSize() const noexcept { return untrusted_size; } + std::uintptr_t getUntrustedEnd() const noexcept { return untrusted + untrusted_size; } + std::uintptr_t getFreeMemSize() const noexcept { return freemem_size; } private: bool simulated{false}; From df8dd86b274d251ed0a01f277a84b724d8b6ebf3 Mon Sep 17 00:00:00 2001 From: red-robby Date: Tue, 31 Jan 2023 00:47:17 -0800 Subject: [PATCH 03/14] ElfFile.hpp/.cpp -- add std:: to standard types; add const/noexcept as appropriate --- sdk/include/host/ElfFile.hpp | 31 ++++++++++++++++--------------- sdk/src/host/ElfFile.cpp | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/sdk/include/host/ElfFile.hpp b/sdk/include/host/ElfFile.hpp index 4f0cb19c2..a0984abb8 100644 --- a/sdk/include/host/ElfFile.hpp +++ b/sdk/include/host/ElfFile.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "./common.h" #include "./keystone_user.h" @@ -21,33 +22,33 @@ class ElfFile { public: explicit ElfFile(std::string filename); ~ElfFile(); - size_t getFileSize() { return fileSize; } - bool isValid(); + std::size_t getFileSize() const noexcept { return fileSize; } + bool isValid() const noexcept; - uintptr_t getMinVaddr() { return minVaddr; } - size_t getTotalMemorySize() { return maxVaddr - minVaddr; } + std::uintptr_t getMinVaddr() const noexcept { return minVaddr; } + std::size_t getTotalMemorySize() const noexcept { return maxVaddr - minVaddr; } bool initialize(bool isRuntime); - unsigned int getPageMode() { return (isRuntime ? RT_FULL : USER_FULL); } + unsigned int getPageMode() const noexcept { return (isRuntime ? RT_FULL : USER_FULL); } /* libelf wrapper function */ - size_t getNumProgramHeaders(void); - size_t getProgramHeaderType(size_t ph); - size_t getProgramHeaderFileSize(size_t ph); - size_t getProgramHeaderMemorySize(size_t ph); - uintptr_t getProgramHeaderVaddr(size_t ph); - uintptr_t getEntryPoint(); - void* getProgramSegment(size_t ph); + std::size_t getNumProgramHeaders(void); + std::size_t getProgramHeaderType(std::size_t ph); + std::size_t getProgramHeaderFileSize(std::size_t ph); + std::size_t getProgramHeaderMemorySize(std::size_t ph); + std::uintptr_t getProgramHeaderVaddr(std::size_t ph); + std::uintptr_t getEntryPoint(); + void* getProgramSegment(std::size_t ph); private: int filep; /* virtual addresses */ - uintptr_t minVaddr; - uintptr_t maxVaddr; + std::uintptr_t minVaddr; + std::uintptr_t maxVaddr; void* ptr; - size_t fileSize; + std::size_t fileSize; /* is this runtime binary */ bool isRuntime; diff --git a/sdk/src/host/ElfFile.cpp b/sdk/src/host/ElfFile.cpp index 2a44c5e2f..db8242d57 100644 --- a/sdk/src/host/ElfFile.cpp +++ b/sdk/src/host/ElfFile.cpp @@ -45,7 +45,7 @@ ElfFile::~ElfFile() { } bool -ElfFile::isValid() { +ElfFile::isValid() const noexcept { return (filep > 0 && fileSize > 0 && ptr != NULL); } From 22e9bcd5c4d995dc9bfdd32a317248bb6f6202f6 Mon Sep 17 00:00:00 2001 From: red-robby Date: Tue, 31 Jan 2023 00:52:01 -0800 Subject: [PATCH 04/14] ElfFile.cpp -- add std:: to standard types (missed before) --- sdk/src/host/ElfFile.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/src/host/ElfFile.cpp b/sdk/src/host/ElfFile.cpp index db8242d57..fe983ad94 100644 --- a/sdk/src/host/ElfFile.cpp +++ b/sdk/src/host/ElfFile.cpp @@ -9,7 +9,7 @@ namespace Keystone { -static size_t +static std::size_t fstatFileSize(int filep) { int rc; struct stat stat_buf; @@ -73,38 +73,38 @@ ElfFile::initialize(bool _isRuntime) { } /* Functions below are wrappers for libelf */ -size_t +std::size_t ElfFile::getNumProgramHeaders(void) { return elf_getNumProgramHeaders(&elf); } -size_t -ElfFile::getProgramHeaderType(size_t ph) { +std::size_t +ElfFile::getProgramHeaderType(std::size_t ph) { return elf_getProgramHeaderType(&elf, ph); } -size_t -ElfFile::getProgramHeaderFileSize(size_t ph) { +std::size_t +ElfFile::getProgramHeaderFileSize(std::size_t ph) { return elf_getProgramHeaderFileSize(&elf, ph); } -size_t -ElfFile::getProgramHeaderMemorySize(size_t ph) { +std::size_t +ElfFile::getProgramHeaderMemorySize(std::size_t ph) { return elf_getProgramHeaderMemorySize(&elf, ph); } -uintptr_t -ElfFile::getProgramHeaderVaddr(size_t ph) { +std::uintptr_t +ElfFile::getProgramHeaderVaddr(std::size_t ph) { return elf_getProgramHeaderVaddr(&elf, ph); } -uintptr_t +std::uintptr_t ElfFile::getEntryPoint() { return elf_getEntryPoint(&elf); } void* -ElfFile::getProgramSegment(size_t ph) { +ElfFile::getProgramSegment(std::size_t ph) { return elf_getProgramSegment(&elf, ph); } } // namespace Keystone From bf2a20525f9584eb0411852d1ad4d828089181ef Mon Sep 17 00:00:00 2001 From: red-robby Date: Tue, 31 Jan 2023 01:00:24 -0800 Subject: [PATCH 05/14] Enclave.hpp/.cpp -- similar improvements --- sdk/include/host/Enclave.hpp | 31 ++++++++-------- sdk/src/host/Enclave.cpp | 72 ++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/sdk/include/host/Enclave.hpp b/sdk/include/host/Enclave.hpp index 88125e05c..b72170821 100644 --- a/sdk/include/host/Enclave.hpp +++ b/sdk/include/host/Enclave.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "./common.h" extern "C" { @@ -28,7 +29,7 @@ extern "C" { namespace Keystone { -typedef std::function OcallFunc; +using OcallFunc = std::function; class Enclave { private: @@ -39,13 +40,13 @@ class Enclave { KeystoneDevice* pDevice; char hash[MDSIZE]; hash_ctx_t hash_ctx; - uintptr_t runtime_stk_sz; + std::uintptr_t runtime_stk_sz; void* shared_buffer; - size_t shared_buffer_size; + std::size_t shared_buffer_size; OcallFunc oFuncDispatch; - bool mapUntrusted(size_t size); - bool allocPage(uintptr_t va, uintptr_t src, unsigned int mode); - bool initStack(uintptr_t start, size_t size, bool is_rt); + bool mapUntrusted(std::size_t size); + bool allocPage(std::uintptr_t va, std::uintptr_t src, unsigned int mode); + bool initStack(std::uintptr_t start, std::size_t size, bool is_rt); Error loadUntrusted(); bool mapElf(ElfFile* file); Error loadElf(ElfFile* file); @@ -53,27 +54,27 @@ class Enclave { bool initFiles(const char*, const char*); bool initDevice(); - bool prepareEnclave(uintptr_t alternatePhysAddr); + bool prepareEnclave(std::uintptr_t alternatePhysAddr); bool initMemory(); public: Enclave(); ~Enclave(); - const char* getHash(); - void* getSharedBuffer(); - size_t getSharedBufferSize(); + const char* getHash() const noexcept; + void* getSharedBuffer() noexcept; + std::size_t getSharedBufferSize() const noexcept; Error registerOcallDispatch(OcallFunc func); Error init(const char* filepath, const char* runtime, Params parameters); Error init( const char* eapppath, const char* runtimepath, Params _params, - uintptr_t alternatePhysAddr); + std::uintptr_t alternatePhysAddr); Error destroy(); - Error run(uintptr_t* ret = nullptr); + Error run(std::uintptr_t* ret = nullptr); }; -uint64_t +std::uint64_t calculate_required_pages( - uint64_t eapp_sz, uint64_t eapp_stack_sz, uint64_t rt_sz, - uint64_t rt_stack_sz); + std::uint64_t eapp_sz, std::uint64_t eapp_stack_sz, std::uint64_t rt_sz, + std::uint64_t rt_stack_sz); } // namespace Keystone diff --git a/sdk/src/host/Enclave.cpp b/sdk/src/host/Enclave.cpp index 7f1d1fa42..b3cd2f263 100644 --- a/sdk/src/host/Enclave.cpp +++ b/sdk/src/host/Enclave.cpp @@ -47,8 +47,8 @@ calculate_required_pages(uint64_t eapp_sz, uint64_t rt_sz) { Error Enclave::loadUntrusted() { - uintptr_t va_start = ROUND_DOWN(params.getUntrustedMem(), PAGE_BITS); - uintptr_t va_end = ROUND_UP(params.getUntrustedEnd(), PAGE_BITS); + std::uintptr_t va_start = ROUND_DOWN(params.getUntrustedMem(), PAGE_BITS); + std::uintptr_t va_end = ROUND_UP(params.getUntrustedEnd(), PAGE_BITS); while (va_start < va_end) { if (!pMemory->allocPage(va_start, 0, UTM_FULL)) { @@ -61,17 +61,17 @@ Enclave::loadUntrusted() { /* This function will be deprecated when we implement freemem */ bool -Enclave::initStack(uintptr_t start, size_t size, bool is_rt) { +Enclave::initStack(std::uintptr_t start, std::size_t size, bool is_rt) { static char nullpage[PAGE_SIZE] = { 0, }; - uintptr_t high_addr = ROUND_UP(start, PAGE_BITS); - uintptr_t va_start_stk = ROUND_DOWN((high_addr - size), PAGE_BITS); + std::uintptr_t high_addr = ROUND_UP(start, PAGE_BITS); + std::uintptr_t va_start_stk = ROUND_DOWN((high_addr - size), PAGE_BITS); int stk_pages = (high_addr - va_start_stk) / PAGE_SIZE; for (int i = 0; i < stk_pages; i++) { if (!pMemory->allocPage( - va_start_stk, (uintptr_t)nullpage, + va_start_stk, (std::uintptr_t)nullpage, (is_rt ? RT_NOEXEC : USER_NOEXEC))) return false; @@ -83,11 +83,11 @@ Enclave::initStack(uintptr_t start, size_t size, bool is_rt) { bool Enclave::mapElf(ElfFile* elf) { - uintptr_t va; + std::uintptr_t va; assert(elf); - size_t num_pages = + std::size_t num_pages = ROUND_DOWN(elf->getTotalMemorySize(), PAGE_BITS) / PAGE_SIZE; va = elf->getMinVaddr(); @@ -111,21 +111,21 @@ Enclave::loadElf(ElfFile* elf) { continue; } - uintptr_t start = elf->getProgramHeaderVaddr(i); - uintptr_t file_end = start + elf->getProgramHeaderFileSize(i); - uintptr_t memory_end = start + elf->getProgramHeaderMemorySize(i); + std::uintptr_t start = elf->getProgramHeaderVaddr(i); + std::uintptr_t file_end = start + elf->getProgramHeaderFileSize(i); + std::uintptr_t memory_end = start + elf->getProgramHeaderMemorySize(i); char* src = reinterpret_cast(elf->getProgramSegment(i)); - uintptr_t va = start; + std::uintptr_t va = start; /* FIXME: This is a temporary fix for loading iozone binary * which has a page-misaligned program header. */ if (!IS_ALIGNED(va, PAGE_SIZE)) { - size_t offset = va - PAGE_DOWN(va); - size_t length = PAGE_UP(va) - va; + std::size_t offset = va - PAGE_DOWN(va); + std::size_t length = PAGE_UP(va) - va; char page[PAGE_SIZE]; memset(page, 0, PAGE_SIZE); memcpy(page + offset, (const void*)src, length); - if (!pMemory->allocPage(PAGE_DOWN(va), (uintptr_t)page, mode)) + if (!pMemory->allocPage(PAGE_DOWN(va), (std::uintptr_t)page, mode)) return Error::PageAllocationFailure; va += length; src += length; @@ -133,7 +133,7 @@ Enclave::loadElf(ElfFile* elf) { /* first load all pages that do not include .bss segment */ while (va + PAGE_SIZE <= file_end) { - if (!pMemory->allocPage(va, (uintptr_t)src, mode)) + if (!pMemory->allocPage(va, (std::uintptr_t)src, mode)) return Error::PageAllocationFailure; src += PAGE_SIZE; @@ -145,15 +145,15 @@ Enclave::loadElf(ElfFile* elf) { if (va < file_end) { char page[PAGE_SIZE]; memset(page, 0, PAGE_SIZE); - memcpy(page, (const void*)src, static_cast(file_end - va)); - if (!pMemory->allocPage(va, (uintptr_t)page, mode)) + memcpy(page, (const void*)src, static_cast(file_end - va)); + if (!pMemory->allocPage(va, (std::uintptr_t)page, mode)) return Error::PageAllocationFailure; va += PAGE_SIZE; } /* finally, load the remaining .bss segments */ while (va < memory_end) { - if (!pMemory->allocPage(va, (uintptr_t)nullpage, mode)) + if (!pMemory->allocPage(va, (std::uintptr_t)nullpage, mode)) return Error::PageAllocationFailure; va += PAGE_SIZE; } @@ -172,8 +172,8 @@ Enclave::validate_and_hash_enclave(struct runtime_params_t args) { // hash the runtime parameters hash_extend(&hash_ctx, &args, sizeof(struct runtime_params_t)); - uintptr_t runtime_max_seen = 0; - uintptr_t user_max_seen = 0; + std::uintptr_t runtime_max_seen = 0; + std::uintptr_t user_max_seen = 0; // hash the epm contents including the virtual addresses int valid = pMemory->validateAndHashEpm( @@ -226,7 +226,7 @@ Enclave::initFiles(const char* eapppath, const char* runtimepath) { } bool -Enclave::prepareEnclave(uintptr_t alternatePhysAddr) { +Enclave::prepareEnclave(std::uintptr_t alternatePhysAddr) { // FIXME: this will be deprecated with complete freemem support. // We just add freemem size for now. uint64_t minPages; @@ -245,7 +245,7 @@ Enclave::prepareEnclave(uintptr_t alternatePhysAddr) { } /* We switch out the phys addr as needed */ - uintptr_t physAddr; + std::uintptr_t physAddr; if (alternatePhysAddr) { physAddr = alternatePhysAddr; } else { @@ -258,18 +258,18 @@ Enclave::prepareEnclave(uintptr_t alternatePhysAddr) { Error Enclave::init(const char* eapppath, const char* runtimepath, Params _params) { - return this->init(eapppath, runtimepath, _params, (uintptr_t)0); + return this->init(eapppath, runtimepath, _params, (std::uintptr_t)0); } const char* -Enclave::getHash() { +Enclave::getHash() const noexcept { return this->hash; } Error Enclave::init( const char* eapppath, const char* runtimepath, Params _params, - uintptr_t alternatePhysAddr) { + std::uintptr_t alternatePhysAddr) { params = _params; if (params.isSimulated()) { @@ -329,7 +329,7 @@ Enclave::init( } #endif /* USE_FREEMEM */ - uintptr_t utm_free; + std::uintptr_t utm_free; utm_free = pMemory->allocUtm(params.getUntrustedSize()); if (!utm_free) { @@ -344,13 +344,13 @@ Enclave::init( struct runtime_params_t runtimeParams; runtimeParams.runtime_entry = - reinterpret_cast(runtimeFile->getEntryPoint()); + reinterpret_cast(runtimeFile->getEntryPoint()); runtimeParams.user_entry = - reinterpret_cast(enclaveFile->getEntryPoint()); + reinterpret_cast(enclaveFile->getEntryPoint()); runtimeParams.untrusted_ptr = - reinterpret_cast(params.getUntrustedMem()); + reinterpret_cast(params.getUntrustedMem()); runtimeParams.untrusted_size = - reinterpret_cast(params.getUntrustedSize()); + reinterpret_cast(params.getUntrustedSize()); pMemory->startFreeMem(); @@ -383,7 +383,7 @@ Enclave::init( } bool -Enclave::mapUntrusted(size_t size) { +Enclave::mapUntrusted(std::size_t size) { if (size == 0) { return true; } @@ -415,7 +415,7 @@ Enclave::destroy() { } Error -Enclave::run(uintptr_t* retval) { +Enclave::run(std::uintptr_t* retval) { if (params.isSimulated()) { return Error::Success; } @@ -439,12 +439,12 @@ Enclave::run(uintptr_t* retval) { } void* -Enclave::getSharedBuffer() { +Enclave::getSharedBuffer() noexcept { return shared_buffer; } -size_t -Enclave::getSharedBufferSize() { +std::size_t +Enclave::getSharedBufferSize() const noexcept { return shared_buffer_size; } From 0828080ebc2f462217a5bdcb32d50440dbe7bae4 Mon Sep 17 00:00:00 2001 From: red-robby Date: Tue, 31 Jan 2023 01:02:04 -0800 Subject: [PATCH 06/14] Enclave.hpp -- reorder includes --- sdk/include/host/Enclave.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/include/host/Enclave.hpp b/sdk/include/host/Enclave.hpp index b72170821..ba19b2b2c 100644 --- a/sdk/include/host/Enclave.hpp +++ b/sdk/include/host/Enclave.hpp @@ -12,10 +12,10 @@ #include #include +#include #include #include #include -#include #include "./common.h" extern "C" { From 033bf35282546f786a5f9f32d35ecc2e8188ace5 Mon Sep 17 00:00:00 2001 From: red-robby Date: Tue, 31 Jan 2023 01:09:40 -0800 Subject: [PATCH 07/14] KeystoneDevice.hpp/.cpp -- similar improvements --- sdk/include/host/KeystoneDevice.hpp | 34 ++++++++++++++--------------- sdk/src/host/KeystoneDevice.cpp | 34 ++++++++++++++--------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/sdk/include/host/KeystoneDevice.hpp b/sdk/include/host/KeystoneDevice.hpp index 8af16785f..cd2dfc0c1 100644 --- a/sdk/include/host/KeystoneDevice.hpp +++ b/sdk/include/host/KeystoneDevice.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "./common.h" #include "./keystone_user.h" @@ -23,28 +24,27 @@ namespace Keystone { class KeystoneDevice { protected: - int eid; - uintptr_t physAddr; + int eid{ -1 }; + std::uintptr_t physAddr; private: int fd; - Error __run(bool resume, uintptr_t* ret); + Error __run(bool resume, std::uintptr_t* ret); public: - virtual uintptr_t getPhysAddr() { return physAddr; } + virtual std::uintptr_t getPhysAddr() { return physAddr; } - KeystoneDevice(); virtual ~KeystoneDevice() {} virtual bool initDevice(Params params); - virtual Error create(uint64_t minPages); - virtual uintptr_t initUTM(size_t size); + virtual Error create(std::uint64_t minPages); + virtual std::uintptr_t initUTM(std::size_t size); virtual Error finalize( - uintptr_t runtimePhysAddr, uintptr_t eappPhysAddr, uintptr_t freePhysAddr, + std::uintptr_t runtimePhysAddr, std::uintptr_t eappPhysAddr, std::uintptr_t freePhysAddr, struct runtime_params_t params); virtual Error destroy(); - virtual Error run(uintptr_t* ret); - virtual Error resume(uintptr_t* ret); - virtual void* map(uintptr_t addr, size_t size); + virtual Error run(std::uintptr_t* ret); + virtual Error resume(std::uintptr_t* ret); + virtual void* map(std::uintptr_t addr, std::size_t size); }; class MockKeystoneDevice : public KeystoneDevice { @@ -56,15 +56,15 @@ class MockKeystoneDevice : public KeystoneDevice { MockKeystoneDevice() {} ~MockKeystoneDevice(); bool initDevice(Params params); - Error create(uint64_t minPages); - uintptr_t initUTM(size_t size); + Error create(std::uint64_t minPages); + std::uintptr_t initUTM(std::size_t size); Error finalize( - uintptr_t runtimePhysAddr, uintptr_t eappPhysAddr, uintptr_t freePhysAddr, + std::uintptr_t runtimePhysAddr, std::uintptr_t eappPhysAddr, std::uintptr_t freePhysAddr, struct runtime_params_t params); Error destroy(); - Error run(uintptr_t* ret); - Error resume(uintptr_t* ret); - void* map(uintptr_t addr, size_t size); + Error run(std::uintptr_t* ret); + Error resume(std::uintptr_t* ret); + void* map(std::uintptr_t addr, std::size_t size); }; } // namespace Keystone diff --git a/sdk/src/host/KeystoneDevice.cpp b/sdk/src/host/KeystoneDevice.cpp index 90597e8ce..777380265 100644 --- a/sdk/src/host/KeystoneDevice.cpp +++ b/sdk/src/host/KeystoneDevice.cpp @@ -7,10 +7,8 @@ namespace Keystone { -KeystoneDevice::KeystoneDevice() { eid = -1; } - Error -KeystoneDevice::create(uint64_t minPages) { +KeystoneDevice::create(std::uint64_t minPages) { struct keystone_ioctl_create_enclave encl; encl.min_pages = minPages; @@ -26,8 +24,8 @@ KeystoneDevice::create(uint64_t minPages) { return Error::Success; } -uintptr_t -KeystoneDevice::initUTM(size_t size) { +std::uintptr_t +KeystoneDevice::initUTM(std::size_t size) { struct keystone_ioctl_create_enclave encl; encl.eid = eid; encl.params.untrusted_size = size; @@ -40,7 +38,7 @@ KeystoneDevice::initUTM(size_t size) { Error KeystoneDevice::finalize( - uintptr_t runtimePhysAddr, uintptr_t eappPhysAddr, uintptr_t freePhysAddr, + std::uintptr_t runtimePhysAddr, std::uintptr_t eappPhysAddr, std::uintptr_t freePhysAddr, struct runtime_params_t params) { struct keystone_ioctl_create_enclave encl; encl.eid = eid; @@ -75,12 +73,12 @@ KeystoneDevice::destroy() { } Error -KeystoneDevice::__run(bool resume, uintptr_t* ret) { +KeystoneDevice::__run(bool resume, std::uintptr_t* ret) { struct keystone_ioctl_run_enclave encl; encl.eid = eid; Error error; - uint64_t request; + std::uint64_t request; if (resume) { error = Error::IoctlErrorResume; @@ -113,17 +111,17 @@ KeystoneDevice::__run(bool resume, uintptr_t* ret) { } Error -KeystoneDevice::run(uintptr_t* ret) { +KeystoneDevice::run(std::uintptr_t* ret) { return __run(false, ret); } Error -KeystoneDevice::resume(uintptr_t* ret) { +KeystoneDevice::resume(std::uintptr_t* ret) { return __run(true, ret); } void* -KeystoneDevice::map(uintptr_t addr, size_t size) { +KeystoneDevice::map(std::uintptr_t addr, std::size_t size) { assert(fd >= 0); void* ret; ret = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, addr); @@ -143,19 +141,19 @@ KeystoneDevice::initDevice(Params params) { } Error -MockKeystoneDevice::create(uint64_t minPages) { +MockKeystoneDevice::create(std::uint64_t minPages) { eid = -1; return Error::Success; } -uintptr_t -MockKeystoneDevice::initUTM(size_t size) { +std::uintptr_t +MockKeystoneDevice::initUTM(std::size_t size) { return 0; } Error MockKeystoneDevice::finalize( - uintptr_t runtimePhysAddr, uintptr_t eappPhysAddr, uintptr_t freePhysAddr, + std::uintptr_t runtimePhysAddr, std::uintptr_t eappPhysAddr, std::uintptr_t freePhysAddr, struct runtime_params_t params) { return Error::Success; } @@ -166,12 +164,12 @@ MockKeystoneDevice::destroy() { } Error -MockKeystoneDevice::run(uintptr_t* ret) { +MockKeystoneDevice::run(std::uintptr_t* ret) { return Error::Success; } Error -MockKeystoneDevice::resume(uintptr_t* ret) { +MockKeystoneDevice::resume(std::uintptr_t* ret) { return Error::Success; } @@ -181,7 +179,7 @@ MockKeystoneDevice::initDevice(Params params) { } void* -MockKeystoneDevice::map(uintptr_t addr, size_t size) { +MockKeystoneDevice::map(std::uintptr_t addr, std::size_t size) { sharedBuffer = malloc(size); return sharedBuffer; } From 2047307d40d8961052f9004d0a933a86b09a6ff9 Mon Sep 17 00:00:00 2001 From: red-robby Date: Tue, 31 Jan 2023 01:19:01 -0800 Subject: [PATCH 08/14] Memory.cpp/.hpp -- similar improvements --- sdk/include/host/Memory.hpp | 100 ++++++++++++++++++------------------ sdk/src/host/Memory.cpp | 69 +++++++++++-------------- 2 files changed, 81 insertions(+), 88 deletions(-) diff --git a/sdk/include/host/Memory.hpp b/sdk/include/host/Memory.hpp index a1bb937f9..c5b6bba55 100644 --- a/sdk/include/host/Memory.hpp +++ b/sdk/include/host/Memory.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "./common.h" #include "KeystoneDevice.hpp" @@ -24,12 +25,12 @@ namespace Keystone { * These are used to make use of C type-checking.. */ typedef struct { - uintptr_t pte; + std::uintptr_t pte; } pte; #define pte_val(x) ((x).pte) -#define __pa(x) ((uintptr_t)(x)) +#define __pa(x) ((std::uintptr_t)(x)) #define __pte(x) ((pte){(x)}) @@ -69,88 +70,87 @@ typedef struct { class Memory { public: - Memory(); ~Memory() {} virtual void init( - KeystoneDevice* dev, uintptr_t phys_addr, size_t min_pages) = 0; - virtual uintptr_t readMem(uintptr_t src, size_t size) = 0; - virtual void writeMem(uintptr_t src, uintptr_t dst, size_t size) = 0; - virtual uintptr_t allocMem(size_t size) = 0; - virtual uintptr_t allocUtm(size_t size) = 0; - bool allocPage(uintptr_t eva, uintptr_t src, unsigned int mode); - size_t epmAllocVspace(uintptr_t addr, size_t num_pages); + KeystoneDevice* dev, std::uintptr_t phys_addr, std::size_t min_pages) = 0; + virtual std::uintptr_t readMem(std::uintptr_t src, std::size_t size) = 0; + virtual void writeMem(std::uintptr_t src, std::uintptr_t dst, std::size_t size) = 0; + virtual std::uintptr_t allocMem(std::size_t size) = 0; + virtual std::uintptr_t allocUtm(std::size_t size) = 0; + bool allocPage(std::uintptr_t eva, std::uintptr_t src, unsigned int mode); + std::size_t epmAllocVspace(std::uintptr_t addr, std::size_t num_pages); // getters to be deprecated - uintptr_t getStartAddr() { return startAddr; } - uintptr_t getCurrentEPMAddress() { return epmFreeList; } - uintptr_t getRootPageTable() { return rootPageTable; } + std::uintptr_t getStartAddr() const noexcept { return startAddr; } + std::uintptr_t getCurrentEPMAddress() const noexcept { return epmFreeList; } + std::uintptr_t getRootPageTable() const noexcept { return rootPageTable; } int validateAndHashEpm( - hash_ctx_t* hash_ctx, int level, pte* tb, uintptr_t vaddr, int contiguous, - uintptr_t* runtime_max_seen, uintptr_t* user_max_seen); + hash_ctx_t* hash_ctx, int level, pte* tb, std::uintptr_t vaddr, int contiguous, + std::uintptr_t* runtime_max_seen, std::uintptr_t* user_max_seen); void startRuntimeMem(); void startEappMem(); void startFreeMem(); - uintptr_t getRuntimePhysAddr() { return runtimePhysAddr; } - uintptr_t getEappPhysAddr() { return eappPhysAddr; } - uintptr_t getFreePhysAddr() { return freePhysAddr; } + std::uintptr_t getRuntimePhysAddr() const noexcept { return runtimePhysAddr; } + std::uintptr_t getEappPhysAddr() const noexcept { return eappPhysAddr; } + std::uintptr_t getFreePhysAddr() const noexcept { return freePhysAddr; } protected: - pte* __ept_walk_create(uintptr_t addr); - pte* __ept_continue_walk_create(uintptr_t addr, pte* pte); - pte* __ept_walk_internal(uintptr_t addr, int create); - pte* __ept_walk(uintptr_t addr); - uintptr_t epm_va_to_pa(uintptr_t addr); + pte* __ept_walk_create(std::uintptr_t addr); + pte* __ept_continue_walk_create(std::uintptr_t addr, pte* pte); + pte* __ept_walk_internal(std::uintptr_t addr, int create); + pte* __ept_walk(std::uintptr_t addr); + std::uintptr_t epm_va_to_pa(std::uintptr_t addr); KeystoneDevice* pDevice; - size_t epmSize; - uintptr_t epmFreeList; - uintptr_t utmFreeList; - uintptr_t rootPageTable; - uintptr_t startAddr; + std::size_t epmSize; + std::uintptr_t epmFreeList{ 0 }; + std::uintptr_t utmFreeList{ 0 }; + std::uintptr_t rootPageTable{ 0 }; + std::uintptr_t startAddr{ 0 }; // for hash calculation - uintptr_t runtimePhysAddr; - uintptr_t eappPhysAddr; - uintptr_t freePhysAddr; - uintptr_t utmPhysAddr; - uintptr_t untrustedPtr; - uintptr_t untrustedSize; + std::uintptr_t runtimePhysAddr; + std::uintptr_t eappPhysAddr; + std::uintptr_t freePhysAddr; + std::uintptr_t utmPhysAddr; + std::uintptr_t untrustedPtr; + std::uintptr_t untrustedSize; private: - pte pte_create(uintptr_t, int); - pte ptd_create(uintptr_t); - uintptr_t pte_ppn(pte); - uintptr_t ppn(uintptr_t); - size_t pt_idx(uintptr_t, int); + pte pte_create(std::uintptr_t, int); + pte ptd_create(std::uintptr_t); + std::uintptr_t pte_ppn(pte); + std::uintptr_t ppn(std::uintptr_t); + std::size_t pt_idx(std::uintptr_t, int); }; class PhysicalEnclaveMemory : public Memory { public: PhysicalEnclaveMemory() {} ~PhysicalEnclaveMemory() {} - void init(KeystoneDevice* dev, uintptr_t phys_addr, size_t min_pages); - uintptr_t readMem(uintptr_t src, size_t size); - void writeMem(uintptr_t src, uintptr_t dst, size_t size); - uintptr_t allocMem(size_t size); - uintptr_t allocUtm(size_t size); + void init(KeystoneDevice* dev, std::uintptr_t phys_addr, std::size_t min_pages); + std::uintptr_t readMem(std::uintptr_t src, std::size_t size); + void writeMem(std::uintptr_t src, std::uintptr_t dst, std::size_t size); + std::uintptr_t allocMem(std::size_t size); + std::uintptr_t allocUtm(std::size_t size); }; // Simulated memory reads/writes from calloc'ed memory class SimulatedEnclaveMemory : public Memory { private: - void* allocateAligned(size_t size, size_t alignment); + void* allocateAligned(std::size_t size, std::size_t alignment); public: SimulatedEnclaveMemory() {} ~SimulatedEnclaveMemory() {} - void init(KeystoneDevice* dev, uintptr_t phys_addr, size_t min_pages); - uintptr_t readMem(uintptr_t src, size_t size); - void writeMem(uintptr_t src, uintptr_t dst, size_t size); - uintptr_t allocMem(size_t size); - uintptr_t allocUtm(size_t size); + void init(KeystoneDevice* dev, std::uintptr_t phys_addr, std::size_t min_pages); + std::uintptr_t readMem(std::uintptr_t src, std::size_t size); + void writeMem(std::uintptr_t src, std::uintptr_t dst, std::size_t size); + std::uintptr_t allocMem(std::size_t size); + std::uintptr_t allocUtm(std::size_t size); }; } // namespace Keystone diff --git a/sdk/src/host/Memory.cpp b/sdk/src/host/Memory.cpp index dd4e7fb89..3e96b81e0 100644 --- a/sdk/src/host/Memory.cpp +++ b/sdk/src/host/Memory.cpp @@ -8,13 +8,6 @@ namespace Keystone { -Memory::Memory() { - epmFreeList = 0; - utmFreeList = 0; - rootPageTable = 0; - startAddr = 0; -} - void Memory::startRuntimeMem() { runtimePhysAddr = getCurrentEPMAddress(); @@ -31,35 +24,35 @@ Memory::startFreeMem() { } inline pte -Memory::pte_create(uintptr_t ppn, int type) { +Memory::pte_create(std::uintptr_t ppn, int type) { return __pte((ppn << PTE_PPN_SHIFT) | PTE_V | type); } inline pte -Memory::ptd_create(uintptr_t ppn) { +Memory::ptd_create(std::uintptr_t ppn) { return pte_create(ppn, PTE_V); } -uintptr_t +std::uintptr_t Memory::pte_ppn(pte pte) { return pte_val(pte) >> PTE_PPN_SHIFT; } -uintptr_t -Memory::ppn(uintptr_t addr) { +std::uintptr_t +Memory::ppn(std::uintptr_t addr) { return __pa(addr) >> RISCV_PGSHIFT; } -size_t -Memory::pt_idx(uintptr_t addr, int level) { - size_t idx = addr >> (RISCV_PGLEVEL_BITS * level + RISCV_PGSHIFT); +std::size_t +Memory::pt_idx(std::uintptr_t addr, int level) { + std::size_t idx = addr >> (RISCV_PGLEVEL_BITS * level + RISCV_PGSHIFT); return idx & ((1 << RISCV_PGLEVEL_BITS) - 1); } bool -Memory::allocPage(uintptr_t va, uintptr_t src, unsigned int mode) { - uintptr_t page_addr; - uintptr_t* pFreeList = (mode == UTM_FULL ? &utmFreeList : &epmFreeList); +Memory::allocPage(std::uintptr_t va, std::uintptr_t src, unsigned int mode) { + std::uintptr_t page_addr; + std::uintptr_t* pFreeList = (mode == UTM_FULL ? &utmFreeList : &epmFreeList); pte* pte = __ept_walk_create(va); @@ -85,13 +78,13 @@ Memory::allocPage(uintptr_t va, uintptr_t src, unsigned int mode) { case RT_FULL: { *pte = pte_create(page_addr, PTE_D | PTE_A | PTE_R | PTE_W | PTE_X | PTE_V); - writeMem(src, (uintptr_t)page_addr << PAGE_BITS, PAGE_SIZE); + writeMem(src, (std::uintptr_t)page_addr << PAGE_BITS, PAGE_SIZE); break; } case USER_FULL: { *pte = pte_create( page_addr, PTE_D | PTE_A | PTE_R | PTE_W | PTE_X | PTE_U | PTE_V); - writeMem(src, (uintptr_t)page_addr << PAGE_BITS, PAGE_SIZE); + writeMem(src, (std::uintptr_t)page_addr << PAGE_BITS, PAGE_SIZE); break; } case UTM_FULL: { @@ -109,43 +102,43 @@ Memory::allocPage(uintptr_t va, uintptr_t src, unsigned int mode) { } pte* -Memory::__ept_continue_walk_create(uintptr_t addr, pte* pte) { - uint64_t free_ppn = ppn(epmFreeList); +Memory::__ept_continue_walk_create(std::uintptr_t addr, pte* pte) { + std::uint64_t free_ppn = ppn(epmFreeList); *pte = ptd_create(free_ppn); epmFreeList += PAGE_SIZE; return __ept_walk_create(addr); } pte* -Memory::__ept_walk_internal(uintptr_t addr, int create) { +Memory::__ept_walk_internal(std::uintptr_t addr, int create) { pte* t = reinterpret_cast(rootPageTable); int i; for (i = (VA_BITS - RISCV_PGSHIFT) / RISCV_PGLEVEL_BITS - 1; i > 0; i--) { - size_t idx = pt_idx(addr, i); + std::size_t idx = pt_idx(addr, i); if (!(pte_val(t[idx]) & PTE_V)) { return create ? __ept_continue_walk_create(addr, &t[idx]) : 0; } t = reinterpret_cast(readMem( - reinterpret_cast(pte_ppn(t[idx]) << RISCV_PGSHIFT), + reinterpret_cast(pte_ppn(t[idx]) << RISCV_PGSHIFT), PAGE_SIZE)); } return &t[pt_idx(addr, 0)]; } pte* -Memory::__ept_walk_create(uintptr_t addr) { +Memory::__ept_walk_create(std::uintptr_t addr) { return __ept_walk_internal(addr, 1); } pte* -Memory::__ept_walk(uintptr_t addr) { +Memory::__ept_walk(std::uintptr_t addr) { return __ept_walk_internal(addr, 0); } -uintptr_t -Memory::epm_va_to_pa(uintptr_t addr) { +std::uintptr_t +Memory::epm_va_to_pa(std::uintptr_t addr) { pte* pte = __ept_walk(addr); if (pte) return pte_ppn(*pte) << RISCV_PGSHIFT; @@ -155,9 +148,9 @@ Memory::epm_va_to_pa(uintptr_t addr) { /* This function pre-allocates the required page tables so that * the virtual addresses are linearly mapped to the physical memory */ -size_t -Memory::epmAllocVspace(uintptr_t addr, size_t num_pages) { - size_t count; +std::size_t +Memory::epmAllocVspace(std::uintptr_t addr, std::size_t num_pages) { + std::size_t count; for (count = 0; count < num_pages; count++, addr += PAGE_SIZE) { pte* pte = __ept_walk_create(addr); @@ -171,8 +164,8 @@ Memory::epmAllocVspace(uintptr_t addr, size_t num_pages) { linear at-most-once paddr mappings, and then hashing valid pages */ int Memory::validateAndHashEpm( - hash_ctx_t* hash_ctx, int level, pte* tb, uintptr_t vaddr, int contiguous, - uintptr_t* runtime_max_seen, uintptr_t* user_max_seen) { + hash_ctx_t* hash_ctx, int level, pte* tb, std::uintptr_t vaddr, int contiguous, + std::uintptr_t* runtime_max_seen, std::uintptr_t* user_max_seen) { pte* walk; int i; @@ -183,8 +176,8 @@ Memory::validateAndHashEpm( contiguous = 0; continue; } - uintptr_t vpn; - uintptr_t phys_addr = (pte_val(*walk) >> PTE_PPN_SHIFT) << RISCV_PGSHIFT; + std::uintptr_t vpn; + std::uintptr_t phys_addr = (pte_val(*walk) >> PTE_PPN_SHIFT) << RISCV_PGSHIFT; /* Check for blatently invalid mappings */ int map_in_epm = (phys_addr >= startAddr && phys_addr < startAddr + epmSize); @@ -203,11 +196,11 @@ Memory::validateAndHashEpm( else vpn = ((vaddr << RISCV_PGLEVEL_BITS) | (i & RISCV_PGLEVEL_MASK)); - uintptr_t va_start = vpn << RISCV_PGSHIFT; + std::uintptr_t va_start = vpn << RISCV_PGSHIFT; /* include the first virtual address of a contiguous range */ if (level == 1 && !contiguous) { - hash_extend(hash_ctx, &va_start, sizeof(uintptr_t)); + hash_extend(hash_ctx, &va_start, sizeof(std::uintptr_t)); // printf("user VA hashed: 0x%lx\n", va_start); contiguous = 1; } From b7c162590456e72d042f3b7978eecd5c50203a3e Mon Sep 17 00:00:00 2001 From: red-robby Date: Fri, 17 Feb 2023 14:33:18 -0800 Subject: [PATCH 09/14] Add .clang-format to top level directory; apply to sdk, sm, bootrom --- bootrom/bootloader.c | 47 +- bootrom/ed25519/ed25519.h | 44 +- bootrom/ed25519/fe.c | 2472 ++++---- bootrom/ed25519/fe.h | 63 +- bootrom/ed25519/fixedint.h | 115 +- bootrom/ed25519/ge.c | 703 +-- bootrom/ed25519/ge.h | 53 +- bootrom/ed25519/keypair.c | 22 +- bootrom/ed25519/precomp_data.h | 2377 +++++--- bootrom/ed25519/sc.c | 1560 ++--- bootrom/ed25519/sc.h | 8 +- bootrom/ed25519/sign.c | 45 +- bootrom/ed25519/verify.c | 130 +- bootrom/sha3/sha3.c | 231 +- bootrom/sha3/sha3.h | 26 +- bootrom/string.h | 29 +- bootrom/test_dev_key.h | 23 +- bootrom/use_test_keys.h | 8 +- .../attestation/host/attestor-runner.cpp | 3 +- sdk/examples/attestation/host/host.h | 46 +- sdk/examples/attestation/host/verifier.h | 1 - sdk/examples/tests/attestation/edge_wrapper.h | 12 +- .../tests/data-sealing/data-sealing.h | 3 +- sdk/examples/tests/edge_wrapper.cpp | 2 + sdk/examples/tests/edge_wrapper.h | 29 +- sdk/examples/tests/long-nop/nop.h | 12 +- sdk/examples/tests/test-runner.cpp | 15 +- sdk/examples/tests/untrusted/edge_wrapper.h | 12 +- sdk/include/app/syscall.h | 1 + sdk/include/edge/edge_syscall.h | 91 +- sdk/src/host/ElfFile.cpp | 2 + sdk/src/host/Enclave.cpp | 7 +- sdk/src/host/KeystoneDevice.cpp | 9 +- sdk/src/host/Memory.cpp | 11 +- sdk/src/verifier/Report.cpp | 5 +- sdk/src/verifier/json11.cpp | 1239 ++-- sdk/tests/keystone_test.cpp | 2 + sm/plat/generic/include/platform_override.h | 29 +- sm/plat/generic/platform.c | 334 +- sm/plat/generic/sifive_fu540.c | 50 +- sm/plat/mpfs/clocks/hw_mss_clks.h | 69 +- sm/plat/mpfs/config.h | 4 +- sm/plat/mpfs/csr_helper.c | 26 +- sm/plat/mpfs/csr_helper.h | 29 +- .../mss_sys_services/mss_sys_services.c | 3200 ++++------ .../mss_sys_services/mss_sys_services.h | 5294 ++++++++--------- .../mss_sys_services/mss_sys_services_regs.h | 43 +- sm/plat/mpfs/drivers/mss_uart/mss_uart.c | 1552 +++-- sm/plat/mpfs/drivers/mss_uart/mss_uart.h | 3695 ++++++------ sm/plat/mpfs/drivers/mss_uart/mss_uart_regs.h | 144 +- sm/plat/mpfs/encoding.h | 904 +-- sm/plat/mpfs/hss_clock.c | 51 +- sm/plat/mpfs/hss_clock.h | 33 +- sm/plat/mpfs/mpfs_reg_map.h | 278 +- sm/plat/mpfs/platform.c | 255 +- sm/plat/mpfs/uart_helper.c | 319 +- sm/plat/mpfs/uart_helper.h | 12 +- sm/plat/sifive/fu540/platform.c | 183 +- sm/src/assert.h | 13 +- sm/src/attest.c | 155 +- sm/src/cpu.c | 23 +- sm/src/cpu.h | 17 +- sm/src/crypto.c | 35 +- sm/src/crypto.h | 34 +- sm/src/ed25519/ed25519.h | 40 +- sm/src/ed25519/fe.c | 2472 ++++---- sm/src/ed25519/fe.h | 63 +- sm/src/ed25519/fixedint.h | 115 +- sm/src/ed25519/ge.c | 703 +-- sm/src/ed25519/ge.h | 53 +- sm/src/ed25519/keypair.c | 22 +- sm/src/ed25519/precomp_data.h | 2377 +++++--- sm/src/ed25519/sc.c | 1560 ++--- sm/src/ed25519/sc.h | 8 +- sm/src/ed25519/sign.c | 45 +- sm/src/enclave.c | 390 +- sm/src/enclave.h | 88 +- sm/src/hkdf_sha3_512/hkdf_sha3_512.c | 132 +- sm/src/hkdf_sha3_512/hkdf_sha3_512.h | 23 +- sm/src/hmac_sha3/hmac_sha3.c | 111 +- sm/src/hmac_sha3/hmac_sha3.h | 21 +- sm/src/ipi.c | 32 +- sm/src/ipi.h | 18 +- sm/src/mprv.h | 160 +- sm/src/page.h | 41 +- sm/src/platform-hook.h | 24 +- sm/src/platform/generic/platform.c | 28 +- sm/src/platform/generic/platform.h | 4 +- sm/src/platform/mpfs/platform.c | 39 +- sm/src/platform/mpfs/platform.h | 4 +- sm/src/platform/sifive/fu540/fu540_internal.c | 183 +- sm/src/platform/sifive/fu540/platform.c | 5 +- sm/src/platform/sifive/fu540/waymasks.c | 131 +- sm/src/platform/sifive/fu540/waymasks.h | 116 +- sm/src/plugins/multimem.c | 29 +- sm/src/plugins/multimem.h | 5 +- sm/src/plugins/plugins.c | 13 +- sm/src/plugins/plugins.h | 14 +- sm/src/pmp.c | 426 +- sm/src/pmp.h | 152 +- sm/src/safe_math_util.h | 6 +- sm/src/sbi_trap_hack.c | 241 +- sm/src/sha3/sha3.c | 231 +- sm/src/sha3/sha3.h | 28 +- sm/src/sm-sbi-opensbi.c | 62 +- sm/src/sm-sbi-opensbi.h | 20 +- sm/src/sm-sbi.c | 69 +- sm/src/sm-sbi.h | 18 +- sm/src/sm.c | 142 +- sm/src/sm.h | 125 +- sm/src/thread.c | 94 +- sm/src/thread.h | 72 +- sm/tools/hash_generator.c | 19 +- 113 files changed, 18921 insertions(+), 18092 deletions(-) diff --git a/bootrom/bootloader.c b/bootrom/bootloader.c index 823125ed0..5e9046cf4 100644 --- a/bootrom/bootloader.c +++ b/bootrom/bootloader.c @@ -4,7 +4,8 @@ #include "sha3/sha3.h" /* Adopted from https://github.com/orlp/ed25519 provides: - - void ed25519_create_keypair(t_pubkey *public_key, t_privkey *private_key, t_seed *seed); + - void ed25519_create_keypair(t_pubkey *public_key, t_privkey *private_key, + t_seed *seed); - void ed25519_sign(t_signature *signature, const unsigned uint8_t *message, size_t message_len, @@ -26,7 +27,6 @@ provides memcpy, memset */ - typedef unsigned char byte; // Sanctum header fields in DRAM @@ -40,18 +40,21 @@ extern byte sanctum_sm_signature[64]; #define DRAM_BASE 0x80000000 /* Update this to generate valid entropy for target platform*/ -inline byte random_byte(unsigned int i) { +inline byte +random_byte(unsigned int i) { #warning Bootloader does not have entropy source, keys are for TESTING ONLY return 0xac + (0xdd ^ i); } -void bootloader() { - //*sanctum_sm_size = 0x200; +void +bootloader() { + //*sanctum_sm_size = 0x200; // Reserve stack space for secrets byte scratchpad[128]; sha3_ctx_t hash_ctx; - // TODO: on real device, copy boot image from memory. In simulator, HTIF writes boot image + // TODO: on real device, copy boot image from memory. In simulator, HTIF + // writes boot image // ... SD card to beginning of memory. // sd_init(); // sd_read_from_start(DRAM, 1024); @@ -62,21 +65,22 @@ void bootloader() { * that do not provide such a source must gather their own * entropy. See the Keystone documentation for further * discussion. For testing purposes, we have no entropy generation. - */ + */ // Create a random seed for keys and nonces from TRNG - for (unsigned int i=0; i<32; i++) { + for (unsigned int i = 0; i < 32; i++) { scratchpad[i] = random_byte(i); } - /* On a real device, the platform must provide a secure root device - keystore. For testing purposes we hardcode a known private/public - keypair */ - // TEST Device key - #include "use_test_keys.h" - +/* On a real device, the platform must provide a secure root device + keystore. For testing purposes we hardcode a known private/public + keypair */ +// TEST Device key +#include "use_test_keys.h" + // Derive {SK_D, PK_D} (device keys) from a 32 B random seed - //ed25519_create_keypair(sanctum_dev_public_key, sanctum_dev_secret_key, scratchpad); + // ed25519_create_keypair(sanctum_dev_public_key, sanctum_dev_secret_key, + // scratchpad); // Measure SM sha3_init(&hash_ctx, 64); @@ -86,17 +90,22 @@ void bootloader() { // Combine SK_D and H_SM via a hash // sm_key_seed <-- H(SK_D, H_SM), truncate to 32B sha3_init(&hash_ctx, 64); - sha3_update(&hash_ctx, sanctum_dev_secret_key, sizeof(*sanctum_dev_secret_key)); + sha3_update( + &hash_ctx, sanctum_dev_secret_key, sizeof(*sanctum_dev_secret_key)); sha3_update(&hash_ctx, sanctum_sm_hash, sizeof(*sanctum_sm_hash)); sha3_final(scratchpad, &hash_ctx); - // Derive {SK_D, PK_D} (device keys) from the first 32 B of the hash (NIST endorses SHA512 truncation as safe) - ed25519_create_keypair(sanctum_sm_public_key, sanctum_sm_secret_key, scratchpad); + // Derive {SK_D, PK_D} (device keys) from the first 32 B of the hash (NIST + // endorses SHA512 truncation as safe) + ed25519_create_keypair( + sanctum_sm_public_key, sanctum_sm_secret_key, scratchpad); // Endorse the SM memcpy(scratchpad, sanctum_sm_hash, 64); memcpy(scratchpad + 64, sanctum_sm_public_key, 32); // Sign (H_SM, PK_SM) with SK_D - ed25519_sign(sanctum_sm_signature, scratchpad, 64 + 32, sanctum_dev_public_key, sanctum_dev_secret_key); + ed25519_sign( + sanctum_sm_signature, scratchpad, 64 + 32, sanctum_dev_public_key, + sanctum_dev_secret_key); // Clean up // Erase SK_D diff --git a/bootrom/ed25519/ed25519.h b/bootrom/ed25519/ed25519.h index b5b1560dc..90370d581 100644 --- a/bootrom/ed25519/ed25519.h +++ b/bootrom/ed25519/ed25519.h @@ -4,33 +4,43 @@ #include #if defined(_WIN32) - #if defined(ED25519_BUILD_DLL) - #define ED25519_DECLSPEC __declspec(dllexport) - #elif defined(ED25519_DLL) - #define ED25519_DECLSPEC __declspec(dllimport) - #else - #define ED25519_DECLSPEC - #endif +#if defined(ED25519_BUILD_DLL) +#define ED25519_DECLSPEC __declspec(dllexport) +#elif defined(ED25519_DLL) +#define ED25519_DECLSPEC __declspec(dllimport) #else - #define ED25519_DECLSPEC +#define ED25519_DECLSPEC +#endif +#else +#define ED25519_DECLSPEC #endif - #ifdef __cplusplus extern "C" { #endif #ifndef ED25519_NO_SEED -int ED25519_DECLSPEC ed25519_create_seed(unsigned char *seed); +int ED25519_DECLSPEC +ed25519_create_seed(unsigned char* seed); #endif -void ED25519_DECLSPEC ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed); -void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key); -int ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key); - -//void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar); -//void ED25519_DECLSPEC ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key); - +void ED25519_DECLSPEC +ed25519_create_keypair( + unsigned char* public_key, unsigned char* private_key, + const unsigned char* seed); +void ED25519_DECLSPEC +ed25519_sign( + unsigned char* signature, const unsigned char* message, size_t message_len, + const unsigned char* public_key, const unsigned char* private_key); +int ED25519_DECLSPEC +ed25519_verify( + const unsigned char* signature, const unsigned char* message, + size_t message_len, const unsigned char* public_key); + +// void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned +// char *private_key, const unsigned char *scalar); void ED25519_DECLSPEC +// ed25519_key_exchange(unsigned char *shared_secret, const unsigned char +// *public_key, const unsigned char *private_key); #ifdef __cplusplus } diff --git a/bootrom/ed25519/fe.c b/bootrom/ed25519/fe.c index 2105eb7b2..4a61827bd 100644 --- a/bootrom/ed25519/fe.c +++ b/bootrom/ed25519/fe.c @@ -1,71 +1,69 @@ -#include "fixedint.h" #include "fe.h" +#include "fixedint.h" /* helper functions */ -static uint64_t load_3(const unsigned char *in) { - uint64_t result; +static uint64_t +load_3(const unsigned char* in) { + uint64_t result; - result = (uint64_t) in[0]; - result |= ((uint64_t) in[1]) << 8; - result |= ((uint64_t) in[2]) << 16; + result = (uint64_t)in[0]; + result |= ((uint64_t)in[1]) << 8; + result |= ((uint64_t)in[2]) << 16; - return result; + return result; } -static uint64_t load_4(const unsigned char *in) { - uint64_t result; - - result = (uint64_t) in[0]; - result |= ((uint64_t) in[1]) << 8; - result |= ((uint64_t) in[2]) << 16; - result |= ((uint64_t) in[3]) << 24; - - return result; -} +static uint64_t +load_4(const unsigned char* in) { + uint64_t result; + result = (uint64_t)in[0]; + result |= ((uint64_t)in[1]) << 8; + result |= ((uint64_t)in[2]) << 16; + result |= ((uint64_t)in[3]) << 24; + return result; +} /* h = 0 */ -void fe_0(fe h) { - h[0] = 0; - h[1] = 0; - h[2] = 0; - h[3] = 0; - h[4] = 0; - h[5] = 0; - h[6] = 0; - h[7] = 0; - h[8] = 0; - h[9] = 0; +void +fe_0(fe h) { + h[0] = 0; + h[1] = 0; + h[2] = 0; + h[3] = 0; + h[4] = 0; + h[5] = 0; + h[6] = 0; + h[7] = 0; + h[8] = 0; + h[9] = 0; } - - /* h = 1 */ -void fe_1(fe h) { - h[0] = 1; - h[1] = 0; - h[2] = 0; - h[3] = 0; - h[4] = 0; - h[5] = 0; - h[6] = 0; - h[7] = 0; - h[8] = 0; - h[9] = 0; +void +fe_1(fe h) { + h[0] = 1; + h[1] = 0; + h[2] = 0; + h[3] = 0; + h[4] = 0; + h[5] = 0; + h[6] = 0; + h[7] = 0; + h[8] = 0; + h[9] = 0; } - - /* h = f + g Can overlap h with f or g. @@ -78,52 +76,51 @@ void fe_1(fe h) { |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */ -void fe_add(fe h, const fe f, const fe g) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t g0 = g[0]; - int32_t g1 = g[1]; - int32_t g2 = g[2]; - int32_t g3 = g[3]; - int32_t g4 = g[4]; - int32_t g5 = g[5]; - int32_t g6 = g[6]; - int32_t g7 = g[7]; - int32_t g8 = g[8]; - int32_t g9 = g[9]; - int32_t h0 = f0 + g0; - int32_t h1 = f1 + g1; - int32_t h2 = f2 + g2; - int32_t h3 = f3 + g3; - int32_t h4 = f4 + g4; - int32_t h5 = f5 + g5; - int32_t h6 = f6 + g6; - int32_t h7 = f7 + g7; - int32_t h8 = f8 + g8; - int32_t h9 = f9 + g9; - - h[0] = h0; - h[1] = h1; - h[2] = h2; - h[3] = h3; - h[4] = h4; - h[5] = h5; - h[6] = h6; - h[7] = h7; - h[8] = h8; - h[9] = h9; +void +fe_add(fe h, const fe f, const fe g) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t g0 = g[0]; + int32_t g1 = g[1]; + int32_t g2 = g[2]; + int32_t g3 = g[3]; + int32_t g4 = g[4]; + int32_t g5 = g[5]; + int32_t g6 = g[6]; + int32_t g7 = g[7]; + int32_t g8 = g[8]; + int32_t g9 = g[9]; + int32_t h0 = f0 + g0; + int32_t h1 = f1 + g1; + int32_t h2 = f2 + g2; + int32_t h3 = f3 + g3; + int32_t h4 = f4 + g4; + int32_t h5 = f5 + g5; + int32_t h6 = f6 + g6; + int32_t h7 = f7 + g7; + int32_t h8 = f8 + g8; + int32_t h9 = f9 + g9; + + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; } - - /* Replace (f,g) with (g,g) if b == 1; replace (f,g) with (f,g) if b == 0. @@ -131,60 +128,61 @@ void fe_add(fe h, const fe f, const fe g) { Preconditions: b in {0,1}. */ -void fe_cmov(fe f, const fe g, unsigned int b) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t g0 = g[0]; - int32_t g1 = g[1]; - int32_t g2 = g[2]; - int32_t g3 = g[3]; - int32_t g4 = g[4]; - int32_t g5 = g[5]; - int32_t g6 = g[6]; - int32_t g7 = g[7]; - int32_t g8 = g[8]; - int32_t g9 = g[9]; - int32_t x0 = f0 ^ g0; - int32_t x1 = f1 ^ g1; - int32_t x2 = f2 ^ g2; - int32_t x3 = f3 ^ g3; - int32_t x4 = f4 ^ g4; - int32_t x5 = f5 ^ g5; - int32_t x6 = f6 ^ g6; - int32_t x7 = f7 ^ g7; - int32_t x8 = f8 ^ g8; - int32_t x9 = f9 ^ g9; - - b = (unsigned int) (- (int) b); /* silence warning */ - x0 &= b; - x1 &= b; - x2 &= b; - x3 &= b; - x4 &= b; - x5 &= b; - x6 &= b; - x7 &= b; - x8 &= b; - x9 &= b; - - f[0] = f0 ^ x0; - f[1] = f1 ^ x1; - f[2] = f2 ^ x2; - f[3] = f3 ^ x3; - f[4] = f4 ^ x4; - f[5] = f5 ^ x5; - f[6] = f6 ^ x6; - f[7] = f7 ^ x7; - f[8] = f8 ^ x8; - f[9] = f9 ^ x9; +void +fe_cmov(fe f, const fe g, unsigned int b) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t g0 = g[0]; + int32_t g1 = g[1]; + int32_t g2 = g[2]; + int32_t g3 = g[3]; + int32_t g4 = g[4]; + int32_t g5 = g[5]; + int32_t g6 = g[6]; + int32_t g7 = g[7]; + int32_t g8 = g[8]; + int32_t g9 = g[9]; + int32_t x0 = f0 ^ g0; + int32_t x1 = f1 ^ g1; + int32_t x2 = f2 ^ g2; + int32_t x3 = f3 ^ g3; + int32_t x4 = f4 ^ g4; + int32_t x5 = f5 ^ g5; + int32_t x6 = f6 ^ g6; + int32_t x7 = f7 ^ g7; + int32_t x8 = f8 ^ g8; + int32_t x9 = f9 ^ g9; + + b = (unsigned int)(-(int)b); /* silence warning */ + x0 &= b; + x1 &= b; + x2 &= b; + x3 &= b; + x4 &= b; + x5 &= b; + x6 &= b; + x7 &= b; + x8 &= b; + x9 &= b; + + f[0] = f0 ^ x0; + f[1] = f1 ^ x1; + f[2] = f2 ^ x2; + f[3] = f3 ^ x3; + f[4] = f4 ^ x4; + f[5] = f5 ^ x5; + f[6] = f6 ^ x6; + f[7] = f7 ^ x7; + f[8] = f8 ^ x8; + f[9] = f9 ^ x9; } /* @@ -194,261 +192,257 @@ void fe_cmov(fe f, const fe g, unsigned int b) { Preconditions: b in {0,1}. */ -void fe_cswap(fe f,fe g,unsigned int b) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t g0 = g[0]; - int32_t g1 = g[1]; - int32_t g2 = g[2]; - int32_t g3 = g[3]; - int32_t g4 = g[4]; - int32_t g5 = g[5]; - int32_t g6 = g[6]; - int32_t g7 = g[7]; - int32_t g8 = g[8]; - int32_t g9 = g[9]; - int32_t x0 = f0 ^ g0; - int32_t x1 = f1 ^ g1; - int32_t x2 = f2 ^ g2; - int32_t x3 = f3 ^ g3; - int32_t x4 = f4 ^ g4; - int32_t x5 = f5 ^ g5; - int32_t x6 = f6 ^ g6; - int32_t x7 = f7 ^ g7; - int32_t x8 = f8 ^ g8; - int32_t x9 = f9 ^ g9; - b = (unsigned int) (- (int) b); /* silence warning */ - x0 &= b; - x1 &= b; - x2 &= b; - x3 &= b; - x4 &= b; - x5 &= b; - x6 &= b; - x7 &= b; - x8 &= b; - x9 &= b; - f[0] = f0 ^ x0; - f[1] = f1 ^ x1; - f[2] = f2 ^ x2; - f[3] = f3 ^ x3; - f[4] = f4 ^ x4; - f[5] = f5 ^ x5; - f[6] = f6 ^ x6; - f[7] = f7 ^ x7; - f[8] = f8 ^ x8; - f[9] = f9 ^ x9; - g[0] = g0 ^ x0; - g[1] = g1 ^ x1; - g[2] = g2 ^ x2; - g[3] = g3 ^ x3; - g[4] = g4 ^ x4; - g[5] = g5 ^ x5; - g[6] = g6 ^ x6; - g[7] = g7 ^ x7; - g[8] = g8 ^ x8; - g[9] = g9 ^ x9; +void +fe_cswap(fe f, fe g, unsigned int b) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t g0 = g[0]; + int32_t g1 = g[1]; + int32_t g2 = g[2]; + int32_t g3 = g[3]; + int32_t g4 = g[4]; + int32_t g5 = g[5]; + int32_t g6 = g[6]; + int32_t g7 = g[7]; + int32_t g8 = g[8]; + int32_t g9 = g[9]; + int32_t x0 = f0 ^ g0; + int32_t x1 = f1 ^ g1; + int32_t x2 = f2 ^ g2; + int32_t x3 = f3 ^ g3; + int32_t x4 = f4 ^ g4; + int32_t x5 = f5 ^ g5; + int32_t x6 = f6 ^ g6; + int32_t x7 = f7 ^ g7; + int32_t x8 = f8 ^ g8; + int32_t x9 = f9 ^ g9; + b = (unsigned int)(-(int)b); /* silence warning */ + x0 &= b; + x1 &= b; + x2 &= b; + x3 &= b; + x4 &= b; + x5 &= b; + x6 &= b; + x7 &= b; + x8 &= b; + x9 &= b; + f[0] = f0 ^ x0; + f[1] = f1 ^ x1; + f[2] = f2 ^ x2; + f[3] = f3 ^ x3; + f[4] = f4 ^ x4; + f[5] = f5 ^ x5; + f[6] = f6 ^ x6; + f[7] = f7 ^ x7; + f[8] = f8 ^ x8; + f[9] = f9 ^ x9; + g[0] = g0 ^ x0; + g[1] = g1 ^ x1; + g[2] = g2 ^ x2; + g[3] = g3 ^ x3; + g[4] = g4 ^ x4; + g[5] = g5 ^ x5; + g[6] = g6 ^ x6; + g[7] = g7 ^ x7; + g[8] = g8 ^ x8; + g[9] = g9 ^ x9; } - - /* h = f */ -void fe_copy(fe h, const fe f) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - - h[0] = f0; - h[1] = f1; - h[2] = f2; - h[3] = f3; - h[4] = f4; - h[5] = f5; - h[6] = f6; - h[7] = f7; - h[8] = f8; - h[9] = f9; +void +fe_copy(fe h, const fe f) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + + h[0] = f0; + h[1] = f1; + h[2] = f2; + h[3] = f3; + h[4] = f4; + h[5] = f5; + h[6] = f6; + h[7] = f7; + h[8] = f8; + h[9] = f9; } - - /* Ignores top bit of h. */ -void fe_frombytes(fe h, const unsigned char *s) { - int64_t h0 = load_4(s); - int64_t h1 = load_3(s + 4) << 6; - int64_t h2 = load_3(s + 7) << 5; - int64_t h3 = load_3(s + 10) << 3; - int64_t h4 = load_3(s + 13) << 2; - int64_t h5 = load_4(s + 16); - int64_t h6 = load_3(s + 20) << 7; - int64_t h7 = load_3(s + 23) << 5; - int64_t h8 = load_3(s + 26) << 4; - int64_t h9 = (load_3(s + 29) & 8388607) << 2; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - - carry9 = (h9 + (int64_t) (1 << 24)) >> 25; - h0 += carry9 * 19; - h9 -= carry9 << 25; - carry1 = (h1 + (int64_t) (1 << 24)) >> 25; - h2 += carry1; - h1 -= carry1 << 25; - carry3 = (h3 + (int64_t) (1 << 24)) >> 25; - h4 += carry3; - h3 -= carry3 << 25; - carry5 = (h5 + (int64_t) (1 << 24)) >> 25; - h6 += carry5; - h5 -= carry5 << 25; - carry7 = (h7 + (int64_t) (1 << 24)) >> 25; - h8 += carry7; - h7 -= carry7 << 25; - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - carry2 = (h2 + (int64_t) (1 << 25)) >> 26; - h3 += carry2; - h2 -= carry2 << 26; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry6 = (h6 + (int64_t) (1 << 25)) >> 26; - h7 += carry6; - h6 -= carry6 << 26; - carry8 = (h8 + (int64_t) (1 << 25)) >> 26; - h9 += carry8; - h8 -= carry8 << 26; - - h[0] = (int32_t) h0; - h[1] = (int32_t) h1; - h[2] = (int32_t) h2; - h[3] = (int32_t) h3; - h[4] = (int32_t) h4; - h[5] = (int32_t) h5; - h[6] = (int32_t) h6; - h[7] = (int32_t) h7; - h[8] = (int32_t) h8; - h[9] = (int32_t) h9; +void +fe_frombytes(fe h, const unsigned char* s) { + int64_t h0 = load_4(s); + int64_t h1 = load_3(s + 4) << 6; + int64_t h2 = load_3(s + 7) << 5; + int64_t h3 = load_3(s + 10) << 3; + int64_t h4 = load_3(s + 13) << 2; + int64_t h5 = load_4(s + 16); + int64_t h6 = load_3(s + 20) << 7; + int64_t h7 = load_3(s + 23) << 5; + int64_t h8 = load_3(s + 26) << 4; + int64_t h9 = (load_3(s + 29) & 8388607) << 2; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + + carry9 = (h9 + (int64_t)(1 << 24)) >> 25; + h0 += carry9 * 19; + h9 -= carry9 << 25; + carry1 = (h1 + (int64_t)(1 << 24)) >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry3 = (h3 + (int64_t)(1 << 24)) >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry5 = (h5 + (int64_t)(1 << 24)) >> 25; + h6 += carry5; + h5 -= carry5 << 25; + carry7 = (h7 + (int64_t)(1 << 24)) >> 25; + h8 += carry7; + h7 -= carry7 << 25; + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry2 = (h2 + (int64_t)(1 << 25)) >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry6 = (h6 + (int64_t)(1 << 25)) >> 26; + h7 += carry6; + h6 -= carry6 << 26; + carry8 = (h8 + (int64_t)(1 << 25)) >> 26; + h9 += carry8; + h8 -= carry8 << 26; + + h[0] = (int32_t)h0; + h[1] = (int32_t)h1; + h[2] = (int32_t)h2; + h[3] = (int32_t)h3; + h[4] = (int32_t)h4; + h[5] = (int32_t)h5; + h[6] = (int32_t)h6; + h[7] = (int32_t)h7; + h[8] = (int32_t)h8; + h[9] = (int32_t)h9; } +void +fe_invert(fe out, const fe z) { + fe t0; + fe t1; + fe t2; + fe t3; + int i; + fe_sq(t0, z); -void fe_invert(fe out, const fe z) { - fe t0; - fe t1; - fe t2; - fe t3; - int i; - - fe_sq(t0, z); + for (i = 1; i < 1; ++i) { + fe_sq(t0, t0); + } - for (i = 1; i < 1; ++i) { - fe_sq(t0, t0); - } + fe_sq(t1, t0); - fe_sq(t1, t0); + for (i = 1; i < 2; ++i) { + fe_sq(t1, t1); + } - for (i = 1; i < 2; ++i) { - fe_sq(t1, t1); - } + fe_mul(t1, z, t1); + fe_mul(t0, t0, t1); + fe_sq(t2, t0); - fe_mul(t1, z, t1); - fe_mul(t0, t0, t1); - fe_sq(t2, t0); + for (i = 1; i < 1; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 1; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t1, t2); + fe_sq(t2, t1); - fe_mul(t1, t1, t2); - fe_sq(t2, t1); + for (i = 1; i < 5; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 5; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t2, t1); + fe_sq(t2, t1); - fe_mul(t1, t2, t1); - fe_sq(t2, t1); + for (i = 1; i < 10; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 10; ++i) { - fe_sq(t2, t2); - } + fe_mul(t2, t2, t1); + fe_sq(t3, t2); - fe_mul(t2, t2, t1); - fe_sq(t3, t2); + for (i = 1; i < 20; ++i) { + fe_sq(t3, t3); + } - for (i = 1; i < 20; ++i) { - fe_sq(t3, t3); - } + fe_mul(t2, t3, t2); + fe_sq(t2, t2); - fe_mul(t2, t3, t2); + for (i = 1; i < 10; ++i) { fe_sq(t2, t2); + } - for (i = 1; i < 10; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t2, t1); + fe_sq(t2, t1); - fe_mul(t1, t2, t1); - fe_sq(t2, t1); + for (i = 1; i < 50; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 50; ++i) { - fe_sq(t2, t2); - } + fe_mul(t2, t2, t1); + fe_sq(t3, t2); - fe_mul(t2, t2, t1); - fe_sq(t3, t2); + for (i = 1; i < 100; ++i) { + fe_sq(t3, t3); + } - for (i = 1; i < 100; ++i) { - fe_sq(t3, t3); - } + fe_mul(t2, t3, t2); + fe_sq(t2, t2); - fe_mul(t2, t3, t2); + for (i = 1; i < 50; ++i) { fe_sq(t2, t2); + } - for (i = 1; i < 50; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t2, t1); + fe_sq(t1, t1); - fe_mul(t1, t2, t1); + for (i = 1; i < 5; ++i) { fe_sq(t1, t1); + } - for (i = 1; i < 5; ++i) { - fe_sq(t1, t1); - } - - fe_mul(out, t1, t0); + fe_mul(out, t1, t0); } - - /* return 1 if f is in {1,3,5,...,q-2} return 0 if f is in {0,2,4,...,q-1} @@ -457,15 +451,14 @@ void fe_invert(fe out, const fe z) { |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */ -int fe_isnegative(const fe f) { - unsigned char s[32]; - - fe_tobytes(s, f); - - return s[0] & 1; -} +int +fe_isnegative(const fe f) { + unsigned char s[32]; + fe_tobytes(s, f); + return s[0] & 1; +} /* return 1 if f == 0 @@ -475,52 +468,51 @@ int fe_isnegative(const fe f) { |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */ -int fe_isnonzero(const fe f) { - unsigned char s[32]; - unsigned char r; - - fe_tobytes(s, f); - - r = s[0]; - #define F(i) r |= s[i] - F(1); - F(2); - F(3); - F(4); - F(5); - F(6); - F(7); - F(8); - F(9); - F(10); - F(11); - F(12); - F(13); - F(14); - F(15); - F(16); - F(17); - F(18); - F(19); - F(20); - F(21); - F(22); - F(23); - F(24); - F(25); - F(26); - F(27); - F(28); - F(29); - F(30); - F(31); - #undef F - - return r != 0; +int +fe_isnonzero(const fe f) { + unsigned char s[32]; + unsigned char r; + + fe_tobytes(s, f); + + r = s[0]; +#define F(i) r |= s[i] + F(1); + F(2); + F(3); + F(4); + F(5); + F(6); + F(7); + F(8); + F(9); + F(10); + F(11); + F(12); + F(13); + F(14); + F(15); + F(16); + F(17); + F(18); + F(19); + F(20); + F(21); + F(22); + F(23); + F(24); + F(25); + F(26); + F(27); + F(28); + F(29); + F(30); + F(31); +#undef F + + return r != 0; } - - /* h = f * g Can overlap h with f or g. @@ -533,238 +525,248 @@ int fe_isnonzero(const fe f) { |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc. */ - /* - Notes on implementation strategy: +/* +Notes on implementation strategy: - Using schoolbook multiplication. - Karatsuba would save a little in some cost models. +Using schoolbook multiplication. +Karatsuba would save a little in some cost models. - Most multiplications by 2 and 19 are 32-bit precomputations; - cheaper than 64-bit postcomputations. +Most multiplications by 2 and 19 are 32-bit precomputations; +cheaper than 64-bit postcomputations. - There is one remaining multiplication by 19 in the carry chain; - one *19 precomputation can be merged into this, - but the resulting data flow is considerably less clean. +There is one remaining multiplication by 19 in the carry chain; +one *19 precomputation can be merged into this, +but the resulting data flow is considerably less clean. - There are 12 carries below. - 10 of them are 2-way parallelizable and vectorizable. - Can get away with 11 carries, but then data flow is much deeper. +There are 12 carries below. +10 of them are 2-way parallelizable and vectorizable. +Can get away with 11 carries, but then data flow is much deeper. - With tighter constraints on inputs can squeeze carries into int32. +With tighter constraints on inputs can squeeze carries into int32. */ -void fe_mul(fe h, const fe f, const fe g) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t g0 = g[0]; - int32_t g1 = g[1]; - int32_t g2 = g[2]; - int32_t g3 = g[3]; - int32_t g4 = g[4]; - int32_t g5 = g[5]; - int32_t g6 = g[6]; - int32_t g7 = g[7]; - int32_t g8 = g[8]; - int32_t g9 = g[9]; - int32_t g1_19 = 19 * g1; /* 1.959375*2^29 */ - int32_t g2_19 = 19 * g2; /* 1.959375*2^30; still ok */ - int32_t g3_19 = 19 * g3; - int32_t g4_19 = 19 * g4; - int32_t g5_19 = 19 * g5; - int32_t g6_19 = 19 * g6; - int32_t g7_19 = 19 * g7; - int32_t g8_19 = 19 * g8; - int32_t g9_19 = 19 * g9; - int32_t f1_2 = 2 * f1; - int32_t f3_2 = 2 * f3; - int32_t f5_2 = 2 * f5; - int32_t f7_2 = 2 * f7; - int32_t f9_2 = 2 * f9; - int64_t f0g0 = f0 * (int64_t) g0; - int64_t f0g1 = f0 * (int64_t) g1; - int64_t f0g2 = f0 * (int64_t) g2; - int64_t f0g3 = f0 * (int64_t) g3; - int64_t f0g4 = f0 * (int64_t) g4; - int64_t f0g5 = f0 * (int64_t) g5; - int64_t f0g6 = f0 * (int64_t) g6; - int64_t f0g7 = f0 * (int64_t) g7; - int64_t f0g8 = f0 * (int64_t) g8; - int64_t f0g9 = f0 * (int64_t) g9; - int64_t f1g0 = f1 * (int64_t) g0; - int64_t f1g1_2 = f1_2 * (int64_t) g1; - int64_t f1g2 = f1 * (int64_t) g2; - int64_t f1g3_2 = f1_2 * (int64_t) g3; - int64_t f1g4 = f1 * (int64_t) g4; - int64_t f1g5_2 = f1_2 * (int64_t) g5; - int64_t f1g6 = f1 * (int64_t) g6; - int64_t f1g7_2 = f1_2 * (int64_t) g7; - int64_t f1g8 = f1 * (int64_t) g8; - int64_t f1g9_38 = f1_2 * (int64_t) g9_19; - int64_t f2g0 = f2 * (int64_t) g0; - int64_t f2g1 = f2 * (int64_t) g1; - int64_t f2g2 = f2 * (int64_t) g2; - int64_t f2g3 = f2 * (int64_t) g3; - int64_t f2g4 = f2 * (int64_t) g4; - int64_t f2g5 = f2 * (int64_t) g5; - int64_t f2g6 = f2 * (int64_t) g6; - int64_t f2g7 = f2 * (int64_t) g7; - int64_t f2g8_19 = f2 * (int64_t) g8_19; - int64_t f2g9_19 = f2 * (int64_t) g9_19; - int64_t f3g0 = f3 * (int64_t) g0; - int64_t f3g1_2 = f3_2 * (int64_t) g1; - int64_t f3g2 = f3 * (int64_t) g2; - int64_t f3g3_2 = f3_2 * (int64_t) g3; - int64_t f3g4 = f3 * (int64_t) g4; - int64_t f3g5_2 = f3_2 * (int64_t) g5; - int64_t f3g6 = f3 * (int64_t) g6; - int64_t f3g7_38 = f3_2 * (int64_t) g7_19; - int64_t f3g8_19 = f3 * (int64_t) g8_19; - int64_t f3g9_38 = f3_2 * (int64_t) g9_19; - int64_t f4g0 = f4 * (int64_t) g0; - int64_t f4g1 = f4 * (int64_t) g1; - int64_t f4g2 = f4 * (int64_t) g2; - int64_t f4g3 = f4 * (int64_t) g3; - int64_t f4g4 = f4 * (int64_t) g4; - int64_t f4g5 = f4 * (int64_t) g5; - int64_t f4g6_19 = f4 * (int64_t) g6_19; - int64_t f4g7_19 = f4 * (int64_t) g7_19; - int64_t f4g8_19 = f4 * (int64_t) g8_19; - int64_t f4g9_19 = f4 * (int64_t) g9_19; - int64_t f5g0 = f5 * (int64_t) g0; - int64_t f5g1_2 = f5_2 * (int64_t) g1; - int64_t f5g2 = f5 * (int64_t) g2; - int64_t f5g3_2 = f5_2 * (int64_t) g3; - int64_t f5g4 = f5 * (int64_t) g4; - int64_t f5g5_38 = f5_2 * (int64_t) g5_19; - int64_t f5g6_19 = f5 * (int64_t) g6_19; - int64_t f5g7_38 = f5_2 * (int64_t) g7_19; - int64_t f5g8_19 = f5 * (int64_t) g8_19; - int64_t f5g9_38 = f5_2 * (int64_t) g9_19; - int64_t f6g0 = f6 * (int64_t) g0; - int64_t f6g1 = f6 * (int64_t) g1; - int64_t f6g2 = f6 * (int64_t) g2; - int64_t f6g3 = f6 * (int64_t) g3; - int64_t f6g4_19 = f6 * (int64_t) g4_19; - int64_t f6g5_19 = f6 * (int64_t) g5_19; - int64_t f6g6_19 = f6 * (int64_t) g6_19; - int64_t f6g7_19 = f6 * (int64_t) g7_19; - int64_t f6g8_19 = f6 * (int64_t) g8_19; - int64_t f6g9_19 = f6 * (int64_t) g9_19; - int64_t f7g0 = f7 * (int64_t) g0; - int64_t f7g1_2 = f7_2 * (int64_t) g1; - int64_t f7g2 = f7 * (int64_t) g2; - int64_t f7g3_38 = f7_2 * (int64_t) g3_19; - int64_t f7g4_19 = f7 * (int64_t) g4_19; - int64_t f7g5_38 = f7_2 * (int64_t) g5_19; - int64_t f7g6_19 = f7 * (int64_t) g6_19; - int64_t f7g7_38 = f7_2 * (int64_t) g7_19; - int64_t f7g8_19 = f7 * (int64_t) g8_19; - int64_t f7g9_38 = f7_2 * (int64_t) g9_19; - int64_t f8g0 = f8 * (int64_t) g0; - int64_t f8g1 = f8 * (int64_t) g1; - int64_t f8g2_19 = f8 * (int64_t) g2_19; - int64_t f8g3_19 = f8 * (int64_t) g3_19; - int64_t f8g4_19 = f8 * (int64_t) g4_19; - int64_t f8g5_19 = f8 * (int64_t) g5_19; - int64_t f8g6_19 = f8 * (int64_t) g6_19; - int64_t f8g7_19 = f8 * (int64_t) g7_19; - int64_t f8g8_19 = f8 * (int64_t) g8_19; - int64_t f8g9_19 = f8 * (int64_t) g9_19; - int64_t f9g0 = f9 * (int64_t) g0; - int64_t f9g1_38 = f9_2 * (int64_t) g1_19; - int64_t f9g2_19 = f9 * (int64_t) g2_19; - int64_t f9g3_38 = f9_2 * (int64_t) g3_19; - int64_t f9g4_19 = f9 * (int64_t) g4_19; - int64_t f9g5_38 = f9_2 * (int64_t) g5_19; - int64_t f9g6_19 = f9 * (int64_t) g6_19; - int64_t f9g7_38 = f9_2 * (int64_t) g7_19; - int64_t f9g8_19 = f9 * (int64_t) g8_19; - int64_t f9g9_38 = f9_2 * (int64_t) g9_19; - int64_t h0 = f0g0 + f1g9_38 + f2g8_19 + f3g7_38 + f4g6_19 + f5g5_38 + f6g4_19 + f7g3_38 + f8g2_19 + f9g1_38; - int64_t h1 = f0g1 + f1g0 + f2g9_19 + f3g8_19 + f4g7_19 + f5g6_19 + f6g5_19 + f7g4_19 + f8g3_19 + f9g2_19; - int64_t h2 = f0g2 + f1g1_2 + f2g0 + f3g9_38 + f4g8_19 + f5g7_38 + f6g6_19 + f7g5_38 + f8g4_19 + f9g3_38; - int64_t h3 = f0g3 + f1g2 + f2g1 + f3g0 + f4g9_19 + f5g8_19 + f6g7_19 + f7g6_19 + f8g5_19 + f9g4_19; - int64_t h4 = f0g4 + f1g3_2 + f2g2 + f3g1_2 + f4g0 + f5g9_38 + f6g8_19 + f7g7_38 + f8g6_19 + f9g5_38; - int64_t h5 = f0g5 + f1g4 + f2g3 + f3g2 + f4g1 + f5g0 + f6g9_19 + f7g8_19 + f8g7_19 + f9g6_19; - int64_t h6 = f0g6 + f1g5_2 + f2g4 + f3g3_2 + f4g2 + f5g1_2 + f6g0 + f7g9_38 + f8g8_19 + f9g7_38; - int64_t h7 = f0g7 + f1g6 + f2g5 + f3g4 + f4g3 + f5g2 + f6g1 + f7g0 + f8g9_19 + f9g8_19; - int64_t h8 = f0g8 + f1g7_2 + f2g6 + f3g5_2 + f4g4 + f5g3_2 + f6g2 + f7g1_2 + f8g0 + f9g9_38; - int64_t h9 = f0g9 + f1g8 + f2g7 + f3g6 + f4g5 + f5g4 + f6g3 + f7g2 + f8g1 + f9g0 ; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - - carry1 = (h1 + (int64_t) (1 << 24)) >> 25; - h2 += carry1; - h1 -= carry1 << 25; - carry5 = (h5 + (int64_t) (1 << 24)) >> 25; - h6 += carry5; - h5 -= carry5 << 25; - - carry2 = (h2 + (int64_t) (1 << 25)) >> 26; - h3 += carry2; - h2 -= carry2 << 26; - carry6 = (h6 + (int64_t) (1 << 25)) >> 26; - h7 += carry6; - h6 -= carry6 << 26; - - carry3 = (h3 + (int64_t) (1 << 24)) >> 25; - h4 += carry3; - h3 -= carry3 << 25; - carry7 = (h7 + (int64_t) (1 << 24)) >> 25; - h8 += carry7; - h7 -= carry7 << 25; - - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry8 = (h8 + (int64_t) (1 << 25)) >> 26; - h9 += carry8; - h8 -= carry8 << 26; - - carry9 = (h9 + (int64_t) (1 << 24)) >> 25; - h0 += carry9 * 19; - h9 -= carry9 << 25; - - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - - h[0] = (int32_t) h0; - h[1] = (int32_t) h1; - h[2] = (int32_t) h2; - h[3] = (int32_t) h3; - h[4] = (int32_t) h4; - h[5] = (int32_t) h5; - h[6] = (int32_t) h6; - h[7] = (int32_t) h7; - h[8] = (int32_t) h8; - h[9] = (int32_t) h9; +void +fe_mul(fe h, const fe f, const fe g) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t g0 = g[0]; + int32_t g1 = g[1]; + int32_t g2 = g[2]; + int32_t g3 = g[3]; + int32_t g4 = g[4]; + int32_t g5 = g[5]; + int32_t g6 = g[6]; + int32_t g7 = g[7]; + int32_t g8 = g[8]; + int32_t g9 = g[9]; + int32_t g1_19 = 19 * g1; /* 1.959375*2^29 */ + int32_t g2_19 = 19 * g2; /* 1.959375*2^30; still ok */ + int32_t g3_19 = 19 * g3; + int32_t g4_19 = 19 * g4; + int32_t g5_19 = 19 * g5; + int32_t g6_19 = 19 * g6; + int32_t g7_19 = 19 * g7; + int32_t g8_19 = 19 * g8; + int32_t g9_19 = 19 * g9; + int32_t f1_2 = 2 * f1; + int32_t f3_2 = 2 * f3; + int32_t f5_2 = 2 * f5; + int32_t f7_2 = 2 * f7; + int32_t f9_2 = 2 * f9; + int64_t f0g0 = f0 * (int64_t)g0; + int64_t f0g1 = f0 * (int64_t)g1; + int64_t f0g2 = f0 * (int64_t)g2; + int64_t f0g3 = f0 * (int64_t)g3; + int64_t f0g4 = f0 * (int64_t)g4; + int64_t f0g5 = f0 * (int64_t)g5; + int64_t f0g6 = f0 * (int64_t)g6; + int64_t f0g7 = f0 * (int64_t)g7; + int64_t f0g8 = f0 * (int64_t)g8; + int64_t f0g9 = f0 * (int64_t)g9; + int64_t f1g0 = f1 * (int64_t)g0; + int64_t f1g1_2 = f1_2 * (int64_t)g1; + int64_t f1g2 = f1 * (int64_t)g2; + int64_t f1g3_2 = f1_2 * (int64_t)g3; + int64_t f1g4 = f1 * (int64_t)g4; + int64_t f1g5_2 = f1_2 * (int64_t)g5; + int64_t f1g6 = f1 * (int64_t)g6; + int64_t f1g7_2 = f1_2 * (int64_t)g7; + int64_t f1g8 = f1 * (int64_t)g8; + int64_t f1g9_38 = f1_2 * (int64_t)g9_19; + int64_t f2g0 = f2 * (int64_t)g0; + int64_t f2g1 = f2 * (int64_t)g1; + int64_t f2g2 = f2 * (int64_t)g2; + int64_t f2g3 = f2 * (int64_t)g3; + int64_t f2g4 = f2 * (int64_t)g4; + int64_t f2g5 = f2 * (int64_t)g5; + int64_t f2g6 = f2 * (int64_t)g6; + int64_t f2g7 = f2 * (int64_t)g7; + int64_t f2g8_19 = f2 * (int64_t)g8_19; + int64_t f2g9_19 = f2 * (int64_t)g9_19; + int64_t f3g0 = f3 * (int64_t)g0; + int64_t f3g1_2 = f3_2 * (int64_t)g1; + int64_t f3g2 = f3 * (int64_t)g2; + int64_t f3g3_2 = f3_2 * (int64_t)g3; + int64_t f3g4 = f3 * (int64_t)g4; + int64_t f3g5_2 = f3_2 * (int64_t)g5; + int64_t f3g6 = f3 * (int64_t)g6; + int64_t f3g7_38 = f3_2 * (int64_t)g7_19; + int64_t f3g8_19 = f3 * (int64_t)g8_19; + int64_t f3g9_38 = f3_2 * (int64_t)g9_19; + int64_t f4g0 = f4 * (int64_t)g0; + int64_t f4g1 = f4 * (int64_t)g1; + int64_t f4g2 = f4 * (int64_t)g2; + int64_t f4g3 = f4 * (int64_t)g3; + int64_t f4g4 = f4 * (int64_t)g4; + int64_t f4g5 = f4 * (int64_t)g5; + int64_t f4g6_19 = f4 * (int64_t)g6_19; + int64_t f4g7_19 = f4 * (int64_t)g7_19; + int64_t f4g8_19 = f4 * (int64_t)g8_19; + int64_t f4g9_19 = f4 * (int64_t)g9_19; + int64_t f5g0 = f5 * (int64_t)g0; + int64_t f5g1_2 = f5_2 * (int64_t)g1; + int64_t f5g2 = f5 * (int64_t)g2; + int64_t f5g3_2 = f5_2 * (int64_t)g3; + int64_t f5g4 = f5 * (int64_t)g4; + int64_t f5g5_38 = f5_2 * (int64_t)g5_19; + int64_t f5g6_19 = f5 * (int64_t)g6_19; + int64_t f5g7_38 = f5_2 * (int64_t)g7_19; + int64_t f5g8_19 = f5 * (int64_t)g8_19; + int64_t f5g9_38 = f5_2 * (int64_t)g9_19; + int64_t f6g0 = f6 * (int64_t)g0; + int64_t f6g1 = f6 * (int64_t)g1; + int64_t f6g2 = f6 * (int64_t)g2; + int64_t f6g3 = f6 * (int64_t)g3; + int64_t f6g4_19 = f6 * (int64_t)g4_19; + int64_t f6g5_19 = f6 * (int64_t)g5_19; + int64_t f6g6_19 = f6 * (int64_t)g6_19; + int64_t f6g7_19 = f6 * (int64_t)g7_19; + int64_t f6g8_19 = f6 * (int64_t)g8_19; + int64_t f6g9_19 = f6 * (int64_t)g9_19; + int64_t f7g0 = f7 * (int64_t)g0; + int64_t f7g1_2 = f7_2 * (int64_t)g1; + int64_t f7g2 = f7 * (int64_t)g2; + int64_t f7g3_38 = f7_2 * (int64_t)g3_19; + int64_t f7g4_19 = f7 * (int64_t)g4_19; + int64_t f7g5_38 = f7_2 * (int64_t)g5_19; + int64_t f7g6_19 = f7 * (int64_t)g6_19; + int64_t f7g7_38 = f7_2 * (int64_t)g7_19; + int64_t f7g8_19 = f7 * (int64_t)g8_19; + int64_t f7g9_38 = f7_2 * (int64_t)g9_19; + int64_t f8g0 = f8 * (int64_t)g0; + int64_t f8g1 = f8 * (int64_t)g1; + int64_t f8g2_19 = f8 * (int64_t)g2_19; + int64_t f8g3_19 = f8 * (int64_t)g3_19; + int64_t f8g4_19 = f8 * (int64_t)g4_19; + int64_t f8g5_19 = f8 * (int64_t)g5_19; + int64_t f8g6_19 = f8 * (int64_t)g6_19; + int64_t f8g7_19 = f8 * (int64_t)g7_19; + int64_t f8g8_19 = f8 * (int64_t)g8_19; + int64_t f8g9_19 = f8 * (int64_t)g9_19; + int64_t f9g0 = f9 * (int64_t)g0; + int64_t f9g1_38 = f9_2 * (int64_t)g1_19; + int64_t f9g2_19 = f9 * (int64_t)g2_19; + int64_t f9g3_38 = f9_2 * (int64_t)g3_19; + int64_t f9g4_19 = f9 * (int64_t)g4_19; + int64_t f9g5_38 = f9_2 * (int64_t)g5_19; + int64_t f9g6_19 = f9 * (int64_t)g6_19; + int64_t f9g7_38 = f9_2 * (int64_t)g7_19; + int64_t f9g8_19 = f9 * (int64_t)g8_19; + int64_t f9g9_38 = f9_2 * (int64_t)g9_19; + int64_t h0 = f0g0 + f1g9_38 + f2g8_19 + f3g7_38 + f4g6_19 + f5g5_38 + + f6g4_19 + f7g3_38 + f8g2_19 + f9g1_38; + int64_t h1 = f0g1 + f1g0 + f2g9_19 + f3g8_19 + f4g7_19 + f5g6_19 + f6g5_19 + + f7g4_19 + f8g3_19 + f9g2_19; + int64_t h2 = f0g2 + f1g1_2 + f2g0 + f3g9_38 + f4g8_19 + f5g7_38 + f6g6_19 + + f7g5_38 + f8g4_19 + f9g3_38; + int64_t h3 = f0g3 + f1g2 + f2g1 + f3g0 + f4g9_19 + f5g8_19 + f6g7_19 + + f7g6_19 + f8g5_19 + f9g4_19; + int64_t h4 = f0g4 + f1g3_2 + f2g2 + f3g1_2 + f4g0 + f5g9_38 + f6g8_19 + + f7g7_38 + f8g6_19 + f9g5_38; + int64_t h5 = f0g5 + f1g4 + f2g3 + f3g2 + f4g1 + f5g0 + f6g9_19 + f7g8_19 + + f8g7_19 + f9g6_19; + int64_t h6 = f0g6 + f1g5_2 + f2g4 + f3g3_2 + f4g2 + f5g1_2 + f6g0 + f7g9_38 + + f8g8_19 + f9g7_38; + int64_t h7 = + f0g7 + f1g6 + f2g5 + f3g4 + f4g3 + f5g2 + f6g1 + f7g0 + f8g9_19 + f9g8_19; + int64_t h8 = f0g8 + f1g7_2 + f2g6 + f3g5_2 + f4g4 + f5g3_2 + f6g2 + f7g1_2 + + f8g0 + f9g9_38; + int64_t h9 = + f0g9 + f1g8 + f2g7 + f3g6 + f4g5 + f5g4 + f6g3 + f7g2 + f8g1 + f9g0; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + + carry1 = (h1 + (int64_t)(1 << 24)) >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry5 = (h5 + (int64_t)(1 << 24)) >> 25; + h6 += carry5; + h5 -= carry5 << 25; + + carry2 = (h2 + (int64_t)(1 << 25)) >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry6 = (h6 + (int64_t)(1 << 25)) >> 26; + h7 += carry6; + h6 -= carry6 << 26; + + carry3 = (h3 + (int64_t)(1 << 24)) >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry7 = (h7 + (int64_t)(1 << 24)) >> 25; + h8 += carry7; + h7 -= carry7 << 25; + + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry8 = (h8 + (int64_t)(1 << 25)) >> 26; + h9 += carry8; + h8 -= carry8 << 26; + + carry9 = (h9 + (int64_t)(1 << 24)) >> 25; + h0 += carry9 * 19; + h9 -= carry9 << 25; + + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + + h[0] = (int32_t)h0; + h[1] = (int32_t)h1; + h[2] = (int32_t)h2; + h[3] = (int32_t)h3; + h[4] = (int32_t)h4; + h[5] = (int32_t)h5; + h[6] = (int32_t)h6; + h[7] = (int32_t)h7; + h[8] = (int32_t)h8; + h[9] = (int32_t)h9; } - /* h = f * 121666 Can overlap h with f. @@ -776,63 +778,83 @@ Can overlap h with f. |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. */ -void fe_mul121666(fe h, fe f) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int64_t h0 = f0 * (int64_t) 121666; - int64_t h1 = f1 * (int64_t) 121666; - int64_t h2 = f2 * (int64_t) 121666; - int64_t h3 = f3 * (int64_t) 121666; - int64_t h4 = f4 * (int64_t) 121666; - int64_t h5 = f5 * (int64_t) 121666; - int64_t h6 = f6 * (int64_t) 121666; - int64_t h7 = f7 * (int64_t) 121666; - int64_t h8 = f8 * (int64_t) 121666; - int64_t h9 = f9 * (int64_t) 121666; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - - carry9 = (h9 + (int64_t) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; - carry1 = (h1 + (int64_t) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25; - carry3 = (h3 + (int64_t) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25; - carry5 = (h5 + (int64_t) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25; - carry7 = (h7 + (int64_t) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25; - - carry0 = (h0 + (int64_t) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; - carry2 = (h2 + (int64_t) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26; - carry4 = (h4 + (int64_t) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; - carry6 = (h6 + (int64_t) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26; - carry8 = (h8 + (int64_t) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26; - - h[0] = (int32_t) h0; - h[1] = (int32_t) h1; - h[2] = (int32_t) h2; - h[3] = (int32_t) h3; - h[4] = (int32_t) h4; - h[5] = (int32_t) h5; - h[6] = (int32_t) h6; - h[7] = (int32_t) h7; - h[8] = (int32_t) h8; - h[9] = (int32_t) h9; +void +fe_mul121666(fe h, fe f) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int64_t h0 = f0 * (int64_t)121666; + int64_t h1 = f1 * (int64_t)121666; + int64_t h2 = f2 * (int64_t)121666; + int64_t h3 = f3 * (int64_t)121666; + int64_t h4 = f4 * (int64_t)121666; + int64_t h5 = f5 * (int64_t)121666; + int64_t h6 = f6 * (int64_t)121666; + int64_t h7 = f7 * (int64_t)121666; + int64_t h8 = f8 * (int64_t)121666; + int64_t h9 = f9 * (int64_t)121666; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + + carry9 = (h9 + (int64_t)(1 << 24)) >> 25; + h0 += carry9 * 19; + h9 -= carry9 << 25; + carry1 = (h1 + (int64_t)(1 << 24)) >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry3 = (h3 + (int64_t)(1 << 24)) >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry5 = (h5 + (int64_t)(1 << 24)) >> 25; + h6 += carry5; + h5 -= carry5 << 25; + carry7 = (h7 + (int64_t)(1 << 24)) >> 25; + h8 += carry7; + h7 -= carry7 << 25; + + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry2 = (h2 + (int64_t)(1 << 25)) >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry6 = (h6 + (int64_t)(1 << 25)) >> 26; + h7 += carry6; + h6 -= carry6 << 26; + carry8 = (h8 + (int64_t)(1 << 25)) >> 26; + h9 += carry8; + h8 -= carry8 << 26; + + h[0] = (int32_t)h0; + h[1] = (int32_t)h1; + h[2] = (int32_t)h2; + h[3] = (int32_t)h3; + h[4] = (int32_t)h4; + h[5] = (int32_t)h5; + h[6] = (int32_t)h6; + h[7] = (int32_t)h7; + h[8] = (int32_t)h8; + h[9] = (int32_t)h9; } - /* h = -f @@ -843,127 +865,127 @@ h = -f |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. */ -void fe_neg(fe h, const fe f) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t h0 = -f0; - int32_t h1 = -f1; - int32_t h2 = -f2; - int32_t h3 = -f3; - int32_t h4 = -f4; - int32_t h5 = -f5; - int32_t h6 = -f6; - int32_t h7 = -f7; - int32_t h8 = -f8; - int32_t h9 = -f9; - - h[0] = h0; - h[1] = h1; - h[2] = h2; - h[3] = h3; - h[4] = h4; - h[5] = h5; - h[6] = h6; - h[7] = h7; - h[8] = h8; - h[9] = h9; +void +fe_neg(fe h, const fe f) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t h0 = -f0; + int32_t h1 = -f1; + int32_t h2 = -f2; + int32_t h3 = -f3; + int32_t h4 = -f4; + int32_t h5 = -f5; + int32_t h6 = -f6; + int32_t h7 = -f7; + int32_t h8 = -f8; + int32_t h9 = -f9; + + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; } +void +fe_pow22523(fe out, const fe z) { + fe t0; + fe t1; + fe t2; + int i; + fe_sq(t0, z); -void fe_pow22523(fe out, const fe z) { - fe t0; - fe t1; - fe t2; - int i; - fe_sq(t0, z); + for (i = 1; i < 1; ++i) { + fe_sq(t0, t0); + } - for (i = 1; i < 1; ++i) { - fe_sq(t0, t0); - } + fe_sq(t1, t0); - fe_sq(t1, t0); + for (i = 1; i < 2; ++i) { + fe_sq(t1, t1); + } - for (i = 1; i < 2; ++i) { - fe_sq(t1, t1); - } + fe_mul(t1, z, t1); + fe_mul(t0, t0, t1); + fe_sq(t0, t0); - fe_mul(t1, z, t1); - fe_mul(t0, t0, t1); + for (i = 1; i < 1; ++i) { fe_sq(t0, t0); + } - for (i = 1; i < 1; ++i) { - fe_sq(t0, t0); - } + fe_mul(t0, t1, t0); + fe_sq(t1, t0); - fe_mul(t0, t1, t0); - fe_sq(t1, t0); + for (i = 1; i < 5; ++i) { + fe_sq(t1, t1); + } - for (i = 1; i < 5; ++i) { - fe_sq(t1, t1); - } + fe_mul(t0, t1, t0); + fe_sq(t1, t0); - fe_mul(t0, t1, t0); - fe_sq(t1, t0); + for (i = 1; i < 10; ++i) { + fe_sq(t1, t1); + } - for (i = 1; i < 10; ++i) { - fe_sq(t1, t1); - } + fe_mul(t1, t1, t0); + fe_sq(t2, t1); - fe_mul(t1, t1, t0); - fe_sq(t2, t1); + for (i = 1; i < 20; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 20; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t2, t1); + fe_sq(t1, t1); - fe_mul(t1, t2, t1); + for (i = 1; i < 10; ++i) { fe_sq(t1, t1); + } - for (i = 1; i < 10; ++i) { - fe_sq(t1, t1); - } + fe_mul(t0, t1, t0); + fe_sq(t1, t0); - fe_mul(t0, t1, t0); - fe_sq(t1, t0); + for (i = 1; i < 50; ++i) { + fe_sq(t1, t1); + } - for (i = 1; i < 50; ++i) { - fe_sq(t1, t1); - } + fe_mul(t1, t1, t0); + fe_sq(t2, t1); - fe_mul(t1, t1, t0); - fe_sq(t2, t1); + for (i = 1; i < 100; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 100; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t2, t1); + fe_sq(t1, t1); - fe_mul(t1, t2, t1); + for (i = 1; i < 50; ++i) { fe_sq(t1, t1); + } - for (i = 1; i < 50; ++i) { - fe_sq(t1, t1); - } + fe_mul(t0, t1, t0); + fe_sq(t0, t0); - fe_mul(t0, t1, t0); + for (i = 1; i < 2; ++i) { fe_sq(t0, t0); + } - for (i = 1; i < 2; ++i) { - fe_sq(t0, t0); - } - - fe_mul(out, t0, z); - return; + fe_mul(out, t0, z); + return; } - /* h = f * f Can overlap h with f. @@ -979,154 +1001,154 @@ Can overlap h with f. See fe_mul.c for discussion of implementation strategy. */ -void fe_sq(fe h, const fe f) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t f0_2 = 2 * f0; - int32_t f1_2 = 2 * f1; - int32_t f2_2 = 2 * f2; - int32_t f3_2 = 2 * f3; - int32_t f4_2 = 2 * f4; - int32_t f5_2 = 2 * f5; - int32_t f6_2 = 2 * f6; - int32_t f7_2 = 2 * f7; - int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */ - int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */ - int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */ - int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */ - int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */ - int64_t f0f0 = f0 * (int64_t) f0; - int64_t f0f1_2 = f0_2 * (int64_t) f1; - int64_t f0f2_2 = f0_2 * (int64_t) f2; - int64_t f0f3_2 = f0_2 * (int64_t) f3; - int64_t f0f4_2 = f0_2 * (int64_t) f4; - int64_t f0f5_2 = f0_2 * (int64_t) f5; - int64_t f0f6_2 = f0_2 * (int64_t) f6; - int64_t f0f7_2 = f0_2 * (int64_t) f7; - int64_t f0f8_2 = f0_2 * (int64_t) f8; - int64_t f0f9_2 = f0_2 * (int64_t) f9; - int64_t f1f1_2 = f1_2 * (int64_t) f1; - int64_t f1f2_2 = f1_2 * (int64_t) f2; - int64_t f1f3_4 = f1_2 * (int64_t) f3_2; - int64_t f1f4_2 = f1_2 * (int64_t) f4; - int64_t f1f5_4 = f1_2 * (int64_t) f5_2; - int64_t f1f6_2 = f1_2 * (int64_t) f6; - int64_t f1f7_4 = f1_2 * (int64_t) f7_2; - int64_t f1f8_2 = f1_2 * (int64_t) f8; - int64_t f1f9_76 = f1_2 * (int64_t) f9_38; - int64_t f2f2 = f2 * (int64_t) f2; - int64_t f2f3_2 = f2_2 * (int64_t) f3; - int64_t f2f4_2 = f2_2 * (int64_t) f4; - int64_t f2f5_2 = f2_2 * (int64_t) f5; - int64_t f2f6_2 = f2_2 * (int64_t) f6; - int64_t f2f7_2 = f2_2 * (int64_t) f7; - int64_t f2f8_38 = f2_2 * (int64_t) f8_19; - int64_t f2f9_38 = f2 * (int64_t) f9_38; - int64_t f3f3_2 = f3_2 * (int64_t) f3; - int64_t f3f4_2 = f3_2 * (int64_t) f4; - int64_t f3f5_4 = f3_2 * (int64_t) f5_2; - int64_t f3f6_2 = f3_2 * (int64_t) f6; - int64_t f3f7_76 = f3_2 * (int64_t) f7_38; - int64_t f3f8_38 = f3_2 * (int64_t) f8_19; - int64_t f3f9_76 = f3_2 * (int64_t) f9_38; - int64_t f4f4 = f4 * (int64_t) f4; - int64_t f4f5_2 = f4_2 * (int64_t) f5; - int64_t f4f6_38 = f4_2 * (int64_t) f6_19; - int64_t f4f7_38 = f4 * (int64_t) f7_38; - int64_t f4f8_38 = f4_2 * (int64_t) f8_19; - int64_t f4f9_38 = f4 * (int64_t) f9_38; - int64_t f5f5_38 = f5 * (int64_t) f5_38; - int64_t f5f6_38 = f5_2 * (int64_t) f6_19; - int64_t f5f7_76 = f5_2 * (int64_t) f7_38; - int64_t f5f8_38 = f5_2 * (int64_t) f8_19; - int64_t f5f9_76 = f5_2 * (int64_t) f9_38; - int64_t f6f6_19 = f6 * (int64_t) f6_19; - int64_t f6f7_38 = f6 * (int64_t) f7_38; - int64_t f6f8_38 = f6_2 * (int64_t) f8_19; - int64_t f6f9_38 = f6 * (int64_t) f9_38; - int64_t f7f7_38 = f7 * (int64_t) f7_38; - int64_t f7f8_38 = f7_2 * (int64_t) f8_19; - int64_t f7f9_76 = f7_2 * (int64_t) f9_38; - int64_t f8f8_19 = f8 * (int64_t) f8_19; - int64_t f8f9_38 = f8 * (int64_t) f9_38; - int64_t f9f9_38 = f9 * (int64_t) f9_38; - int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38; - int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38; - int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19; - int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38; - int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38; - int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38; - int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19; - int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38; - int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38; - int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry1 = (h1 + (int64_t) (1 << 24)) >> 25; - h2 += carry1; - h1 -= carry1 << 25; - carry5 = (h5 + (int64_t) (1 << 24)) >> 25; - h6 += carry5; - h5 -= carry5 << 25; - carry2 = (h2 + (int64_t) (1 << 25)) >> 26; - h3 += carry2; - h2 -= carry2 << 26; - carry6 = (h6 + (int64_t) (1 << 25)) >> 26; - h7 += carry6; - h6 -= carry6 << 26; - carry3 = (h3 + (int64_t) (1 << 24)) >> 25; - h4 += carry3; - h3 -= carry3 << 25; - carry7 = (h7 + (int64_t) (1 << 24)) >> 25; - h8 += carry7; - h7 -= carry7 << 25; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry8 = (h8 + (int64_t) (1 << 25)) >> 26; - h9 += carry8; - h8 -= carry8 << 26; - carry9 = (h9 + (int64_t) (1 << 24)) >> 25; - h0 += carry9 * 19; - h9 -= carry9 << 25; - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - h[0] = (int32_t) h0; - h[1] = (int32_t) h1; - h[2] = (int32_t) h2; - h[3] = (int32_t) h3; - h[4] = (int32_t) h4; - h[5] = (int32_t) h5; - h[6] = (int32_t) h6; - h[7] = (int32_t) h7; - h[8] = (int32_t) h8; - h[9] = (int32_t) h9; +void +fe_sq(fe h, const fe f) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t f0_2 = 2 * f0; + int32_t f1_2 = 2 * f1; + int32_t f2_2 = 2 * f2; + int32_t f3_2 = 2 * f3; + int32_t f4_2 = 2 * f4; + int32_t f5_2 = 2 * f5; + int32_t f6_2 = 2 * f6; + int32_t f7_2 = 2 * f7; + int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */ + int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */ + int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */ + int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */ + int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */ + int64_t f0f0 = f0 * (int64_t)f0; + int64_t f0f1_2 = f0_2 * (int64_t)f1; + int64_t f0f2_2 = f0_2 * (int64_t)f2; + int64_t f0f3_2 = f0_2 * (int64_t)f3; + int64_t f0f4_2 = f0_2 * (int64_t)f4; + int64_t f0f5_2 = f0_2 * (int64_t)f5; + int64_t f0f6_2 = f0_2 * (int64_t)f6; + int64_t f0f7_2 = f0_2 * (int64_t)f7; + int64_t f0f8_2 = f0_2 * (int64_t)f8; + int64_t f0f9_2 = f0_2 * (int64_t)f9; + int64_t f1f1_2 = f1_2 * (int64_t)f1; + int64_t f1f2_2 = f1_2 * (int64_t)f2; + int64_t f1f3_4 = f1_2 * (int64_t)f3_2; + int64_t f1f4_2 = f1_2 * (int64_t)f4; + int64_t f1f5_4 = f1_2 * (int64_t)f5_2; + int64_t f1f6_2 = f1_2 * (int64_t)f6; + int64_t f1f7_4 = f1_2 * (int64_t)f7_2; + int64_t f1f8_2 = f1_2 * (int64_t)f8; + int64_t f1f9_76 = f1_2 * (int64_t)f9_38; + int64_t f2f2 = f2 * (int64_t)f2; + int64_t f2f3_2 = f2_2 * (int64_t)f3; + int64_t f2f4_2 = f2_2 * (int64_t)f4; + int64_t f2f5_2 = f2_2 * (int64_t)f5; + int64_t f2f6_2 = f2_2 * (int64_t)f6; + int64_t f2f7_2 = f2_2 * (int64_t)f7; + int64_t f2f8_38 = f2_2 * (int64_t)f8_19; + int64_t f2f9_38 = f2 * (int64_t)f9_38; + int64_t f3f3_2 = f3_2 * (int64_t)f3; + int64_t f3f4_2 = f3_2 * (int64_t)f4; + int64_t f3f5_4 = f3_2 * (int64_t)f5_2; + int64_t f3f6_2 = f3_2 * (int64_t)f6; + int64_t f3f7_76 = f3_2 * (int64_t)f7_38; + int64_t f3f8_38 = f3_2 * (int64_t)f8_19; + int64_t f3f9_76 = f3_2 * (int64_t)f9_38; + int64_t f4f4 = f4 * (int64_t)f4; + int64_t f4f5_2 = f4_2 * (int64_t)f5; + int64_t f4f6_38 = f4_2 * (int64_t)f6_19; + int64_t f4f7_38 = f4 * (int64_t)f7_38; + int64_t f4f8_38 = f4_2 * (int64_t)f8_19; + int64_t f4f9_38 = f4 * (int64_t)f9_38; + int64_t f5f5_38 = f5 * (int64_t)f5_38; + int64_t f5f6_38 = f5_2 * (int64_t)f6_19; + int64_t f5f7_76 = f5_2 * (int64_t)f7_38; + int64_t f5f8_38 = f5_2 * (int64_t)f8_19; + int64_t f5f9_76 = f5_2 * (int64_t)f9_38; + int64_t f6f6_19 = f6 * (int64_t)f6_19; + int64_t f6f7_38 = f6 * (int64_t)f7_38; + int64_t f6f8_38 = f6_2 * (int64_t)f8_19; + int64_t f6f9_38 = f6 * (int64_t)f9_38; + int64_t f7f7_38 = f7 * (int64_t)f7_38; + int64_t f7f8_38 = f7_2 * (int64_t)f8_19; + int64_t f7f9_76 = f7_2 * (int64_t)f9_38; + int64_t f8f8_19 = f8 * (int64_t)f8_19; + int64_t f8f9_38 = f8 * (int64_t)f9_38; + int64_t f9f9_38 = f9 * (int64_t)f9_38; + int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38; + int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38; + int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19; + int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38; + int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38; + int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38; + int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19; + int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38; + int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38; + int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry1 = (h1 + (int64_t)(1 << 24)) >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry5 = (h5 + (int64_t)(1 << 24)) >> 25; + h6 += carry5; + h5 -= carry5 << 25; + carry2 = (h2 + (int64_t)(1 << 25)) >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry6 = (h6 + (int64_t)(1 << 25)) >> 26; + h7 += carry6; + h6 -= carry6 << 26; + carry3 = (h3 + (int64_t)(1 << 24)) >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry7 = (h7 + (int64_t)(1 << 24)) >> 25; + h8 += carry7; + h7 -= carry7 << 25; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry8 = (h8 + (int64_t)(1 << 25)) >> 26; + h9 += carry8; + h8 -= carry8 << 26; + carry9 = (h9 + (int64_t)(1 << 24)) >> 25; + h0 += carry9 * 19; + h9 -= carry9 << 25; + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + h[0] = (int32_t)h0; + h[1] = (int32_t)h1; + h[2] = (int32_t)h2; + h[3] = (int32_t)h3; + h[4] = (int32_t)h4; + h[5] = (int32_t)h5; + h[6] = (int32_t)h6; + h[7] = (int32_t)h7; + h[8] = (int32_t)h8; + h[9] = (int32_t)h9; } - /* h = 2 * f * f Can overlap h with f. @@ -1142,164 +1164,164 @@ Can overlap h with f. See fe_mul.c for discussion of implementation strategy. */ -void fe_sq2(fe h, const fe f) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t f0_2 = 2 * f0; - int32_t f1_2 = 2 * f1; - int32_t f2_2 = 2 * f2; - int32_t f3_2 = 2 * f3; - int32_t f4_2 = 2 * f4; - int32_t f5_2 = 2 * f5; - int32_t f6_2 = 2 * f6; - int32_t f7_2 = 2 * f7; - int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */ - int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */ - int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */ - int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */ - int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */ - int64_t f0f0 = f0 * (int64_t) f0; - int64_t f0f1_2 = f0_2 * (int64_t) f1; - int64_t f0f2_2 = f0_2 * (int64_t) f2; - int64_t f0f3_2 = f0_2 * (int64_t) f3; - int64_t f0f4_2 = f0_2 * (int64_t) f4; - int64_t f0f5_2 = f0_2 * (int64_t) f5; - int64_t f0f6_2 = f0_2 * (int64_t) f6; - int64_t f0f7_2 = f0_2 * (int64_t) f7; - int64_t f0f8_2 = f0_2 * (int64_t) f8; - int64_t f0f9_2 = f0_2 * (int64_t) f9; - int64_t f1f1_2 = f1_2 * (int64_t) f1; - int64_t f1f2_2 = f1_2 * (int64_t) f2; - int64_t f1f3_4 = f1_2 * (int64_t) f3_2; - int64_t f1f4_2 = f1_2 * (int64_t) f4; - int64_t f1f5_4 = f1_2 * (int64_t) f5_2; - int64_t f1f6_2 = f1_2 * (int64_t) f6; - int64_t f1f7_4 = f1_2 * (int64_t) f7_2; - int64_t f1f8_2 = f1_2 * (int64_t) f8; - int64_t f1f9_76 = f1_2 * (int64_t) f9_38; - int64_t f2f2 = f2 * (int64_t) f2; - int64_t f2f3_2 = f2_2 * (int64_t) f3; - int64_t f2f4_2 = f2_2 * (int64_t) f4; - int64_t f2f5_2 = f2_2 * (int64_t) f5; - int64_t f2f6_2 = f2_2 * (int64_t) f6; - int64_t f2f7_2 = f2_2 * (int64_t) f7; - int64_t f2f8_38 = f2_2 * (int64_t) f8_19; - int64_t f2f9_38 = f2 * (int64_t) f9_38; - int64_t f3f3_2 = f3_2 * (int64_t) f3; - int64_t f3f4_2 = f3_2 * (int64_t) f4; - int64_t f3f5_4 = f3_2 * (int64_t) f5_2; - int64_t f3f6_2 = f3_2 * (int64_t) f6; - int64_t f3f7_76 = f3_2 * (int64_t) f7_38; - int64_t f3f8_38 = f3_2 * (int64_t) f8_19; - int64_t f3f9_76 = f3_2 * (int64_t) f9_38; - int64_t f4f4 = f4 * (int64_t) f4; - int64_t f4f5_2 = f4_2 * (int64_t) f5; - int64_t f4f6_38 = f4_2 * (int64_t) f6_19; - int64_t f4f7_38 = f4 * (int64_t) f7_38; - int64_t f4f8_38 = f4_2 * (int64_t) f8_19; - int64_t f4f9_38 = f4 * (int64_t) f9_38; - int64_t f5f5_38 = f5 * (int64_t) f5_38; - int64_t f5f6_38 = f5_2 * (int64_t) f6_19; - int64_t f5f7_76 = f5_2 * (int64_t) f7_38; - int64_t f5f8_38 = f5_2 * (int64_t) f8_19; - int64_t f5f9_76 = f5_2 * (int64_t) f9_38; - int64_t f6f6_19 = f6 * (int64_t) f6_19; - int64_t f6f7_38 = f6 * (int64_t) f7_38; - int64_t f6f8_38 = f6_2 * (int64_t) f8_19; - int64_t f6f9_38 = f6 * (int64_t) f9_38; - int64_t f7f7_38 = f7 * (int64_t) f7_38; - int64_t f7f8_38 = f7_2 * (int64_t) f8_19; - int64_t f7f9_76 = f7_2 * (int64_t) f9_38; - int64_t f8f8_19 = f8 * (int64_t) f8_19; - int64_t f8f9_38 = f8 * (int64_t) f9_38; - int64_t f9f9_38 = f9 * (int64_t) f9_38; - int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38; - int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38; - int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19; - int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38; - int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38; - int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38; - int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19; - int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38; - int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38; - int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - h0 += h0; - h1 += h1; - h2 += h2; - h3 += h3; - h4 += h4; - h5 += h5; - h6 += h6; - h7 += h7; - h8 += h8; - h9 += h9; - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry1 = (h1 + (int64_t) (1 << 24)) >> 25; - h2 += carry1; - h1 -= carry1 << 25; - carry5 = (h5 + (int64_t) (1 << 24)) >> 25; - h6 += carry5; - h5 -= carry5 << 25; - carry2 = (h2 + (int64_t) (1 << 25)) >> 26; - h3 += carry2; - h2 -= carry2 << 26; - carry6 = (h6 + (int64_t) (1 << 25)) >> 26; - h7 += carry6; - h6 -= carry6 << 26; - carry3 = (h3 + (int64_t) (1 << 24)) >> 25; - h4 += carry3; - h3 -= carry3 << 25; - carry7 = (h7 + (int64_t) (1 << 24)) >> 25; - h8 += carry7; - h7 -= carry7 << 25; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry8 = (h8 + (int64_t) (1 << 25)) >> 26; - h9 += carry8; - h8 -= carry8 << 26; - carry9 = (h9 + (int64_t) (1 << 24)) >> 25; - h0 += carry9 * 19; - h9 -= carry9 << 25; - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - h[0] = (int32_t) h0; - h[1] = (int32_t) h1; - h[2] = (int32_t) h2; - h[3] = (int32_t) h3; - h[4] = (int32_t) h4; - h[5] = (int32_t) h5; - h[6] = (int32_t) h6; - h[7] = (int32_t) h7; - h[8] = (int32_t) h8; - h[9] = (int32_t) h9; +void +fe_sq2(fe h, const fe f) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t f0_2 = 2 * f0; + int32_t f1_2 = 2 * f1; + int32_t f2_2 = 2 * f2; + int32_t f3_2 = 2 * f3; + int32_t f4_2 = 2 * f4; + int32_t f5_2 = 2 * f5; + int32_t f6_2 = 2 * f6; + int32_t f7_2 = 2 * f7; + int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */ + int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */ + int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */ + int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */ + int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */ + int64_t f0f0 = f0 * (int64_t)f0; + int64_t f0f1_2 = f0_2 * (int64_t)f1; + int64_t f0f2_2 = f0_2 * (int64_t)f2; + int64_t f0f3_2 = f0_2 * (int64_t)f3; + int64_t f0f4_2 = f0_2 * (int64_t)f4; + int64_t f0f5_2 = f0_2 * (int64_t)f5; + int64_t f0f6_2 = f0_2 * (int64_t)f6; + int64_t f0f7_2 = f0_2 * (int64_t)f7; + int64_t f0f8_2 = f0_2 * (int64_t)f8; + int64_t f0f9_2 = f0_2 * (int64_t)f9; + int64_t f1f1_2 = f1_2 * (int64_t)f1; + int64_t f1f2_2 = f1_2 * (int64_t)f2; + int64_t f1f3_4 = f1_2 * (int64_t)f3_2; + int64_t f1f4_2 = f1_2 * (int64_t)f4; + int64_t f1f5_4 = f1_2 * (int64_t)f5_2; + int64_t f1f6_2 = f1_2 * (int64_t)f6; + int64_t f1f7_4 = f1_2 * (int64_t)f7_2; + int64_t f1f8_2 = f1_2 * (int64_t)f8; + int64_t f1f9_76 = f1_2 * (int64_t)f9_38; + int64_t f2f2 = f2 * (int64_t)f2; + int64_t f2f3_2 = f2_2 * (int64_t)f3; + int64_t f2f4_2 = f2_2 * (int64_t)f4; + int64_t f2f5_2 = f2_2 * (int64_t)f5; + int64_t f2f6_2 = f2_2 * (int64_t)f6; + int64_t f2f7_2 = f2_2 * (int64_t)f7; + int64_t f2f8_38 = f2_2 * (int64_t)f8_19; + int64_t f2f9_38 = f2 * (int64_t)f9_38; + int64_t f3f3_2 = f3_2 * (int64_t)f3; + int64_t f3f4_2 = f3_2 * (int64_t)f4; + int64_t f3f5_4 = f3_2 * (int64_t)f5_2; + int64_t f3f6_2 = f3_2 * (int64_t)f6; + int64_t f3f7_76 = f3_2 * (int64_t)f7_38; + int64_t f3f8_38 = f3_2 * (int64_t)f8_19; + int64_t f3f9_76 = f3_2 * (int64_t)f9_38; + int64_t f4f4 = f4 * (int64_t)f4; + int64_t f4f5_2 = f4_2 * (int64_t)f5; + int64_t f4f6_38 = f4_2 * (int64_t)f6_19; + int64_t f4f7_38 = f4 * (int64_t)f7_38; + int64_t f4f8_38 = f4_2 * (int64_t)f8_19; + int64_t f4f9_38 = f4 * (int64_t)f9_38; + int64_t f5f5_38 = f5 * (int64_t)f5_38; + int64_t f5f6_38 = f5_2 * (int64_t)f6_19; + int64_t f5f7_76 = f5_2 * (int64_t)f7_38; + int64_t f5f8_38 = f5_2 * (int64_t)f8_19; + int64_t f5f9_76 = f5_2 * (int64_t)f9_38; + int64_t f6f6_19 = f6 * (int64_t)f6_19; + int64_t f6f7_38 = f6 * (int64_t)f7_38; + int64_t f6f8_38 = f6_2 * (int64_t)f8_19; + int64_t f6f9_38 = f6 * (int64_t)f9_38; + int64_t f7f7_38 = f7 * (int64_t)f7_38; + int64_t f7f8_38 = f7_2 * (int64_t)f8_19; + int64_t f7f9_76 = f7_2 * (int64_t)f9_38; + int64_t f8f8_19 = f8 * (int64_t)f8_19; + int64_t f8f9_38 = f8 * (int64_t)f9_38; + int64_t f9f9_38 = f9 * (int64_t)f9_38; + int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38; + int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38; + int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19; + int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38; + int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38; + int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38; + int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19; + int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38; + int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38; + int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + h0 += h0; + h1 += h1; + h2 += h2; + h3 += h3; + h4 += h4; + h5 += h5; + h6 += h6; + h7 += h7; + h8 += h8; + h9 += h9; + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry1 = (h1 + (int64_t)(1 << 24)) >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry5 = (h5 + (int64_t)(1 << 24)) >> 25; + h6 += carry5; + h5 -= carry5 << 25; + carry2 = (h2 + (int64_t)(1 << 25)) >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry6 = (h6 + (int64_t)(1 << 25)) >> 26; + h7 += carry6; + h6 -= carry6 << 26; + carry3 = (h3 + (int64_t)(1 << 24)) >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry7 = (h7 + (int64_t)(1 << 24)) >> 25; + h8 += carry7; + h7 -= carry7 << 25; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry8 = (h8 + (int64_t)(1 << 25)) >> 26; + h9 += carry8; + h8 -= carry8 << 26; + carry9 = (h9 + (int64_t)(1 << 24)) >> 25; + h0 += carry9 * 19; + h9 -= carry9 << 25; + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + h[0] = (int32_t)h0; + h[1] = (int32_t)h1; + h[2] = (int32_t)h2; + h[3] = (int32_t)h3; + h[4] = (int32_t)h4; + h[5] = (int32_t)h5; + h[6] = (int32_t)h6; + h[7] = (int32_t)h7; + h[8] = (int32_t)h8; + h[9] = (int32_t)h9; } - /* h = f - g Can overlap h with f or g. @@ -1312,52 +1334,51 @@ Can overlap h with f or g. |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */ -void fe_sub(fe h, const fe f, const fe g) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t g0 = g[0]; - int32_t g1 = g[1]; - int32_t g2 = g[2]; - int32_t g3 = g[3]; - int32_t g4 = g[4]; - int32_t g5 = g[5]; - int32_t g6 = g[6]; - int32_t g7 = g[7]; - int32_t g8 = g[8]; - int32_t g9 = g[9]; - int32_t h0 = f0 - g0; - int32_t h1 = f1 - g1; - int32_t h2 = f2 - g2; - int32_t h3 = f3 - g3; - int32_t h4 = f4 - g4; - int32_t h5 = f5 - g5; - int32_t h6 = f6 - g6; - int32_t h7 = f7 - g7; - int32_t h8 = f8 - g8; - int32_t h9 = f9 - g9; - - h[0] = h0; - h[1] = h1; - h[2] = h2; - h[3] = h3; - h[4] = h4; - h[5] = h5; - h[6] = h6; - h[7] = h7; - h[8] = h8; - h[9] = h9; +void +fe_sub(fe h, const fe f, const fe g) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t g0 = g[0]; + int32_t g1 = g[1]; + int32_t g2 = g[2]; + int32_t g3 = g[3]; + int32_t g4 = g[4]; + int32_t g5 = g[5]; + int32_t g6 = g[6]; + int32_t g7 = g[7]; + int32_t g8 = g[8]; + int32_t g9 = g[9]; + int32_t h0 = f0 - g0; + int32_t h1 = f1 - g1; + int32_t h2 = f2 - g2; + int32_t h3 = f3 - g3; + int32_t h4 = f4 - g4; + int32_t h5 = f5 - g5; + int32_t h6 = f6 - g6; + int32_t h7 = f7 - g7; + int32_t h8 = f8 - g8; + int32_t h9 = f9 - g9; + + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; } - - /* Preconditions: |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. @@ -1383,109 +1404,110 @@ Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))). so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q. */ -void fe_tobytes(unsigned char *s, const fe h) { - int32_t h0 = h[0]; - int32_t h1 = h[1]; - int32_t h2 = h[2]; - int32_t h3 = h[3]; - int32_t h4 = h[4]; - int32_t h5 = h[5]; - int32_t h6 = h[6]; - int32_t h7 = h[7]; - int32_t h8 = h[8]; - int32_t h9 = h[9]; - int32_t q; - int32_t carry0; - int32_t carry1; - int32_t carry2; - int32_t carry3; - int32_t carry4; - int32_t carry5; - int32_t carry6; - int32_t carry7; - int32_t carry8; - int32_t carry9; - q = (19 * h9 + (((int32_t) 1) << 24)) >> 25; - q = (h0 + q) >> 26; - q = (h1 + q) >> 25; - q = (h2 + q) >> 26; - q = (h3 + q) >> 25; - q = (h4 + q) >> 26; - q = (h5 + q) >> 25; - q = (h6 + q) >> 26; - q = (h7 + q) >> 25; - q = (h8 + q) >> 26; - q = (h9 + q) >> 25; - /* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */ - h0 += 19 * q; - /* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */ - carry0 = h0 >> 26; - h1 += carry0; - h0 -= carry0 << 26; - carry1 = h1 >> 25; - h2 += carry1; - h1 -= carry1 << 25; - carry2 = h2 >> 26; - h3 += carry2; - h2 -= carry2 << 26; - carry3 = h3 >> 25; - h4 += carry3; - h3 -= carry3 << 25; - carry4 = h4 >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry5 = h5 >> 25; - h6 += carry5; - h5 -= carry5 << 25; - carry6 = h6 >> 26; - h7 += carry6; - h6 -= carry6 << 26; - carry7 = h7 >> 25; - h8 += carry7; - h7 -= carry7 << 25; - carry8 = h8 >> 26; - h9 += carry8; - h8 -= carry8 << 26; - carry9 = h9 >> 25; - h9 -= carry9 << 25; - - /* h10 = carry9 */ - /* - Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20. - Have h0+...+2^230 h9 between 0 and 2^255-1; - evidently 2^255 h10-2^255 q = 0. - Goal: Output h0+...+2^230 h9. - */ - s[0] = (unsigned char) (h0 >> 0); - s[1] = (unsigned char) (h0 >> 8); - s[2] = (unsigned char) (h0 >> 16); - s[3] = (unsigned char) ((h0 >> 24) | (h1 << 2)); - s[4] = (unsigned char) (h1 >> 6); - s[5] = (unsigned char) (h1 >> 14); - s[6] = (unsigned char) ((h1 >> 22) | (h2 << 3)); - s[7] = (unsigned char) (h2 >> 5); - s[8] = (unsigned char) (h2 >> 13); - s[9] = (unsigned char) ((h2 >> 21) | (h3 << 5)); - s[10] = (unsigned char) (h3 >> 3); - s[11] = (unsigned char) (h3 >> 11); - s[12] = (unsigned char) ((h3 >> 19) | (h4 << 6)); - s[13] = (unsigned char) (h4 >> 2); - s[14] = (unsigned char) (h4 >> 10); - s[15] = (unsigned char) (h4 >> 18); - s[16] = (unsigned char) (h5 >> 0); - s[17] = (unsigned char) (h5 >> 8); - s[18] = (unsigned char) (h5 >> 16); - s[19] = (unsigned char) ((h5 >> 24) | (h6 << 1)); - s[20] = (unsigned char) (h6 >> 7); - s[21] = (unsigned char) (h6 >> 15); - s[22] = (unsigned char) ((h6 >> 23) | (h7 << 3)); - s[23] = (unsigned char) (h7 >> 5); - s[24] = (unsigned char) (h7 >> 13); - s[25] = (unsigned char) ((h7 >> 21) | (h8 << 4)); - s[26] = (unsigned char) (h8 >> 4); - s[27] = (unsigned char) (h8 >> 12); - s[28] = (unsigned char) ((h8 >> 20) | (h9 << 6)); - s[29] = (unsigned char) (h9 >> 2); - s[30] = (unsigned char) (h9 >> 10); - s[31] = (unsigned char) (h9 >> 18); +void +fe_tobytes(unsigned char* s, const fe h) { + int32_t h0 = h[0]; + int32_t h1 = h[1]; + int32_t h2 = h[2]; + int32_t h3 = h[3]; + int32_t h4 = h[4]; + int32_t h5 = h[5]; + int32_t h6 = h[6]; + int32_t h7 = h[7]; + int32_t h8 = h[8]; + int32_t h9 = h[9]; + int32_t q; + int32_t carry0; + int32_t carry1; + int32_t carry2; + int32_t carry3; + int32_t carry4; + int32_t carry5; + int32_t carry6; + int32_t carry7; + int32_t carry8; + int32_t carry9; + q = (19 * h9 + (((int32_t)1) << 24)) >> 25; + q = (h0 + q) >> 26; + q = (h1 + q) >> 25; + q = (h2 + q) >> 26; + q = (h3 + q) >> 25; + q = (h4 + q) >> 26; + q = (h5 + q) >> 25; + q = (h6 + q) >> 26; + q = (h7 + q) >> 25; + q = (h8 + q) >> 26; + q = (h9 + q) >> 25; + /* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */ + h0 += 19 * q; + /* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */ + carry0 = h0 >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry1 = h1 >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry2 = h2 >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry3 = h3 >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry4 = h4 >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry5 = h5 >> 25; + h6 += carry5; + h5 -= carry5 << 25; + carry6 = h6 >> 26; + h7 += carry6; + h6 -= carry6 << 26; + carry7 = h7 >> 25; + h8 += carry7; + h7 -= carry7 << 25; + carry8 = h8 >> 26; + h9 += carry8; + h8 -= carry8 << 26; + carry9 = h9 >> 25; + h9 -= carry9 << 25; + + /* h10 = carry9 */ + /* + Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20. + Have h0+...+2^230 h9 between 0 and 2^255-1; + evidently 2^255 h10-2^255 q = 0. + Goal: Output h0+...+2^230 h9. + */ + s[0] = (unsigned char)(h0 >> 0); + s[1] = (unsigned char)(h0 >> 8); + s[2] = (unsigned char)(h0 >> 16); + s[3] = (unsigned char)((h0 >> 24) | (h1 << 2)); + s[4] = (unsigned char)(h1 >> 6); + s[5] = (unsigned char)(h1 >> 14); + s[6] = (unsigned char)((h1 >> 22) | (h2 << 3)); + s[7] = (unsigned char)(h2 >> 5); + s[8] = (unsigned char)(h2 >> 13); + s[9] = (unsigned char)((h2 >> 21) | (h3 << 5)); + s[10] = (unsigned char)(h3 >> 3); + s[11] = (unsigned char)(h3 >> 11); + s[12] = (unsigned char)((h3 >> 19) | (h4 << 6)); + s[13] = (unsigned char)(h4 >> 2); + s[14] = (unsigned char)(h4 >> 10); + s[15] = (unsigned char)(h4 >> 18); + s[16] = (unsigned char)(h5 >> 0); + s[17] = (unsigned char)(h5 >> 8); + s[18] = (unsigned char)(h5 >> 16); + s[19] = (unsigned char)((h5 >> 24) | (h6 << 1)); + s[20] = (unsigned char)(h6 >> 7); + s[21] = (unsigned char)(h6 >> 15); + s[22] = (unsigned char)((h6 >> 23) | (h7 << 3)); + s[23] = (unsigned char)(h7 >> 5); + s[24] = (unsigned char)(h7 >> 13); + s[25] = (unsigned char)((h7 >> 21) | (h8 << 4)); + s[26] = (unsigned char)(h8 >> 4); + s[27] = (unsigned char)(h8 >> 12); + s[28] = (unsigned char)((h8 >> 20) | (h9 << 6)); + s[29] = (unsigned char)(h9 >> 2); + s[30] = (unsigned char)(h9 >> 10); + s[31] = (unsigned char)(h9 >> 18); } diff --git a/bootrom/ed25519/fe.h b/bootrom/ed25519/fe.h index b4b62d282..367f5042c 100644 --- a/bootrom/ed25519/fe.h +++ b/bootrom/ed25519/fe.h @@ -3,7 +3,6 @@ #include "fixedint.h" - /* fe means field element. Here the field is \Z/(2^255-19). @@ -12,30 +11,46 @@ Bounds on each t[i] vary depending on context. */ - typedef int32_t fe[10]; - -void fe_0(fe h); -void fe_1(fe h); - -void fe_frombytes(fe h, const unsigned char *s); -void fe_tobytes(unsigned char *s, const fe h); - -void fe_copy(fe h, const fe f); -int fe_isnegative(const fe f); -int fe_isnonzero(const fe f); -void fe_cmov(fe f, const fe g, unsigned int b); -void fe_cswap(fe f, fe g, unsigned int b); - -void fe_neg(fe h, const fe f); -void fe_add(fe h, const fe f, const fe g); -void fe_invert(fe out, const fe z); -void fe_sq(fe h, const fe f); -void fe_sq2(fe h, const fe f); -void fe_mul(fe h, const fe f, const fe g); -void fe_mul121666(fe h, fe f); -void fe_pow22523(fe out, const fe z); -void fe_sub(fe h, const fe f, const fe g); +void +fe_0(fe h); +void +fe_1(fe h); + +void +fe_frombytes(fe h, const unsigned char* s); +void +fe_tobytes(unsigned char* s, const fe h); + +void +fe_copy(fe h, const fe f); +int +fe_isnegative(const fe f); +int +fe_isnonzero(const fe f); +void +fe_cmov(fe f, const fe g, unsigned int b); +void +fe_cswap(fe f, fe g, unsigned int b); + +void +fe_neg(fe h, const fe f); +void +fe_add(fe h, const fe f, const fe g); +void +fe_invert(fe out, const fe z); +void +fe_sq(fe h, const fe f); +void +fe_sq2(fe h, const fe f); +void +fe_mul(fe h, const fe f, const fe g); +void +fe_mul121666(fe h, fe f); +void +fe_pow22523(fe out, const fe z); +void +fe_sub(fe h, const fe f, const fe g); #endif diff --git a/bootrom/ed25519/fixedint.h b/bootrom/ed25519/fixedint.h index 1a8745b1e..5b3272c9e 100644 --- a/bootrom/ed25519/fixedint.h +++ b/bootrom/ed25519/fixedint.h @@ -4,69 +4,78 @@ Not a compatible replacement for , do not blindly use it as such. */ -#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__WATCOMC__) && (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined(__UINT_FAST64_TYPE__)) )) && !defined(FIXEDINT_H_INCLUDED) - #include - #define FIXEDINT_H_INCLUDED +#if ( \ + (defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || \ + (defined(__WATCOMC__) && \ + (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || \ + (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || \ + defined(__UINT_FAST64_TYPE__)))) && \ + !defined(FIXEDINT_H_INCLUDED) +#include +#define FIXEDINT_H_INCLUDED - #if defined(__WATCOMC__) && __WATCOMC__ >= 1250 && !defined(UINT64_C) - #include - #define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX)) - #endif +#if defined(__WATCOMC__) && __WATCOMC__ >= 1250 && !defined(UINT64_C) +#include +#define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX)) +#endif #endif - #ifndef FIXEDINT_H_INCLUDED - #define FIXEDINT_H_INCLUDED - - #include +#define FIXEDINT_H_INCLUDED - /* (u)int32_t */ - #ifndef uint32_t - #if (ULONG_MAX == 0xffffffffUL) - typedef unsigned long uint32_t; - #elif (UINT_MAX == 0xffffffffUL) - typedef unsigned int uint32_t; - #elif (USHRT_MAX == 0xffffffffUL) - typedef unsigned short uint32_t; - #endif - #endif +#include +/* (u)int32_t */ +#ifndef uint32_t +#if (ULONG_MAX == 0xffffffffUL) +typedef unsigned long uint32_t; +#elif (UINT_MAX == 0xffffffffUL) +typedef unsigned int uint32_t; +#elif (USHRT_MAX == 0xffffffffUL) +typedef unsigned short uint32_t; +#endif +#endif - #ifndef int32_t - #if (LONG_MAX == 0x7fffffffL) - typedef signed long int32_t; - #elif (INT_MAX == 0x7fffffffL) - typedef signed int int32_t; - #elif (SHRT_MAX == 0x7fffffffL) - typedef signed short int32_t; - #endif - #endif - +#ifndef int32_t +#if (LONG_MAX == 0x7fffffffL) +typedef signed long int32_t; +#elif (INT_MAX == 0x7fffffffL) +typedef signed int int32_t; +#elif (SHRT_MAX == 0x7fffffffL) +typedef signed short int32_t; +#endif +#endif - /* (u)int64_t */ - #if (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC__ && __STDC_VERSION__ >= 199901L) - typedef long long int64_t; - typedef unsigned long long uint64_t; +/* (u)int64_t */ +#if ( \ + defined(__STDC__) && defined(__STDC_VERSION__) && __STDC__ && \ + __STDC_VERSION__ >= 199901L) +typedef long long int64_t; +typedef unsigned long long uint64_t; - #define UINT64_C(v) v ##ULL - #define INT64_C(v) v ##LL - #elif defined(__GNUC__) - __extension__ typedef long long int64_t; - __extension__ typedef unsigned long long uint64_t; +#define UINT64_C(v) v##ULL +#define INT64_C(v) v##LL +#elif defined(__GNUC__) +__extension__ typedef long long int64_t; +__extension__ typedef unsigned long long uint64_t; - #define UINT64_C(v) v ##ULL - #define INT64_C(v) v ##LL - #elif defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__APPLE_CC__) || defined(_LONG_LONG) || defined(_CRAYC) - typedef long long int64_t; - typedef unsigned long long uint64_t; +#define UINT64_C(v) v##ULL +#define INT64_C(v) v##LL +#elif defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || \ + defined(__APPLE_CC__) || defined(_LONG_LONG) || defined(_CRAYC) +typedef long long int64_t; +typedef unsigned long long uint64_t; - #define UINT64_C(v) v ##ULL - #define INT64_C(v) v ##LL - #elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || defined(__alpha) || defined(__DECC) - typedef __int64 int64_t; - typedef unsigned __int64 uint64_t; +#define UINT64_C(v) v##ULL +#define INT64_C(v) v##LL +#elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || \ + (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || \ + (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || defined(__alpha) || \ + defined(__DECC) +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; - #define UINT64_C(v) v ##UI64 - #define INT64_C(v) v ##I64 - #endif +#define UINT64_C(v) v##UI64 +#define INT64_C(v) v##I64 +#endif #endif diff --git a/bootrom/ed25519/ge.c b/bootrom/ed25519/ge.c index 87c691bff..1a8d70e1b 100644 --- a/bootrom/ed25519/ge.c +++ b/bootrom/ed25519/ge.c @@ -1,60 +1,61 @@ #include "ge.h" -#include "precomp_data.h" +#include "precomp_data.h" /* r = p + q */ -void ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) { - fe t0; - fe_add(r->X, p->Y, p->X); - fe_sub(r->Y, p->Y, p->X); - fe_mul(r->Z, r->X, q->YplusX); - fe_mul(r->Y, r->Y, q->YminusX); - fe_mul(r->T, q->T2d, p->T); - fe_mul(r->X, p->Z, q->Z); - fe_add(t0, r->X, r->X); - fe_sub(r->X, r->Z, r->Y); - fe_add(r->Y, r->Z, r->Y); - fe_add(r->Z, t0, r->T); - fe_sub(r->T, t0, r->T); +void +ge_add(ge_p1p1* r, const ge_p3* p, const ge_cached* q) { + fe t0; + fe_add(r->X, p->Y, p->X); + fe_sub(r->Y, p->Y, p->X); + fe_mul(r->Z, r->X, q->YplusX); + fe_mul(r->Y, r->Y, q->YminusX); + fe_mul(r->T, q->T2d, p->T); + fe_mul(r->X, p->Z, q->Z); + fe_add(t0, r->X, r->X); + fe_sub(r->X, r->Z, r->Y); + fe_add(r->Y, r->Z, r->Y); + fe_add(r->Z, t0, r->T); + fe_sub(r->T, t0, r->T); } - -static void slide(signed char *r, const unsigned char *a) { - int i; - int b; - int k; - - for (i = 0; i < 256; ++i) { - r[i] = 1 & (a[i >> 3] >> (i & 7)); - } - - for (i = 0; i < 256; ++i) - if (r[i]) { - for (b = 1; b <= 6 && i + b < 256; ++b) { - if (r[i + b]) { - if (r[i] + (r[i + b] << b) <= 15) { - r[i] += r[i + b] << b; - r[i + b] = 0; - } else if (r[i] - (r[i + b] << b) >= -15) { - r[i] -= r[i + b] << b; - - for (k = i + b; k < 256; ++k) { - if (!r[k]) { - r[k] = 1; - break; - } - - r[k] = 0; - } - } else { - break; - } - } +static void +slide(signed char* r, const unsigned char* a) { + int i; + int b; + int k; + + for (i = 0; i < 256; ++i) { + r[i] = 1 & (a[i >> 3] >> (i & 7)); + } + + for (i = 0; i < 256; ++i) + if (r[i]) { + for (b = 1; b <= 6 && i + b < 256; ++b) { + if (r[i + b]) { + if (r[i] + (r[i + b] << b) <= 15) { + r[i] += r[i + b] << b; + r[i + b] = 0; + } else if (r[i] - (r[i + b] << b) >= -15) { + r[i] -= r[i + b] << b; + + for (k = i + b; k < 256; ++k) { + if (!r[k]) { + r[k] = 1; + break; + } + + r[k] = 0; } + } else { + break; + } } + } + } } /* @@ -64,314 +65,313 @@ and b = b[0]+256*b[1]+...+256^31 b[31]. B is the Ed25519 base point (x,4/5) with x positive. */ -void ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b) { - signed char aslide[256]; - signed char bslide[256]; - ge_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */ - ge_p1p1 t; - ge_p3 u; - ge_p3 A2; - int i; - slide(aslide, a); - slide(bslide, b); - ge_p3_to_cached(&Ai[0], A); - ge_p3_dbl(&t, A); - ge_p1p1_to_p3(&A2, &t); - ge_add(&t, &A2, &Ai[0]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[1], &u); - ge_add(&t, &A2, &Ai[1]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[2], &u); - ge_add(&t, &A2, &Ai[2]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[3], &u); - ge_add(&t, &A2, &Ai[3]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[4], &u); - ge_add(&t, &A2, &Ai[4]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[5], &u); - ge_add(&t, &A2, &Ai[5]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[6], &u); - ge_add(&t, &A2, &Ai[6]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[7], &u); - ge_p2_0(r); - - for (i = 255; i >= 0; --i) { - if (aslide[i] || bslide[i]) { - break; - } +void +ge_double_scalarmult_vartime( + ge_p2* r, const unsigned char* a, const ge_p3* A, const unsigned char* b) { + signed char aslide[256]; + signed char bslide[256]; + ge_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */ + ge_p1p1 t; + ge_p3 u; + ge_p3 A2; + int i; + slide(aslide, a); + slide(bslide, b); + ge_p3_to_cached(&Ai[0], A); + ge_p3_dbl(&t, A); + ge_p1p1_to_p3(&A2, &t); + ge_add(&t, &A2, &Ai[0]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[1], &u); + ge_add(&t, &A2, &Ai[1]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[2], &u); + ge_add(&t, &A2, &Ai[2]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[3], &u); + ge_add(&t, &A2, &Ai[3]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[4], &u); + ge_add(&t, &A2, &Ai[4]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[5], &u); + ge_add(&t, &A2, &Ai[5]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[6], &u); + ge_add(&t, &A2, &Ai[6]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[7], &u); + ge_p2_0(r); + + for (i = 255; i >= 0; --i) { + if (aslide[i] || bslide[i]) { + break; } + } - for (; i >= 0; --i) { - ge_p2_dbl(&t, r); + for (; i >= 0; --i) { + ge_p2_dbl(&t, r); - if (aslide[i] > 0) { - ge_p1p1_to_p3(&u, &t); - ge_add(&t, &u, &Ai[aslide[i] / 2]); - } else if (aslide[i] < 0) { - ge_p1p1_to_p3(&u, &t); - ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]); - } - - if (bslide[i] > 0) { - ge_p1p1_to_p3(&u, &t); - ge_madd(&t, &u, &Bi[bslide[i] / 2]); - } else if (bslide[i] < 0) { - ge_p1p1_to_p3(&u, &t); - ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]); - } + if (aslide[i] > 0) { + ge_p1p1_to_p3(&u, &t); + ge_add(&t, &u, &Ai[aslide[i] / 2]); + } else if (aslide[i] < 0) { + ge_p1p1_to_p3(&u, &t); + ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]); + } - ge_p1p1_to_p2(r, &t); + if (bslide[i] > 0) { + ge_p1p1_to_p3(&u, &t); + ge_madd(&t, &u, &Bi[bslide[i] / 2]); + } else if (bslide[i] < 0) { + ge_p1p1_to_p3(&u, &t); + ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]); } -} + ge_p1p1_to_p2(r, &t); + } +} -static const fe d = { - -10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116 -}; - -static const fe sqrtm1 = { - -32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482 -}; - -int ge_frombytes_negate_vartime(ge_p3 *h, const unsigned char *s) { - fe u; - fe v; - fe v3; - fe vxx; - fe check; - fe_frombytes(h->Y, s); - fe_1(h->Z); - fe_sq(u, h->Y); - fe_mul(v, u, d); - fe_sub(u, u, h->Z); /* u = y^2-1 */ - fe_add(v, v, h->Z); /* v = dy^2+1 */ - fe_sq(v3, v); - fe_mul(v3, v3, v); /* v3 = v^3 */ - fe_sq(h->X, v3); - fe_mul(h->X, h->X, v); - fe_mul(h->X, h->X, u); /* x = uv^7 */ - fe_pow22523(h->X, h->X); /* x = (uv^7)^((q-5)/8) */ - fe_mul(h->X, h->X, v3); - fe_mul(h->X, h->X, u); /* x = uv^3(uv^7)^((q-5)/8) */ - fe_sq(vxx, h->X); - fe_mul(vxx, vxx, v); - fe_sub(check, vxx, u); /* vx^2-u */ +static const fe d = {-10913610, 13857413, -15372611, 6949391, 114729, + -8787816, -6275908, -3247719, -18696448, -12055116}; + +static const fe sqrtm1 = {-32595792, -7943725, 9377950, 3500415, 12389472, + -272473, -25146209, -2005654, 326686, 11406482}; + +int +ge_frombytes_negate_vartime(ge_p3* h, const unsigned char* s) { + fe u; + fe v; + fe v3; + fe vxx; + fe check; + fe_frombytes(h->Y, s); + fe_1(h->Z); + fe_sq(u, h->Y); + fe_mul(v, u, d); + fe_sub(u, u, h->Z); /* u = y^2-1 */ + fe_add(v, v, h->Z); /* v = dy^2+1 */ + fe_sq(v3, v); + fe_mul(v3, v3, v); /* v3 = v^3 */ + fe_sq(h->X, v3); + fe_mul(h->X, h->X, v); + fe_mul(h->X, h->X, u); /* x = uv^7 */ + fe_pow22523(h->X, h->X); /* x = (uv^7)^((q-5)/8) */ + fe_mul(h->X, h->X, v3); + fe_mul(h->X, h->X, u); /* x = uv^3(uv^7)^((q-5)/8) */ + fe_sq(vxx, h->X); + fe_mul(vxx, vxx, v); + fe_sub(check, vxx, u); /* vx^2-u */ + + if (fe_isnonzero(check)) { + fe_add(check, vxx, u); /* vx^2+u */ if (fe_isnonzero(check)) { - fe_add(check, vxx, u); /* vx^2+u */ - - if (fe_isnonzero(check)) { - return -1; - } - - fe_mul(h->X, h->X, sqrtm1); + return -1; } - if (fe_isnegative(h->X) == (s[31] >> 7)) { - fe_neg(h->X, h->X); - } + fe_mul(h->X, h->X, sqrtm1); + } - fe_mul(h->T, h->X, h->Y); - return 0; -} + if (fe_isnegative(h->X) == (s[31] >> 7)) { + fe_neg(h->X, h->X); + } + fe_mul(h->T, h->X, h->Y); + return 0; +} /* r = p + q */ -void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) { - fe t0; - fe_add(r->X, p->Y, p->X); - fe_sub(r->Y, p->Y, p->X); - fe_mul(r->Z, r->X, q->yplusx); - fe_mul(r->Y, r->Y, q->yminusx); - fe_mul(r->T, q->xy2d, p->T); - fe_add(t0, p->Z, p->Z); - fe_sub(r->X, r->Z, r->Y); - fe_add(r->Y, r->Z, r->Y); - fe_add(r->Z, t0, r->T); - fe_sub(r->T, t0, r->T); +void +ge_madd(ge_p1p1* r, const ge_p3* p, const ge_precomp* q) { + fe t0; + fe_add(r->X, p->Y, p->X); + fe_sub(r->Y, p->Y, p->X); + fe_mul(r->Z, r->X, q->yplusx); + fe_mul(r->Y, r->Y, q->yminusx); + fe_mul(r->T, q->xy2d, p->T); + fe_add(t0, p->Z, p->Z); + fe_sub(r->X, r->Z, r->Y); + fe_add(r->Y, r->Z, r->Y); + fe_add(r->Z, t0, r->T); + fe_sub(r->T, t0, r->T); } - /* r = p - q */ -void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) { - fe t0; - - fe_add(r->X, p->Y, p->X); - fe_sub(r->Y, p->Y, p->X); - fe_mul(r->Z, r->X, q->yminusx); - fe_mul(r->Y, r->Y, q->yplusx); - fe_mul(r->T, q->xy2d, p->T); - fe_add(t0, p->Z, p->Z); - fe_sub(r->X, r->Z, r->Y); - fe_add(r->Y, r->Z, r->Y); - fe_sub(r->Z, t0, r->T); - fe_add(r->T, t0, r->T); +void +ge_msub(ge_p1p1* r, const ge_p3* p, const ge_precomp* q) { + fe t0; + + fe_add(r->X, p->Y, p->X); + fe_sub(r->Y, p->Y, p->X); + fe_mul(r->Z, r->X, q->yminusx); + fe_mul(r->Y, r->Y, q->yplusx); + fe_mul(r->T, q->xy2d, p->T); + fe_add(t0, p->Z, p->Z); + fe_sub(r->X, r->Z, r->Y); + fe_add(r->Y, r->Z, r->Y); + fe_sub(r->Z, t0, r->T); + fe_add(r->T, t0, r->T); } - /* r = p */ -void ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p) { - fe_mul(r->X, p->X, p->T); - fe_mul(r->Y, p->Y, p->Z); - fe_mul(r->Z, p->Z, p->T); +void +ge_p1p1_to_p2(ge_p2* r, const ge_p1p1* p) { + fe_mul(r->X, p->X, p->T); + fe_mul(r->Y, p->Y, p->Z); + fe_mul(r->Z, p->Z, p->T); } - - /* r = p */ -void ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p) { - fe_mul(r->X, p->X, p->T); - fe_mul(r->Y, p->Y, p->Z); - fe_mul(r->Z, p->Z, p->T); - fe_mul(r->T, p->X, p->Y); +void +ge_p1p1_to_p3(ge_p3* r, const ge_p1p1* p) { + fe_mul(r->X, p->X, p->T); + fe_mul(r->Y, p->Y, p->Z); + fe_mul(r->Z, p->Z, p->T); + fe_mul(r->T, p->X, p->Y); } - -void ge_p2_0(ge_p2 *h) { - fe_0(h->X); - fe_1(h->Y); - fe_1(h->Z); +void +ge_p2_0(ge_p2* h) { + fe_0(h->X); + fe_1(h->Y); + fe_1(h->Z); } - - /* r = 2 * p */ -void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p) { - fe t0; - - fe_sq(r->X, p->X); - fe_sq(r->Z, p->Y); - fe_sq2(r->T, p->Z); - fe_add(r->Y, p->X, p->Y); - fe_sq(t0, r->Y); - fe_add(r->Y, r->Z, r->X); - fe_sub(r->Z, r->Z, r->X); - fe_sub(r->X, t0, r->Y); - fe_sub(r->T, r->T, r->Z); +void +ge_p2_dbl(ge_p1p1* r, const ge_p2* p) { + fe t0; + + fe_sq(r->X, p->X); + fe_sq(r->Z, p->Y); + fe_sq2(r->T, p->Z); + fe_add(r->Y, p->X, p->Y); + fe_sq(t0, r->Y); + fe_add(r->Y, r->Z, r->X); + fe_sub(r->Z, r->Z, r->X); + fe_sub(r->X, t0, r->Y); + fe_sub(r->T, r->T, r->Z); } - -void ge_p3_0(ge_p3 *h) { - fe_0(h->X); - fe_1(h->Y); - fe_1(h->Z); - fe_0(h->T); +void +ge_p3_0(ge_p3* h) { + fe_0(h->X); + fe_1(h->Y); + fe_1(h->Z); + fe_0(h->T); } - /* r = 2 * p */ -void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p) { - ge_p2 q; - ge_p3_to_p2(&q, p); - ge_p2_dbl(r, &q); +void +ge_p3_dbl(ge_p1p1* r, const ge_p3* p) { + ge_p2 q; + ge_p3_to_p2(&q, p); + ge_p2_dbl(r, &q); } - - /* r = p */ -static const fe d2 = { - -21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199 -}; +static const fe d2 = {-21827239, -5839606, -30745221, 13898782, 229458, + 15978800, -12551817, -6495438, 29715968, 9444199}; -void ge_p3_to_cached(ge_cached *r, const ge_p3 *p) { - fe_add(r->YplusX, p->Y, p->X); - fe_sub(r->YminusX, p->Y, p->X); - fe_copy(r->Z, p->Z); - fe_mul(r->T2d, p->T, d2); +void +ge_p3_to_cached(ge_cached* r, const ge_p3* p) { + fe_add(r->YplusX, p->Y, p->X); + fe_sub(r->YminusX, p->Y, p->X); + fe_copy(r->Z, p->Z); + fe_mul(r->T2d, p->T, d2); } - /* r = p */ -void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p) { - fe_copy(r->X, p->X); - fe_copy(r->Y, p->Y); - fe_copy(r->Z, p->Z); +void +ge_p3_to_p2(ge_p2* r, const ge_p3* p) { + fe_copy(r->X, p->X); + fe_copy(r->Y, p->Y); + fe_copy(r->Z, p->Z); } - -void ge_p3_tobytes(unsigned char *s, const ge_p3 *h) { - fe recip; - fe x; - fe y; - fe_invert(recip, h->Z); - fe_mul(x, h->X, recip); - fe_mul(y, h->Y, recip); - fe_tobytes(s, y); - s[31] ^= fe_isnegative(x) << 7; +void +ge_p3_tobytes(unsigned char* s, const ge_p3* h) { + fe recip; + fe x; + fe y; + fe_invert(recip, h->Z); + fe_mul(x, h->X, recip); + fe_mul(y, h->Y, recip); + fe_tobytes(s, y); + s[31] ^= fe_isnegative(x) << 7; } - -static unsigned char equal(signed char b, signed char c) { - unsigned char ub = b; - unsigned char uc = c; - unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */ - uint64_t y = x; /* 0: yes; 1..255: no */ - y -= 1; /* large: yes; 0..254: no */ - y >>= 63; /* 1: yes; 0: no */ - return (unsigned char) y; +static unsigned char +equal(signed char b, signed char c) { + unsigned char ub = b; + unsigned char uc = c; + unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */ + uint64_t y = x; /* 0: yes; 1..255: no */ + y -= 1; /* large: yes; 0..254: no */ + y >>= 63; /* 1: yes; 0: no */ + return (unsigned char)y; } -static unsigned char negative(signed char b) { - uint64_t x = b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */ - x >>= 63; /* 1: yes; 0: no */ - return (unsigned char) x; +static unsigned char +negative(signed char b) { + uint64_t x = + b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */ + x >>= 63; /* 1: yes; 0: no */ + return (unsigned char)x; } -static void cmov(ge_precomp *t, const ge_precomp *u, unsigned char b) { - fe_cmov(t->yplusx, u->yplusx, b); - fe_cmov(t->yminusx, u->yminusx, b); - fe_cmov(t->xy2d, u->xy2d, b); +static void +cmov(ge_precomp* t, const ge_precomp* u, unsigned char b) { + fe_cmov(t->yplusx, u->yplusx, b); + fe_cmov(t->yminusx, u->yminusx, b); + fe_cmov(t->xy2d, u->xy2d, b); } - -static void select(ge_precomp *t, int pos, signed char b) { - ge_precomp minust; - unsigned char bnegative = negative(b); - unsigned char babs = b - (((-bnegative) & b) << 1); - fe_1(t->yplusx); - fe_1(t->yminusx); - fe_0(t->xy2d); - cmov(t, &base[pos][0], equal(babs, 1)); - cmov(t, &base[pos][1], equal(babs, 2)); - cmov(t, &base[pos][2], equal(babs, 3)); - cmov(t, &base[pos][3], equal(babs, 4)); - cmov(t, &base[pos][4], equal(babs, 5)); - cmov(t, &base[pos][5], equal(babs, 6)); - cmov(t, &base[pos][6], equal(babs, 7)); - cmov(t, &base[pos][7], equal(babs, 8)); - fe_copy(minust.yplusx, t->yminusx); - fe_copy(minust.yminusx, t->yplusx); - fe_neg(minust.xy2d, t->xy2d); - cmov(t, &minust, bnegative); +static void +select(ge_precomp* t, int pos, signed char b) { + ge_precomp minust; + unsigned char bnegative = negative(b); + unsigned char babs = b - (((-bnegative) & b) << 1); + fe_1(t->yplusx); + fe_1(t->yminusx); + fe_0(t->xy2d); + cmov(t, &base[pos][0], equal(babs, 1)); + cmov(t, &base[pos][1], equal(babs, 2)); + cmov(t, &base[pos][2], equal(babs, 3)); + cmov(t, &base[pos][3], equal(babs, 4)); + cmov(t, &base[pos][4], equal(babs, 5)); + cmov(t, &base[pos][5], equal(babs, 6)); + cmov(t, &base[pos][6], equal(babs, 7)); + cmov(t, &base[pos][7], equal(babs, 8)); + fe_copy(minust.yplusx, t->yminusx); + fe_copy(minust.yminusx, t->yplusx); + fe_neg(minust.xy2d, t->xy2d); + cmov(t, &minust, bnegative); } /* @@ -383,85 +383,86 @@ B is the Ed25519 base point (x,4/5) with x positive. a[31] <= 127 */ -void ge_scalarmult_base(ge_p3 *h, const unsigned char *a) { - signed char e[64]; - signed char carry; - ge_p1p1 r; - ge_p2 s; - ge_precomp t; - int i; - - for (i = 0; i < 32; ++i) { - e[2 * i + 0] = (a[i] >> 0) & 15; - e[2 * i + 1] = (a[i] >> 4) & 15; - } - - /* each e[i] is between 0 and 15 */ - /* e[63] is between 0 and 7 */ - carry = 0; - - for (i = 0; i < 63; ++i) { - e[i] += carry; - carry = e[i] + 8; - carry >>= 4; - e[i] -= carry << 4; - } - - e[63] += carry; - /* each e[i] is between -8 and 8 */ - ge_p3_0(h); - - for (i = 1; i < 64; i += 2) { - select(&t, i / 2, e[i]); - ge_madd(&r, h, &t); - ge_p1p1_to_p3(h, &r); - } - - ge_p3_dbl(&r, h); - ge_p1p1_to_p2(&s, &r); - ge_p2_dbl(&r, &s); - ge_p1p1_to_p2(&s, &r); - ge_p2_dbl(&r, &s); - ge_p1p1_to_p2(&s, &r); - ge_p2_dbl(&r, &s); +void +ge_scalarmult_base(ge_p3* h, const unsigned char* a) { + signed char e[64]; + signed char carry; + ge_p1p1 r; + ge_p2 s; + ge_precomp t; + int i; + + for (i = 0; i < 32; ++i) { + e[2 * i + 0] = (a[i] >> 0) & 15; + e[2 * i + 1] = (a[i] >> 4) & 15; + } + + /* each e[i] is between 0 and 15 */ + /* e[63] is between 0 and 7 */ + carry = 0; + + for (i = 0; i < 63; ++i) { + e[i] += carry; + carry = e[i] + 8; + carry >>= 4; + e[i] -= carry << 4; + } + + e[63] += carry; + /* each e[i] is between -8 and 8 */ + ge_p3_0(h); + + for (i = 1; i < 64; i += 2) { + select(&t, i / 2, e[i]); + ge_madd(&r, h, &t); ge_p1p1_to_p3(h, &r); - - for (i = 0; i < 64; i += 2) { - select(&t, i / 2, e[i]); - ge_madd(&r, h, &t); - ge_p1p1_to_p3(h, &r); - } + } + + ge_p3_dbl(&r, h); + ge_p1p1_to_p2(&s, &r); + ge_p2_dbl(&r, &s); + ge_p1p1_to_p2(&s, &r); + ge_p2_dbl(&r, &s); + ge_p1p1_to_p2(&s, &r); + ge_p2_dbl(&r, &s); + ge_p1p1_to_p3(h, &r); + + for (i = 0; i < 64; i += 2) { + select(&t, i / 2, e[i]); + ge_madd(&r, h, &t); + ge_p1p1_to_p3(h, &r); + } } - /* r = p - q */ -void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) { - fe t0; - - fe_add(r->X, p->Y, p->X); - fe_sub(r->Y, p->Y, p->X); - fe_mul(r->Z, r->X, q->YminusX); - fe_mul(r->Y, r->Y, q->YplusX); - fe_mul(r->T, q->T2d, p->T); - fe_mul(r->X, p->Z, q->Z); - fe_add(t0, r->X, r->X); - fe_sub(r->X, r->Z, r->Y); - fe_add(r->Y, r->Z, r->Y); - fe_sub(r->Z, t0, r->T); - fe_add(r->T, t0, r->T); +void +ge_sub(ge_p1p1* r, const ge_p3* p, const ge_cached* q) { + fe t0; + + fe_add(r->X, p->Y, p->X); + fe_sub(r->Y, p->Y, p->X); + fe_mul(r->Z, r->X, q->YminusX); + fe_mul(r->Y, r->Y, q->YplusX); + fe_mul(r->T, q->T2d, p->T); + fe_mul(r->X, p->Z, q->Z); + fe_add(t0, r->X, r->X); + fe_sub(r->X, r->Z, r->Y); + fe_add(r->Y, r->Z, r->Y); + fe_sub(r->Z, t0, r->T); + fe_add(r->T, t0, r->T); } - -void ge_tobytes(unsigned char *s, const ge_p2 *h) { - fe recip; - fe x; - fe y; - fe_invert(recip, h->Z); - fe_mul(x, h->X, recip); - fe_mul(y, h->Y, recip); - fe_tobytes(s, y); - s[31] ^= fe_isnegative(x) << 7; +void +ge_tobytes(unsigned char* s, const ge_p2* h) { + fe recip; + fe x; + fe y; + fe_invert(recip, h->Z); + fe_mul(x, h->X, recip); + fe_mul(y, h->Y, recip); + fe_tobytes(s, y); + s[31] ^= fe_isnegative(x) << 7; } diff --git a/bootrom/ed25519/ge.h b/bootrom/ed25519/ge.h index 17fde2df1..d8a159eb5 100644 --- a/bootrom/ed25519/ge.h +++ b/bootrom/ed25519/ge.h @@ -3,7 +3,6 @@ #include "fe.h" - /* ge means group element. @@ -51,24 +50,42 @@ typedef struct { fe T2d; } ge_cached; -void ge_p3_tobytes(unsigned char *s, const ge_p3 *h); -void ge_tobytes(unsigned char *s, const ge_p2 *h); -int ge_frombytes_negate_vartime(ge_p3 *h, const unsigned char *s); +void +ge_p3_tobytes(unsigned char* s, const ge_p3* h); +void +ge_tobytes(unsigned char* s, const ge_p2* h); +int +ge_frombytes_negate_vartime(ge_p3* h, const unsigned char* s); -void ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q); -void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q); -void ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b); -void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q); -void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q); -void ge_scalarmult_base(ge_p3 *h, const unsigned char *a); +void +ge_add(ge_p1p1* r, const ge_p3* p, const ge_cached* q); +void +ge_sub(ge_p1p1* r, const ge_p3* p, const ge_cached* q); +void +ge_double_scalarmult_vartime( + ge_p2* r, const unsigned char* a, const ge_p3* A, const unsigned char* b); +void +ge_madd(ge_p1p1* r, const ge_p3* p, const ge_precomp* q); +void +ge_msub(ge_p1p1* r, const ge_p3* p, const ge_precomp* q); +void +ge_scalarmult_base(ge_p3* h, const unsigned char* a); -void ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p); -void ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p); -void ge_p2_0(ge_p2 *h); -void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p); -void ge_p3_0(ge_p3 *h); -void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p); -void ge_p3_to_cached(ge_cached *r, const ge_p3 *p); -void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p); +void +ge_p1p1_to_p2(ge_p2* r, const ge_p1p1* p); +void +ge_p1p1_to_p3(ge_p3* r, const ge_p1p1* p); +void +ge_p2_0(ge_p2* h); +void +ge_p2_dbl(ge_p1p1* r, const ge_p2* p); +void +ge_p3_0(ge_p3* h); +void +ge_p3_dbl(ge_p1p1* r, const ge_p3* p); +void +ge_p3_to_cached(ge_cached* r, const ge_p3* p); +void +ge_p3_to_p2(ge_p2* r, const ge_p3* p); #endif diff --git a/bootrom/ed25519/keypair.c b/bootrom/ed25519/keypair.c index 253b2c277..744ccf1b8 100644 --- a/bootrom/ed25519/keypair.c +++ b/bootrom/ed25519/keypair.c @@ -1,16 +1,18 @@ #include "ed25519.h" -#include "sha3/sha3.h" #include "ge.h" +#include "sha3/sha3.h" +void +ed25519_create_keypair( + unsigned char* public_key, unsigned char* private_key, + const unsigned char* seed) { + ge_p3 A; -void ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed) { - ge_p3 A; - - sha3(seed, 32, private_key, 64); - private_key[0] &= 248; - private_key[31] &= 63; - private_key[31] |= 64; + sha3(seed, 32, private_key, 64); + private_key[0] &= 248; + private_key[31] &= 63; + private_key[31] |= 64; - ge_scalarmult_base(&A, private_key); - ge_p3_tobytes(public_key, &A); + ge_scalarmult_base(&A, private_key); + ge_p3_tobytes(public_key, &A); } diff --git a/bootrom/ed25519/precomp_data.h b/bootrom/ed25519/precomp_data.h index ff23986c3..13be672e6 100644 --- a/bootrom/ed25519/precomp_data.h +++ b/bootrom/ed25519/precomp_data.h @@ -1,1391 +1,2182 @@ static const ge_precomp Bi[8] = { { - { 25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605 }, - { -12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378 }, - { -8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, 11864899, -24514362, -4438546 }, + {25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, + -11754271, -6079156, 2047605}, + {-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, + 5043384, 19500929, -15469378}, + {-8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, + 11864899, -24514362, -4438546}, }, { - { 15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, -14772189, 28944400, -1550024 }, - { 16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, -11775962, 7689662, 11199574 }, - { 30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, 10017326, -17749093, -9920357 }, + {15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, + -14772189, 28944400, -1550024}, + {16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, + -11775962, 7689662, 11199574}, + {30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, + 10017326, -17749093, -9920357}, }, { - { 10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, 14515107, -15438304, 10819380 }, - { 4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, 12483688, -12668491, 5581306 }, - { 19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, 13850243, -23678021, -15815942 }, + {10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, + 14515107, -15438304, 10819380}, + {4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, + 12483688, -12668491, 5581306}, + {19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, + 13850243, -23678021, -15815942}, }, { - { 5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, 5230134, -23952439, -15175766 }, - { -30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, 16520125, 30598449, 7715701 }, - { 28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, 1370708, 29794553, -1409300 }, + {5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, + 5230134, -23952439, -15175766}, + {-30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, + 16520125, 30598449, 7715701}, + {28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, + 1370708, 29794553, -1409300}, }, { - { -22518993, -6692182, 14201702, -8745502, -23510406, 8844726, 18474211, -1361450, -13062696, 13821877 }, - { -6455177, -7839871, 3374702, -4740862, -27098617, -10571707, 31655028, -7212327, 18853322, -14220951 }, - { 4566830, -12963868, -28974889, -12240689, -7602672, -2830569, -8514358, -10431137, 2207753, -3209784 }, + {-22518993, -6692182, 14201702, -8745502, -23510406, 8844726, 18474211, + -1361450, -13062696, 13821877}, + {-6455177, -7839871, 3374702, -4740862, -27098617, -10571707, 31655028, + -7212327, 18853322, -14220951}, + {4566830, -12963868, -28974889, -12240689, -7602672, -2830569, -8514358, + -10431137, 2207753, -3209784}, }, { - { -25154831, -4185821, 29681144, 7868801, -6854661, -9423865, -12437364, -663000, -31111463, -16132436 }, - { 25576264, -2703214, 7349804, -11814844, 16472782, 9300885, 3844789, 15725684, 171356, 6466918 }, - { 23103977, 13316479, 9739013, -16149481, 817875, -15038942, 8965339, -14088058, -30714912, 16193877 }, + {-25154831, -4185821, 29681144, 7868801, -6854661, -9423865, -12437364, + -663000, -31111463, -16132436}, + {25576264, -2703214, 7349804, -11814844, 16472782, 9300885, 3844789, + 15725684, 171356, 6466918}, + {23103977, 13316479, 9739013, -16149481, 817875, -15038942, 8965339, + -14088058, -30714912, 16193877}, }, { - { -33521811, 3180713, -2394130, 14003687, -16903474, -16270840, 17238398, 4729455, -18074513, 9256800 }, - { -25182317, -4174131, 32336398, 5036987, -21236817, 11360617, 22616405, 9761698, -19827198, 630305 }, - { -13720693, 2639453, -24237460, -7406481, 9494427, -5774029, -6554551, -15960994, -2449256, -14291300 }, + {-33521811, 3180713, -2394130, 14003687, -16903474, -16270840, 17238398, + 4729455, -18074513, 9256800}, + {-25182317, -4174131, 32336398, 5036987, -21236817, 11360617, 22616405, + 9761698, -19827198, 630305}, + {-13720693, 2639453, -24237460, -7406481, 9494427, -5774029, -6554551, + -15960994, -2449256, -14291300}, }, { - { -3151181, -5046075, 9282714, 6866145, -31907062, -863023, -18940575, 15033784, 25105118, -7894876 }, - { -24326370, 15950226, -31801215, -14592823, -11662737, -5090925, 1573892, -2625887, 2198790, -15804619 }, - { -3099351, 10324967, -2241613, 7453183, -5446979, -2735503, -13812022, -16236442, -32461234, -12290683 }, + {-3151181, -5046075, 9282714, 6866145, -31907062, -863023, -18940575, + 15033784, 25105118, -7894876}, + {-24326370, 15950226, -31801215, -14592823, -11662737, -5090925, + 1573892, -2625887, 2198790, -15804619}, + {-3099351, 10324967, -2241613, 7453183, -5446979, -2735503, -13812022, + -16236442, -32461234, -12290683}, }, }; - /* base[i][j] = (j+1)*256^i*B */ static const ge_precomp base[32][8] = { { { - { 25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605 }, - { -12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378 }, - { -8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, 11864899, -24514362, -4438546 }, + {25967493, -14356035, 29566456, 3660896, -12694345, 4014787, + 27544626, -11754271, -6079156, 2047605}, + {-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, + 5043384, 19500929, -15469378}, + {-8738181, 4489570, 9688441, -14785194, 10184609, -12363380, + 29287919, 11864899, -24514362, -4438546}, }, { - { -12815894, -12976347, -21581243, 11784320, -25355658, -2750717, -11717903, -3814571, -358445, -10211303 }, - { -21703237, 6903825, 27185491, 6451973, -29577724, -9554005, -15616551, 11189268, -26829678, -5319081 }, - { 26966642, 11152617, 32442495, 15396054, 14353839, -12752335, -3128826, -9541118, -15472047, -4166697 }, + {-12815894, -12976347, -21581243, 11784320, -25355658, -2750717, + -11717903, -3814571, -358445, -10211303}, + {-21703237, 6903825, 27185491, 6451973, -29577724, -9554005, + -15616551, 11189268, -26829678, -5319081}, + {26966642, 11152617, 32442495, 15396054, 14353839, -12752335, + -3128826, -9541118, -15472047, -4166697}, }, { - { 15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, -14772189, 28944400, -1550024 }, - { 16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, -11775962, 7689662, 11199574 }, - { 30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, 10017326, -17749093, -9920357 }, + {15636291, -9688557, 24204773, -7912398, 616977, -16685262, + 27787600, -14772189, 28944400, -1550024}, + {16568933, 4717097, -11556148, -1102322, 15682896, -11807043, + 16354577, -11775962, 7689662, 11199574}, + {30464156, -5976125, -11779434, -15670865, 23220365, 15915852, + 7512774, 10017326, -17749093, -9920357}, }, { - { -17036878, 13921892, 10945806, -6033431, 27105052, -16084379, -28926210, 15006023, 3284568, -6276540 }, - { 23599295, -8306047, -11193664, -7687416, 13236774, 10506355, 7464579, 9656445, 13059162, 10374397 }, - { 7798556, 16710257, 3033922, 2874086, 28997861, 2835604, 32406664, -3839045, -641708, -101325 }, + {-17036878, 13921892, 10945806, -6033431, 27105052, -16084379, + -28926210, 15006023, 3284568, -6276540}, + {23599295, -8306047, -11193664, -7687416, 13236774, 10506355, + 7464579, 9656445, 13059162, 10374397}, + {7798556, 16710257, 3033922, 2874086, 28997861, 2835604, 32406664, + -3839045, -641708, -101325}, }, { - { 10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, 14515107, -15438304, 10819380 }, - { 4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, 12483688, -12668491, 5581306 }, - { 19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, 13850243, -23678021, -15815942 }, + {10861363, 11473154, 27284546, 1981175, -30064349, 12577861, + 32867885, 14515107, -15438304, 10819380}, + {4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, + 12483688, -12668491, 5581306}, + {19563160, 16186464, -29386857, 4097519, 10237984, -4348115, + 28542350, 13850243, -23678021, -15815942}, }, { - { -15371964, -12862754, 32573250, 4720197, -26436522, 5875511, -19188627, -15224819, -9818940, -12085777 }, - { -8549212, 109983, 15149363, 2178705, 22900618, 4543417, 3044240, -15689887, 1762328, 14866737 }, - { -18199695, -15951423, -10473290, 1707278, -17185920, 3916101, -28236412, 3959421, 27914454, 4383652 }, + {-15371964, -12862754, 32573250, 4720197, -26436522, 5875511, + -19188627, -15224819, -9818940, -12085777}, + {-8549212, 109983, 15149363, 2178705, 22900618, 4543417, 3044240, + -15689887, 1762328, 14866737}, + {-18199695, -15951423, -10473290, 1707278, -17185920, 3916101, + -28236412, 3959421, 27914454, 4383652}, }, { - { 5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, 5230134, -23952439, -15175766 }, - { -30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, 16520125, 30598449, 7715701 }, - { 28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, 1370708, 29794553, -1409300 }, + {5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, + 5230134, -23952439, -15175766}, + {-30269007, -3463509, 7665486, 10083793, 28475525, 1649722, + 20654025, 16520125, 30598449, 7715701}, + {28881845, 14381568, 9657904, 3680757, -20181635, 7843316, + -31400660, 1370708, 29794553, -1409300}, }, { - { 14499471, -2729599, -33191113, -4254652, 28494862, 14271267, 30290735, 10876454, -33154098, 2381726 }, - { -7195431, -2655363, -14730155, 462251, -27724326, 3941372, -6236617, 3696005, -32300832, 15351955 }, - { 27431194, 8222322, 16448760, -3907995, -18707002, 11938355, -32961401, -2970515, 29551813, 10109425 }, + {14499471, -2729599, -33191113, -4254652, 28494862, 14271267, + 30290735, 10876454, -33154098, 2381726}, + {-7195431, -2655363, -14730155, 462251, -27724326, 3941372, + -6236617, 3696005, -32300832, 15351955}, + {27431194, 8222322, 16448760, -3907995, -18707002, 11938355, + -32961401, -2970515, 29551813, 10109425}, }, }, { { - { -13657040, -13155431, -31283750, 11777098, 21447386, 6519384, -2378284, -1627556, 10092783, -4764171 }, - { 27939166, 14210322, 4677035, 16277044, -22964462, -12398139, -32508754, 12005538, -17810127, 12803510 }, - { 17228999, -15661624, -1233527, 300140, -1224870, -11714777, 30364213, -9038194, 18016357, 4397660 }, + {-13657040, -13155431, -31283750, 11777098, 21447386, 6519384, + -2378284, -1627556, 10092783, -4764171}, + {27939166, 14210322, 4677035, 16277044, -22964462, -12398139, + -32508754, 12005538, -17810127, 12803510}, + {17228999, -15661624, -1233527, 300140, -1224870, -11714777, + 30364213, -9038194, 18016357, 4397660}, }, { - { -10958843, -7690207, 4776341, -14954238, 27850028, -15602212, -26619106, 14544525, -17477504, 982639 }, - { 29253598, 15796703, -2863982, -9908884, 10057023, 3163536, 7332899, -4120128, -21047696, 9934963 }, - { 5793303, 16271923, -24131614, -10116404, 29188560, 1206517, -14747930, 4559895, -30123922, -10897950 }, + {-10958843, -7690207, 4776341, -14954238, 27850028, -15602212, + -26619106, 14544525, -17477504, 982639}, + {29253598, 15796703, -2863982, -9908884, 10057023, 3163536, 7332899, + -4120128, -21047696, 9934963}, + {5793303, 16271923, -24131614, -10116404, 29188560, 1206517, + -14747930, 4559895, -30123922, -10897950}, }, { - { -27643952, -11493006, 16282657, -11036493, 28414021, -15012264, 24191034, 4541697, -13338309, 5500568 }, - { 12650548, -1497113, 9052871, 11355358, -17680037, -8400164, -17430592, 12264343, 10874051, 13524335 }, - { 25556948, -3045990, 714651, 2510400, 23394682, -10415330, 33119038, 5080568, -22528059, 5376628 }, + {-27643952, -11493006, 16282657, -11036493, 28414021, -15012264, + 24191034, 4541697, -13338309, 5500568}, + {12650548, -1497113, 9052871, 11355358, -17680037, -8400164, + -17430592, 12264343, 10874051, 13524335}, + {25556948, -3045990, 714651, 2510400, 23394682, -10415330, 33119038, + 5080568, -22528059, 5376628}, }, { - { -26088264, -4011052, -17013699, -3537628, -6726793, 1920897, -22321305, -9447443, 4535768, 1569007 }, - { -2255422, 14606630, -21692440, -8039818, 28430649, 8775819, -30494562, 3044290, 31848280, 12543772 }, - { -22028579, 2943893, -31857513, 6777306, 13784462, -4292203, -27377195, -2062731, 7718482, 14474653 }, + {-26088264, -4011052, -17013699, -3537628, -6726793, 1920897, + -22321305, -9447443, 4535768, 1569007}, + {-2255422, 14606630, -21692440, -8039818, 28430649, 8775819, + -30494562, 3044290, 31848280, 12543772}, + {-22028579, 2943893, -31857513, 6777306, 13784462, -4292203, + -27377195, -2062731, 7718482, 14474653}, }, { - { 2385315, 2454213, -22631320, 46603, -4437935, -15680415, 656965, -7236665, 24316168, -5253567 }, - { 13741529, 10911568, -33233417, -8603737, -20177830, -1033297, 33040651, -13424532, -20729456, 8321686 }, - { 21060490, -2212744, 15712757, -4336099, 1639040, 10656336, 23845965, -11874838, -9984458, 608372 }, + {2385315, 2454213, -22631320, 46603, -4437935, -15680415, 656965, + -7236665, 24316168, -5253567}, + {13741529, 10911568, -33233417, -8603737, -20177830, -1033297, + 33040651, -13424532, -20729456, 8321686}, + {21060490, -2212744, 15712757, -4336099, 1639040, 10656336, + 23845965, -11874838, -9984458, 608372}, }, { - { -13672732, -15087586, -10889693, -7557059, -6036909, 11305547, 1123968, -6780577, 27229399, 23887 }, - { -23244140, -294205, -11744728, 14712571, -29465699, -2029617, 12797024, -6440308, -1633405, 16678954 }, - { -29500620, 4770662, -16054387, 14001338, 7830047, 9564805, -1508144, -4795045, -17169265, 4904953 }, + {-13672732, -15087586, -10889693, -7557059, -6036909, 11305547, + 1123968, -6780577, 27229399, 23887}, + {-23244140, -294205, -11744728, 14712571, -29465699, -2029617, + 12797024, -6440308, -1633405, 16678954}, + {-29500620, 4770662, -16054387, 14001338, 7830047, 9564805, + -1508144, -4795045, -17169265, 4904953}, }, { - { 24059557, 14617003, 19037157, -15039908, 19766093, -14906429, 5169211, 16191880, 2128236, -4326833 }, - { -16981152, 4124966, -8540610, -10653797, 30336522, -14105247, -29806336, 916033, -6882542, -2986532 }, - { -22630907, 12419372, -7134229, -7473371, -16478904, 16739175, 285431, 2763829, 15736322, 4143876 }, + {24059557, 14617003, 19037157, -15039908, 19766093, -14906429, + 5169211, 16191880, 2128236, -4326833}, + {-16981152, 4124966, -8540610, -10653797, 30336522, -14105247, + -29806336, 916033, -6882542, -2986532}, + {-22630907, 12419372, -7134229, -7473371, -16478904, 16739175, + 285431, 2763829, 15736322, 4143876}, }, { - { 2379352, 11839345, -4110402, -5988665, 11274298, 794957, 212801, -14594663, 23527084, -16458268 }, - { 33431127, -11130478, -17838966, -15626900, 8909499, 8376530, -32625340, 4087881, -15188911, -14416214 }, - { 1767683, 7197987, -13205226, -2022635, -13091350, 448826, 5799055, 4357868, -4774191, -16323038 }, + {2379352, 11839345, -4110402, -5988665, 11274298, 794957, 212801, + -14594663, 23527084, -16458268}, + {33431127, -11130478, -17838966, -15626900, 8909499, 8376530, + -32625340, 4087881, -15188911, -14416214}, + {1767683, 7197987, -13205226, -2022635, -13091350, 448826, 5799055, + 4357868, -4774191, -16323038}, }, }, { { - { 6721966, 13833823, -23523388, -1551314, 26354293, -11863321, 23365147, -3949732, 7390890, 2759800 }, - { 4409041, 2052381, 23373853, 10530217, 7676779, -12885954, 21302353, -4264057, 1244380, -12919645 }, - { -4421239, 7169619, 4982368, -2957590, 30256825, -2777540, 14086413, 9208236, 15886429, 16489664 }, + {6721966, 13833823, -23523388, -1551314, 26354293, -11863321, + 23365147, -3949732, 7390890, 2759800}, + {4409041, 2052381, 23373853, 10530217, 7676779, -12885954, 21302353, + -4264057, 1244380, -12919645}, + {-4421239, 7169619, 4982368, -2957590, 30256825, -2777540, 14086413, + 9208236, 15886429, 16489664}, }, { - { 1996075, 10375649, 14346367, 13311202, -6874135, -16438411, -13693198, 398369, -30606455, -712933 }, - { -25307465, 9795880, -2777414, 14878809, -33531835, 14780363, 13348553, 12076947, -30836462, 5113182 }, - { -17770784, 11797796, 31950843, 13929123, -25888302, 12288344, -30341101, -7336386, 13847711, 5387222 }, + {1996075, 10375649, 14346367, 13311202, -6874135, -16438411, + -13693198, 398369, -30606455, -712933}, + {-25307465, 9795880, -2777414, 14878809, -33531835, 14780363, + 13348553, 12076947, -30836462, 5113182}, + {-17770784, 11797796, 31950843, 13929123, -25888302, 12288344, + -30341101, -7336386, 13847711, 5387222}, }, { - { -18582163, -3416217, 17824843, -2340966, 22744343, -10442611, 8763061, 3617786, -19600662, 10370991 }, - { 20246567, -14369378, 22358229, -543712, 18507283, -10413996, 14554437, -8746092, 32232924, 16763880 }, - { 9648505, 10094563, 26416693, 14745928, -30374318, -6472621, 11094161, 15689506, 3140038, -16510092 }, + {-18582163, -3416217, 17824843, -2340966, 22744343, -10442611, + 8763061, 3617786, -19600662, 10370991}, + {20246567, -14369378, 22358229, -543712, 18507283, -10413996, + 14554437, -8746092, 32232924, 16763880}, + {9648505, 10094563, 26416693, 14745928, -30374318, -6472621, + 11094161, 15689506, 3140038, -16510092}, }, { - { -16160072, 5472695, 31895588, 4744994, 8823515, 10365685, -27224800, 9448613, -28774454, 366295 }, - { 19153450, 11523972, -11096490, -6503142, -24647631, 5420647, 28344573, 8041113, 719605, 11671788 }, - { 8678025, 2694440, -6808014, 2517372, 4964326, 11152271, -15432916, -15266516, 27000813, -10195553 }, + {-16160072, 5472695, 31895588, 4744994, 8823515, 10365685, + -27224800, 9448613, -28774454, 366295}, + {19153450, 11523972, -11096490, -6503142, -24647631, 5420647, + 28344573, 8041113, 719605, 11671788}, + {8678025, 2694440, -6808014, 2517372, 4964326, 11152271, -15432916, + -15266516, 27000813, -10195553}, }, { - { -15157904, 7134312, 8639287, -2814877, -7235688, 10421742, 564065, 5336097, 6750977, -14521026 }, - { 11836410, -3979488, 26297894, 16080799, 23455045, 15735944, 1695823, -8819122, 8169720, 16220347 }, - { -18115838, 8653647, 17578566, -6092619, -8025777, -16012763, -11144307, -2627664, -5990708, -14166033 }, + {-15157904, 7134312, 8639287, -2814877, -7235688, 10421742, 564065, + 5336097, 6750977, -14521026}, + {11836410, -3979488, 26297894, 16080799, 23455045, 15735944, + 1695823, -8819122, 8169720, 16220347}, + {-18115838, 8653647, 17578566, -6092619, -8025777, -16012763, + -11144307, -2627664, -5990708, -14166033}, }, { - { -23308498, -10968312, 15213228, -10081214, -30853605, -11050004, 27884329, 2847284, 2655861, 1738395 }, - { -27537433, -14253021, -25336301, -8002780, -9370762, 8129821, 21651608, -3239336, -19087449, -11005278 }, - { 1533110, 3437855, 23735889, 459276, 29970501, 11335377, 26030092, 5821408, 10478196, 8544890 }, + {-23308498, -10968312, 15213228, -10081214, -30853605, -11050004, + 27884329, 2847284, 2655861, 1738395}, + {-27537433, -14253021, -25336301, -8002780, -9370762, 8129821, + 21651608, -3239336, -19087449, -11005278}, + {1533110, 3437855, 23735889, 459276, 29970501, 11335377, 26030092, + 5821408, 10478196, 8544890}, }, { - { 32173121, -16129311, 24896207, 3921497, 22579056, -3410854, 19270449, 12217473, 17789017, -3395995 }, - { -30552961, -2228401, -15578829, -10147201, 13243889, 517024, 15479401, -3853233, 30460520, 1052596 }, - { -11614875, 13323618, 32618793, 8175907, -15230173, 12596687, 27491595, -4612359, 3179268, -9478891 }, + {32173121, -16129311, 24896207, 3921497, 22579056, -3410854, + 19270449, 12217473, 17789017, -3395995}, + {-30552961, -2228401, -15578829, -10147201, 13243889, 517024, + 15479401, -3853233, 30460520, 1052596}, + {-11614875, 13323618, 32618793, 8175907, -15230173, 12596687, + 27491595, -4612359, 3179268, -9478891}, }, { - { 31947069, -14366651, -4640583, -15339921, -15125977, -6039709, -14756777, -16411740, 19072640, -9511060 }, - { 11685058, 11822410, 3158003, -13952594, 33402194, -4165066, 5977896, -5215017, 473099, 5040608 }, - { -20290863, 8198642, -27410132, 11602123, 1290375, -2799760, 28326862, 1721092, -19558642, -3131606 }, + {31947069, -14366651, -4640583, -15339921, -15125977, -6039709, + -14756777, -16411740, 19072640, -9511060}, + {11685058, 11822410, 3158003, -13952594, 33402194, -4165066, + 5977896, -5215017, 473099, 5040608}, + {-20290863, 8198642, -27410132, 11602123, 1290375, -2799760, + 28326862, 1721092, -19558642, -3131606}, }, }, { { - { 7881532, 10687937, 7578723, 7738378, -18951012, -2553952, 21820786, 8076149, -27868496, 11538389 }, - { -19935666, 3899861, 18283497, -6801568, -15728660, -11249211, 8754525, 7446702, -5676054, 5797016 }, - { -11295600, -3793569, -15782110, -7964573, 12708869, -8456199, 2014099, -9050574, -2369172, -5877341 }, + {7881532, 10687937, 7578723, 7738378, -18951012, -2553952, 21820786, + 8076149, -27868496, 11538389}, + {-19935666, 3899861, 18283497, -6801568, -15728660, -11249211, + 8754525, 7446702, -5676054, 5797016}, + {-11295600, -3793569, -15782110, -7964573, 12708869, -8456199, + 2014099, -9050574, -2369172, -5877341}, }, { - { -22472376, -11568741, -27682020, 1146375, 18956691, 16640559, 1192730, -3714199, 15123619, 10811505 }, - { 14352098, -3419715, -18942044, 10822655, 32750596, 4699007, -70363, 15776356, -28886779, -11974553 }, - { -28241164, -8072475, -4978962, -5315317, 29416931, 1847569, -20654173, -16484855, 4714547, -9600655 }, + {-22472376, -11568741, -27682020, 1146375, 18956691, 16640559, + 1192730, -3714199, 15123619, 10811505}, + {14352098, -3419715, -18942044, 10822655, 32750596, 4699007, -70363, + 15776356, -28886779, -11974553}, + {-28241164, -8072475, -4978962, -5315317, 29416931, 1847569, + -20654173, -16484855, 4714547, -9600655}, }, { - { 15200332, 8368572, 19679101, 15970074, -31872674, 1959451, 24611599, -4543832, -11745876, 12340220 }, - { 12876937, -10480056, 33134381, 6590940, -6307776, 14872440, 9613953, 8241152, 15370987, 9608631 }, - { -4143277, -12014408, 8446281, -391603, 4407738, 13629032, -7724868, 15866074, -28210621, -8814099 }, + {15200332, 8368572, 19679101, 15970074, -31872674, 1959451, + 24611599, -4543832, -11745876, 12340220}, + {12876937, -10480056, 33134381, 6590940, -6307776, 14872440, + 9613953, 8241152, 15370987, 9608631}, + {-4143277, -12014408, 8446281, -391603, 4407738, 13629032, -7724868, + 15866074, -28210621, -8814099}, }, { - { 26660628, -15677655, 8393734, 358047, -7401291, 992988, -23904233, 858697, 20571223, 8420556 }, - { 14620715, 13067227, -15447274, 8264467, 14106269, 15080814, 33531827, 12516406, -21574435, -12476749 }, - { 236881, 10476226, 57258, -14677024, 6472998, 2466984, 17258519, 7256740, 8791136, 15069930 }, + {26660628, -15677655, 8393734, 358047, -7401291, 992988, -23904233, + 858697, 20571223, 8420556}, + {14620715, 13067227, -15447274, 8264467, 14106269, 15080814, + 33531827, 12516406, -21574435, -12476749}, + {236881, 10476226, 57258, -14677024, 6472998, 2466984, 17258519, + 7256740, 8791136, 15069930}, }, { - { 1276410, -9371918, 22949635, -16322807, -23493039, -5702186, 14711875, 4874229, -30663140, -2331391 }, - { 5855666, 4990204, -13711848, 7294284, -7804282, 1924647, -1423175, -7912378, -33069337, 9234253 }, - { 20590503, -9018988, 31529744, -7352666, -2706834, 10650548, 31559055, -11609587, 18979186, 13396066 }, + {1276410, -9371918, 22949635, -16322807, -23493039, -5702186, + 14711875, 4874229, -30663140, -2331391}, + {5855666, 4990204, -13711848, 7294284, -7804282, 1924647, -1423175, + -7912378, -33069337, 9234253}, + {20590503, -9018988, 31529744, -7352666, -2706834, 10650548, + 31559055, -11609587, 18979186, 13396066}, }, { - { 24474287, 4968103, 22267082, 4407354, 24063882, -8325180, -18816887, 13594782, 33514650, 7021958 }, - { -11566906, -6565505, -21365085, 15928892, -26158305, 4315421, -25948728, -3916677, -21480480, 12868082 }, - { -28635013, 13504661, 19988037, -2132761, 21078225, 6443208, -21446107, 2244500, -12455797, -8089383 }, + {24474287, 4968103, 22267082, 4407354, 24063882, -8325180, + -18816887, 13594782, 33514650, 7021958}, + {-11566906, -6565505, -21365085, 15928892, -26158305, 4315421, + -25948728, -3916677, -21480480, 12868082}, + {-28635013, 13504661, 19988037, -2132761, 21078225, 6443208, + -21446107, 2244500, -12455797, -8089383}, }, { - { -30595528, 13793479, -5852820, 319136, -25723172, -6263899, 33086546, 8957937, -15233648, 5540521 }, - { -11630176, -11503902, -8119500, -7643073, 2620056, 1022908, -23710744, -1568984, -16128528, -14962807 }, - { 23152971, 775386, 27395463, 14006635, -9701118, 4649512, 1689819, 892185, -11513277, -15205948 }, + {-30595528, 13793479, -5852820, 319136, -25723172, -6263899, + 33086546, 8957937, -15233648, 5540521}, + {-11630176, -11503902, -8119500, -7643073, 2620056, 1022908, + -23710744, -1568984, -16128528, -14962807}, + {23152971, 775386, 27395463, 14006635, -9701118, 4649512, 1689819, + 892185, -11513277, -15205948}, }, { - { 9770129, 9586738, 26496094, 4324120, 1556511, -3550024, 27453819, 4763127, -19179614, 5867134 }, - { -32765025, 1927590, 31726409, -4753295, 23962434, -16019500, 27846559, 5931263, -29749703, -16108455 }, - { 27461885, -2977536, 22380810, 1815854, -23033753, -3031938, 7283490, -15148073, -19526700, 7734629 }, + {9770129, 9586738, 26496094, 4324120, 1556511, -3550024, 27453819, + 4763127, -19179614, 5867134}, + {-32765025, 1927590, 31726409, -4753295, 23962434, -16019500, + 27846559, 5931263, -29749703, -16108455}, + {27461885, -2977536, 22380810, 1815854, -23033753, -3031938, + 7283490, -15148073, -19526700, 7734629}, }, }, { { - { -8010264, -9590817, -11120403, 6196038, 29344158, -13430885, 7585295, -3176626, 18549497, 15302069 }, - { -32658337, -6171222, -7672793, -11051681, 6258878, 13504381, 10458790, -6418461, -8872242, 8424746 }, - { 24687205, 8613276, -30667046, -3233545, 1863892, -1830544, 19206234, 7134917, -11284482, -828919 }, + {-8010264, -9590817, -11120403, 6196038, 29344158, -13430885, + 7585295, -3176626, 18549497, 15302069}, + {-32658337, -6171222, -7672793, -11051681, 6258878, 13504381, + 10458790, -6418461, -8872242, 8424746}, + {24687205, 8613276, -30667046, -3233545, 1863892, -1830544, + 19206234, 7134917, -11284482, -828919}, }, { - { 11334899, -9218022, 8025293, 12707519, 17523892, -10476071, 10243738, -14685461, -5066034, 16498837 }, - { 8911542, 6887158, -9584260, -6958590, 11145641, -9543680, 17303925, -14124238, 6536641, 10543906 }, - { -28946384, 15479763, -17466835, 568876, -1497683, 11223454, -2669190, -16625574, -27235709, 8876771 }, + {11334899, -9218022, 8025293, 12707519, 17523892, -10476071, + 10243738, -14685461, -5066034, 16498837}, + {8911542, 6887158, -9584260, -6958590, 11145641, -9543680, 17303925, + -14124238, 6536641, 10543906}, + {-28946384, 15479763, -17466835, 568876, -1497683, 11223454, + -2669190, -16625574, -27235709, 8876771}, }, { - { -25742899, -12566864, -15649966, -846607, -33026686, -796288, -33481822, 15824474, -604426, -9039817 }, - { 10330056, 70051, 7957388, -9002667, 9764902, 15609756, 27698697, -4890037, 1657394, 3084098 }, - { 10477963, -7470260, 12119566, -13250805, 29016247, -5365589, 31280319, 14396151, -30233575, 15272409 }, + {-25742899, -12566864, -15649966, -846607, -33026686, -796288, + -33481822, 15824474, -604426, -9039817}, + {10330056, 70051, 7957388, -9002667, 9764902, 15609756, 27698697, + -4890037, 1657394, 3084098}, + {10477963, -7470260, 12119566, -13250805, 29016247, -5365589, + 31280319, 14396151, -30233575, 15272409}, }, { - { -12288309, 3169463, 28813183, 16658753, 25116432, -5630466, -25173957, -12636138, -25014757, 1950504 }, - { -26180358, 9489187, 11053416, -14746161, -31053720, 5825630, -8384306, -8767532, 15341279, 8373727 }, - { 28685821, 7759505, -14378516, -12002860, -31971820, 4079242, 298136, -10232602, -2878207, 15190420 }, + {-12288309, 3169463, 28813183, 16658753, 25116432, -5630466, + -25173957, -12636138, -25014757, 1950504}, + {-26180358, 9489187, 11053416, -14746161, -31053720, 5825630, + -8384306, -8767532, 15341279, 8373727}, + {28685821, 7759505, -14378516, -12002860, -31971820, 4079242, + 298136, -10232602, -2878207, 15190420}, }, { - { -32932876, 13806336, -14337485, -15794431, -24004620, 10940928, 8669718, 2742393, -26033313, -6875003 }, - { -1580388, -11729417, -25979658, -11445023, -17411874, -10912854, 9291594, -16247779, -12154742, 6048605 }, - { -30305315, 14843444, 1539301, 11864366, 20201677, 1900163, 13934231, 5128323, 11213262, 9168384 }, + {-32932876, 13806336, -14337485, -15794431, -24004620, 10940928, + 8669718, 2742393, -26033313, -6875003}, + {-1580388, -11729417, -25979658, -11445023, -17411874, -10912854, + 9291594, -16247779, -12154742, 6048605}, + {-30305315, 14843444, 1539301, 11864366, 20201677, 1900163, + 13934231, 5128323, 11213262, 9168384}, }, { - { -26280513, 11007847, 19408960, -940758, -18592965, -4328580, -5088060, -11105150, 20470157, -16398701 }, - { -23136053, 9282192, 14855179, -15390078, -7362815, -14408560, -22783952, 14461608, 14042978, 5230683 }, - { 29969567, -2741594, -16711867, -8552442, 9175486, -2468974, 21556951, 3506042, -5933891, -12449708 }, + {-26280513, 11007847, 19408960, -940758, -18592965, -4328580, + -5088060, -11105150, 20470157, -16398701}, + {-23136053, 9282192, 14855179, -15390078, -7362815, -14408560, + -22783952, 14461608, 14042978, 5230683}, + {29969567, -2741594, -16711867, -8552442, 9175486, -2468974, + 21556951, 3506042, -5933891, -12449708}, }, { - { -3144746, 8744661, 19704003, 4581278, -20430686, 6830683, -21284170, 8971513, -28539189, 15326563 }, - { -19464629, 10110288, -17262528, -3503892, -23500387, 1355669, -15523050, 15300988, -20514118, 9168260 }, - { -5353335, 4488613, -23803248, 16314347, 7780487, -15638939, -28948358, 9601605, 33087103, -9011387 }, + {-3144746, 8744661, 19704003, 4581278, -20430686, 6830683, + -21284170, 8971513, -28539189, 15326563}, + {-19464629, 10110288, -17262528, -3503892, -23500387, 1355669, + -15523050, 15300988, -20514118, 9168260}, + {-5353335, 4488613, -23803248, 16314347, 7780487, -15638939, + -28948358, 9601605, 33087103, -9011387}, }, { - { -19443170, -15512900, -20797467, -12445323, -29824447, 10229461, -27444329, -15000531, -5996870, 15664672 }, - { 23294591, -16632613, -22650781, -8470978, 27844204, 11461195, 13099750, -2460356, 18151676, 13417686 }, - { -24722913, -4176517, -31150679, 5988919, -26858785, 6685065, 1661597, -12551441, 15271676, -15452665 }, + {-19443170, -15512900, -20797467, -12445323, -29824447, 10229461, + -27444329, -15000531, -5996870, 15664672}, + {23294591, -16632613, -22650781, -8470978, 27844204, 11461195, + 13099750, -2460356, 18151676, 13417686}, + {-24722913, -4176517, -31150679, 5988919, -26858785, 6685065, + 1661597, -12551441, 15271676, -15452665}, }, }, { { - { 11433042, -13228665, 8239631, -5279517, -1985436, -725718, -18698764, 2167544, -6921301, -13440182 }, - { -31436171, 15575146, 30436815, 12192228, -22463353, 9395379, -9917708, -8638997, 12215110, 12028277 }, - { 14098400, 6555944, 23007258, 5757252, -15427832, -12950502, 30123440, 4617780, -16900089, -655628 }, + {11433042, -13228665, 8239631, -5279517, -1985436, -725718, + -18698764, 2167544, -6921301, -13440182}, + {-31436171, 15575146, 30436815, 12192228, -22463353, 9395379, + -9917708, -8638997, 12215110, 12028277}, + {14098400, 6555944, 23007258, 5757252, -15427832, -12950502, + 30123440, 4617780, -16900089, -655628}, }, { - { -4026201, -15240835, 11893168, 13718664, -14809462, 1847385, -15819999, 10154009, 23973261, -12684474 }, - { -26531820, -3695990, -1908898, 2534301, -31870557, -16550355, 18341390, -11419951, 32013174, -10103539 }, - { -25479301, 10876443, -11771086, -14625140, -12369567, 1838104, 21911214, 6354752, 4425632, -837822 }, + {-4026201, -15240835, 11893168, 13718664, -14809462, 1847385, + -15819999, 10154009, 23973261, -12684474}, + {-26531820, -3695990, -1908898, 2534301, -31870557, -16550355, + 18341390, -11419951, 32013174, -10103539}, + {-25479301, 10876443, -11771086, -14625140, -12369567, 1838104, + 21911214, 6354752, 4425632, -837822}, }, { - { -10433389, -14612966, 22229858, -3091047, -13191166, 776729, -17415375, -12020462, 4725005, 14044970 }, - { 19268650, -7304421, 1555349, 8692754, -21474059, -9910664, 6347390, -1411784, -19522291, -16109756 }, - { -24864089, 12986008, -10898878, -5558584, -11312371, -148526, 19541418, 8180106, 9282262, 10282508 }, + {-10433389, -14612966, 22229858, -3091047, -13191166, 776729, + -17415375, -12020462, 4725005, 14044970}, + {19268650, -7304421, 1555349, 8692754, -21474059, -9910664, 6347390, + -1411784, -19522291, -16109756}, + {-24864089, 12986008, -10898878, -5558584, -11312371, -148526, + 19541418, 8180106, 9282262, 10282508}, }, { - { -26205082, 4428547, -8661196, -13194263, 4098402, -14165257, 15522535, 8372215, 5542595, -10702683 }, - { -10562541, 14895633, 26814552, -16673850, -17480754, -2489360, -2781891, 6993761, -18093885, 10114655 }, - { -20107055, -929418, 31422704, 10427861, -7110749, 6150669, -29091755, -11529146, 25953725, -106158 }, + {-26205082, 4428547, -8661196, -13194263, 4098402, -14165257, + 15522535, 8372215, 5542595, -10702683}, + {-10562541, 14895633, 26814552, -16673850, -17480754, -2489360, + -2781891, 6993761, -18093885, 10114655}, + {-20107055, -929418, 31422704, 10427861, -7110749, 6150669, + -29091755, -11529146, 25953725, -106158}, }, { - { -4234397, -8039292, -9119125, 3046000, 2101609, -12607294, 19390020, 6094296, -3315279, 12831125 }, - { -15998678, 7578152, 5310217, 14408357, -33548620, -224739, 31575954, 6326196, 7381791, -2421839 }, - { -20902779, 3296811, 24736065, -16328389, 18374254, 7318640, 6295303, 8082724, -15362489, 12339664 }, + {-4234397, -8039292, -9119125, 3046000, 2101609, -12607294, + 19390020, 6094296, -3315279, 12831125}, + {-15998678, 7578152, 5310217, 14408357, -33548620, -224739, + 31575954, 6326196, 7381791, -2421839}, + {-20902779, 3296811, 24736065, -16328389, 18374254, 7318640, + 6295303, 8082724, -15362489, 12339664}, }, { - { 27724736, 2291157, 6088201, -14184798, 1792727, 5857634, 13848414, 15768922, 25091167, 14856294 }, - { -18866652, 8331043, 24373479, 8541013, -701998, -9269457, 12927300, -12695493, -22182473, -9012899 }, - { -11423429, -5421590, 11632845, 3405020, 30536730, -11674039, -27260765, 13866390, 30146206, 9142070 }, + {27724736, 2291157, 6088201, -14184798, 1792727, 5857634, 13848414, + 15768922, 25091167, 14856294}, + {-18866652, 8331043, 24373479, 8541013, -701998, -9269457, 12927300, + -12695493, -22182473, -9012899}, + {-11423429, -5421590, 11632845, 3405020, 30536730, -11674039, + -27260765, 13866390, 30146206, 9142070}, }, { - { 3924129, -15307516, -13817122, -10054960, 12291820, -668366, -27702774, 9326384, -8237858, 4171294 }, - { -15921940, 16037937, 6713787, 16606682, -21612135, 2790944, 26396185, 3731949, 345228, -5462949 }, - { -21327538, 13448259, 25284571, 1143661, 20614966, -8849387, 2031539, -12391231, -16253183, -13582083 }, + {3924129, -15307516, -13817122, -10054960, 12291820, -668366, + -27702774, 9326384, -8237858, 4171294}, + {-15921940, 16037937, 6713787, 16606682, -21612135, 2790944, + 26396185, 3731949, 345228, -5462949}, + {-21327538, 13448259, 25284571, 1143661, 20614966, -8849387, + 2031539, -12391231, -16253183, -13582083}, }, { - { 31016211, -16722429, 26371392, -14451233, -5027349, 14854137, 17477601, 3842657, 28012650, -16405420 }, - { -5075835, 9368966, -8562079, -4600902, -15249953, 6970560, -9189873, 16292057, -8867157, 3507940 }, - { 29439664, 3537914, 23333589, 6997794, -17555561, -11018068, -15209202, -15051267, -9164929, 6580396 }, + {31016211, -16722429, 26371392, -14451233, -5027349, 14854137, + 17477601, 3842657, 28012650, -16405420}, + {-5075835, 9368966, -8562079, -4600902, -15249953, 6970560, + -9189873, 16292057, -8867157, 3507940}, + {29439664, 3537914, 23333589, 6997794, -17555561, -11018068, + -15209202, -15051267, -9164929, 6580396}, }, }, { { - { -12185861, -7679788, 16438269, 10826160, -8696817, -6235611, 17860444, -9273846, -2095802, 9304567 }, - { 20714564, -4336911, 29088195, 7406487, 11426967, -5095705, 14792667, -14608617, 5289421, -477127 }, - { -16665533, -10650790, -6160345, -13305760, 9192020, -1802462, 17271490, 12349094, 26939669, -3752294 }, + {-12185861, -7679788, 16438269, 10826160, -8696817, -6235611, + 17860444, -9273846, -2095802, 9304567}, + {20714564, -4336911, 29088195, 7406487, 11426967, -5095705, + 14792667, -14608617, 5289421, -477127}, + {-16665533, -10650790, -6160345, -13305760, 9192020, -1802462, + 17271490, 12349094, 26939669, -3752294}, }, { - { -12889898, 9373458, 31595848, 16374215, 21471720, 13221525, -27283495, -12348559, -3698806, 117887 }, - { 22263325, -6560050, 3984570, -11174646, -15114008, -566785, 28311253, 5358056, -23319780, 541964 }, - { 16259219, 3261970, 2309254, -15534474, -16885711, -4581916, 24134070, -16705829, -13337066, -13552195 }, + {-12889898, 9373458, 31595848, 16374215, 21471720, 13221525, + -27283495, -12348559, -3698806, 117887}, + {22263325, -6560050, 3984570, -11174646, -15114008, -566785, + 28311253, 5358056, -23319780, 541964}, + {16259219, 3261970, 2309254, -15534474, -16885711, -4581916, + 24134070, -16705829, -13337066, -13552195}, }, { - { 9378160, -13140186, -22845982, -12745264, 28198281, -7244098, -2399684, -717351, 690426, 14876244 }, - { 24977353, -314384, -8223969, -13465086, 28432343, -1176353, -13068804, -12297348, -22380984, 6618999 }, - { -1538174, 11685646, 12944378, 13682314, -24389511, -14413193, 8044829, -13817328, 32239829, -5652762 }, + {9378160, -13140186, -22845982, -12745264, 28198281, -7244098, + -2399684, -717351, 690426, 14876244}, + {24977353, -314384, -8223969, -13465086, 28432343, -1176353, + -13068804, -12297348, -22380984, 6618999}, + {-1538174, 11685646, 12944378, 13682314, -24389511, -14413193, + 8044829, -13817328, 32239829, -5652762}, }, { - { -18603066, 4762990, -926250, 8885304, -28412480, -3187315, 9781647, -10350059, 32779359, 5095274 }, - { -33008130, -5214506, -32264887, -3685216, 9460461, -9327423, -24601656, 14506724, 21639561, -2630236 }, - { -16400943, -13112215, 25239338, 15531969, 3987758, -4499318, -1289502, -6863535, 17874574, 558605 }, + {-18603066, 4762990, -926250, 8885304, -28412480, -3187315, 9781647, + -10350059, 32779359, 5095274}, + {-33008130, -5214506, -32264887, -3685216, 9460461, -9327423, + -24601656, 14506724, 21639561, -2630236}, + {-16400943, -13112215, 25239338, 15531969, 3987758, -4499318, + -1289502, -6863535, 17874574, 558605}, }, { - { -13600129, 10240081, 9171883, 16131053, -20869254, 9599700, 33499487, 5080151, 2085892, 5119761 }, - { -22205145, -2519528, -16381601, 414691, -25019550, 2170430, 30634760, -8363614, -31999993, -5759884 }, - { -6845704, 15791202, 8550074, -1312654, 29928809, -12092256, 27534430, -7192145, -22351378, 12961482 }, + {-13600129, 10240081, 9171883, 16131053, -20869254, 9599700, + 33499487, 5080151, 2085892, 5119761}, + {-22205145, -2519528, -16381601, 414691, -25019550, 2170430, + 30634760, -8363614, -31999993, -5759884}, + {-6845704, 15791202, 8550074, -1312654, 29928809, -12092256, + 27534430, -7192145, -22351378, 12961482}, }, { - { -24492060, -9570771, 10368194, 11582341, -23397293, -2245287, 16533930, 8206996, -30194652, -5159638 }, - { -11121496, -3382234, 2307366, 6362031, -135455, 8868177, -16835630, 7031275, 7589640, 8945490 }, - { -32152748, 8917967, 6661220, -11677616, -1192060, -15793393, 7251489, -11182180, 24099109, -14456170 }, + {-24492060, -9570771, 10368194, 11582341, -23397293, -2245287, + 16533930, 8206996, -30194652, -5159638}, + {-11121496, -3382234, 2307366, 6362031, -135455, 8868177, -16835630, + 7031275, 7589640, 8945490}, + {-32152748, 8917967, 6661220, -11677616, -1192060, -15793393, + 7251489, -11182180, 24099109, -14456170}, }, { - { 5019558, -7907470, 4244127, -14714356, -26933272, 6453165, -19118182, -13289025, -6231896, -10280736 }, - { 10853594, 10721687, 26480089, 5861829, -22995819, 1972175, -1866647, -10557898, -3363451, -6441124 }, - { -17002408, 5906790, 221599, -6563147, 7828208, -13248918, 24362661, -2008168, -13866408, 7421392 }, + {5019558, -7907470, 4244127, -14714356, -26933272, 6453165, + -19118182, -13289025, -6231896, -10280736}, + {10853594, 10721687, 26480089, 5861829, -22995819, 1972175, + -1866647, -10557898, -3363451, -6441124}, + {-17002408, 5906790, 221599, -6563147, 7828208, -13248918, 24362661, + -2008168, -13866408, 7421392}, }, { - { 8139927, -6546497, 32257646, -5890546, 30375719, 1886181, -21175108, 15441252, 28826358, -4123029 }, - { 6267086, 9695052, 7709135, -16603597, -32869068, -1886135, 14795160, -7840124, 13746021, -1742048 }, - { 28584902, 7787108, -6732942, -15050729, 22846041, -7571236, -3181936, -363524, 4771362, -8419958 }, + {8139927, -6546497, 32257646, -5890546, 30375719, 1886181, + -21175108, 15441252, 28826358, -4123029}, + {6267086, 9695052, 7709135, -16603597, -32869068, -1886135, + 14795160, -7840124, 13746021, -1742048}, + {28584902, 7787108, -6732942, -15050729, 22846041, -7571236, + -3181936, -363524, 4771362, -8419958}, }, }, { { - { 24949256, 6376279, -27466481, -8174608, -18646154, -9930606, 33543569, -12141695, 3569627, 11342593 }, - { 26514989, 4740088, 27912651, 3697550, 19331575, -11472339, 6809886, 4608608, 7325975, -14801071 }, - { -11618399, -14554430, -24321212, 7655128, -1369274, 5214312, -27400540, 10258390, -17646694, -8186692 }, + {24949256, 6376279, -27466481, -8174608, -18646154, -9930606, + 33543569, -12141695, 3569627, 11342593}, + {26514989, 4740088, 27912651, 3697550, 19331575, -11472339, 6809886, + 4608608, 7325975, -14801071}, + {-11618399, -14554430, -24321212, 7655128, -1369274, 5214312, + -27400540, 10258390, -17646694, -8186692}, }, { - { 11431204, 15823007, 26570245, 14329124, 18029990, 4796082, -31446179, 15580664, 9280358, -3973687 }, - { -160783, -10326257, -22855316, -4304997, -20861367, -13621002, -32810901, -11181622, -15545091, 4387441 }, - { -20799378, 12194512, 3937617, -5805892, -27154820, 9340370, -24513992, 8548137, 20617071, -7482001 }, + {11431204, 15823007, 26570245, 14329124, 18029990, 4796082, + -31446179, 15580664, 9280358, -3973687}, + {-160783, -10326257, -22855316, -4304997, -20861367, -13621002, + -32810901, -11181622, -15545091, 4387441}, + {-20799378, 12194512, 3937617, -5805892, -27154820, 9340370, + -24513992, 8548137, 20617071, -7482001}, }, { - { -938825, -3930586, -8714311, 16124718, 24603125, -6225393, -13775352, -11875822, 24345683, 10325460 }, - { -19855277, -1568885, -22202708, 8714034, 14007766, 6928528, 16318175, -1010689, 4766743, 3552007 }, - { -21751364, -16730916, 1351763, -803421, -4009670, 3950935, 3217514, 14481909, 10988822, -3994762 }, + {-938825, -3930586, -8714311, 16124718, 24603125, -6225393, + -13775352, -11875822, 24345683, 10325460}, + {-19855277, -1568885, -22202708, 8714034, 14007766, 6928528, + 16318175, -1010689, 4766743, 3552007}, + {-21751364, -16730916, 1351763, -803421, -4009670, 3950935, 3217514, + 14481909, 10988822, -3994762}, }, { - { 15564307, -14311570, 3101243, 5684148, 30446780, -8051356, 12677127, -6505343, -8295852, 13296005 }, - { -9442290, 6624296, -30298964, -11913677, -4670981, -2057379, 31521204, 9614054, -30000824, 12074674 }, - { 4771191, -135239, 14290749, -13089852, 27992298, 14998318, -1413936, -1556716, 29832613, -16391035 }, + {15564307, -14311570, 3101243, 5684148, 30446780, -8051356, + 12677127, -6505343, -8295852, 13296005}, + {-9442290, 6624296, -30298964, -11913677, -4670981, -2057379, + 31521204, 9614054, -30000824, 12074674}, + {4771191, -135239, 14290749, -13089852, 27992298, 14998318, + -1413936, -1556716, 29832613, -16391035}, }, { - { 7064884, -7541174, -19161962, -5067537, -18891269, -2912736, 25825242, 5293297, -27122660, 13101590 }, - { -2298563, 2439670, -7466610, 1719965, -27267541, -16328445, 32512469, -5317593, -30356070, -4190957 }, - { -30006540, 10162316, -33180176, 3981723, -16482138, -13070044, 14413974, 9515896, 19568978, 9628812 }, + {7064884, -7541174, -19161962, -5067537, -18891269, -2912736, + 25825242, 5293297, -27122660, 13101590}, + {-2298563, 2439670, -7466610, 1719965, -27267541, -16328445, + 32512469, -5317593, -30356070, -4190957}, + {-30006540, 10162316, -33180176, 3981723, -16482138, -13070044, + 14413974, 9515896, 19568978, 9628812}, }, { - { 33053803, 199357, 15894591, 1583059, 27380243, -4580435, -17838894, -6106839, -6291786, 3437740 }, - { -18978877, 3884493, 19469877, 12726490, 15913552, 13614290, -22961733, 70104, 7463304, 4176122 }, - { -27124001, 10659917, 11482427, -16070381, 12771467, -6635117, -32719404, -5322751, 24216882, 5944158 }, + {33053803, 199357, 15894591, 1583059, 27380243, -4580435, -17838894, + -6106839, -6291786, 3437740}, + {-18978877, 3884493, 19469877, 12726490, 15913552, 13614290, + -22961733, 70104, 7463304, 4176122}, + {-27124001, 10659917, 11482427, -16070381, 12771467, -6635117, + -32719404, -5322751, 24216882, 5944158}, }, { - { 8894125, 7450974, -2664149, -9765752, -28080517, -12389115, 19345746, 14680796, 11632993, 5847885 }, - { 26942781, -2315317, 9129564, -4906607, 26024105, 11769399, -11518837, 6367194, -9727230, 4782140 }, - { 19916461, -4828410, -22910704, -11414391, 25606324, -5972441, 33253853, 8220911, 6358847, -1873857 }, + {8894125, 7450974, -2664149, -9765752, -28080517, -12389115, + 19345746, 14680796, 11632993, 5847885}, + {26942781, -2315317, 9129564, -4906607, 26024105, 11769399, + -11518837, 6367194, -9727230, 4782140}, + {19916461, -4828410, -22910704, -11414391, 25606324, -5972441, + 33253853, 8220911, 6358847, -1873857}, }, { - { 801428, -2081702, 16569428, 11065167, 29875704, 96627, 7908388, -4480480, -13538503, 1387155 }, - { 19646058, 5720633, -11416706, 12814209, 11607948, 12749789, 14147075, 15156355, -21866831, 11835260 }, - { 19299512, 1155910, 28703737, 14890794, 2925026, 7269399, 26121523, 15467869, -26560550, 5052483 }, + {801428, -2081702, 16569428, 11065167, 29875704, 96627, 7908388, + -4480480, -13538503, 1387155}, + {19646058, 5720633, -11416706, 12814209, 11607948, 12749789, + 14147075, 15156355, -21866831, 11835260}, + {19299512, 1155910, 28703737, 14890794, 2925026, 7269399, 26121523, + 15467869, -26560550, 5052483}, }, }, { { - { -3017432, 10058206, 1980837, 3964243, 22160966, 12322533, -6431123, -12618185, 12228557, -7003677 }, - { 32944382, 14922211, -22844894, 5188528, 21913450, -8719943, 4001465, 13238564, -6114803, 8653815 }, - { 22865569, -4652735, 27603668, -12545395, 14348958, 8234005, 24808405, 5719875, 28483275, 2841751 }, + {-3017432, 10058206, 1980837, 3964243, 22160966, 12322533, -6431123, + -12618185, 12228557, -7003677}, + {32944382, 14922211, -22844894, 5188528, 21913450, -8719943, + 4001465, 13238564, -6114803, 8653815}, + {22865569, -4652735, 27603668, -12545395, 14348958, 8234005, + 24808405, 5719875, 28483275, 2841751}, }, { - { -16420968, -1113305, -327719, -12107856, 21886282, -15552774, -1887966, -315658, 19932058, -12739203 }, - { -11656086, 10087521, -8864888, -5536143, -19278573, -3055912, 3999228, 13239134, -4777469, -13910208 }, - { 1382174, -11694719, 17266790, 9194690, -13324356, 9720081, 20403944, 11284705, -14013818, 3093230 }, + {-16420968, -1113305, -327719, -12107856, 21886282, -15552774, + -1887966, -315658, 19932058, -12739203}, + {-11656086, 10087521, -8864888, -5536143, -19278573, -3055912, + 3999228, 13239134, -4777469, -13910208}, + {1382174, -11694719, 17266790, 9194690, -13324356, 9720081, + 20403944, 11284705, -14013818, 3093230}, }, { - { 16650921, -11037932, -1064178, 1570629, -8329746, 7352753, -302424, 16271225, -24049421, -6691850 }, - { -21911077, -5927941, -4611316, -5560156, -31744103, -10785293, 24123614, 15193618, -21652117, -16739389 }, - { -9935934, -4289447, -25279823, 4372842, 2087473, 10399484, 31870908, 14690798, 17361620, 11864968 }, + {16650921, -11037932, -1064178, 1570629, -8329746, 7352753, -302424, + 16271225, -24049421, -6691850}, + {-21911077, -5927941, -4611316, -5560156, -31744103, -10785293, + 24123614, 15193618, -21652117, -16739389}, + {-9935934, -4289447, -25279823, 4372842, 2087473, 10399484, + 31870908, 14690798, 17361620, 11864968}, }, { - { -11307610, 6210372, 13206574, 5806320, -29017692, -13967200, -12331205, -7486601, -25578460, -16240689 }, - { 14668462, -12270235, 26039039, 15305210, 25515617, 4542480, 10453892, 6577524, 9145645, -6443880 }, - { 5974874, 3053895, -9433049, -10385191, -31865124, 3225009, -7972642, 3936128, -5652273, -3050304 }, + {-11307610, 6210372, 13206574, 5806320, -29017692, -13967200, + -12331205, -7486601, -25578460, -16240689}, + {14668462, -12270235, 26039039, 15305210, 25515617, 4542480, + 10453892, 6577524, 9145645, -6443880}, + {5974874, 3053895, -9433049, -10385191, -31865124, 3225009, + -7972642, 3936128, -5652273, -3050304}, }, { - { 30625386, -4729400, -25555961, -12792866, -20484575, 7695099, 17097188, -16303496, -27999779, 1803632 }, - { -3553091, 9865099, -5228566, 4272701, -5673832, -16689700, 14911344, 12196514, -21405489, 7047412 }, - { 20093277, 9920966, -11138194, -5343857, 13161587, 12044805, -32856851, 4124601, -32343828, -10257566 }, + {30625386, -4729400, -25555961, -12792866, -20484575, 7695099, + 17097188, -16303496, -27999779, 1803632}, + {-3553091, 9865099, -5228566, 4272701, -5673832, -16689700, + 14911344, 12196514, -21405489, 7047412}, + {20093277, 9920966, -11138194, -5343857, 13161587, 12044805, + -32856851, 4124601, -32343828, -10257566}, }, { - { -20788824, 14084654, -13531713, 7842147, 19119038, -13822605, 4752377, -8714640, -21679658, 2288038 }, - { -26819236, -3283715, 29965059, 3039786, -14473765, 2540457, 29457502, 14625692, -24819617, 12570232 }, - { -1063558, -11551823, 16920318, 12494842, 1278292, -5869109, -21159943, -3498680, -11974704, 4724943 }, + {-20788824, 14084654, -13531713, 7842147, 19119038, -13822605, + 4752377, -8714640, -21679658, 2288038}, + {-26819236, -3283715, 29965059, 3039786, -14473765, 2540457, + 29457502, 14625692, -24819617, 12570232}, + {-1063558, -11551823, 16920318, 12494842, 1278292, -5869109, + -21159943, -3498680, -11974704, 4724943}, }, { - { 17960970, -11775534, -4140968, -9702530, -8876562, -1410617, -12907383, -8659932, -29576300, 1903856 }, - { 23134274, -14279132, -10681997, -1611936, 20684485, 15770816, -12989750, 3190296, 26955097, 14109738 }, - { 15308788, 5320727, -30113809, -14318877, 22902008, 7767164, 29425325, -11277562, 31960942, 11934971 }, + {17960970, -11775534, -4140968, -9702530, -8876562, -1410617, + -12907383, -8659932, -29576300, 1903856}, + {23134274, -14279132, -10681997, -1611936, 20684485, 15770816, + -12989750, 3190296, 26955097, 14109738}, + {15308788, 5320727, -30113809, -14318877, 22902008, 7767164, + 29425325, -11277562, 31960942, 11934971}, }, { - { -27395711, 8435796, 4109644, 12222639, -24627868, 14818669, 20638173, 4875028, 10491392, 1379718 }, - { -13159415, 9197841, 3875503, -8936108, -1383712, -5879801, 33518459, 16176658, 21432314, 12180697 }, - { -11787308, 11500838, 13787581, -13832590, -22430679, 10140205, 1465425, 12689540, -10301319, -13872883 }, + {-27395711, 8435796, 4109644, 12222639, -24627868, 14818669, + 20638173, 4875028, 10491392, 1379718}, + {-13159415, 9197841, 3875503, -8936108, -1383712, -5879801, + 33518459, 16176658, 21432314, 12180697}, + {-11787308, 11500838, 13787581, -13832590, -22430679, 10140205, + 1465425, 12689540, -10301319, -13872883}, }, }, { { - { 5414091, -15386041, -21007664, 9643570, 12834970, 1186149, -2622916, -1342231, 26128231, 6032912 }, - { -26337395, -13766162, 32496025, -13653919, 17847801, -12669156, 3604025, 8316894, -25875034, -10437358 }, - { 3296484, 6223048, 24680646, -12246460, -23052020, 5903205, -8862297, -4639164, 12376617, 3188849 }, + {5414091, -15386041, -21007664, 9643570, 12834970, 1186149, + -2622916, -1342231, 26128231, 6032912}, + {-26337395, -13766162, 32496025, -13653919, 17847801, -12669156, + 3604025, 8316894, -25875034, -10437358}, + {3296484, 6223048, 24680646, -12246460, -23052020, 5903205, + -8862297, -4639164, 12376617, 3188849}, }, { - { 29190488, -14659046, 27549113, -1183516, 3520066, -10697301, 32049515, -7309113, -16109234, -9852307 }, - { -14744486, -9309156, 735818, -598978, -20407687, -5057904, 25246078, -15795669, 18640741, -960977 }, - { -6928835, -16430795, 10361374, 5642961, 4910474, 12345252, -31638386, -494430, 10530747, 1053335 }, + {29190488, -14659046, 27549113, -1183516, 3520066, -10697301, + 32049515, -7309113, -16109234, -9852307}, + {-14744486, -9309156, 735818, -598978, -20407687, -5057904, + 25246078, -15795669, 18640741, -960977}, + {-6928835, -16430795, 10361374, 5642961, 4910474, 12345252, + -31638386, -494430, 10530747, 1053335}, }, { - { -29265967, -14186805, -13538216, -12117373, -19457059, -10655384, -31462369, -2948985, 24018831, 15026644 }, - { -22592535, -3145277, -2289276, 5953843, -13440189, 9425631, 25310643, 13003497, -2314791, -15145616 }, - { -27419985, -603321, -8043984, -1669117, -26092265, 13987819, -27297622, 187899, -23166419, -2531735 }, + {-29265967, -14186805, -13538216, -12117373, -19457059, -10655384, + -31462369, -2948985, 24018831, 15026644}, + {-22592535, -3145277, -2289276, 5953843, -13440189, 9425631, + 25310643, 13003497, -2314791, -15145616}, + {-27419985, -603321, -8043984, -1669117, -26092265, 13987819, + -27297622, 187899, -23166419, -2531735}, }, { - { -21744398, -13810475, 1844840, 5021428, -10434399, -15911473, 9716667, 16266922, -5070217, 726099 }, - { 29370922, -6053998, 7334071, -15342259, 9385287, 2247707, -13661962, -4839461, 30007388, -15823341 }, - { -936379, 16086691, 23751945, -543318, -1167538, -5189036, 9137109, 730663, 9835848, 4555336 }, + {-21744398, -13810475, 1844840, 5021428, -10434399, -15911473, + 9716667, 16266922, -5070217, 726099}, + {29370922, -6053998, 7334071, -15342259, 9385287, 2247707, + -13661962, -4839461, 30007388, -15823341}, + {-936379, 16086691, 23751945, -543318, -1167538, -5189036, 9137109, + 730663, 9835848, 4555336}, }, { - { -23376435, 1410446, -22253753, -12899614, 30867635, 15826977, 17693930, 544696, -11985298, 12422646 }, - { 31117226, -12215734, -13502838, 6561947, -9876867, -12757670, -5118685, -4096706, 29120153, 13924425 }, - { -17400879, -14233209, 19675799, -2734756, -11006962, -5858820, -9383939, -11317700, 7240931, -237388 }, + {-23376435, 1410446, -22253753, -12899614, 30867635, 15826977, + 17693930, 544696, -11985298, 12422646}, + {31117226, -12215734, -13502838, 6561947, -9876867, -12757670, + -5118685, -4096706, 29120153, 13924425}, + {-17400879, -14233209, 19675799, -2734756, -11006962, -5858820, + -9383939, -11317700, 7240931, -237388}, }, { - { -31361739, -11346780, -15007447, -5856218, -22453340, -12152771, 1222336, 4389483, 3293637, -15551743 }, - { -16684801, -14444245, 11038544, 11054958, -13801175, -3338533, -24319580, 7733547, 12796905, -6335822 }, - { -8759414, -10817836, -25418864, 10783769, -30615557, -9746811, -28253339, 3647836, 3222231, -11160462 }, + {-31361739, -11346780, -15007447, -5856218, -22453340, -12152771, + 1222336, 4389483, 3293637, -15551743}, + {-16684801, -14444245, 11038544, 11054958, -13801175, -3338533, + -24319580, 7733547, 12796905, -6335822}, + {-8759414, -10817836, -25418864, 10783769, -30615557, -9746811, + -28253339, 3647836, 3222231, -11160462}, }, { - { 18606113, 1693100, -25448386, -15170272, 4112353, 10045021, 23603893, -2048234, -7550776, 2484985 }, - { 9255317, -3131197, -12156162, -1004256, 13098013, -9214866, 16377220, -2102812, -19802075, -3034702 }, - { -22729289, 7496160, -5742199, 11329249, 19991973, -3347502, -31718148, 9936966, -30097688, -10618797 }, + {18606113, 1693100, -25448386, -15170272, 4112353, 10045021, + 23603893, -2048234, -7550776, 2484985}, + {9255317, -3131197, -12156162, -1004256, 13098013, -9214866, + 16377220, -2102812, -19802075, -3034702}, + {-22729289, 7496160, -5742199, 11329249, 19991973, -3347502, + -31718148, 9936966, -30097688, -10618797}, }, { - { 21878590, -5001297, 4338336, 13643897, -3036865, 13160960, 19708896, 5415497, -7360503, -4109293 }, - { 27736861, 10103576, 12500508, 8502413, -3413016, -9633558, 10436918, -1550276, -23659143, -8132100 }, - { 19492550, -12104365, -29681976, -852630, -3208171, 12403437, 30066266, 8367329, 13243957, 8709688 }, + {21878590, -5001297, 4338336, 13643897, -3036865, 13160960, + 19708896, 5415497, -7360503, -4109293}, + {27736861, 10103576, 12500508, 8502413, -3413016, -9633558, + 10436918, -1550276, -23659143, -8132100}, + {19492550, -12104365, -29681976, -852630, -3208171, 12403437, + 30066266, 8367329, 13243957, 8709688}, }, }, { { - { 12015105, 2801261, 28198131, 10151021, 24818120, -4743133, -11194191, -5645734, 5150968, 7274186 }, - { 2831366, -12492146, 1478975, 6122054, 23825128, -12733586, 31097299, 6083058, 31021603, -9793610 }, - { -2529932, -2229646, 445613, 10720828, -13849527, -11505937, -23507731, 16354465, 15067285, -14147707 }, + {12015105, 2801261, 28198131, 10151021, 24818120, -4743133, + -11194191, -5645734, 5150968, 7274186}, + {2831366, -12492146, 1478975, 6122054, 23825128, -12733586, + 31097299, 6083058, 31021603, -9793610}, + {-2529932, -2229646, 445613, 10720828, -13849527, -11505937, + -23507731, 16354465, 15067285, -14147707}, }, { - { 7840942, 14037873, -33364863, 15934016, -728213, -3642706, 21403988, 1057586, -19379462, -12403220 }, - { 915865, -16469274, 15608285, -8789130, -24357026, 6060030, -17371319, 8410997, -7220461, 16527025 }, - { 32922597, -556987, 20336074, -16184568, 10903705, -5384487, 16957574, 52992, 23834301, 6588044 }, + {7840942, 14037873, -33364863, 15934016, -728213, -3642706, + 21403988, 1057586, -19379462, -12403220}, + {915865, -16469274, 15608285, -8789130, -24357026, 6060030, + -17371319, 8410997, -7220461, 16527025}, + {32922597, -556987, 20336074, -16184568, 10903705, -5384487, + 16957574, 52992, 23834301, 6588044}, }, { - { 32752030, 11232950, 3381995, -8714866, 22652988, -10744103, 17159699, 16689107, -20314580, -1305992 }, - { -4689649, 9166776, -25710296, -10847306, 11576752, 12733943, 7924251, -2752281, 1976123, -7249027 }, - { 21251222, 16309901, -2983015, -6783122, 30810597, 12967303, 156041, -3371252, 12331345, -8237197 }, + {32752030, 11232950, 3381995, -8714866, 22652988, -10744103, + 17159699, 16689107, -20314580, -1305992}, + {-4689649, 9166776, -25710296, -10847306, 11576752, 12733943, + 7924251, -2752281, 1976123, -7249027}, + {21251222, 16309901, -2983015, -6783122, 30810597, 12967303, 156041, + -3371252, 12331345, -8237197}, }, { - { 8651614, -4477032, -16085636, -4996994, 13002507, 2950805, 29054427, -5106970, 10008136, -4667901 }, - { 31486080, 15114593, -14261250, 12951354, 14369431, -7387845, 16347321, -13662089, 8684155, -10532952 }, - { 19443825, 11385320, 24468943, -9659068, -23919258, 2187569, -26263207, -6086921, 31316348, 14219878 }, + {8651614, -4477032, -16085636, -4996994, 13002507, 2950805, + 29054427, -5106970, 10008136, -4667901}, + {31486080, 15114593, -14261250, 12951354, 14369431, -7387845, + 16347321, -13662089, 8684155, -10532952}, + {19443825, 11385320, 24468943, -9659068, -23919258, 2187569, + -26263207, -6086921, 31316348, 14219878}, }, { - { -28594490, 1193785, 32245219, 11392485, 31092169, 15722801, 27146014, 6992409, 29126555, 9207390 }, - { 32382935, 1110093, 18477781, 11028262, -27411763, -7548111, -4980517, 10843782, -7957600, -14435730 }, - { 2814918, 7836403, 27519878, -7868156, -20894015, -11553689, -21494559, 8550130, 28346258, 1994730 }, + {-28594490, 1193785, 32245219, 11392485, 31092169, 15722801, + 27146014, 6992409, 29126555, 9207390}, + {32382935, 1110093, 18477781, 11028262, -27411763, -7548111, + -4980517, 10843782, -7957600, -14435730}, + {2814918, 7836403, 27519878, -7868156, -20894015, -11553689, + -21494559, 8550130, 28346258, 1994730}, }, { - { -19578299, 8085545, -14000519, -3948622, 2785838, -16231307, -19516951, 7174894, 22628102, 8115180 }, - { -30405132, 955511, -11133838, -15078069, -32447087, -13278079, -25651578, 3317160, -9943017, 930272 }, - { -15303681, -6833769, 28856490, 1357446, 23421993, 1057177, 24091212, -1388970, -22765376, -10650715 }, + {-19578299, 8085545, -14000519, -3948622, 2785838, -16231307, + -19516951, 7174894, 22628102, 8115180}, + {-30405132, 955511, -11133838, -15078069, -32447087, -13278079, + -25651578, 3317160, -9943017, 930272}, + {-15303681, -6833769, 28856490, 1357446, 23421993, 1057177, + 24091212, -1388970, -22765376, -10650715}, }, { - { -22751231, -5303997, -12907607, -12768866, -15811511, -7797053, -14839018, -16554220, -1867018, 8398970 }, - { -31969310, 2106403, -4736360, 1362501, 12813763, 16200670, 22981545, -6291273, 18009408, -15772772 }, - { -17220923, -9545221, -27784654, 14166835, 29815394, 7444469, 29551787, -3727419, 19288549, 1325865 }, + {-22751231, -5303997, -12907607, -12768866, -15811511, -7797053, + -14839018, -16554220, -1867018, 8398970}, + {-31969310, 2106403, -4736360, 1362501, 12813763, 16200670, + 22981545, -6291273, 18009408, -15772772}, + {-17220923, -9545221, -27784654, 14166835, 29815394, 7444469, + 29551787, -3727419, 19288549, 1325865}, }, { - { 15100157, -15835752, -23923978, -1005098, -26450192, 15509408, 12376730, -3479146, 33166107, -8042750 }, - { 20909231, 13023121, -9209752, 16251778, -5778415, -8094914, 12412151, 10018715, 2213263, -13878373 }, - { 32529814, -11074689, 30361439, -16689753, -9135940, 1513226, 22922121, 6382134, -5766928, 8371348 }, + {15100157, -15835752, -23923978, -1005098, -26450192, 15509408, + 12376730, -3479146, 33166107, -8042750}, + {20909231, 13023121, -9209752, 16251778, -5778415, -8094914, + 12412151, 10018715, 2213263, -13878373}, + {32529814, -11074689, 30361439, -16689753, -9135940, 1513226, + 22922121, 6382134, -5766928, 8371348}, }, }, { { - { 9923462, 11271500, 12616794, 3544722, -29998368, -1721626, 12891687, -8193132, -26442943, 10486144 }, - { -22597207, -7012665, 8587003, -8257861, 4084309, -12970062, 361726, 2610596, -23921530, -11455195 }, - { 5408411, -1136691, -4969122, 10561668, 24145918, 14240566, 31319731, -4235541, 19985175, -3436086 }, + {9923462, 11271500, 12616794, 3544722, -29998368, -1721626, + 12891687, -8193132, -26442943, 10486144}, + {-22597207, -7012665, 8587003, -8257861, 4084309, -12970062, 361726, + 2610596, -23921530, -11455195}, + {5408411, -1136691, -4969122, 10561668, 24145918, 14240566, + 31319731, -4235541, 19985175, -3436086}, }, { - { -13994457, 16616821, 14549246, 3341099, 32155958, 13648976, -17577068, 8849297, 65030, 8370684 }, - { -8320926, -12049626, 31204563, 5839400, -20627288, -1057277, -19442942, 6922164, 12743482, -9800518 }, - { -2361371, 12678785, 28815050, 4759974, -23893047, 4884717, 23783145, 11038569, 18800704, 255233 }, + {-13994457, 16616821, 14549246, 3341099, 32155958, 13648976, + -17577068, 8849297, 65030, 8370684}, + {-8320926, -12049626, 31204563, 5839400, -20627288, -1057277, + -19442942, 6922164, 12743482, -9800518}, + {-2361371, 12678785, 28815050, 4759974, -23893047, 4884717, + 23783145, 11038569, 18800704, 255233}, }, { - { -5269658, -1773886, 13957886, 7990715, 23132995, 728773, 13393847, 9066957, 19258688, -14753793 }, - { -2936654, -10827535, -10432089, 14516793, -3640786, 4372541, -31934921, 2209390, -1524053, 2055794 }, - { 580882, 16705327, 5468415, -2683018, -30926419, -14696000, -7203346, -8994389, -30021019, 7394435 }, + {-5269658, -1773886, 13957886, 7990715, 23132995, 728773, 13393847, + 9066957, 19258688, -14753793}, + {-2936654, -10827535, -10432089, 14516793, -3640786, 4372541, + -31934921, 2209390, -1524053, 2055794}, + {580882, 16705327, 5468415, -2683018, -30926419, -14696000, + -7203346, -8994389, -30021019, 7394435}, }, { - { 23838809, 1822728, -15738443, 15242727, 8318092, -3733104, -21672180, -3492205, -4821741, 14799921 }, - { 13345610, 9759151, 3371034, -16137791, 16353039, 8577942, 31129804, 13496856, -9056018, 7402518 }, - { 2286874, -4435931, -20042458, -2008336, -13696227, 5038122, 11006906, -15760352, 8205061, 1607563 }, + {23838809, 1822728, -15738443, 15242727, 8318092, -3733104, + -21672180, -3492205, -4821741, 14799921}, + {13345610, 9759151, 3371034, -16137791, 16353039, 8577942, 31129804, + 13496856, -9056018, 7402518}, + {2286874, -4435931, -20042458, -2008336, -13696227, 5038122, + 11006906, -15760352, 8205061, 1607563}, }, { - { 14414086, -8002132, 3331830, -3208217, 22249151, -5594188, 18364661, -2906958, 30019587, -9029278 }, - { -27688051, 1585953, -10775053, 931069, -29120221, -11002319, -14410829, 12029093, 9944378, 8024 }, - { 4368715, -3709630, 29874200, -15022983, -20230386, -11410704, -16114594, -999085, -8142388, 5640030 }, + {14414086, -8002132, 3331830, -3208217, 22249151, -5594188, + 18364661, -2906958, 30019587, -9029278}, + {-27688051, 1585953, -10775053, 931069, -29120221, -11002319, + -14410829, 12029093, 9944378, 8024}, + {4368715, -3709630, 29874200, -15022983, -20230386, -11410704, + -16114594, -999085, -8142388, 5640030}, }, { - { 10299610, 13746483, 11661824, 16234854, 7630238, 5998374, 9809887, -16694564, 15219798, -14327783 }, - { 27425505, -5719081, 3055006, 10660664, 23458024, 595578, -15398605, -1173195, -18342183, 9742717 }, - { 6744077, 2427284, 26042789, 2720740, -847906, 1118974, 32324614, 7406442, 12420155, 1994844 }, + {10299610, 13746483, 11661824, 16234854, 7630238, 5998374, 9809887, + -16694564, 15219798, -14327783}, + {27425505, -5719081, 3055006, 10660664, 23458024, 595578, -15398605, + -1173195, -18342183, 9742717}, + {6744077, 2427284, 26042789, 2720740, -847906, 1118974, 32324614, + 7406442, 12420155, 1994844}, }, { - { 14012521, -5024720, -18384453, -9578469, -26485342, -3936439, -13033478, -10909803, 24319929, -6446333 }, - { 16412690, -4507367, 10772641, 15929391, -17068788, -4658621, 10555945, -10484049, -30102368, -4739048 }, - { 22397382, -7767684, -9293161, -12792868, 17166287, -9755136, -27333065, 6199366, 21880021, -12250760 }, + {14012521, -5024720, -18384453, -9578469, -26485342, -3936439, + -13033478, -10909803, 24319929, -6446333}, + {16412690, -4507367, 10772641, 15929391, -17068788, -4658621, + 10555945, -10484049, -30102368, -4739048}, + {22397382, -7767684, -9293161, -12792868, 17166287, -9755136, + -27333065, 6199366, 21880021, -12250760}, }, { - { -4283307, 5368523, -31117018, 8163389, -30323063, 3209128, 16557151, 8890729, 8840445, 4957760 }, - { -15447727, 709327, -6919446, -10870178, -29777922, 6522332, -21720181, 12130072, -14796503, 5005757 }, - { -2114751, -14308128, 23019042, 15765735, -25269683, 6002752, 10183197, -13239326, -16395286, -2176112 }, + {-4283307, 5368523, -31117018, 8163389, -30323063, 3209128, + 16557151, 8890729, 8840445, 4957760}, + {-15447727, 709327, -6919446, -10870178, -29777922, 6522332, + -21720181, 12130072, -14796503, 5005757}, + {-2114751, -14308128, 23019042, 15765735, -25269683, 6002752, + 10183197, -13239326, -16395286, -2176112}, }, }, { { - { -19025756, 1632005, 13466291, -7995100, -23640451, 16573537, -32013908, -3057104, 22208662, 2000468 }, - { 3065073, -1412761, -25598674, -361432, -17683065, -5703415, -8164212, 11248527, -3691214, -7414184 }, - { 10379208, -6045554, 8877319, 1473647, -29291284, -12507580, 16690915, 2553332, -3132688, 16400289 }, + {-19025756, 1632005, 13466291, -7995100, -23640451, 16573537, + -32013908, -3057104, 22208662, 2000468}, + {3065073, -1412761, -25598674, -361432, -17683065, -5703415, + -8164212, 11248527, -3691214, -7414184}, + {10379208, -6045554, 8877319, 1473647, -29291284, -12507580, + 16690915, 2553332, -3132688, 16400289}, }, { - { 15716668, 1254266, -18472690, 7446274, -8448918, 6344164, -22097271, -7285580, 26894937, 9132066 }, - { 24158887, 12938817, 11085297, -8177598, -28063478, -4457083, -30576463, 64452, -6817084, -2692882 }, - { 13488534, 7794716, 22236231, 5989356, 25426474, -12578208, 2350710, -3418511, -4688006, 2364226 }, + {15716668, 1254266, -18472690, 7446274, -8448918, 6344164, + -22097271, -7285580, 26894937, 9132066}, + {24158887, 12938817, 11085297, -8177598, -28063478, -4457083, + -30576463, 64452, -6817084, -2692882}, + {13488534, 7794716, 22236231, 5989356, 25426474, -12578208, 2350710, + -3418511, -4688006, 2364226}, }, { - { 16335052, 9132434, 25640582, 6678888, 1725628, 8517937, -11807024, -11697457, 15445875, -7798101 }, - { 29004207, -7867081, 28661402, -640412, -12794003, -7943086, 31863255, -4135540, -278050, -15759279 }, - { -6122061, -14866665, -28614905, 14569919, -10857999, -3591829, 10343412, -6976290, -29828287, -10815811 }, + {16335052, 9132434, 25640582, 6678888, 1725628, 8517937, -11807024, + -11697457, 15445875, -7798101}, + {29004207, -7867081, 28661402, -640412, -12794003, -7943086, + 31863255, -4135540, -278050, -15759279}, + {-6122061, -14866665, -28614905, 14569919, -10857999, -3591829, + 10343412, -6976290, -29828287, -10815811}, }, { - { 27081650, 3463984, 14099042, -4517604, 1616303, -6205604, 29542636, 15372179, 17293797, 960709 }, - { 20263915, 11434237, -5765435, 11236810, 13505955, -10857102, -16111345, 6493122, -19384511, 7639714 }, - { -2830798, -14839232, 25403038, -8215196, -8317012, -16173699, 18006287, -16043750, 29994677, -15808121 }, + {27081650, 3463984, 14099042, -4517604, 1616303, -6205604, 29542636, + 15372179, 17293797, 960709}, + {20263915, 11434237, -5765435, 11236810, 13505955, -10857102, + -16111345, 6493122, -19384511, 7639714}, + {-2830798, -14839232, 25403038, -8215196, -8317012, -16173699, + 18006287, -16043750, 29994677, -15808121}, }, { - { 9769828, 5202651, -24157398, -13631392, -28051003, -11561624, -24613141, -13860782, -31184575, 709464 }, - { 12286395, 13076066, -21775189, -1176622, -25003198, 4057652, -32018128, -8890874, 16102007, 13205847 }, - { 13733362, 5599946, 10557076, 3195751, -5557991, 8536970, -25540170, 8525972, 10151379, 10394400 }, + {9769828, 5202651, -24157398, -13631392, -28051003, -11561624, + -24613141, -13860782, -31184575, 709464}, + {12286395, 13076066, -21775189, -1176622, -25003198, 4057652, + -32018128, -8890874, 16102007, 13205847}, + {13733362, 5599946, 10557076, 3195751, -5557991, 8536970, -25540170, + 8525972, 10151379, 10394400}, }, { - { 4024660, -16137551, 22436262, 12276534, -9099015, -2686099, 19698229, 11743039, -33302334, 8934414 }, - { -15879800, -4525240, -8580747, -2934061, 14634845, -698278, -9449077, 3137094, -11536886, 11721158 }, - { 17555939, -5013938, 8268606, 2331751, -22738815, 9761013, 9319229, 8835153, -9205489, -1280045 }, + {4024660, -16137551, 22436262, 12276534, -9099015, -2686099, + 19698229, 11743039, -33302334, 8934414}, + {-15879800, -4525240, -8580747, -2934061, 14634845, -698278, + -9449077, 3137094, -11536886, 11721158}, + {17555939, -5013938, 8268606, 2331751, -22738815, 9761013, 9319229, + 8835153, -9205489, -1280045}, }, { - { -461409, -7830014, 20614118, 16688288, -7514766, -4807119, 22300304, 505429, 6108462, -6183415 }, - { -5070281, 12367917, -30663534, 3234473, 32617080, -8422642, 29880583, -13483331, -26898490, -7867459 }, - { -31975283, 5726539, 26934134, 10237677, -3173717, -605053, 24199304, 3795095, 7592688, -14992079 }, + {-461409, -7830014, 20614118, 16688288, -7514766, -4807119, + 22300304, 505429, 6108462, -6183415}, + {-5070281, 12367917, -30663534, 3234473, 32617080, -8422642, + 29880583, -13483331, -26898490, -7867459}, + {-31975283, 5726539, 26934134, 10237677, -3173717, -605053, + 24199304, 3795095, 7592688, -14992079}, }, { - { 21594432, -14964228, 17466408, -4077222, 32537084, 2739898, 6407723, 12018833, -28256052, 4298412 }, - { -20650503, -11961496, -27236275, 570498, 3767144, -1717540, 13891942, -1569194, 13717174, 10805743 }, - { -14676630, -15644296, 15287174, 11927123, 24177847, -8175568, -796431, 14860609, -26938930, -5863836 }, + {21594432, -14964228, 17466408, -4077222, 32537084, 2739898, + 6407723, 12018833, -28256052, 4298412}, + {-20650503, -11961496, -27236275, 570498, 3767144, -1717540, + 13891942, -1569194, 13717174, 10805743}, + {-14676630, -15644296, 15287174, 11927123, 24177847, -8175568, + -796431, 14860609, -26938930, -5863836}, }, }, { { - { 12962541, 5311799, -10060768, 11658280, 18855286, -7954201, 13286263, -12808704, -4381056, 9882022 }, - { 18512079, 11319350, -20123124, 15090309, 18818594, 5271736, -22727904, 3666879, -23967430, -3299429 }, - { -6789020, -3146043, 16192429, 13241070, 15898607, -14206114, -10084880, -6661110, -2403099, 5276065 }, + {12962541, 5311799, -10060768, 11658280, 18855286, -7954201, + 13286263, -12808704, -4381056, 9882022}, + {18512079, 11319350, -20123124, 15090309, 18818594, 5271736, + -22727904, 3666879, -23967430, -3299429}, + {-6789020, -3146043, 16192429, 13241070, 15898607, -14206114, + -10084880, -6661110, -2403099, 5276065}, }, { - { 30169808, -5317648, 26306206, -11750859, 27814964, 7069267, 7152851, 3684982, 1449224, 13082861 }, - { 10342826, 3098505, 2119311, 193222, 25702612, 12233820, 23697382, 15056736, -21016438, -8202000 }, - { -33150110, 3261608, 22745853, 7948688, 19370557, -15177665, -26171976, 6482814, -10300080, -11060101 }, + {30169808, -5317648, 26306206, -11750859, 27814964, 7069267, + 7152851, 3684982, 1449224, 13082861}, + {10342826, 3098505, 2119311, 193222, 25702612, 12233820, 23697382, + 15056736, -21016438, -8202000}, + {-33150110, 3261608, 22745853, 7948688, 19370557, -15177665, + -26171976, 6482814, -10300080, -11060101}, }, { - { 32869458, -5408545, 25609743, 15678670, -10687769, -15471071, 26112421, 2521008, -22664288, 6904815 }, - { 29506923, 4457497, 3377935, -9796444, -30510046, 12935080, 1561737, 3841096, -29003639, -6657642 }, - { 10340844, -6630377, -18656632, -2278430, 12621151, -13339055, 30878497, -11824370, -25584551, 5181966 }, + {32869458, -5408545, 25609743, 15678670, -10687769, -15471071, + 26112421, 2521008, -22664288, 6904815}, + {29506923, 4457497, 3377935, -9796444, -30510046, 12935080, 1561737, + 3841096, -29003639, -6657642}, + {10340844, -6630377, -18656632, -2278430, 12621151, -13339055, + 30878497, -11824370, -25584551, 5181966}, }, { - { 25940115, -12658025, 17324188, -10307374, -8671468, 15029094, 24396252, -16450922, -2322852, -12388574 }, - { -21765684, 9916823, -1300409, 4079498, -1028346, 11909559, 1782390, 12641087, 20603771, -6561742 }, - { -18882287, -11673380, 24849422, 11501709, 13161720, -4768874, 1925523, 11914390, 4662781, 7820689 }, + {25940115, -12658025, 17324188, -10307374, -8671468, 15029094, + 24396252, -16450922, -2322852, -12388574}, + {-21765684, 9916823, -1300409, 4079498, -1028346, 11909559, 1782390, + 12641087, 20603771, -6561742}, + {-18882287, -11673380, 24849422, 11501709, 13161720, -4768874, + 1925523, 11914390, 4662781, 7820689}, }, { - { 12241050, -425982, 8132691, 9393934, 32846760, -1599620, 29749456, 12172924, 16136752, 15264020 }, - { -10349955, -14680563, -8211979, 2330220, -17662549, -14545780, 10658213, 6671822, 19012087, 3772772 }, - { 3753511, -3421066, 10617074, 2028709, 14841030, -6721664, 28718732, -15762884, 20527771, 12988982 }, + {12241050, -425982, 8132691, 9393934, 32846760, -1599620, 29749456, + 12172924, 16136752, 15264020}, + {-10349955, -14680563, -8211979, 2330220, -17662549, -14545780, + 10658213, 6671822, 19012087, 3772772}, + {3753511, -3421066, 10617074, 2028709, 14841030, -6721664, 28718732, + -15762884, 20527771, 12988982}, }, { - { -14822485, -5797269, -3707987, 12689773, -898983, -10914866, -24183046, -10564943, 3299665, -12424953 }, - { -16777703, -15253301, -9642417, 4978983, 3308785, 8755439, 6943197, 6461331, -25583147, 8991218 }, - { -17226263, 1816362, -1673288, -6086439, 31783888, -8175991, -32948145, 7417950, -30242287, 1507265 }, + {-14822485, -5797269, -3707987, 12689773, -898983, -10914866, + -24183046, -10564943, 3299665, -12424953}, + {-16777703, -15253301, -9642417, 4978983, 3308785, 8755439, 6943197, + 6461331, -25583147, 8991218}, + {-17226263, 1816362, -1673288, -6086439, 31783888, -8175991, + -32948145, 7417950, -30242287, 1507265}, }, { - { 29692663, 6829891, -10498800, 4334896, 20945975, -11906496, -28887608, 8209391, 14606362, -10647073 }, - { -3481570, 8707081, 32188102, 5672294, 22096700, 1711240, -33020695, 9761487, 4170404, -2085325 }, - { -11587470, 14855945, -4127778, -1531857, -26649089, 15084046, 22186522, 16002000, -14276837, -8400798 }, + {29692663, 6829891, -10498800, 4334896, 20945975, -11906496, + -28887608, 8209391, 14606362, -10647073}, + {-3481570, 8707081, 32188102, 5672294, 22096700, 1711240, -33020695, + 9761487, 4170404, -2085325}, + {-11587470, 14855945, -4127778, -1531857, -26649089, 15084046, + 22186522, 16002000, -14276837, -8400798}, }, { - { -4811456, 13761029, -31703877, -2483919, -3312471, 7869047, -7113572, -9620092, 13240845, 10965870 }, - { -7742563, -8256762, -14768334, -13656260, -23232383, 12387166, 4498947, 14147411, 29514390, 4302863 }, - { -13413405, -12407859, 20757302, -13801832, 14785143, 8976368, -5061276, -2144373, 17846988, -13971927 }, + {-4811456, 13761029, -31703877, -2483919, -3312471, 7869047, + -7113572, -9620092, 13240845, 10965870}, + {-7742563, -8256762, -14768334, -13656260, -23232383, 12387166, + 4498947, 14147411, 29514390, 4302863}, + {-13413405, -12407859, 20757302, -13801832, 14785143, 8976368, + -5061276, -2144373, 17846988, -13971927}, }, }, { { - { -2244452, -754728, -4597030, -1066309, -6247172, 1455299, -21647728, -9214789, -5222701, 12650267 }, - { -9906797, -16070310, 21134160, 12198166, -27064575, 708126, 387813, 13770293, -19134326, 10958663 }, - { 22470984, 12369526, 23446014, -5441109, -21520802, -9698723, -11772496, -11574455, -25083830, 4271862 }, + {-2244452, -754728, -4597030, -1066309, -6247172, 1455299, + -21647728, -9214789, -5222701, 12650267}, + {-9906797, -16070310, 21134160, 12198166, -27064575, 708126, 387813, + 13770293, -19134326, 10958663}, + {22470984, 12369526, 23446014, -5441109, -21520802, -9698723, + -11772496, -11574455, -25083830, 4271862}, }, { - { -25169565, -10053642, -19909332, 15361595, -5984358, 2159192, 75375, -4278529, -32526221, 8469673 }, - { 15854970, 4148314, -8893890, 7259002, 11666551, 13824734, -30531198, 2697372, 24154791, -9460943 }, - { 15446137, -15806644, 29759747, 14019369, 30811221, -9610191, -31582008, 12840104, 24913809, 9815020 }, + {-25169565, -10053642, -19909332, 15361595, -5984358, 2159192, + 75375, -4278529, -32526221, 8469673}, + {15854970, 4148314, -8893890, 7259002, 11666551, 13824734, + -30531198, 2697372, 24154791, -9460943}, + {15446137, -15806644, 29759747, 14019369, 30811221, -9610191, + -31582008, 12840104, 24913809, 9815020}, }, { - { -4709286, -5614269, -31841498, -12288893, -14443537, 10799414, -9103676, 13438769, 18735128, 9466238 }, - { 11933045, 9281483, 5081055, -5183824, -2628162, -4905629, -7727821, -10896103, -22728655, 16199064 }, - { 14576810, 379472, -26786533, -8317236, -29426508, -10812974, -102766, 1876699, 30801119, 2164795 }, + {-4709286, -5614269, -31841498, -12288893, -14443537, 10799414, + -9103676, 13438769, 18735128, 9466238}, + {11933045, 9281483, 5081055, -5183824, -2628162, -4905629, -7727821, + -10896103, -22728655, 16199064}, + {14576810, 379472, -26786533, -8317236, -29426508, -10812974, + -102766, 1876699, 30801119, 2164795}, }, { - { 15995086, 3199873, 13672555, 13712240, -19378835, -4647646, -13081610, -15496269, -13492807, 1268052 }, - { -10290614, -3659039, -3286592, 10948818, 23037027, 3794475, -3470338, -12600221, -17055369, 3565904 }, - { 29210088, -9419337, -5919792, -4952785, 10834811, -13327726, -16512102, -10820713, -27162222, -14030531 }, + {15995086, 3199873, 13672555, 13712240, -19378835, -4647646, + -13081610, -15496269, -13492807, 1268052}, + {-10290614, -3659039, -3286592, 10948818, 23037027, 3794475, + -3470338, -12600221, -17055369, 3565904}, + {29210088, -9419337, -5919792, -4952785, 10834811, -13327726, + -16512102, -10820713, -27162222, -14030531}, }, { - { -13161890, 15508588, 16663704, -8156150, -28349942, 9019123, -29183421, -3769423, 2244111, -14001979 }, - { -5152875, -3800936, -9306475, -6071583, 16243069, 14684434, -25673088, -16180800, 13491506, 4641841 }, - { 10813417, 643330, -19188515, -728916, 30292062, -16600078, 27548447, -7721242, 14476989, -12767431 }, + {-13161890, 15508588, 16663704, -8156150, -28349942, 9019123, + -29183421, -3769423, 2244111, -14001979}, + {-5152875, -3800936, -9306475, -6071583, 16243069, 14684434, + -25673088, -16180800, 13491506, 4641841}, + {10813417, 643330, -19188515, -728916, 30292062, -16600078, + 27548447, -7721242, 14476989, -12767431}, }, { - { 10292079, 9984945, 6481436, 8279905, -7251514, 7032743, 27282937, -1644259, -27912810, 12651324 }, - { -31185513, -813383, 22271204, 11835308, 10201545, 15351028, 17099662, 3988035, 21721536, -3148940 }, - { 10202177, -6545839, -31373232, -9574638, -32150642, -8119683, -12906320, 3852694, 13216206, 14842320 }, + {10292079, 9984945, 6481436, 8279905, -7251514, 7032743, 27282937, + -1644259, -27912810, 12651324}, + {-31185513, -813383, 22271204, 11835308, 10201545, 15351028, + 17099662, 3988035, 21721536, -3148940}, + {10202177, -6545839, -31373232, -9574638, -32150642, -8119683, + -12906320, 3852694, 13216206, 14842320}, }, { - { -15815640, -10601066, -6538952, -7258995, -6984659, -6581778, -31500847, 13765824, -27434397, 9900184 }, - { 14465505, -13833331, -32133984, -14738873, -27443187, 12990492, 33046193, 15796406, -7051866, -8040114 }, - { 30924417, -8279620, 6359016, -12816335, 16508377, 9071735, -25488601, 15413635, 9524356, -7018878 }, + {-15815640, -10601066, -6538952, -7258995, -6984659, -6581778, + -31500847, 13765824, -27434397, 9900184}, + {14465505, -13833331, -32133984, -14738873, -27443187, 12990492, + 33046193, 15796406, -7051866, -8040114}, + {30924417, -8279620, 6359016, -12816335, 16508377, 9071735, + -25488601, 15413635, 9524356, -7018878}, }, { - { 12274201, -13175547, 32627641, -1785326, 6736625, 13267305, 5237659, -5109483, 15663516, 4035784 }, - { -2951309, 8903985, 17349946, 601635, -16432815, -4612556, -13732739, -15889334, -22258478, 4659091 }, - { -16916263, -4952973, -30393711, -15158821, 20774812, 15897498, 5736189, 15026997, -2178256, -13455585 }, + {12274201, -13175547, 32627641, -1785326, 6736625, 13267305, + 5237659, -5109483, 15663516, 4035784}, + {-2951309, 8903985, 17349946, 601635, -16432815, -4612556, + -13732739, -15889334, -22258478, 4659091}, + {-16916263, -4952973, -30393711, -15158821, 20774812, 15897498, + 5736189, 15026997, -2178256, -13455585}, }, }, { { - { -8858980, -2219056, 28571666, -10155518, -474467, -10105698, -3801496, 278095, 23440562, -290208 }, - { 10226241, -5928702, 15139956, 120818, -14867693, 5218603, 32937275, 11551483, -16571960, -7442864 }, - { 17932739, -12437276, -24039557, 10749060, 11316803, 7535897, 22503767, 5561594, -3646624, 3898661 }, + {-8858980, -2219056, 28571666, -10155518, -474467, -10105698, + -3801496, 278095, 23440562, -290208}, + {10226241, -5928702, 15139956, 120818, -14867693, 5218603, 32937275, + 11551483, -16571960, -7442864}, + {17932739, -12437276, -24039557, 10749060, 11316803, 7535897, + 22503767, 5561594, -3646624, 3898661}, }, { - { 7749907, -969567, -16339731, -16464, -25018111, 15122143, -1573531, 7152530, 21831162, 1245233 }, - { 26958459, -14658026, 4314586, 8346991, -5677764, 11960072, -32589295, -620035, -30402091, -16716212 }, - { -12165896, 9166947, 33491384, 13673479, 29787085, 13096535, 6280834, 14587357, -22338025, 13987525 }, + {7749907, -969567, -16339731, -16464, -25018111, 15122143, -1573531, + 7152530, 21831162, 1245233}, + {26958459, -14658026, 4314586, 8346991, -5677764, 11960072, + -32589295, -620035, -30402091, -16716212}, + {-12165896, 9166947, 33491384, 13673479, 29787085, 13096535, + 6280834, 14587357, -22338025, 13987525}, }, { - { -24349909, 7778775, 21116000, 15572597, -4833266, -5357778, -4300898, -5124639, -7469781, -2858068 }, - { 9681908, -6737123, -31951644, 13591838, -6883821, 386950, 31622781, 6439245, -14581012, 4091397 }, - { -8426427, 1470727, -28109679, -1596990, 3978627, -5123623, -19622683, 12092163, 29077877, -14741988 }, + {-24349909, 7778775, 21116000, 15572597, -4833266, -5357778, + -4300898, -5124639, -7469781, -2858068}, + {9681908, -6737123, -31951644, 13591838, -6883821, 386950, 31622781, + 6439245, -14581012, 4091397}, + {-8426427, 1470727, -28109679, -1596990, 3978627, -5123623, + -19622683, 12092163, 29077877, -14741988}, }, { - { 5269168, -6859726, -13230211, -8020715, 25932563, 1763552, -5606110, -5505881, -20017847, 2357889 }, - { 32264008, -15407652, -5387735, -1160093, -2091322, -3946900, 23104804, -12869908, 5727338, 189038 }, - { 14609123, -8954470, -6000566, -16622781, -14577387, -7743898, -26745169, 10942115, -25888931, -14884697 }, + {5269168, -6859726, -13230211, -8020715, 25932563, 1763552, + -5606110, -5505881, -20017847, 2357889}, + {32264008, -15407652, -5387735, -1160093, -2091322, -3946900, + 23104804, -12869908, 5727338, 189038}, + {14609123, -8954470, -6000566, -16622781, -14577387, -7743898, + -26745169, 10942115, -25888931, -14884697}, }, { - { 20513500, 5557931, -15604613, 7829531, 26413943, -2019404, -21378968, 7471781, 13913677, -5137875 }, - { -25574376, 11967826, 29233242, 12948236, -6754465, 4713227, -8940970, 14059180, 12878652, 8511905 }, - { -25656801, 3393631, -2955415, -7075526, -2250709, 9366908, -30223418, 6812974, 5568676, -3127656 }, + {20513500, 5557931, -15604613, 7829531, 26413943, -2019404, + -21378968, 7471781, 13913677, -5137875}, + {-25574376, 11967826, 29233242, 12948236, -6754465, 4713227, + -8940970, 14059180, 12878652, 8511905}, + {-25656801, 3393631, -2955415, -7075526, -2250709, 9366908, + -30223418, 6812974, 5568676, -3127656}, }, { - { 11630004, 12144454, 2116339, 13606037, 27378885, 15676917, -17408753, -13504373, -14395196, 8070818 }, - { 27117696, -10007378, -31282771, -5570088, 1127282, 12772488, -29845906, 10483306, -11552749, -1028714 }, - { 10637467, -5688064, 5674781, 1072708, -26343588, -6982302, -1683975, 9177853, -27493162, 15431203 }, + {11630004, 12144454, 2116339, 13606037, 27378885, 15676917, + -17408753, -13504373, -14395196, 8070818}, + {27117696, -10007378, -31282771, -5570088, 1127282, 12772488, + -29845906, 10483306, -11552749, -1028714}, + {10637467, -5688064, 5674781, 1072708, -26343588, -6982302, + -1683975, 9177853, -27493162, 15431203}, }, { - { 20525145, 10892566, -12742472, 12779443, -29493034, 16150075, -28240519, 14943142, -15056790, -7935931 }, - { -30024462, 5626926, -551567, -9981087, 753598, 11981191, 25244767, -3239766, -3356550, 9594024 }, - { -23752644, 2636870, -5163910, -10103818, 585134, 7877383, 11345683, -6492290, 13352335, -10977084 }, + {20525145, 10892566, -12742472, 12779443, -29493034, 16150075, + -28240519, 14943142, -15056790, -7935931}, + {-30024462, 5626926, -551567, -9981087, 753598, 11981191, 25244767, + -3239766, -3356550, 9594024}, + {-23752644, 2636870, -5163910, -10103818, 585134, 7877383, 11345683, + -6492290, 13352335, -10977084}, }, { - { -1931799, -5407458, 3304649, -12884869, 17015806, -4877091, -29783850, -7752482, -13215537, -319204 }, - { 20239939, 6607058, 6203985, 3483793, -18386976, -779229, -20723742, 15077870, -22750759, 14523817 }, - { 27406042, -6041657, 27423596, -4497394, 4996214, 10002360, -28842031, -4545494, -30172742, -4805667 }, + {-1931799, -5407458, 3304649, -12884869, 17015806, -4877091, + -29783850, -7752482, -13215537, -319204}, + {20239939, 6607058, 6203985, 3483793, -18386976, -779229, -20723742, + 15077870, -22750759, 14523817}, + {27406042, -6041657, 27423596, -4497394, 4996214, 10002360, + -28842031, -4545494, -30172742, -4805667}, }, }, { { - { 11374242, 12660715, 17861383, -12540833, 10935568, 1099227, -13886076, -9091740, -27727044, 11358504 }, - { -12730809, 10311867, 1510375, 10778093, -2119455, -9145702, 32676003, 11149336, -26123651, 4985768 }, - { -19096303, 341147, -6197485, -239033, 15756973, -8796662, -983043, 13794114, -19414307, -15621255 }, + {11374242, 12660715, 17861383, -12540833, 10935568, 1099227, + -13886076, -9091740, -27727044, 11358504}, + {-12730809, 10311867, 1510375, 10778093, -2119455, -9145702, + 32676003, 11149336, -26123651, 4985768}, + {-19096303, 341147, -6197485, -239033, 15756973, -8796662, -983043, + 13794114, -19414307, -15621255}, }, { - { 6490081, 11940286, 25495923, -7726360, 8668373, -8751316, 3367603, 6970005, -1691065, -9004790 }, - { 1656497, 13457317, 15370807, 6364910, 13605745, 8362338, -19174622, -5475723, -16796596, -5031438 }, - { -22273315, -13524424, -64685, -4334223, -18605636, -10921968, -20571065, -7007978, -99853, -10237333 }, + {6490081, 11940286, 25495923, -7726360, 8668373, -8751316, 3367603, + 6970005, -1691065, -9004790}, + {1656497, 13457317, 15370807, 6364910, 13605745, 8362338, -19174622, + -5475723, -16796596, -5031438}, + {-22273315, -13524424, -64685, -4334223, -18605636, -10921968, + -20571065, -7007978, -99853, -10237333}, }, { - { 17747465, 10039260, 19368299, -4050591, -20630635, -16041286, 31992683, -15857976, -29260363, -5511971 }, - { 31932027, -4986141, -19612382, 16366580, 22023614, 88450, 11371999, -3744247, 4882242, -10626905 }, - { 29796507, 37186, 19818052, 10115756, -11829032, 3352736, 18551198, 3272828, -5190932, -4162409 }, + {17747465, 10039260, 19368299, -4050591, -20630635, -16041286, + 31992683, -15857976, -29260363, -5511971}, + {31932027, -4986141, -19612382, 16366580, 22023614, 88450, 11371999, + -3744247, 4882242, -10626905}, + {29796507, 37186, 19818052, 10115756, -11829032, 3352736, 18551198, + 3272828, -5190932, -4162409}, }, { - { 12501286, 4044383, -8612957, -13392385, -32430052, 5136599, -19230378, -3529697, 330070, -3659409 }, - { 6384877, 2899513, 17807477, 7663917, -2358888, 12363165, 25366522, -8573892, -271295, 12071499 }, - { -8365515, -4042521, 25133448, -4517355, -6211027, 2265927, -32769618, 1936675, -5159697, 3829363 }, + {12501286, 4044383, -8612957, -13392385, -32430052, 5136599, + -19230378, -3529697, 330070, -3659409}, + {6384877, 2899513, 17807477, 7663917, -2358888, 12363165, 25366522, + -8573892, -271295, 12071499}, + {-8365515, -4042521, 25133448, -4517355, -6211027, 2265927, + -32769618, 1936675, -5159697, 3829363}, }, { - { 28425966, -5835433, -577090, -4697198, -14217555, 6870930, 7921550, -6567787, 26333140, 14267664 }, - { -11067219, 11871231, 27385719, -10559544, -4585914, -11189312, 10004786, -8709488, -21761224, 8930324 }, - { -21197785, -16396035, 25654216, -1725397, 12282012, 11008919, 1541940, 4757911, -26491501, -16408940 }, + {28425966, -5835433, -577090, -4697198, -14217555, 6870930, 7921550, + -6567787, 26333140, 14267664}, + {-11067219, 11871231, 27385719, -10559544, -4585914, -11189312, + 10004786, -8709488, -21761224, 8930324}, + {-21197785, -16396035, 25654216, -1725397, 12282012, 11008919, + 1541940, 4757911, -26491501, -16408940}, }, { - { 13537262, -7759490, -20604840, 10961927, -5922820, -13218065, -13156584, 6217254, -15943699, 13814990 }, - { -17422573, 15157790, 18705543, 29619, 24409717, -260476, 27361681, 9257833, -1956526, -1776914 }, - { -25045300, -10191966, 15366585, 15166509, -13105086, 8423556, -29171540, 12361135, -18685978, 4578290 }, + {13537262, -7759490, -20604840, 10961927, -5922820, -13218065, + -13156584, 6217254, -15943699, 13814990}, + {-17422573, 15157790, 18705543, 29619, 24409717, -260476, 27361681, + 9257833, -1956526, -1776914}, + {-25045300, -10191966, 15366585, 15166509, -13105086, 8423556, + -29171540, 12361135, -18685978, 4578290}, }, { - { 24579768, 3711570, 1342322, -11180126, -27005135, 14124956, -22544529, 14074919, 21964432, 8235257 }, - { -6528613, -2411497, 9442966, -5925588, 12025640, -1487420, -2981514, -1669206, 13006806, 2355433 }, - { -16304899, -13605259, -6632427, -5142349, 16974359, -10911083, 27202044, 1719366, 1141648, -12796236 }, + {24579768, 3711570, 1342322, -11180126, -27005135, 14124956, + -22544529, 14074919, 21964432, 8235257}, + {-6528613, -2411497, 9442966, -5925588, 12025640, -1487420, + -2981514, -1669206, 13006806, 2355433}, + {-16304899, -13605259, -6632427, -5142349, 16974359, -10911083, + 27202044, 1719366, 1141648, -12796236}, }, { - { -12863944, -13219986, -8318266, -11018091, -6810145, -4843894, 13475066, -3133972, 32674895, 13715045 }, - { 11423335, -5468059, 32344216, 8962751, 24989809, 9241752, -13265253, 16086212, -28740881, -15642093 }, - { -1409668, 12530728, -6368726, 10847387, 19531186, -14132160, -11709148, 7791794, -27245943, 4383347 }, + {-12863944, -13219986, -8318266, -11018091, -6810145, -4843894, + 13475066, -3133972, 32674895, 13715045}, + {11423335, -5468059, 32344216, 8962751, 24989809, 9241752, + -13265253, 16086212, -28740881, -15642093}, + {-1409668, 12530728, -6368726, 10847387, 19531186, -14132160, + -11709148, 7791794, -27245943, 4383347}, }, }, { { - { -28970898, 5271447, -1266009, -9736989, -12455236, 16732599, -4862407, -4906449, 27193557, 6245191 }, - { -15193956, 5362278, -1783893, 2695834, 4960227, 12840725, 23061898, 3260492, 22510453, 8577507 }, - { -12632451, 11257346, -32692994, 13548177, -721004, 10879011, 31168030, 13952092, -29571492, -3635906 }, + {-28970898, 5271447, -1266009, -9736989, -12455236, 16732599, + -4862407, -4906449, 27193557, 6245191}, + {-15193956, 5362278, -1783893, 2695834, 4960227, 12840725, 23061898, + 3260492, 22510453, 8577507}, + {-12632451, 11257346, -32692994, 13548177, -721004, 10879011, + 31168030, 13952092, -29571492, -3635906}, }, { - { 3877321, -9572739, 32416692, 5405324, -11004407, -13656635, 3759769, 11935320, 5611860, 8164018 }, - { -16275802, 14667797, 15906460, 12155291, -22111149, -9039718, 32003002, -8832289, 5773085, -8422109 }, - { -23788118, -8254300, 1950875, 8937633, 18686727, 16459170, -905725, 12376320, 31632953, 190926 }, + {3877321, -9572739, 32416692, 5405324, -11004407, -13656635, + 3759769, 11935320, 5611860, 8164018}, + {-16275802, 14667797, 15906460, 12155291, -22111149, -9039718, + 32003002, -8832289, 5773085, -8422109}, + {-23788118, -8254300, 1950875, 8937633, 18686727, 16459170, -905725, + 12376320, 31632953, 190926}, }, { - { -24593607, -16138885, -8423991, 13378746, 14162407, 6901328, -8288749, 4508564, -25341555, -3627528 }, - { 8884438, -5884009, 6023974, 10104341, -6881569, -4941533, 18722941, -14786005, -1672488, 827625 }, - { -32720583, -16289296, -32503547, 7101210, 13354605, 2659080, -1800575, -14108036, -24878478, 1541286 }, + {-24593607, -16138885, -8423991, 13378746, 14162407, 6901328, + -8288749, 4508564, -25341555, -3627528}, + {8884438, -5884009, 6023974, 10104341, -6881569, -4941533, 18722941, + -14786005, -1672488, 827625}, + {-32720583, -16289296, -32503547, 7101210, 13354605, 2659080, + -1800575, -14108036, -24878478, 1541286}, }, { - { 2901347, -1117687, 3880376, -10059388, -17620940, -3612781, -21802117, -3567481, 20456845, -1885033 }, - { 27019610, 12299467, -13658288, -1603234, -12861660, -4861471, -19540150, -5016058, 29439641, 15138866 }, - { 21536104, -6626420, -32447818, -10690208, -22408077, 5175814, -5420040, -16361163, 7779328, 109896 }, + {2901347, -1117687, 3880376, -10059388, -17620940, -3612781, + -21802117, -3567481, 20456845, -1885033}, + {27019610, 12299467, -13658288, -1603234, -12861660, -4861471, + -19540150, -5016058, 29439641, 15138866}, + {21536104, -6626420, -32447818, -10690208, -22408077, 5175814, + -5420040, -16361163, 7779328, 109896}, }, { - { 30279744, 14648750, -8044871, 6425558, 13639621, -743509, 28698390, 12180118, 23177719, -554075 }, - { 26572847, 3405927, -31701700, 12890905, -19265668, 5335866, -6493768, 2378492, 4439158, -13279347 }, - { -22716706, 3489070, -9225266, -332753, 18875722, -1140095, 14819434, -12731527, -17717757, -5461437 }, + {30279744, 14648750, -8044871, 6425558, 13639621, -743509, 28698390, + 12180118, 23177719, -554075}, + {26572847, 3405927, -31701700, 12890905, -19265668, 5335866, + -6493768, 2378492, 4439158, -13279347}, + {-22716706, 3489070, -9225266, -332753, 18875722, -1140095, + 14819434, -12731527, -17717757, -5461437}, }, { - { -5056483, 16566551, 15953661, 3767752, -10436499, 15627060, -820954, 2177225, 8550082, -15114165 }, - { -18473302, 16596775, -381660, 15663611, 22860960, 15585581, -27844109, -3582739, -23260460, -8428588 }, - { -32480551, 15707275, -8205912, -5652081, 29464558, 2713815, -22725137, 15860482, -21902570, 1494193 }, + {-5056483, 16566551, 15953661, 3767752, -10436499, 15627060, + -820954, 2177225, 8550082, -15114165}, + {-18473302, 16596775, -381660, 15663611, 22860960, 15585581, + -27844109, -3582739, -23260460, -8428588}, + {-32480551, 15707275, -8205912, -5652081, 29464558, 2713815, + -22725137, 15860482, -21902570, 1494193}, }, { - { -19562091, -14087393, -25583872, -9299552, 13127842, 759709, 21923482, 16529112, 8742704, 12967017 }, - { -28464899, 1553205, 32536856, -10473729, -24691605, -406174, -8914625, -2933896, -29903758, 15553883 }, - { 21877909, 3230008, 9881174, 10539357, -4797115, 2841332, 11543572, 14513274, 19375923, -12647961 }, + {-19562091, -14087393, -25583872, -9299552, 13127842, 759709, + 21923482, 16529112, 8742704, 12967017}, + {-28464899, 1553205, 32536856, -10473729, -24691605, -406174, + -8914625, -2933896, -29903758, 15553883}, + {21877909, 3230008, 9881174, 10539357, -4797115, 2841332, 11543572, + 14513274, 19375923, -12647961}, }, { - { 8832269, -14495485, 13253511, 5137575, 5037871, 4078777, 24880818, -6222716, 2862653, 9455043 }, - { 29306751, 5123106, 20245049, -14149889, 9592566, 8447059, -2077124, -2990080, 15511449, 4789663 }, - { -20679756, 7004547, 8824831, -9434977, -4045704, -3750736, -5754762, 108893, 23513200, 16652362 }, + {8832269, -14495485, 13253511, 5137575, 5037871, 4078777, 24880818, + -6222716, 2862653, 9455043}, + {29306751, 5123106, 20245049, -14149889, 9592566, 8447059, -2077124, + -2990080, 15511449, 4789663}, + {-20679756, 7004547, 8824831, -9434977, -4045704, -3750736, + -5754762, 108893, 23513200, 16652362}, }, }, { { - { -33256173, 4144782, -4476029, -6579123, 10770039, -7155542, -6650416, -12936300, -18319198, 10212860 }, - { 2756081, 8598110, 7383731, -6859892, 22312759, -1105012, 21179801, 2600940, -9988298, -12506466 }, - { -24645692, 13317462, -30449259, -15653928, 21365574, -10869657, 11344424, 864440, -2499677, -16710063 }, + {-33256173, 4144782, -4476029, -6579123, 10770039, -7155542, + -6650416, -12936300, -18319198, 10212860}, + {2756081, 8598110, 7383731, -6859892, 22312759, -1105012, 21179801, + 2600940, -9988298, -12506466}, + {-24645692, 13317462, -30449259, -15653928, 21365574, -10869657, + 11344424, 864440, -2499677, -16710063}, }, { - { -26432803, 6148329, -17184412, -14474154, 18782929, -275997, -22561534, 211300, 2719757, 4940997 }, - { -1323882, 3911313, -6948744, 14759765, -30027150, 7851207, 21690126, 8518463, 26699843, 5276295 }, - { -13149873, -6429067, 9396249, 365013, 24703301, -10488939, 1321586, 149635, -15452774, 7159369 }, + {-26432803, 6148329, -17184412, -14474154, 18782929, -275997, + -22561534, 211300, 2719757, 4940997}, + {-1323882, 3911313, -6948744, 14759765, -30027150, 7851207, + 21690126, 8518463, 26699843, 5276295}, + {-13149873, -6429067, 9396249, 365013, 24703301, -10488939, 1321586, + 149635, -15452774, 7159369}, }, { - { 9987780, -3404759, 17507962, 9505530, 9731535, -2165514, 22356009, 8312176, 22477218, -8403385 }, - { 18155857, -16504990, 19744716, 9006923, 15154154, -10538976, 24256460, -4864995, -22548173, 9334109 }, - { 2986088, -4911893, 10776628, -3473844, 10620590, -7083203, -21413845, 14253545, -22587149, 536906 }, + {9987780, -3404759, 17507962, 9505530, 9731535, -2165514, 22356009, + 8312176, 22477218, -8403385}, + {18155857, -16504990, 19744716, 9006923, 15154154, -10538976, + 24256460, -4864995, -22548173, 9334109}, + {2986088, -4911893, 10776628, -3473844, 10620590, -7083203, + -21413845, 14253545, -22587149, 536906}, }, { - { 4377756, 8115836, 24567078, 15495314, 11625074, 13064599, 7390551, 10589625, 10838060, -15420424 }, - { -19342404, 867880, 9277171, -3218459, -14431572, -1986443, 19295826, -15796950, 6378260, 699185 }, - { 7895026, 4057113, -7081772, -13077756, -17886831, -323126, -716039, 15693155, -5045064, -13373962 }, + {4377756, 8115836, 24567078, 15495314, 11625074, 13064599, 7390551, + 10589625, 10838060, -15420424}, + {-19342404, 867880, 9277171, -3218459, -14431572, -1986443, + 19295826, -15796950, 6378260, 699185}, + {7895026, 4057113, -7081772, -13077756, -17886831, -323126, -716039, + 15693155, -5045064, -13373962}, }, { - { -7737563, -5869402, -14566319, -7406919, 11385654, 13201616, 31730678, -10962840, -3918636, -9669325 }, - { 10188286, -15770834, -7336361, 13427543, 22223443, 14896287, 30743455, 7116568, -21786507, 5427593 }, - { 696102, 13206899, 27047647, -10632082, 15285305, -9853179, 10798490, -4578720, 19236243, 12477404 }, + {-7737563, -5869402, -14566319, -7406919, 11385654, 13201616, + 31730678, -10962840, -3918636, -9669325}, + {10188286, -15770834, -7336361, 13427543, 22223443, 14896287, + 30743455, 7116568, -21786507, 5427593}, + {696102, 13206899, 27047647, -10632082, 15285305, -9853179, + 10798490, -4578720, 19236243, 12477404}, }, { - { -11229439, 11243796, -17054270, -8040865, -788228, -8167967, -3897669, 11180504, -23169516, 7733644 }, - { 17800790, -14036179, -27000429, -11766671, 23887827, 3149671, 23466177, -10538171, 10322027, 15313801 }, - { 26246234, 11968874, 32263343, -5468728, 6830755, -13323031, -15794704, -101982, -24449242, 10890804 }, + {-11229439, 11243796, -17054270, -8040865, -788228, -8167967, + -3897669, 11180504, -23169516, 7733644}, + {17800790, -14036179, -27000429, -11766671, 23887827, 3149671, + 23466177, -10538171, 10322027, 15313801}, + {26246234, 11968874, 32263343, -5468728, 6830755, -13323031, + -15794704, -101982, -24449242, 10890804}, }, { - { -31365647, 10271363, -12660625, -6267268, 16690207, -13062544, -14982212, 16484931, 25180797, -5334884 }, - { -586574, 10376444, -32586414, -11286356, 19801893, 10997610, 2276632, 9482883, 316878, 13820577 }, - { -9882808, -4510367, -2115506, 16457136, -11100081, 11674996, 30756178, -7515054, 30696930, -3712849 }, + {-31365647, 10271363, -12660625, -6267268, 16690207, -13062544, + -14982212, 16484931, 25180797, -5334884}, + {-586574, 10376444, -32586414, -11286356, 19801893, 10997610, + 2276632, 9482883, 316878, 13820577}, + {-9882808, -4510367, -2115506, 16457136, -11100081, 11674996, + 30756178, -7515054, 30696930, -3712849}, }, { - { 32988917, -9603412, 12499366, 7910787, -10617257, -11931514, -7342816, -9985397, -32349517, 7392473 }, - { -8855661, 15927861, 9866406, -3649411, -2396914, -16655781, -30409476, -9134995, 25112947, -2926644 }, - { -2504044, -436966, 25621774, -5678772, 15085042, -5479877, -24884878, -13526194, 5537438, -13914319 }, + {32988917, -9603412, 12499366, 7910787, -10617257, -11931514, + -7342816, -9985397, -32349517, 7392473}, + {-8855661, 15927861, 9866406, -3649411, -2396914, -16655781, + -30409476, -9134995, 25112947, -2926644}, + {-2504044, -436966, 25621774, -5678772, 15085042, -5479877, + -24884878, -13526194, 5537438, -13914319}, }, }, { { - { -11225584, 2320285, -9584280, 10149187, -33444663, 5808648, -14876251, -1729667, 31234590, 6090599 }, - { -9633316, 116426, 26083934, 2897444, -6364437, -2688086, 609721, 15878753, -6970405, -9034768 }, - { -27757857, 247744, -15194774, -9002551, 23288161, -10011936, -23869595, 6503646, 20650474, 1804084 }, + {-11225584, 2320285, -9584280, 10149187, -33444663, 5808648, + -14876251, -1729667, 31234590, 6090599}, + {-9633316, 116426, 26083934, 2897444, -6364437, -2688086, 609721, + 15878753, -6970405, -9034768}, + {-27757857, 247744, -15194774, -9002551, 23288161, -10011936, + -23869595, 6503646, 20650474, 1804084}, }, { - { -27589786, 15456424, 8972517, 8469608, 15640622, 4439847, 3121995, -10329713, 27842616, -202328 }, - { -15306973, 2839644, 22530074, 10026331, 4602058, 5048462, 28248656, 5031932, -11375082, 12714369 }, - { 20807691, -7270825, 29286141, 11421711, -27876523, -13868230, -21227475, 1035546, -19733229, 12796920 }, + {-27589786, 15456424, 8972517, 8469608, 15640622, 4439847, 3121995, + -10329713, 27842616, -202328}, + {-15306973, 2839644, 22530074, 10026331, 4602058, 5048462, 28248656, + 5031932, -11375082, 12714369}, + {20807691, -7270825, 29286141, 11421711, -27876523, -13868230, + -21227475, 1035546, -19733229, 12796920}, }, { - { 12076899, -14301286, -8785001, -11848922, -25012791, 16400684, -17591495, -12899438, 3480665, -15182815 }, - { -32361549, 5457597, 28548107, 7833186, 7303070, -11953545, -24363064, -15921875, -33374054, 2771025 }, - { -21389266, 421932, 26597266, 6860826, 22486084, -6737172, -17137485, -4210226, -24552282, 15673397 }, + {12076899, -14301286, -8785001, -11848922, -25012791, 16400684, + -17591495, -12899438, 3480665, -15182815}, + {-32361549, 5457597, 28548107, 7833186, 7303070, -11953545, + -24363064, -15921875, -33374054, 2771025}, + {-21389266, 421932, 26597266, 6860826, 22486084, -6737172, + -17137485, -4210226, -24552282, 15673397}, }, { - { -20184622, 2338216, 19788685, -9620956, -4001265, -8740893, -20271184, 4733254, 3727144, -12934448 }, - { 6120119, 814863, -11794402, -622716, 6812205, -15747771, 2019594, 7975683, 31123697, -10958981 }, - { 30069250, -11435332, 30434654, 2958439, 18399564, -976289, 12296869, 9204260, -16432438, 9648165 }, + {-20184622, 2338216, 19788685, -9620956, -4001265, -8740893, + -20271184, 4733254, 3727144, -12934448}, + {6120119, 814863, -11794402, -622716, 6812205, -15747771, 2019594, + 7975683, 31123697, -10958981}, + {30069250, -11435332, 30434654, 2958439, 18399564, -976289, + 12296869, 9204260, -16432438, 9648165}, }, { - { 32705432, -1550977, 30705658, 7451065, -11805606, 9631813, 3305266, 5248604, -26008332, -11377501 }, - { 17219865, 2375039, -31570947, -5575615, -19459679, 9219903, 294711, 15298639, 2662509, -16297073 }, - { -1172927, -7558695, -4366770, -4287744, -21346413, -8434326, 32087529, -1222777, 32247248, -14389861 }, + {32705432, -1550977, 30705658, 7451065, -11805606, 9631813, 3305266, + 5248604, -26008332, -11377501}, + {17219865, 2375039, -31570947, -5575615, -19459679, 9219903, 294711, + 15298639, 2662509, -16297073}, + {-1172927, -7558695, -4366770, -4287744, -21346413, -8434326, + 32087529, -1222777, 32247248, -14389861}, }, { - { 14312628, 1221556, 17395390, -8700143, -4945741, -8684635, -28197744, -9637817, -16027623, -13378845 }, - { -1428825, -9678990, -9235681, 6549687, -7383069, -468664, 23046502, 9803137, 17597934, 2346211 }, - { 18510800, 15337574, 26171504, 981392, -22241552, 7827556, -23491134, -11323352, 3059833, -11782870 }, + {14312628, 1221556, 17395390, -8700143, -4945741, -8684635, + -28197744, -9637817, -16027623, -13378845}, + {-1428825, -9678990, -9235681, 6549687, -7383069, -468664, 23046502, + 9803137, 17597934, 2346211}, + {18510800, 15337574, 26171504, 981392, -22241552, 7827556, + -23491134, -11323352, 3059833, -11782870}, }, { - { 10141598, 6082907, 17829293, -1947643, 9830092, 13613136, -25556636, -5544586, -33502212, 3592096 }, - { 33114168, -15889352, -26525686, -13343397, 33076705, 8716171, 1151462, 1521897, -982665, -6837803 }, - { -32939165, -4255815, 23947181, -324178, -33072974, -12305637, -16637686, 3891704, 26353178, 693168 }, + {10141598, 6082907, 17829293, -1947643, 9830092, 13613136, + -25556636, -5544586, -33502212, 3592096}, + {33114168, -15889352, -26525686, -13343397, 33076705, 8716171, + 1151462, 1521897, -982665, -6837803}, + {-32939165, -4255815, 23947181, -324178, -33072974, -12305637, + -16637686, 3891704, 26353178, 693168}, }, { - { 30374239, 1595580, -16884039, 13186931, 4600344, 406904, 9585294, -400668, 31375464, 14369965 }, - { -14370654, -7772529, 1510301, 6434173, -18784789, -6262728, 32732230, -13108839, 17901441, 16011505 }, - { 18171223, -11934626, -12500402, 15197122, -11038147, -15230035, -19172240, -16046376, 8764035, 12309598 }, + {30374239, 1595580, -16884039, 13186931, 4600344, 406904, 9585294, + -400668, 31375464, 14369965}, + {-14370654, -7772529, 1510301, 6434173, -18784789, -6262728, + 32732230, -13108839, 17901441, 16011505}, + {18171223, -11934626, -12500402, 15197122, -11038147, -15230035, + -19172240, -16046376, 8764035, 12309598}, }, }, { { - { 5975908, -5243188, -19459362, -9681747, -11541277, 14015782, -23665757, 1228319, 17544096, -10593782 }, - { 5811932, -1715293, 3442887, -2269310, -18367348, -8359541, -18044043, -15410127, -5565381, 12348900 }, - { -31399660, 11407555, 25755363, 6891399, -3256938, 14872274, -24849353, 8141295, -10632534, -585479 }, + {5975908, -5243188, -19459362, -9681747, -11541277, 14015782, + -23665757, 1228319, 17544096, -10593782}, + {5811932, -1715293, 3442887, -2269310, -18367348, -8359541, + -18044043, -15410127, -5565381, 12348900}, + {-31399660, 11407555, 25755363, 6891399, -3256938, 14872274, + -24849353, 8141295, -10632534, -585479}, }, { - { -12675304, 694026, -5076145, 13300344, 14015258, -14451394, -9698672, -11329050, 30944593, 1130208 }, - { 8247766, -6710942, -26562381, -7709309, -14401939, -14648910, 4652152, 2488540, 23550156, -271232 }, - { 17294316, -3788438, 7026748, 15626851, 22990044, 113481, 2267737, -5908146, -408818, -137719 }, + {-12675304, 694026, -5076145, 13300344, 14015258, -14451394, + -9698672, -11329050, 30944593, 1130208}, + {8247766, -6710942, -26562381, -7709309, -14401939, -14648910, + 4652152, 2488540, 23550156, -271232}, + {17294316, -3788438, 7026748, 15626851, 22990044, 113481, 2267737, + -5908146, -408818, -137719}, }, { - { 16091085, -16253926, 18599252, 7340678, 2137637, -1221657, -3364161, 14550936, 3260525, -7166271 }, - { -4910104, -13332887, 18550887, 10864893, -16459325, -7291596, -23028869, -13204905, -12748722, 2701326 }, - { -8574695, 16099415, 4629974, -16340524, -20786213, -6005432, -10018363, 9276971, 11329923, 1862132 }, + {16091085, -16253926, 18599252, 7340678, 2137637, -1221657, + -3364161, 14550936, 3260525, -7166271}, + {-4910104, -13332887, 18550887, 10864893, -16459325, -7291596, + -23028869, -13204905, -12748722, 2701326}, + {-8574695, 16099415, 4629974, -16340524, -20786213, -6005432, + -10018363, 9276971, 11329923, 1862132}, }, { - { 14763076, -15903608, -30918270, 3689867, 3511892, 10313526, -21951088, 12219231, -9037963, -940300 }, - { 8894987, -3446094, 6150753, 3013931, 301220, 15693451, -31981216, -2909717, -15438168, 11595570 }, - { 15214962, 3537601, -26238722, -14058872, 4418657, -15230761, 13947276, 10730794, -13489462, -4363670 }, + {14763076, -15903608, -30918270, 3689867, 3511892, 10313526, + -21951088, 12219231, -9037963, -940300}, + {8894987, -3446094, 6150753, 3013931, 301220, 15693451, -31981216, + -2909717, -15438168, 11595570}, + {15214962, 3537601, -26238722, -14058872, 4418657, -15230761, + 13947276, 10730794, -13489462, -4363670}, }, { - { -2538306, 7682793, 32759013, 263109, -29984731, -7955452, -22332124, -10188635, 977108, 699994 }, - { -12466472, 4195084, -9211532, 550904, -15565337, 12917920, 19118110, -439841, -30534533, -14337913 }, - { 31788461, -14507657, 4799989, 7372237, 8808585, -14747943, 9408237, -10051775, 12493932, -5409317 }, + {-2538306, 7682793, 32759013, 263109, -29984731, -7955452, + -22332124, -10188635, 977108, 699994}, + {-12466472, 4195084, -9211532, 550904, -15565337, 12917920, + 19118110, -439841, -30534533, -14337913}, + {31788461, -14507657, 4799989, 7372237, 8808585, -14747943, 9408237, + -10051775, 12493932, -5409317}, }, { - { -25680606, 5260744, -19235809, -6284470, -3695942, 16566087, 27218280, 2607121, 29375955, 6024730 }, - { 842132, -2794693, -4763381, -8722815, 26332018, -12405641, 11831880, 6985184, -9940361, 2854096 }, - { -4847262, -7969331, 2516242, -5847713, 9695691, -7221186, 16512645, 960770, 12121869, 16648078 }, + {-25680606, 5260744, -19235809, -6284470, -3695942, 16566087, + 27218280, 2607121, 29375955, 6024730}, + {842132, -2794693, -4763381, -8722815, 26332018, -12405641, + 11831880, 6985184, -9940361, 2854096}, + {-4847262, -7969331, 2516242, -5847713, 9695691, -7221186, 16512645, + 960770, 12121869, 16648078}, }, { - { -15218652, 14667096, -13336229, 2013717, 30598287, -464137, -31504922, -7882064, 20237806, 2838411 }, - { -19288047, 4453152, 15298546, -16178388, 22115043, -15972604, 12544294, -13470457, 1068881, -12499905 }, - { -9558883, -16518835, 33238498, 13506958, 30505848, -1114596, -8486907, -2630053, 12521378, 4845654 }, + {-15218652, 14667096, -13336229, 2013717, 30598287, -464137, + -31504922, -7882064, 20237806, 2838411}, + {-19288047, 4453152, 15298546, -16178388, 22115043, -15972604, + 12544294, -13470457, 1068881, -12499905}, + {-9558883, -16518835, 33238498, 13506958, 30505848, -1114596, + -8486907, -2630053, 12521378, 4845654}, }, { - { -28198521, 10744108, -2958380, 10199664, 7759311, -13088600, 3409348, -873400, -6482306, -12885870 }, - { -23561822, 6230156, -20382013, 10655314, -24040585, -11621172, 10477734, -1240216, -3113227, 13974498 }, - { 12966261, 15550616, -32038948, -1615346, 21025980, -629444, 5642325, 7188737, 18895762, 12629579 }, + {-28198521, 10744108, -2958380, 10199664, 7759311, -13088600, + 3409348, -873400, -6482306, -12885870}, + {-23561822, 6230156, -20382013, 10655314, -24040585, -11621172, + 10477734, -1240216, -3113227, 13974498}, + {12966261, 15550616, -32038948, -1615346, 21025980, -629444, + 5642325, 7188737, 18895762, 12629579}, }, }, { { - { 14741879, -14946887, 22177208, -11721237, 1279741, 8058600, 11758140, 789443, 32195181, 3895677 }, - { 10758205, 15755439, -4509950, 9243698, -4879422, 6879879, -2204575, -3566119, -8982069, 4429647 }, - { -2453894, 15725973, -20436342, -10410672, -5803908, -11040220, -7135870, -11642895, 18047436, -15281743 }, + {14741879, -14946887, 22177208, -11721237, 1279741, 8058600, + 11758140, 789443, 32195181, 3895677}, + {10758205, 15755439, -4509950, 9243698, -4879422, 6879879, -2204575, + -3566119, -8982069, 4429647}, + {-2453894, 15725973, -20436342, -10410672, -5803908, -11040220, + -7135870, -11642895, 18047436, -15281743}, }, { - { -25173001, -11307165, 29759956, 11776784, -22262383, -15820455, 10993114, -12850837, -17620701, -9408468 }, - { 21987233, 700364, -24505048, 14972008, -7774265, -5718395, 32155026, 2581431, -29958985, 8773375 }, - { -25568350, 454463, -13211935, 16126715, 25240068, 8594567, 20656846, 12017935, -7874389, -13920155 }, + {-25173001, -11307165, 29759956, 11776784, -22262383, -15820455, + 10993114, -12850837, -17620701, -9408468}, + {21987233, 700364, -24505048, 14972008, -7774265, -5718395, + 32155026, 2581431, -29958985, 8773375}, + {-25568350, 454463, -13211935, 16126715, 25240068, 8594567, + 20656846, 12017935, -7874389, -13920155}, }, { - { 6028182, 6263078, -31011806, -11301710, -818919, 2461772, -31841174, -5468042, -1721788, -2776725 }, - { -12278994, 16624277, 987579, -5922598, 32908203, 1248608, 7719845, -4166698, 28408820, 6816612 }, - { -10358094, -8237829, 19549651, -12169222, 22082623, 16147817, 20613181, 13982702, -10339570, 5067943 }, + {6028182, 6263078, -31011806, -11301710, -818919, 2461772, + -31841174, -5468042, -1721788, -2776725}, + {-12278994, 16624277, 987579, -5922598, 32908203, 1248608, 7719845, + -4166698, 28408820, 6816612}, + {-10358094, -8237829, 19549651, -12169222, 22082623, 16147817, + 20613181, 13982702, -10339570, 5067943}, }, { - { -30505967, -3821767, 12074681, 13582412, -19877972, 2443951, -19719286, 12746132, 5331210, -10105944 }, - { 30528811, 3601899, -1957090, 4619785, -27361822, -15436388, 24180793, -12570394, 27679908, -1648928 }, - { 9402404, -13957065, 32834043, 10838634, -26580150, -13237195, 26653274, -8685565, 22611444, -12715406 }, + {-30505967, -3821767, 12074681, 13582412, -19877972, 2443951, + -19719286, 12746132, 5331210, -10105944}, + {30528811, 3601899, -1957090, 4619785, -27361822, -15436388, + 24180793, -12570394, 27679908, -1648928}, + {9402404, -13957065, 32834043, 10838634, -26580150, -13237195, + 26653274, -8685565, 22611444, -12715406}, }, { - { 22190590, 1118029, 22736441, 15130463, -30460692, -5991321, 19189625, -4648942, 4854859, 6622139 }, - { -8310738, -2953450, -8262579, -3388049, -10401731, -271929, 13424426, -3567227, 26404409, 13001963 }, - { -31241838, -15415700, -2994250, 8939346, 11562230, -12840670, -26064365, -11621720, -15405155, 11020693 }, + {22190590, 1118029, 22736441, 15130463, -30460692, -5991321, + 19189625, -4648942, 4854859, 6622139}, + {-8310738, -2953450, -8262579, -3388049, -10401731, -271929, + 13424426, -3567227, 26404409, 13001963}, + {-31241838, -15415700, -2994250, 8939346, 11562230, -12840670, + -26064365, -11621720, -15405155, 11020693}, }, { - { 1866042, -7949489, -7898649, -10301010, 12483315, 13477547, 3175636, -12424163, 28761762, 1406734 }, - { -448555, -1777666, 13018551, 3194501, -9580420, -11161737, 24760585, -4347088, 25577411, -13378680 }, - { -24290378, 4759345, -690653, -1852816, 2066747, 10693769, -29595790, 9884936, -9368926, 4745410 }, + {1866042, -7949489, -7898649, -10301010, 12483315, 13477547, + 3175636, -12424163, 28761762, 1406734}, + {-448555, -1777666, 13018551, 3194501, -9580420, -11161737, + 24760585, -4347088, 25577411, -13378680}, + {-24290378, 4759345, -690653, -1852816, 2066747, 10693769, + -29595790, 9884936, -9368926, 4745410}, }, { - { -9141284, 6049714, -19531061, -4341411, -31260798, 9944276, -15462008, -11311852, 10931924, -11931931 }, - { -16561513, 14112680, -8012645, 4817318, -8040464, -11414606, -22853429, 10856641, -20470770, 13434654 }, - { 22759489, -10073434, -16766264, -1871422, 13637442, -10168091, 1765144, -12654326, 28445307, -5364710 }, + {-9141284, 6049714, -19531061, -4341411, -31260798, 9944276, + -15462008, -11311852, 10931924, -11931931}, + {-16561513, 14112680, -8012645, 4817318, -8040464, -11414606, + -22853429, 10856641, -20470770, 13434654}, + {22759489, -10073434, -16766264, -1871422, 13637442, -10168091, + 1765144, -12654326, 28445307, -5364710}, }, { - { 29875063, 12493613, 2795536, -3786330, 1710620, 15181182, -10195717, -8788675, 9074234, 1167180 }, - { -26205683, 11014233, -9842651, -2635485, -26908120, 7532294, -18716888, -9535498, 3843903, 9367684 }, - { -10969595, -6403711, 9591134, 9582310, 11349256, 108879, 16235123, 8601684, -139197, 4242895 }, + {29875063, 12493613, 2795536, -3786330, 1710620, 15181182, + -10195717, -8788675, 9074234, 1167180}, + {-26205683, 11014233, -9842651, -2635485, -26908120, 7532294, + -18716888, -9535498, 3843903, 9367684}, + {-10969595, -6403711, 9591134, 9582310, 11349256, 108879, 16235123, + 8601684, -139197, 4242895}, }, }, { { - { 22092954, -13191123, -2042793, -11968512, 32186753, -11517388, -6574341, 2470660, -27417366, 16625501 }, - { -11057722, 3042016, 13770083, -9257922, 584236, -544855, -7770857, 2602725, -27351616, 14247413 }, - { 6314175, -10264892, -32772502, 15957557, -10157730, 168750, -8618807, 14290061, 27108877, -1180880 }, + {22092954, -13191123, -2042793, -11968512, 32186753, -11517388, + -6574341, 2470660, -27417366, 16625501}, + {-11057722, 3042016, 13770083, -9257922, 584236, -544855, -7770857, + 2602725, -27351616, 14247413}, + {6314175, -10264892, -32772502, 15957557, -10157730, 168750, + -8618807, 14290061, 27108877, -1180880}, }, { - { -8586597, -7170966, 13241782, 10960156, -32991015, -13794596, 33547976, -11058889, -27148451, 981874 }, - { 22833440, 9293594, -32649448, -13618667, -9136966, 14756819, -22928859, -13970780, -10479804, -16197962 }, - { -7768587, 3326786, -28111797, 10783824, 19178761, 14905060, 22680049, 13906969, -15933690, 3797899 }, + {-8586597, -7170966, 13241782, 10960156, -32991015, -13794596, + 33547976, -11058889, -27148451, 981874}, + {22833440, 9293594, -32649448, -13618667, -9136966, 14756819, + -22928859, -13970780, -10479804, -16197962}, + {-7768587, 3326786, -28111797, 10783824, 19178761, 14905060, + 22680049, 13906969, -15933690, 3797899}, }, { - { 21721356, -4212746, -12206123, 9310182, -3882239, -13653110, 23740224, -2709232, 20491983, -8042152 }, - { 9209270, -15135055, -13256557, -6167798, -731016, 15289673, 25947805, 15286587, 30997318, -6703063 }, - { 7392032, 16618386, 23946583, -8039892, -13265164, -1533858, -14197445, -2321576, 17649998, -250080 }, + {21721356, -4212746, -12206123, 9310182, -3882239, -13653110, + 23740224, -2709232, 20491983, -8042152}, + {9209270, -15135055, -13256557, -6167798, -731016, 15289673, + 25947805, 15286587, 30997318, -6703063}, + {7392032, 16618386, 23946583, -8039892, -13265164, -1533858, + -14197445, -2321576, 17649998, -250080}, }, { - { -9301088, -14193827, 30609526, -3049543, -25175069, -1283752, -15241566, -9525724, -2233253, 7662146 }, - { -17558673, 1763594, -33114336, 15908610, -30040870, -12174295, 7335080, -8472199, -3174674, 3440183 }, - { -19889700, -5977008, -24111293, -9688870, 10799743, -16571957, 40450, -4431835, 4862400, 1133 }, + {-9301088, -14193827, 30609526, -3049543, -25175069, -1283752, + -15241566, -9525724, -2233253, 7662146}, + {-17558673, 1763594, -33114336, 15908610, -30040870, -12174295, + 7335080, -8472199, -3174674, 3440183}, + {-19889700, -5977008, -24111293, -9688870, 10799743, -16571957, + 40450, -4431835, 4862400, 1133}, }, { - { -32856209, -7873957, -5422389, 14860950, -16319031, 7956142, 7258061, 311861, -30594991, -7379421 }, - { -3773428, -1565936, 28985340, 7499440, 24445838, 9325937, 29727763, 16527196, 18278453, 15405622 }, - { -4381906, 8508652, -19898366, -3674424, -5984453, 15149970, -13313598, 843523, -21875062, 13626197 }, + {-32856209, -7873957, -5422389, 14860950, -16319031, 7956142, + 7258061, 311861, -30594991, -7379421}, + {-3773428, -1565936, 28985340, 7499440, 24445838, 9325937, 29727763, + 16527196, 18278453, 15405622}, + {-4381906, 8508652, -19898366, -3674424, -5984453, 15149970, + -13313598, 843523, -21875062, 13626197}, }, { - { 2281448, -13487055, -10915418, -2609910, 1879358, 16164207, -10783882, 3953792, 13340839, 15928663 }, - { 31727126, -7179855, -18437503, -8283652, 2875793, -16390330, -25269894, -7014826, -23452306, 5964753 }, - { 4100420, -5959452, -17179337, 6017714, -18705837, 12227141, -26684835, 11344144, 2538215, -7570755 }, + {2281448, -13487055, -10915418, -2609910, 1879358, 16164207, + -10783882, 3953792, 13340839, 15928663}, + {31727126, -7179855, -18437503, -8283652, 2875793, -16390330, + -25269894, -7014826, -23452306, 5964753}, + {4100420, -5959452, -17179337, 6017714, -18705837, 12227141, + -26684835, 11344144, 2538215, -7570755}, }, { - { -9433605, 6123113, 11159803, -2156608, 30016280, 14966241, -20474983, 1485421, -629256, -15958862 }, - { -26804558, 4260919, 11851389, 9658551, -32017107, 16367492, -20205425, -13191288, 11659922, -11115118 }, - { 26180396, 10015009, -30844224, -8581293, 5418197, 9480663, 2231568, -10170080, 33100372, -1306171 }, + {-9433605, 6123113, 11159803, -2156608, 30016280, 14966241, + -20474983, 1485421, -629256, -15958862}, + {-26804558, 4260919, 11851389, 9658551, -32017107, 16367492, + -20205425, -13191288, 11659922, -11115118}, + {26180396, 10015009, -30844224, -8581293, 5418197, 9480663, 2231568, + -10170080, 33100372, -1306171}, }, { - { 15121113, -5201871, -10389905, 15427821, -27509937, -15992507, 21670947, 4486675, -5931810, -14466380 }, - { 16166486, -9483733, -11104130, 6023908, -31926798, -1364923, 2340060, -16254968, -10735770, -10039824 }, - { 28042865, -3557089, -12126526, 12259706, -3717498, -6945899, 6766453, -8689599, 18036436, 5803270 }, + {15121113, -5201871, -10389905, 15427821, -27509937, -15992507, + 21670947, 4486675, -5931810, -14466380}, + {16166486, -9483733, -11104130, 6023908, -31926798, -1364923, + 2340060, -16254968, -10735770, -10039824}, + {28042865, -3557089, -12126526, 12259706, -3717498, -6945899, + 6766453, -8689599, 18036436, 5803270}, }, }, { { - { -817581, 6763912, 11803561, 1585585, 10958447, -2671165, 23855391, 4598332, -6159431, -14117438 }, - { -31031306, -14256194, 17332029, -2383520, 31312682, -5967183, 696309, 50292, -20095739, 11763584 }, - { -594563, -2514283, -32234153, 12643980, 12650761, 14811489, 665117, -12613632, -19773211, -10713562 }, + {-817581, 6763912, 11803561, 1585585, 10958447, -2671165, 23855391, + 4598332, -6159431, -14117438}, + {-31031306, -14256194, 17332029, -2383520, 31312682, -5967183, + 696309, 50292, -20095739, 11763584}, + {-594563, -2514283, -32234153, 12643980, 12650761, 14811489, 665117, + -12613632, -19773211, -10713562}, }, { - { 30464590, -11262872, -4127476, -12734478, 19835327, -7105613, -24396175, 2075773, -17020157, 992471 }, - { 18357185, -6994433, 7766382, 16342475, -29324918, 411174, 14578841, 8080033, -11574335, -10601610 }, - { 19598397, 10334610, 12555054, 2555664, 18821899, -10339780, 21873263, 16014234, 26224780, 16452269 }, + {30464590, -11262872, -4127476, -12734478, 19835327, -7105613, + -24396175, 2075773, -17020157, 992471}, + {18357185, -6994433, 7766382, 16342475, -29324918, 411174, 14578841, + 8080033, -11574335, -10601610}, + {19598397, 10334610, 12555054, 2555664, 18821899, -10339780, + 21873263, 16014234, 26224780, 16452269}, }, { - { -30223925, 5145196, 5944548, 16385966, 3976735, 2009897, -11377804, -7618186, -20533829, 3698650 }, - { 14187449, 3448569, -10636236, -10810935, -22663880, -3433596, 7268410, -10890444, 27394301, 12015369 }, - { 19695761, 16087646, 28032085, 12999827, 6817792, 11427614, 20244189, -1312777, -13259127, -3402461 }, + {-30223925, 5145196, 5944548, 16385966, 3976735, 2009897, -11377804, + -7618186, -20533829, 3698650}, + {14187449, 3448569, -10636236, -10810935, -22663880, -3433596, + 7268410, -10890444, 27394301, 12015369}, + {19695761, 16087646, 28032085, 12999827, 6817792, 11427614, + 20244189, -1312777, -13259127, -3402461}, }, { - { 30860103, 12735208, -1888245, -4699734, -16974906, 2256940, -8166013, 12298312, -8550524, -10393462 }, - { -5719826, -11245325, -1910649, 15569035, 26642876, -7587760, -5789354, -15118654, -4976164, 12651793 }, - { -2848395, 9953421, 11531313, -5282879, 26895123, -12697089, -13118820, -16517902, 9768698, -2533218 }, + {30860103, 12735208, -1888245, -4699734, -16974906, 2256940, + -8166013, 12298312, -8550524, -10393462}, + {-5719826, -11245325, -1910649, 15569035, 26642876, -7587760, + -5789354, -15118654, -4976164, 12651793}, + {-2848395, 9953421, 11531313, -5282879, 26895123, -12697089, + -13118820, -16517902, 9768698, -2533218}, }, { - { -24719459, 1894651, -287698, -4704085, 15348719, -8156530, 32767513, 12765450, 4940095, 10678226 }, - { 18860224, 15980149, -18987240, -1562570, -26233012, -11071856, -7843882, 13944024, -24372348, 16582019 }, - { -15504260, 4970268, -29893044, 4175593, -20993212, -2199756, -11704054, 15444560, -11003761, 7989037 }, + {-24719459, 1894651, -287698, -4704085, 15348719, -8156530, + 32767513, 12765450, 4940095, 10678226}, + {18860224, 15980149, -18987240, -1562570, -26233012, -11071856, + -7843882, 13944024, -24372348, 16582019}, + {-15504260, 4970268, -29893044, 4175593, -20993212, -2199756, + -11704054, 15444560, -11003761, 7989037}, }, { - { 31490452, 5568061, -2412803, 2182383, -32336847, 4531686, -32078269, 6200206, -19686113, -14800171 }, - { -17308668, -15879940, -31522777, -2831, -32887382, 16375549, 8680158, -16371713, 28550068, -6857132 }, - { -28126887, -5688091, 16837845, -1820458, -6850681, 12700016, -30039981, 4364038, 1155602, 5988841 }, + {31490452, 5568061, -2412803, 2182383, -32336847, 4531686, + -32078269, 6200206, -19686113, -14800171}, + {-17308668, -15879940, -31522777, -2831, -32887382, 16375549, + 8680158, -16371713, 28550068, -6857132}, + {-28126887, -5688091, 16837845, -1820458, -6850681, 12700016, + -30039981, 4364038, 1155602, 5988841}, }, { - { 21890435, -13272907, -12624011, 12154349, -7831873, 15300496, 23148983, -4470481, 24618407, 8283181 }, - { -33136107, -10512751, 9975416, 6841041, -31559793, 16356536, 3070187, -7025928, 1466169, 10740210 }, - { -1509399, -15488185, -13503385, -10655916, 32799044, 909394, -13938903, -5779719, -32164649, -15327040 }, + {21890435, -13272907, -12624011, 12154349, -7831873, 15300496, + 23148983, -4470481, 24618407, 8283181}, + {-33136107, -10512751, 9975416, 6841041, -31559793, 16356536, + 3070187, -7025928, 1466169, 10740210}, + {-1509399, -15488185, -13503385, -10655916, 32799044, 909394, + -13938903, -5779719, -32164649, -15327040}, }, { - { 3960823, -14267803, -28026090, -15918051, -19404858, 13146868, 15567327, 951507, -3260321, -573935 }, - { 24740841, 5052253, -30094131, 8961361, 25877428, 6165135, -24368180, 14397372, -7380369, -6144105 }, - { -28888365, 3510803, -28103278, -1158478, -11238128, -10631454, -15441463, -14453128, -1625486, -6494814 }, + {3960823, -14267803, -28026090, -15918051, -19404858, 13146868, + 15567327, 951507, -3260321, -573935}, + {24740841, 5052253, -30094131, 8961361, 25877428, 6165135, + -24368180, 14397372, -7380369, -6144105}, + {-28888365, 3510803, -28103278, -1158478, -11238128, -10631454, + -15441463, -14453128, -1625486, -6494814}, }, }, { { - { 793299, -9230478, 8836302, -6235707, -27360908, -2369593, 33152843, -4885251, -9906200, -621852 }, - { 5666233, 525582, 20782575, -8038419, -24538499, 14657740, 16099374, 1468826, -6171428, -15186581 }, - { -4859255, -3779343, -2917758, -6748019, 7778750, 11688288, -30404353, -9871238, -1558923, -9863646 }, + {793299, -9230478, 8836302, -6235707, -27360908, -2369593, 33152843, + -4885251, -9906200, -621852}, + {5666233, 525582, 20782575, -8038419, -24538499, 14657740, 16099374, + 1468826, -6171428, -15186581}, + {-4859255, -3779343, -2917758, -6748019, 7778750, 11688288, + -30404353, -9871238, -1558923, -9863646}, }, { - { 10896332, -7719704, 824275, 472601, -19460308, 3009587, 25248958, 14783338, -30581476, -15757844 }, - { 10566929, 12612572, -31944212, 11118703, -12633376, 12362879, 21752402, 8822496, 24003793, 14264025 }, - { 27713862, -7355973, -11008240, 9227530, 27050101, 2504721, 23886875, -13117525, 13958495, -5732453 }, + {10896332, -7719704, 824275, 472601, -19460308, 3009587, 25248958, + 14783338, -30581476, -15757844}, + {10566929, 12612572, -31944212, 11118703, -12633376, 12362879, + 21752402, 8822496, 24003793, 14264025}, + {27713862, -7355973, -11008240, 9227530, 27050101, 2504721, + 23886875, -13117525, 13958495, -5732453}, }, { - { -23481610, 4867226, -27247128, 3900521, 29838369, -8212291, -31889399, -10041781, 7340521, -15410068 }, - { 4646514, -8011124, -22766023, -11532654, 23184553, 8566613, 31366726, -1381061, -15066784, -10375192 }, - { -17270517, 12723032, -16993061, 14878794, 21619651, -6197576, 27584817, 3093888, -8843694, 3849921 }, + {-23481610, 4867226, -27247128, 3900521, 29838369, -8212291, + -31889399, -10041781, 7340521, -15410068}, + {4646514, -8011124, -22766023, -11532654, 23184553, 8566613, + 31366726, -1381061, -15066784, -10375192}, + {-17270517, 12723032, -16993061, 14878794, 21619651, -6197576, + 27584817, 3093888, -8843694, 3849921}, }, { - { -9064912, 2103172, 25561640, -15125738, -5239824, 9582958, 32477045, -9017955, 5002294, -15550259 }, - { -12057553, -11177906, 21115585, -13365155, 8808712, -12030708, 16489530, 13378448, -25845716, 12741426 }, - { -5946367, 10645103, -30911586, 15390284, -3286982, -7118677, 24306472, 15852464, 28834118, -7646072 }, + {-9064912, 2103172, 25561640, -15125738, -5239824, 9582958, + 32477045, -9017955, 5002294, -15550259}, + {-12057553, -11177906, 21115585, -13365155, 8808712, -12030708, + 16489530, 13378448, -25845716, 12741426}, + {-5946367, 10645103, -30911586, 15390284, -3286982, -7118677, + 24306472, 15852464, 28834118, -7646072}, }, { - { -17335748, -9107057, -24531279, 9434953, -8472084, -583362, -13090771, 455841, 20461858, 5491305 }, - { 13669248, -16095482, -12481974, -10203039, -14569770, -11893198, -24995986, 11293807, -28588204, -9421832 }, - { 28497928, 6272777, -33022994, 14470570, 8906179, -1225630, 18504674, -14165166, 29867745, -8795943 }, + {-17335748, -9107057, -24531279, 9434953, -8472084, -583362, + -13090771, 455841, 20461858, 5491305}, + {13669248, -16095482, -12481974, -10203039, -14569770, -11893198, + -24995986, 11293807, -28588204, -9421832}, + {28497928, 6272777, -33022994, 14470570, 8906179, -1225630, + 18504674, -14165166, 29867745, -8795943}, }, { - { -16207023, 13517196, -27799630, -13697798, 24009064, -6373891, -6367600, -13175392, 22853429, -4012011 }, - { 24191378, 16712145, -13931797, 15217831, 14542237, 1646131, 18603514, -11037887, 12876623, -2112447 }, - { 17902668, 4518229, -411702, -2829247, 26878217, 5258055, -12860753, 608397, 16031844, 3723494 }, + {-16207023, 13517196, -27799630, -13697798, 24009064, -6373891, + -6367600, -13175392, 22853429, -4012011}, + {24191378, 16712145, -13931797, 15217831, 14542237, 1646131, + 18603514, -11037887, 12876623, -2112447}, + {17902668, 4518229, -411702, -2829247, 26878217, 5258055, -12860753, + 608397, 16031844, 3723494}, }, { - { -28632773, 12763728, -20446446, 7577504, 33001348, -13017745, 17558842, -7872890, 23896954, -4314245 }, - { -20005381, -12011952, 31520464, 605201, 2543521, 5991821, -2945064, 7229064, -9919646, -8826859 }, - { 28816045, 298879, -28165016, -15920938, 19000928, -1665890, -12680833, -2949325, -18051778, -2082915 }, + {-28632773, 12763728, -20446446, 7577504, 33001348, -13017745, + 17558842, -7872890, 23896954, -4314245}, + {-20005381, -12011952, 31520464, 605201, 2543521, 5991821, -2945064, + 7229064, -9919646, -8826859}, + {28816045, 298879, -28165016, -15920938, 19000928, -1665890, + -12680833, -2949325, -18051778, -2082915}, }, { - { 16000882, -344896, 3493092, -11447198, -29504595, -13159789, 12577740, 16041268, -19715240, 7847707 }, - { 10151868, 10572098, 27312476, 7922682, 14825339, 4723128, -32855931, -6519018, -10020567, 3852848 }, - { -11430470, 15697596, -21121557, -4420647, 5386314, 15063598, 16514493, -15932110, 29330899, -15076224 }, + {16000882, -344896, 3493092, -11447198, -29504595, -13159789, + 12577740, 16041268, -19715240, 7847707}, + {10151868, 10572098, 27312476, 7922682, 14825339, 4723128, + -32855931, -6519018, -10020567, 3852848}, + {-11430470, 15697596, -21121557, -4420647, 5386314, 15063598, + 16514493, -15932110, 29330899, -15076224}, }, }, { { - { -25499735, -4378794, -15222908, -6901211, 16615731, 2051784, 3303702, 15490, -27548796, 12314391 }, - { 15683520, -6003043, 18109120, -9980648, 15337968, -5997823, -16717435, 15921866, 16103996, -3731215 }, - { -23169824, -10781249, 13588192, -1628807, -3798557, -1074929, -19273607, 5402699, -29815713, -9841101 }, + {-25499735, -4378794, -15222908, -6901211, 16615731, 2051784, + 3303702, 15490, -27548796, 12314391}, + {15683520, -6003043, 18109120, -9980648, 15337968, -5997823, + -16717435, 15921866, 16103996, -3731215}, + {-23169824, -10781249, 13588192, -1628807, -3798557, -1074929, + -19273607, 5402699, -29815713, -9841101}, }, { - { 23190676, 2384583, -32714340, 3462154, -29903655, -1529132, -11266856, 8911517, -25205859, 2739713 }, - { 21374101, -3554250, -33524649, 9874411, 15377179, 11831242, -33529904, 6134907, 4931255, 11987849 }, - { -7732, -2978858, -16223486, 7277597, 105524, -322051, -31480539, 13861388, -30076310, 10117930 }, + {23190676, 2384583, -32714340, 3462154, -29903655, -1529132, + -11266856, 8911517, -25205859, 2739713}, + {21374101, -3554250, -33524649, 9874411, 15377179, 11831242, + -33529904, 6134907, 4931255, 11987849}, + {-7732, -2978858, -16223486, 7277597, 105524, -322051, -31480539, + 13861388, -30076310, 10117930}, }, { - { -29501170, -10744872, -26163768, 13051539, -25625564, 5089643, -6325503, 6704079, 12890019, 15728940 }, - { -21972360, -11771379, -951059, -4418840, 14704840, 2695116, 903376, -10428139, 12885167, 8311031 }, - { -17516482, 5352194, 10384213, -13811658, 7506451, 13453191, 26423267, 4384730, 1888765, -5435404 }, + {-29501170, -10744872, -26163768, 13051539, -25625564, 5089643, + -6325503, 6704079, 12890019, 15728940}, + {-21972360, -11771379, -951059, -4418840, 14704840, 2695116, 903376, + -10428139, 12885167, 8311031}, + {-17516482, 5352194, 10384213, -13811658, 7506451, 13453191, + 26423267, 4384730, 1888765, -5435404}, }, { - { -25817338, -3107312, -13494599, -3182506, 30896459, -13921729, -32251644, -12707869, -19464434, -3340243 }, - { -23607977, -2665774, -526091, 4651136, 5765089, 4618330, 6092245, 14845197, 17151279, -9854116 }, - { -24830458, -12733720, -15165978, 10367250, -29530908, -265356, 22825805, -7087279, -16866484, 16176525 }, + {-25817338, -3107312, -13494599, -3182506, 30896459, -13921729, + -32251644, -12707869, -19464434, -3340243}, + {-23607977, -2665774, -526091, 4651136, 5765089, 4618330, 6092245, + 14845197, 17151279, -9854116}, + {-24830458, -12733720, -15165978, 10367250, -29530908, -265356, + 22825805, -7087279, -16866484, 16176525}, }, { - { -23583256, 6564961, 20063689, 3798228, -4740178, 7359225, 2006182, -10363426, -28746253, -10197509 }, - { -10626600, -4486402, -13320562, -5125317, 3432136, -6393229, 23632037, -1940610, 32808310, 1099883 }, - { 15030977, 5768825, -27451236, -2887299, -6427378, -15361371, -15277896, -6809350, 2051441, -15225865 }, + {-23583256, 6564961, 20063689, 3798228, -4740178, 7359225, 2006182, + -10363426, -28746253, -10197509}, + {-10626600, -4486402, -13320562, -5125317, 3432136, -6393229, + 23632037, -1940610, 32808310, 1099883}, + {15030977, 5768825, -27451236, -2887299, -6427378, -15361371, + -15277896, -6809350, 2051441, -15225865}, }, { - { -3362323, -7239372, 7517890, 9824992, 23555850, 295369, 5148398, -14154188, -22686354, 16633660 }, - { 4577086, -16752288, 13249841, -15304328, 19958763, -14537274, 18559670, -10759549, 8402478, -9864273 }, - { -28406330, -1051581, -26790155, -907698, -17212414, -11030789, 9453451, -14980072, 17983010, 9967138 }, + {-3362323, -7239372, 7517890, 9824992, 23555850, 295369, 5148398, + -14154188, -22686354, 16633660}, + {4577086, -16752288, 13249841, -15304328, 19958763, -14537274, + 18559670, -10759549, 8402478, -9864273}, + {-28406330, -1051581, -26790155, -907698, -17212414, -11030789, + 9453451, -14980072, 17983010, 9967138}, }, { - { -25762494, 6524722, 26585488, 9969270, 24709298, 1220360, -1677990, 7806337, 17507396, 3651560 }, - { -10420457, -4118111, 14584639, 15971087, -15768321, 8861010, 26556809, -5574557, -18553322, -11357135 }, - { 2839101, 14284142, 4029895, 3472686, 14402957, 12689363, -26642121, 8459447, -5605463, -7621941 }, + {-25762494, 6524722, 26585488, 9969270, 24709298, 1220360, -1677990, + 7806337, 17507396, 3651560}, + {-10420457, -4118111, 14584639, 15971087, -15768321, 8861010, + 26556809, -5574557, -18553322, -11357135}, + {2839101, 14284142, 4029895, 3472686, 14402957, 12689363, -26642121, + 8459447, -5605463, -7621941}, }, { - { -4839289, -3535444, 9744961, 2871048, 25113978, 3187018, -25110813, -849066, 17258084, -7977739 }, - { 18164541, -10595176, -17154882, -1542417, 19237078, -9745295, 23357533, -15217008, 26908270, 12150756 }, - { -30264870, -7647865, 5112249, -7036672, -1499807, -6974257, 43168, -5537701, -32302074, 16215819 }, + {-4839289, -3535444, 9744961, 2871048, 25113978, 3187018, -25110813, + -849066, 17258084, -7977739}, + {18164541, -10595176, -17154882, -1542417, 19237078, -9745295, + 23357533, -15217008, 26908270, 12150756}, + {-30264870, -7647865, 5112249, -7036672, -1499807, -6974257, 43168, + -5537701, -32302074, 16215819}, }, }, { { - { -6898905, 9824394, -12304779, -4401089, -31397141, -6276835, 32574489, 12532905, -7503072, -8675347 }, - { -27343522, -16515468, -27151524, -10722951, 946346, 16291093, 254968, 7168080, 21676107, -1943028 }, - { 21260961, -8424752, -16831886, -11920822, -23677961, 3968121, -3651949, -6215466, -3556191, -7913075 }, + {-6898905, 9824394, -12304779, -4401089, -31397141, -6276835, + 32574489, 12532905, -7503072, -8675347}, + {-27343522, -16515468, -27151524, -10722951, 946346, 16291093, + 254968, 7168080, 21676107, -1943028}, + {21260961, -8424752, -16831886, -11920822, -23677961, 3968121, + -3651949, -6215466, -3556191, -7913075}, }, { - { 16544754, 13250366, -16804428, 15546242, -4583003, 12757258, -2462308, -8680336, -18907032, -9662799 }, - { -2415239, -15577728, 18312303, 4964443, -15272530, -12653564, 26820651, 16690659, 25459437, -4564609 }, - { -25144690, 11425020, 28423002, -11020557, -6144921, -15826224, 9142795, -2391602, -6432418, -1644817 }, + {16544754, 13250366, -16804428, 15546242, -4583003, 12757258, + -2462308, -8680336, -18907032, -9662799}, + {-2415239, -15577728, 18312303, 4964443, -15272530, -12653564, + 26820651, 16690659, 25459437, -4564609}, + {-25144690, 11425020, 28423002, -11020557, -6144921, -15826224, + 9142795, -2391602, -6432418, -1644817}, }, { - { -23104652, 6253476, 16964147, -3768872, -25113972, -12296437, -27457225, -16344658, 6335692, 7249989 }, - { -30333227, 13979675, 7503222, -12368314, -11956721, -4621693, -30272269, 2682242, 25993170, -12478523 }, - { 4364628, 5930691, 32304656, -10044554, -8054781, 15091131, 22857016, -10598955, 31820368, 15075278 }, + {-23104652, 6253476, 16964147, -3768872, -25113972, -12296437, + -27457225, -16344658, 6335692, 7249989}, + {-30333227, 13979675, 7503222, -12368314, -11956721, -4621693, + -30272269, 2682242, 25993170, -12478523}, + {4364628, 5930691, 32304656, -10044554, -8054781, 15091131, + 22857016, -10598955, 31820368, 15075278}, }, { - { 31879134, -8918693, 17258761, 90626, -8041836, -4917709, 24162788, -9650886, -17970238, 12833045 }, - { 19073683, 14851414, -24403169, -11860168, 7625278, 11091125, -19619190, 2074449, -9413939, 14905377 }, - { 24483667, -11935567, -2518866, -11547418, -1553130, 15355506, -25282080, 9253129, 27628530, -7555480 }, + {31879134, -8918693, 17258761, 90626, -8041836, -4917709, 24162788, + -9650886, -17970238, 12833045}, + {19073683, 14851414, -24403169, -11860168, 7625278, 11091125, + -19619190, 2074449, -9413939, 14905377}, + {24483667, -11935567, -2518866, -11547418, -1553130, 15355506, + -25282080, 9253129, 27628530, -7555480}, }, { - { 17597607, 8340603, 19355617, 552187, 26198470, -3176583, 4593324, -9157582, -14110875, 15297016 }, - { 510886, 14337390, -31785257, 16638632, 6328095, 2713355, -20217417, -11864220, 8683221, 2921426 }, - { 18606791, 11874196, 27155355, -5281482, -24031742, 6265446, -25178240, -1278924, 4674690, 13890525 }, + {17597607, 8340603, 19355617, 552187, 26198470, -3176583, 4593324, + -9157582, -14110875, 15297016}, + {510886, 14337390, -31785257, 16638632, 6328095, 2713355, -20217417, + -11864220, 8683221, 2921426}, + {18606791, 11874196, 27155355, -5281482, -24031742, 6265446, + -25178240, -1278924, 4674690, 13890525}, }, { - { 13609624, 13069022, -27372361, -13055908, 24360586, 9592974, 14977157, 9835105, 4389687, 288396 }, - { 9922506, -519394, 13613107, 5883594, -18758345, -434263, -12304062, 8317628, 23388070, 16052080 }, - { 12720016, 11937594, -31970060, -5028689, 26900120, 8561328, -20155687, -11632979, -14754271, -10812892 }, + {13609624, 13069022, -27372361, -13055908, 24360586, 9592974, + 14977157, 9835105, 4389687, 288396}, + {9922506, -519394, 13613107, 5883594, -18758345, -434263, -12304062, + 8317628, 23388070, 16052080}, + {12720016, 11937594, -31970060, -5028689, 26900120, 8561328, + -20155687, -11632979, -14754271, -10812892}, }, { - { 15961858, 14150409, 26716931, -665832, -22794328, 13603569, 11829573, 7467844, -28822128, 929275 }, - { 11038231, -11582396, -27310482, -7316562, -10498527, -16307831, -23479533, -9371869, -21393143, 2465074 }, - { 20017163, -4323226, 27915242, 1529148, 12396362, 15675764, 13817261, -9658066, 2463391, -4622140 }, + {15961858, 14150409, 26716931, -665832, -22794328, 13603569, + 11829573, 7467844, -28822128, 929275}, + {11038231, -11582396, -27310482, -7316562, -10498527, -16307831, + -23479533, -9371869, -21393143, 2465074}, + {20017163, -4323226, 27915242, 1529148, 12396362, 15675764, + 13817261, -9658066, 2463391, -4622140}, }, { - { -16358878, -12663911, -12065183, 4996454, -1256422, 1073572, 9583558, 12851107, 4003896, 12673717 }, - { -1731589, -15155870, -3262930, 16143082, 19294135, 13385325, 14741514, -9103726, 7903886, 2348101 }, - { 24536016, -16515207, 12715592, -3862155, 1511293, 10047386, -3842346, -7129159, -28377538, 10048127 }, + {-16358878, -12663911, -12065183, 4996454, -1256422, 1073572, + 9583558, 12851107, 4003896, 12673717}, + {-1731589, -15155870, -3262930, 16143082, 19294135, 13385325, + 14741514, -9103726, 7903886, 2348101}, + {24536016, -16515207, 12715592, -3862155, 1511293, 10047386, + -3842346, -7129159, -28377538, 10048127}, }, }, { { - { -12622226, -6204820, 30718825, 2591312, -10617028, 12192840, 18873298, -7297090, -32297756, 15221632 }, - { -26478122, -11103864, 11546244, -1852483, 9180880, 7656409, -21343950, 2095755, 29769758, 6593415 }, - { -31994208, -2907461, 4176912, 3264766, 12538965, -868111, 26312345, -6118678, 30958054, 8292160 }, + {-12622226, -6204820, 30718825, 2591312, -10617028, 12192840, + 18873298, -7297090, -32297756, 15221632}, + {-26478122, -11103864, 11546244, -1852483, 9180880, 7656409, + -21343950, 2095755, 29769758, 6593415}, + {-31994208, -2907461, 4176912, 3264766, 12538965, -868111, 26312345, + -6118678, 30958054, 8292160}, }, { - { 31429822, -13959116, 29173532, 15632448, 12174511, -2760094, 32808831, 3977186, 26143136, -3148876 }, - { 22648901, 1402143, -22799984, 13746059, 7936347, 365344, -8668633, -1674433, -3758243, -2304625 }, - { -15491917, 8012313, -2514730, -12702462, -23965846, -10254029, -1612713, -1535569, -16664475, 8194478 }, + {31429822, -13959116, 29173532, 15632448, 12174511, -2760094, + 32808831, 3977186, 26143136, -3148876}, + {22648901, 1402143, -22799984, 13746059, 7936347, 365344, -8668633, + -1674433, -3758243, -2304625}, + {-15491917, 8012313, -2514730, -12702462, -23965846, -10254029, + -1612713, -1535569, -16664475, 8194478}, }, { - { 27338066, -7507420, -7414224, 10140405, -19026427, -6589889, 27277191, 8855376, 28572286, 3005164 }, - { 26287124, 4821776, 25476601, -4145903, -3764513, -15788984, -18008582, 1182479, -26094821, -13079595 }, - { -7171154, 3178080, 23970071, 6201893, -17195577, -4489192, -21876275, -13982627, 32208683, -1198248 }, + {27338066, -7507420, -7414224, 10140405, -19026427, -6589889, + 27277191, 8855376, 28572286, 3005164}, + {26287124, 4821776, 25476601, -4145903, -3764513, -15788984, + -18008582, 1182479, -26094821, -13079595}, + {-7171154, 3178080, 23970071, 6201893, -17195577, -4489192, + -21876275, -13982627, 32208683, -1198248}, }, { - { -16657702, 2817643, -10286362, 14811298, 6024667, 13349505, -27315504, -10497842, -27672585, -11539858 }, - { 15941029, -9405932, -21367050, 8062055, 31876073, -238629, -15278393, -1444429, 15397331, -4130193 }, - { 8934485, -13485467, -23286397, -13423241, -32446090, 14047986, 31170398, -1441021, -27505566, 15087184 }, + {-16657702, 2817643, -10286362, 14811298, 6024667, 13349505, + -27315504, -10497842, -27672585, -11539858}, + {15941029, -9405932, -21367050, 8062055, 31876073, -238629, + -15278393, -1444429, 15397331, -4130193}, + {8934485, -13485467, -23286397, -13423241, -32446090, 14047986, + 31170398, -1441021, -27505566, 15087184}, }, { - { -18357243, -2156491, 24524913, -16677868, 15520427, -6360776, -15502406, 11461896, 16788528, -5868942 }, - { -1947386, 16013773, 21750665, 3714552, -17401782, -16055433, -3770287, -10323320, 31322514, -11615635 }, - { 21426655, -5650218, -13648287, -5347537, -28812189, -4920970, -18275391, -14621414, 13040862, -12112948 }, + {-18357243, -2156491, 24524913, -16677868, 15520427, -6360776, + -15502406, 11461896, 16788528, -5868942}, + {-1947386, 16013773, 21750665, 3714552, -17401782, -16055433, + -3770287, -10323320, 31322514, -11615635}, + {21426655, -5650218, -13648287, -5347537, -28812189, -4920970, + -18275391, -14621414, 13040862, -12112948}, }, { - { 11293895, 12478086, -27136401, 15083750, -29307421, 14748872, 14555558, -13417103, 1613711, 4896935 }, - { -25894883, 15323294, -8489791, -8057900, 25967126, -13425460, 2825960, -4897045, -23971776, -11267415 }, - { -15924766, -5229880, -17443532, 6410664, 3622847, 10243618, 20615400, 12405433, -23753030, -8436416 }, + {11293895, 12478086, -27136401, 15083750, -29307421, 14748872, + 14555558, -13417103, 1613711, 4896935}, + {-25894883, 15323294, -8489791, -8057900, 25967126, -13425460, + 2825960, -4897045, -23971776, -11267415}, + {-15924766, -5229880, -17443532, 6410664, 3622847, 10243618, + 20615400, 12405433, -23753030, -8436416}, }, { - { -7091295, 12556208, -20191352, 9025187, -17072479, 4333801, 4378436, 2432030, 23097949, -566018 }, - { 4565804, -16025654, 20084412, -7842817, 1724999, 189254, 24767264, 10103221, -18512313, 2424778 }, - { 366633, -11976806, 8173090, -6890119, 30788634, 5745705, -7168678, 1344109, -3642553, 12412659 }, + {-7091295, 12556208, -20191352, 9025187, -17072479, 4333801, + 4378436, 2432030, 23097949, -566018}, + {4565804, -16025654, 20084412, -7842817, 1724999, 189254, 24767264, + 10103221, -18512313, 2424778}, + {366633, -11976806, 8173090, -6890119, 30788634, 5745705, -7168678, + 1344109, -3642553, 12412659}, }, { - { -24001791, 7690286, 14929416, -168257, -32210835, -13412986, 24162697, -15326504, -3141501, 11179385 }, - { 18289522, -14724954, 8056945, 16430056, -21729724, 7842514, -6001441, -1486897, -18684645, -11443503 }, - { 476239, 6601091, -6152790, -9723375, 17503545, -4863900, 27672959, 13403813, 11052904, 5219329 }, + {-24001791, 7690286, 14929416, -168257, -32210835, -13412986, + 24162697, -15326504, -3141501, 11179385}, + {18289522, -14724954, 8056945, 16430056, -21729724, 7842514, + -6001441, -1486897, -18684645, -11443503}, + {476239, 6601091, -6152790, -9723375, 17503545, -4863900, 27672959, + 13403813, 11052904, 5219329}, }, }, { { - { 20678546, -8375738, -32671898, 8849123, -5009758, 14574752, 31186971, -3973730, 9014762, -8579056 }, - { -13644050, -10350239, -15962508, 5075808, -1514661, -11534600, -33102500, 9160280, 8473550, -3256838 }, - { 24900749, 14435722, 17209120, -15292541, -22592275, 9878983, -7689309, -16335821, -24568481, 11788948 }, + {20678546, -8375738, -32671898, 8849123, -5009758, 14574752, + 31186971, -3973730, 9014762, -8579056}, + {-13644050, -10350239, -15962508, 5075808, -1514661, -11534600, + -33102500, 9160280, 8473550, -3256838}, + {24900749, 14435722, 17209120, -15292541, -22592275, 9878983, + -7689309, -16335821, -24568481, 11788948}, }, { - { -3118155, -11395194, -13802089, 14797441, 9652448, -6845904, -20037437, 10410733, -24568470, -1458691 }, - { -15659161, 16736706, -22467150, 10215878, -9097177, 7563911, 11871841, -12505194, -18513325, 8464118 }, - { -23400612, 8348507, -14585951, -861714, -3950205, -6373419, 14325289, 8628612, 33313881, -8370517 }, + {-3118155, -11395194, -13802089, 14797441, 9652448, -6845904, + -20037437, 10410733, -24568470, -1458691}, + {-15659161, 16736706, -22467150, 10215878, -9097177, 7563911, + 11871841, -12505194, -18513325, 8464118}, + {-23400612, 8348507, -14585951, -861714, -3950205, -6373419, + 14325289, 8628612, 33313881, -8370517}, }, { - { -20186973, -4967935, 22367356, 5271547, -1097117, -4788838, -24805667, -10236854, -8940735, -5818269 }, - { -6948785, -1795212, -32625683, -16021179, 32635414, -7374245, 15989197, -12838188, 28358192, -4253904 }, - { -23561781, -2799059, -32351682, -1661963, -9147719, 10429267, -16637684, 4072016, -5351664, 5596589 }, + {-20186973, -4967935, 22367356, 5271547, -1097117, -4788838, + -24805667, -10236854, -8940735, -5818269}, + {-6948785, -1795212, -32625683, -16021179, 32635414, -7374245, + 15989197, -12838188, 28358192, -4253904}, + {-23561781, -2799059, -32351682, -1661963, -9147719, 10429267, + -16637684, 4072016, -5351664, 5596589}, }, { - { -28236598, -3390048, 12312896, 6213178, 3117142, 16078565, 29266239, 2557221, 1768301, 15373193 }, - { -7243358, -3246960, -4593467, -7553353, -127927, -912245, -1090902, -4504991, -24660491, 3442910 }, - { -30210571, 5124043, 14181784, 8197961, 18964734, -11939093, 22597931, 7176455, -18585478, 13365930 }, + {-28236598, -3390048, 12312896, 6213178, 3117142, 16078565, + 29266239, 2557221, 1768301, 15373193}, + {-7243358, -3246960, -4593467, -7553353, -127927, -912245, -1090902, + -4504991, -24660491, 3442910}, + {-30210571, 5124043, 14181784, 8197961, 18964734, -11939093, + 22597931, 7176455, -18585478, 13365930}, }, { - { -7877390, -1499958, 8324673, 4690079, 6261860, 890446, 24538107, -8570186, -9689599, -3031667 }, - { 25008904, -10771599, -4305031, -9638010, 16265036, 15721635, 683793, -11823784, 15723479, -15163481 }, - { -9660625, 12374379, -27006999, -7026148, -7724114, -12314514, 11879682, 5400171, 519526, -1235876 }, + {-7877390, -1499958, 8324673, 4690079, 6261860, 890446, 24538107, + -8570186, -9689599, -3031667}, + {25008904, -10771599, -4305031, -9638010, 16265036, 15721635, + 683793, -11823784, 15723479, -15163481}, + {-9660625, 12374379, -27006999, -7026148, -7724114, -12314514, + 11879682, 5400171, 519526, -1235876}, }, { - { 22258397, -16332233, -7869817, 14613016, -22520255, -2950923, -20353881, 7315967, 16648397, 7605640 }, - { -8081308, -8464597, -8223311, 9719710, 19259459, -15348212, 23994942, -5281555, -9468848, 4763278 }, - { -21699244, 9220969, -15730624, 1084137, -25476107, -2852390, 31088447, -7764523, -11356529, 728112 }, + {22258397, -16332233, -7869817, 14613016, -22520255, -2950923, + -20353881, 7315967, 16648397, 7605640}, + {-8081308, -8464597, -8223311, 9719710, 19259459, -15348212, + 23994942, -5281555, -9468848, 4763278}, + {-21699244, 9220969, -15730624, 1084137, -25476107, -2852390, + 31088447, -7764523, -11356529, 728112}, }, { - { 26047220, -11751471, -6900323, -16521798, 24092068, 9158119, -4273545, -12555558, -29365436, -5498272 }, - { 17510331, -322857, 5854289, 8403524, 17133918, -3112612, -28111007, 12327945, 10750447, 10014012 }, - { -10312768, 3936952, 9156313, -8897683, 16498692, -994647, -27481051, -666732, 3424691, 7540221 }, + {26047220, -11751471, -6900323, -16521798, 24092068, 9158119, + -4273545, -12555558, -29365436, -5498272}, + {17510331, -322857, 5854289, 8403524, 17133918, -3112612, -28111007, + 12327945, 10750447, 10014012}, + {-10312768, 3936952, 9156313, -8897683, 16498692, -994647, + -27481051, -666732, 3424691, 7540221}, }, { - { 30322361, -6964110, 11361005, -4143317, 7433304, 4989748, -7071422, -16317219, -9244265, 15258046 }, - { 13054562, -2779497, 19155474, 469045, -12482797, 4566042, 5631406, 2711395, 1062915, -5136345 }, - { -19240248, -11254599, -29509029, -7499965, -5835763, 13005411, -6066489, 12194497, 32960380, 1459310 }, + {30322361, -6964110, 11361005, -4143317, 7433304, 4989748, -7071422, + -16317219, -9244265, 15258046}, + {13054562, -2779497, 19155474, 469045, -12482797, 4566042, 5631406, + 2711395, 1062915, -5136345}, + {-19240248, -11254599, -29509029, -7499965, -5835763, 13005411, + -6066489, 12194497, 32960380, 1459310}, }, }, { { - { 19852034, 7027924, 23669353, 10020366, 8586503, -6657907, 394197, -6101885, 18638003, -11174937 }, - { 31395534, 15098109, 26581030, 8030562, -16527914, -5007134, 9012486, -7584354, -6643087, -5442636 }, - { -9192165, -2347377, -1997099, 4529534, 25766844, 607986, -13222, 9677543, -32294889, -6456008 }, + {19852034, 7027924, 23669353, 10020366, 8586503, -6657907, 394197, + -6101885, 18638003, -11174937}, + {31395534, 15098109, 26581030, 8030562, -16527914, -5007134, + 9012486, -7584354, -6643087, -5442636}, + {-9192165, -2347377, -1997099, 4529534, 25766844, 607986, -13222, + 9677543, -32294889, -6456008}, }, { - { -2444496, -149937, 29348902, 8186665, 1873760, 12489863, -30934579, -7839692, -7852844, -8138429 }, - { -15236356, -15433509, 7766470, 746860, 26346930, -10221762, -27333451, 10754588, -9431476, 5203576 }, - { 31834314, 14135496, -770007, 5159118, 20917671, -16768096, -7467973, -7337524, 31809243, 7347066 }, + {-2444496, -149937, 29348902, 8186665, 1873760, 12489863, -30934579, + -7839692, -7852844, -8138429}, + {-15236356, -15433509, 7766470, 746860, 26346930, -10221762, + -27333451, 10754588, -9431476, 5203576}, + {31834314, 14135496, -770007, 5159118, 20917671, -16768096, + -7467973, -7337524, 31809243, 7347066}, }, { - { -9606723, -11874240, 20414459, 13033986, 13716524, -11691881, 19797970, -12211255, 15192876, -2087490 }, - { -12663563, -2181719, 1168162, -3804809, 26747877, -14138091, 10609330, 12694420, 33473243, -13382104 }, - { 33184999, 11180355, 15832085, -11385430, -1633671, 225884, 15089336, -11023903, -6135662, 14480053 }, + {-9606723, -11874240, 20414459, 13033986, 13716524, -11691881, + 19797970, -12211255, 15192876, -2087490}, + {-12663563, -2181719, 1168162, -3804809, 26747877, -14138091, + 10609330, 12694420, 33473243, -13382104}, + {33184999, 11180355, 15832085, -11385430, -1633671, 225884, + 15089336, -11023903, -6135662, 14480053}, }, { - { 31308717, -5619998, 31030840, -1897099, 15674547, -6582883, 5496208, 13685227, 27595050, 8737275 }, - { -20318852, -15150239, 10933843, -16178022, 8335352, -7546022, -31008351, -12610604, 26498114, 66511 }, - { 22644454, -8761729, -16671776, 4884562, -3105614, -13559366, 30540766, -4286747, -13327787, -7515095 }, + {31308717, -5619998, 31030840, -1897099, 15674547, -6582883, + 5496208, 13685227, 27595050, 8737275}, + {-20318852, -15150239, 10933843, -16178022, 8335352, -7546022, + -31008351, -12610604, 26498114, 66511}, + {22644454, -8761729, -16671776, 4884562, -3105614, -13559366, + 30540766, -4286747, -13327787, -7515095}, }, { - { -28017847, 9834845, 18617207, -2681312, -3401956, -13307506, 8205540, 13585437, -17127465, 15115439 }, - { 23711543, -672915, 31206561, -8362711, 6164647, -9709987, -33535882, -1426096, 8236921, 16492939 }, - { -23910559, -13515526, -26299483, -4503841, 25005590, -7687270, 19574902, 10071562, 6708380, -6222424 }, + {-28017847, 9834845, 18617207, -2681312, -3401956, -13307506, + 8205540, 13585437, -17127465, 15115439}, + {23711543, -672915, 31206561, -8362711, 6164647, -9709987, + -33535882, -1426096, 8236921, 16492939}, + {-23910559, -13515526, -26299483, -4503841, 25005590, -7687270, + 19574902, 10071562, 6708380, -6222424}, }, { - { 2101391, -4930054, 19702731, 2367575, -15427167, 1047675, 5301017, 9328700, 29955601, -11678310 }, - { 3096359, 9271816, -21620864, -15521844, -14847996, -7592937, -25892142, -12635595, -9917575, 6216608 }, - { -32615849, 338663, -25195611, 2510422, -29213566, -13820213, 24822830, -6146567, -26767480, 7525079 }, + {2101391, -4930054, 19702731, 2367575, -15427167, 1047675, 5301017, + 9328700, 29955601, -11678310}, + {3096359, 9271816, -21620864, -15521844, -14847996, -7592937, + -25892142, -12635595, -9917575, 6216608}, + {-32615849, 338663, -25195611, 2510422, -29213566, -13820213, + 24822830, -6146567, -26767480, 7525079}, }, { - { -23066649, -13985623, 16133487, -7896178, -3389565, 778788, -910336, -2782495, -19386633, 11994101 }, - { 21691500, -13624626, -641331, -14367021, 3285881, -3483596, -25064666, 9718258, -7477437, 13381418 }, - { 18445390, -4202236, 14979846, 11622458, -1727110, -3582980, 23111648, -6375247, 28535282, 15779576 }, + {-23066649, -13985623, 16133487, -7896178, -3389565, 778788, + -910336, -2782495, -19386633, 11994101}, + {21691500, -13624626, -641331, -14367021, 3285881, -3483596, + -25064666, 9718258, -7477437, 13381418}, + {18445390, -4202236, 14979846, 11622458, -1727110, -3582980, + 23111648, -6375247, 28535282, 15779576}, }, { - { 30098053, 3089662, -9234387, 16662135, -21306940, 11308411, -14068454, 12021730, 9955285, -16303356 }, - { 9734894, -14576830, -7473633, -9138735, 2060392, 11313496, -18426029, 9924399, 20194861, 13380996 }, - { -26378102, -7965207, -22167821, 15789297, -18055342, -6168792, -1984914, 15707771, 26342023, 10146099 }, + {30098053, 3089662, -9234387, 16662135, -21306940, 11308411, + -14068454, 12021730, 9955285, -16303356}, + {9734894, -14576830, -7473633, -9138735, 2060392, 11313496, + -18426029, 9924399, 20194861, 13380996}, + {-26378102, -7965207, -22167821, 15789297, -18055342, -6168792, + -1984914, 15707771, 26342023, 10146099}, }, }, { { - { -26016874, -219943, 21339191, -41388, 19745256, -2878700, -29637280, 2227040, 21612326, -545728 }, - { -13077387, 1184228, 23562814, -5970442, -20351244, -6348714, 25764461, 12243797, -20856566, 11649658 }, - { -10031494, 11262626, 27384172, 2271902, 26947504, -15997771, 39944, 6114064, 33514190, 2333242 }, + {-26016874, -219943, 21339191, -41388, 19745256, -2878700, + -29637280, 2227040, 21612326, -545728}, + {-13077387, 1184228, 23562814, -5970442, -20351244, -6348714, + 25764461, 12243797, -20856566, 11649658}, + {-10031494, 11262626, 27384172, 2271902, 26947504, -15997771, 39944, + 6114064, 33514190, 2333242}, }, { - { -21433588, -12421821, 8119782, 7219913, -21830522, -9016134, -6679750, -12670638, 24350578, -13450001 }, - { -4116307, -11271533, -23886186, 4843615, -30088339, 690623, -31536088, -10406836, 8317860, 12352766 }, - { 18200138, -14475911, -33087759, -2696619, -23702521, -9102511, -23552096, -2287550, 20712163, 6719373 }, + {-21433588, -12421821, 8119782, 7219913, -21830522, -9016134, + -6679750, -12670638, 24350578, -13450001}, + {-4116307, -11271533, -23886186, 4843615, -30088339, 690623, + -31536088, -10406836, 8317860, 12352766}, + {18200138, -14475911, -33087759, -2696619, -23702521, -9102511, + -23552096, -2287550, 20712163, 6719373}, }, { - { 26656208, 6075253, -7858556, 1886072, -28344043, 4262326, 11117530, -3763210, 26224235, -3297458 }, - { -17168938, -14854097, -3395676, -16369877, -19954045, 14050420, 21728352, 9493610, 18620611, -16428628 }, - { -13323321, 13325349, 11432106, 5964811, 18609221, 6062965, -5269471, -9725556, -30701573, -16479657 }, + {26656208, 6075253, -7858556, 1886072, -28344043, 4262326, 11117530, + -3763210, 26224235, -3297458}, + {-17168938, -14854097, -3395676, -16369877, -19954045, 14050420, + 21728352, 9493610, 18620611, -16428628}, + {-13323321, 13325349, 11432106, 5964811, 18609221, 6062965, + -5269471, -9725556, -30701573, -16479657}, }, { - { -23860538, -11233159, 26961357, 1640861, -32413112, -16737940, 12248509, -5240639, 13735342, 1934062 }, - { 25089769, 6742589, 17081145, -13406266, 21909293, -16067981, -15136294, -3765346, -21277997, 5473616 }, - { 31883677, -7961101, 1083432, -11572403, 22828471, 13290673, -7125085, 12469656, 29111212, -5451014 }, + {-23860538, -11233159, 26961357, 1640861, -32413112, -16737940, + 12248509, -5240639, 13735342, 1934062}, + {25089769, 6742589, 17081145, -13406266, 21909293, -16067981, + -15136294, -3765346, -21277997, 5473616}, + {31883677, -7961101, 1083432, -11572403, 22828471, 13290673, + -7125085, 12469656, 29111212, -5451014}, }, { - { 24244947, -15050407, -26262976, 2791540, -14997599, 16666678, 24367466, 6388839, -10295587, 452383 }, - { -25640782, -3417841, 5217916, 16224624, 19987036, -4082269, -24236251, -5915248, 15766062, 8407814 }, - { -20406999, 13990231, 15495425, 16395525, 5377168, 15166495, -8917023, -4388953, -8067909, 2276718 }, + {24244947, -15050407, -26262976, 2791540, -14997599, 16666678, + 24367466, 6388839, -10295587, 452383}, + {-25640782, -3417841, 5217916, 16224624, 19987036, -4082269, + -24236251, -5915248, 15766062, 8407814}, + {-20406999, 13990231, 15495425, 16395525, 5377168, 15166495, + -8917023, -4388953, -8067909, 2276718}, }, { - { 30157918, 12924066, -17712050, 9245753, 19895028, 3368142, -23827587, 5096219, 22740376, -7303417 }, - { 2041139, -14256350, 7783687, 13876377, -25946985, -13352459, 24051124, 13742383, -15637599, 13295222 }, - { 33338237, -8505733, 12532113, 7977527, 9106186, -1715251, -17720195, -4612972, -4451357, -14669444 }, + {30157918, 12924066, -17712050, 9245753, 19895028, 3368142, + -23827587, 5096219, 22740376, -7303417}, + {2041139, -14256350, 7783687, 13876377, -25946985, -13352459, + 24051124, 13742383, -15637599, 13295222}, + {33338237, -8505733, 12532113, 7977527, 9106186, -1715251, + -17720195, -4612972, -4451357, -14669444}, }, { - { -20045281, 5454097, -14346548, 6447146, 28862071, 1883651, -2469266, -4141880, 7770569, 9620597 }, - { 23208068, 7979712, 33071466, 8149229, 1758231, -10834995, 30945528, -1694323, -33502340, -14767970 }, - { 1439958, -16270480, -1079989, -793782, 4625402, 10647766, -5043801, 1220118, 30494170, -11440799 }, + {-20045281, 5454097, -14346548, 6447146, 28862071, 1883651, + -2469266, -4141880, 7770569, 9620597}, + {23208068, 7979712, 33071466, 8149229, 1758231, -10834995, 30945528, + -1694323, -33502340, -14767970}, + {1439958, -16270480, -1079989, -793782, 4625402, 10647766, -5043801, + 1220118, 30494170, -11440799}, }, { - { -5037580, -13028295, -2970559, -3061767, 15640974, -6701666, -26739026, 926050, -1684339, -13333647 }, - { 13908495, -3549272, 30919928, -6273825, -21521863, 7989039, 9021034, 9078865, 3353509, 4033511 }, - { -29663431, -15113610, 32259991, -344482, 24295849, -12912123, 23161163, 8839127, 27485041, 7356032 }, + {-5037580, -13028295, -2970559, -3061767, 15640974, -6701666, + -26739026, 926050, -1684339, -13333647}, + {13908495, -3549272, 30919928, -6273825, -21521863, 7989039, + 9021034, 9078865, 3353509, 4033511}, + {-29663431, -15113610, 32259991, -344482, 24295849, -12912123, + 23161163, 8839127, 27485041, 7356032}, }, }, { { - { 9661027, 705443, 11980065, -5370154, -1628543, 14661173, -6346142, 2625015, 28431036, -16771834 }, - { -23839233, -8311415, -25945511, 7480958, -17681669, -8354183, -22545972, 14150565, 15970762, 4099461 }, - { 29262576, 16756590, 26350592, -8793563, 8529671, -11208050, 13617293, -9937143, 11465739, 8317062 }, + {9661027, 705443, 11980065, -5370154, -1628543, 14661173, -6346142, + 2625015, 28431036, -16771834}, + {-23839233, -8311415, -25945511, 7480958, -17681669, -8354183, + -22545972, 14150565, 15970762, 4099461}, + {29262576, 16756590, 26350592, -8793563, 8529671, -11208050, + 13617293, -9937143, 11465739, 8317062}, }, { - { -25493081, -6962928, 32500200, -9419051, -23038724, -2302222, 14898637, 3848455, 20969334, -5157516 }, - { -20384450, -14347713, -18336405, 13884722, -33039454, 2842114, -21610826, -3649888, 11177095, 14989547 }, - { -24496721, -11716016, 16959896, 2278463, 12066309, 10137771, 13515641, 2581286, -28487508, 9930240 }, + {-25493081, -6962928, 32500200, -9419051, -23038724, -2302222, + 14898637, 3848455, 20969334, -5157516}, + {-20384450, -14347713, -18336405, 13884722, -33039454, 2842114, + -21610826, -3649888, 11177095, 14989547}, + {-24496721, -11716016, 16959896, 2278463, 12066309, 10137771, + 13515641, 2581286, -28487508, 9930240}, }, { - { -17751622, -2097826, 16544300, -13009300, -15914807, -14949081, 18345767, -13403753, 16291481, -5314038 }, - { -33229194, 2553288, 32678213, 9875984, 8534129, 6889387, -9676774, 6957617, 4368891, 9788741 }, - { 16660756, 7281060, -10830758, 12911820, 20108584, -8101676, -21722536, -8613148, 16250552, -11111103 }, + {-17751622, -2097826, 16544300, -13009300, -15914807, -14949081, + 18345767, -13403753, 16291481, -5314038}, + {-33229194, 2553288, 32678213, 9875984, 8534129, 6889387, -9676774, + 6957617, 4368891, 9788741}, + {16660756, 7281060, -10830758, 12911820, 20108584, -8101676, + -21722536, -8613148, 16250552, -11111103}, }, { - { -19765507, 2390526, -16551031, 14161980, 1905286, 6414907, 4689584, 10604807, -30190403, 4782747 }, - { -1354539, 14736941, -7367442, -13292886, 7710542, -14155590, -9981571, 4383045, 22546403, 437323 }, - { 31665577, -12180464, -16186830, 1491339, -18368625, 3294682, 27343084, 2786261, -30633590, -14097016 }, + {-19765507, 2390526, -16551031, 14161980, 1905286, 6414907, 4689584, + 10604807, -30190403, 4782747}, + {-1354539, 14736941, -7367442, -13292886, 7710542, -14155590, + -9981571, 4383045, 22546403, 437323}, + {31665577, -12180464, -16186830, 1491339, -18368625, 3294682, + 27343084, 2786261, -30633590, -14097016}, }, { - { -14467279, -683715, -33374107, 7448552, 19294360, 14334329, -19690631, 2355319, -19284671, -6114373 }, - { 15121312, -15796162, 6377020, -6031361, -10798111, -12957845, 18952177, 15496498, -29380133, 11754228 }, - { -2637277, -13483075, 8488727, -14303896, 12728761, -1622493, 7141596, 11724556, 22761615, -10134141 }, + {-14467279, -683715, -33374107, 7448552, 19294360, 14334329, + -19690631, 2355319, -19284671, -6114373}, + {15121312, -15796162, 6377020, -6031361, -10798111, -12957845, + 18952177, 15496498, -29380133, 11754228}, + {-2637277, -13483075, 8488727, -14303896, 12728761, -1622493, + 7141596, 11724556, 22761615, -10134141}, }, { - { 16918416, 11729663, -18083579, 3022987, -31015732, -13339659, -28741185, -12227393, 32851222, 11717399 }, - { 11166634, 7338049, -6722523, 4531520, -29468672, -7302055, 31474879, 3483633, -1193175, -4030831 }, - { -185635, 9921305, 31456609, -13536438, -12013818, 13348923, 33142652, 6546660, -19985279, -3948376 }, + {16918416, 11729663, -18083579, 3022987, -31015732, -13339659, + -28741185, -12227393, 32851222, 11717399}, + {11166634, 7338049, -6722523, 4531520, -29468672, -7302055, + 31474879, 3483633, -1193175, -4030831}, + {-185635, 9921305, 31456609, -13536438, -12013818, 13348923, + 33142652, 6546660, -19985279, -3948376}, }, { - { -32460596, 11266712, -11197107, -7899103, 31703694, 3855903, -8537131, -12833048, -30772034, -15486313 }, - { -18006477, 12709068, 3991746, -6479188, -21491523, -10550425, -31135347, -16049879, 10928917, 3011958 }, - { -6957757, -15594337, 31696059, 334240, 29576716, 14796075, -30831056, -12805180, 18008031, 10258577 }, + {-32460596, 11266712, -11197107, -7899103, 31703694, 3855903, + -8537131, -12833048, -30772034, -15486313}, + {-18006477, 12709068, 3991746, -6479188, -21491523, -10550425, + -31135347, -16049879, 10928917, 3011958}, + {-6957757, -15594337, 31696059, 334240, 29576716, 14796075, + -30831056, -12805180, 18008031, 10258577}, }, { - { -22448644, 15655569, 7018479, -4410003, -30314266, -1201591, -1853465, 1367120, 25127874, 6671743 }, - { 29701166, -14373934, -10878120, 9279288, -17568, 13127210, 21382910, 11042292, 25838796, 4642684 }, - { -20430234, 14955537, -24126347, 8124619, -5369288, -5990470, 30468147, -13900640, 18423289, 4177476 }, + {-22448644, 15655569, 7018479, -4410003, -30314266, -1201591, + -1853465, 1367120, 25127874, 6671743}, + {29701166, -14373934, -10878120, 9279288, -17568, 13127210, + 21382910, 11042292, 25838796, 4642684}, + {-20430234, 14955537, -24126347, 8124619, -5369288, -5990470, + 30468147, -13900640, 18423289, 4177476}, }, }, }; diff --git a/bootrom/ed25519/sc.c b/bootrom/ed25519/sc.c index ca5bad2ca..25c342e97 100644 --- a/bootrom/ed25519/sc.c +++ b/bootrom/ed25519/sc.c @@ -1,25 +1,28 @@ -#include "fixedint.h" #include "sc.h" -static uint64_t load_3(const unsigned char *in) { - uint64_t result; +#include "fixedint.h" + +static uint64_t +load_3(const unsigned char* in) { + uint64_t result; - result = (uint64_t) in[0]; - result |= ((uint64_t) in[1]) << 8; - result |= ((uint64_t) in[2]) << 16; + result = (uint64_t)in[0]; + result |= ((uint64_t)in[1]) << 8; + result |= ((uint64_t)in[2]) << 16; - return result; + return result; } -static uint64_t load_4(const unsigned char *in) { - uint64_t result; +static uint64_t +load_4(const unsigned char* in) { + uint64_t result; + + result = (uint64_t)in[0]; + result |= ((uint64_t)in[1]) << 8; + result |= ((uint64_t)in[2]) << 16; + result |= ((uint64_t)in[3]) << 24; - result = (uint64_t) in[0]; - result |= ((uint64_t) in[1]) << 8; - result |= ((uint64_t) in[2]) << 16; - result |= ((uint64_t) in[3]) << 24; - - return result; + return result; } /* @@ -32,322 +35,321 @@ static uint64_t load_4(const unsigned char *in) { Overwrites s in place. */ -void sc_reduce(unsigned char *s) { - int64_t s0 = 2097151 & load_3(s); - int64_t s1 = 2097151 & (load_4(s + 2) >> 5); - int64_t s2 = 2097151 & (load_3(s + 5) >> 2); - int64_t s3 = 2097151 & (load_4(s + 7) >> 7); - int64_t s4 = 2097151 & (load_4(s + 10) >> 4); - int64_t s5 = 2097151 & (load_3(s + 13) >> 1); - int64_t s6 = 2097151 & (load_4(s + 15) >> 6); - int64_t s7 = 2097151 & (load_3(s + 18) >> 3); - int64_t s8 = 2097151 & load_3(s + 21); - int64_t s9 = 2097151 & (load_4(s + 23) >> 5); - int64_t s10 = 2097151 & (load_3(s + 26) >> 2); - int64_t s11 = 2097151 & (load_4(s + 28) >> 7); - int64_t s12 = 2097151 & (load_4(s + 31) >> 4); - int64_t s13 = 2097151 & (load_3(s + 34) >> 1); - int64_t s14 = 2097151 & (load_4(s + 36) >> 6); - int64_t s15 = 2097151 & (load_3(s + 39) >> 3); - int64_t s16 = 2097151 & load_3(s + 42); - int64_t s17 = 2097151 & (load_4(s + 44) >> 5); - int64_t s18 = 2097151 & (load_3(s + 47) >> 2); - int64_t s19 = 2097151 & (load_4(s + 49) >> 7); - int64_t s20 = 2097151 & (load_4(s + 52) >> 4); - int64_t s21 = 2097151 & (load_3(s + 55) >> 1); - int64_t s22 = 2097151 & (load_4(s + 57) >> 6); - int64_t s23 = (load_4(s + 60) >> 3); - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - int64_t carry10; - int64_t carry11; - int64_t carry12; - int64_t carry13; - int64_t carry14; - int64_t carry15; - int64_t carry16; +void +sc_reduce(unsigned char* s) { + int64_t s0 = 2097151 & load_3(s); + int64_t s1 = 2097151 & (load_4(s + 2) >> 5); + int64_t s2 = 2097151 & (load_3(s + 5) >> 2); + int64_t s3 = 2097151 & (load_4(s + 7) >> 7); + int64_t s4 = 2097151 & (load_4(s + 10) >> 4); + int64_t s5 = 2097151 & (load_3(s + 13) >> 1); + int64_t s6 = 2097151 & (load_4(s + 15) >> 6); + int64_t s7 = 2097151 & (load_3(s + 18) >> 3); + int64_t s8 = 2097151 & load_3(s + 21); + int64_t s9 = 2097151 & (load_4(s + 23) >> 5); + int64_t s10 = 2097151 & (load_3(s + 26) >> 2); + int64_t s11 = 2097151 & (load_4(s + 28) >> 7); + int64_t s12 = 2097151 & (load_4(s + 31) >> 4); + int64_t s13 = 2097151 & (load_3(s + 34) >> 1); + int64_t s14 = 2097151 & (load_4(s + 36) >> 6); + int64_t s15 = 2097151 & (load_3(s + 39) >> 3); + int64_t s16 = 2097151 & load_3(s + 42); + int64_t s17 = 2097151 & (load_4(s + 44) >> 5); + int64_t s18 = 2097151 & (load_3(s + 47) >> 2); + int64_t s19 = 2097151 & (load_4(s + 49) >> 7); + int64_t s20 = 2097151 & (load_4(s + 52) >> 4); + int64_t s21 = 2097151 & (load_3(s + 55) >> 1); + int64_t s22 = 2097151 & (load_4(s + 57) >> 6); + int64_t s23 = (load_4(s + 60) >> 3); + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + int64_t carry10; + int64_t carry11; + int64_t carry12; + int64_t carry13; + int64_t carry14; + int64_t carry15; + int64_t carry16; - s11 += s23 * 666643; - s12 += s23 * 470296; - s13 += s23 * 654183; - s14 -= s23 * 997805; - s15 += s23 * 136657; - s16 -= s23 * 683901; - s23 = 0; - s10 += s22 * 666643; - s11 += s22 * 470296; - s12 += s22 * 654183; - s13 -= s22 * 997805; - s14 += s22 * 136657; - s15 -= s22 * 683901; - s22 = 0; - s9 += s21 * 666643; - s10 += s21 * 470296; - s11 += s21 * 654183; - s12 -= s21 * 997805; - s13 += s21 * 136657; - s14 -= s21 * 683901; - s21 = 0; - s8 += s20 * 666643; - s9 += s20 * 470296; - s10 += s20 * 654183; - s11 -= s20 * 997805; - s12 += s20 * 136657; - s13 -= s20 * 683901; - s20 = 0; - s7 += s19 * 666643; - s8 += s19 * 470296; - s9 += s19 * 654183; - s10 -= s19 * 997805; - s11 += s19 * 136657; - s12 -= s19 * 683901; - s19 = 0; - s6 += s18 * 666643; - s7 += s18 * 470296; - s8 += s18 * 654183; - s9 -= s18 * 997805; - s10 += s18 * 136657; - s11 -= s18 * 683901; - s18 = 0; - carry6 = (s6 + (1 << 20)) >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry8 = (s8 + (1 << 20)) >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry10 = (s10 + (1 << 20)) >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry12 = (s12 + (1 << 20)) >> 21; - s13 += carry12; - s12 -= carry12 << 21; - carry14 = (s14 + (1 << 20)) >> 21; - s15 += carry14; - s14 -= carry14 << 21; - carry16 = (s16 + (1 << 20)) >> 21; - s17 += carry16; - s16 -= carry16 << 21; - carry7 = (s7 + (1 << 20)) >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry9 = (s9 + (1 << 20)) >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry11 = (s11 + (1 << 20)) >> 21; - s12 += carry11; - s11 -= carry11 << 21; - carry13 = (s13 + (1 << 20)) >> 21; - s14 += carry13; - s13 -= carry13 << 21; - carry15 = (s15 + (1 << 20)) >> 21; - s16 += carry15; - s15 -= carry15 << 21; - s5 += s17 * 666643; - s6 += s17 * 470296; - s7 += s17 * 654183; - s8 -= s17 * 997805; - s9 += s17 * 136657; - s10 -= s17 * 683901; - s17 = 0; - s4 += s16 * 666643; - s5 += s16 * 470296; - s6 += s16 * 654183; - s7 -= s16 * 997805; - s8 += s16 * 136657; - s9 -= s16 * 683901; - s16 = 0; - s3 += s15 * 666643; - s4 += s15 * 470296; - s5 += s15 * 654183; - s6 -= s15 * 997805; - s7 += s15 * 136657; - s8 -= s15 * 683901; - s15 = 0; - s2 += s14 * 666643; - s3 += s14 * 470296; - s4 += s14 * 654183; - s5 -= s14 * 997805; - s6 += s14 * 136657; - s7 -= s14 * 683901; - s14 = 0; - s1 += s13 * 666643; - s2 += s13 * 470296; - s3 += s13 * 654183; - s4 -= s13 * 997805; - s5 += s13 * 136657; - s6 -= s13 * 683901; - s13 = 0; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = (s0 + (1 << 20)) >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry2 = (s2 + (1 << 20)) >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry4 = (s4 + (1 << 20)) >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry6 = (s6 + (1 << 20)) >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry8 = (s8 + (1 << 20)) >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry10 = (s10 + (1 << 20)) >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry1 = (s1 + (1 << 20)) >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry3 = (s3 + (1 << 20)) >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry5 = (s5 + (1 << 20)) >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry7 = (s7 + (1 << 20)) >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry9 = (s9 + (1 << 20)) >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry11 = (s11 + (1 << 20)) >> 21; - s12 += carry11; - s11 -= carry11 << 21; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = s0 >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry1 = s1 >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry2 = s2 >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry3 = s3 >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry4 = s4 >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry5 = s5 >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry6 = s6 >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry7 = s7 >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry8 = s8 >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry9 = s9 >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry10 = s10 >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry11 = s11 >> 21; - s12 += carry11; - s11 -= carry11 << 21; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = s0 >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry1 = s1 >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry2 = s2 >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry3 = s3 >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry4 = s4 >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry5 = s5 >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry6 = s6 >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry7 = s7 >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry8 = s8 >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry9 = s9 >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry10 = s10 >> 21; - s11 += carry10; - s10 -= carry10 << 21; + s11 += s23 * 666643; + s12 += s23 * 470296; + s13 += s23 * 654183; + s14 -= s23 * 997805; + s15 += s23 * 136657; + s16 -= s23 * 683901; + s23 = 0; + s10 += s22 * 666643; + s11 += s22 * 470296; + s12 += s22 * 654183; + s13 -= s22 * 997805; + s14 += s22 * 136657; + s15 -= s22 * 683901; + s22 = 0; + s9 += s21 * 666643; + s10 += s21 * 470296; + s11 += s21 * 654183; + s12 -= s21 * 997805; + s13 += s21 * 136657; + s14 -= s21 * 683901; + s21 = 0; + s8 += s20 * 666643; + s9 += s20 * 470296; + s10 += s20 * 654183; + s11 -= s20 * 997805; + s12 += s20 * 136657; + s13 -= s20 * 683901; + s20 = 0; + s7 += s19 * 666643; + s8 += s19 * 470296; + s9 += s19 * 654183; + s10 -= s19 * 997805; + s11 += s19 * 136657; + s12 -= s19 * 683901; + s19 = 0; + s6 += s18 * 666643; + s7 += s18 * 470296; + s8 += s18 * 654183; + s9 -= s18 * 997805; + s10 += s18 * 136657; + s11 -= s18 * 683901; + s18 = 0; + carry6 = (s6 + (1 << 20)) >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry12 = (s12 + (1 << 20)) >> 21; + s13 += carry12; + s12 -= carry12 << 21; + carry14 = (s14 + (1 << 20)) >> 21; + s15 += carry14; + s14 -= carry14 << 21; + carry16 = (s16 + (1 << 20)) >> 21; + s17 += carry16; + s16 -= carry16 << 21; + carry7 = (s7 + (1 << 20)) >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; + s12 += carry11; + s11 -= carry11 << 21; + carry13 = (s13 + (1 << 20)) >> 21; + s14 += carry13; + s13 -= carry13 << 21; + carry15 = (s15 + (1 << 20)) >> 21; + s16 += carry15; + s15 -= carry15 << 21; + s5 += s17 * 666643; + s6 += s17 * 470296; + s7 += s17 * 654183; + s8 -= s17 * 997805; + s9 += s17 * 136657; + s10 -= s17 * 683901; + s17 = 0; + s4 += s16 * 666643; + s5 += s16 * 470296; + s6 += s16 * 654183; + s7 -= s16 * 997805; + s8 += s16 * 136657; + s9 -= s16 * 683901; + s16 = 0; + s3 += s15 * 666643; + s4 += s15 * 470296; + s5 += s15 * 654183; + s6 -= s15 * 997805; + s7 += s15 * 136657; + s8 -= s15 * 683901; + s15 = 0; + s2 += s14 * 666643; + s3 += s14 * 470296; + s4 += s14 * 654183; + s5 -= s14 * 997805; + s6 += s14 * 136657; + s7 -= s14 * 683901; + s14 = 0; + s1 += s13 * 666643; + s2 += s13 * 470296; + s3 += s13 * 654183; + s4 -= s13 * 997805; + s5 += s13 * 136657; + s6 -= s13 * 683901; + s13 = 0; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = (s0 + (1 << 20)) >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry2 = (s2 + (1 << 20)) >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry4 = (s4 + (1 << 20)) >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry6 = (s6 + (1 << 20)) >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry1 = (s1 + (1 << 20)) >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry3 = (s3 + (1 << 20)) >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry5 = (s5 + (1 << 20)) >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry7 = (s7 + (1 << 20)) >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; + s12 += carry11; + s11 -= carry11 << 21; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = s0 >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry1 = s1 >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry2 = s2 >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry3 = s3 >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry4 = s4 >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry5 = s5 >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry6 = s6 >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry7 = s7 >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry8 = s8 >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry9 = s9 >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry10 = s10 >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry11 = s11 >> 21; + s12 += carry11; + s11 -= carry11 << 21; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = s0 >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry1 = s1 >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry2 = s2 >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry3 = s3 >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry4 = s4 >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry5 = s5 >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry6 = s6 >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry7 = s7 >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry8 = s8 >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry9 = s9 >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry10 = s10 >> 21; + s11 += carry10; + s10 -= carry10 << 21; - s[0] = (unsigned char) (s0 >> 0); - s[1] = (unsigned char) (s0 >> 8); - s[2] = (unsigned char) ((s0 >> 16) | (s1 << 5)); - s[3] = (unsigned char) (s1 >> 3); - s[4] = (unsigned char) (s1 >> 11); - s[5] = (unsigned char) ((s1 >> 19) | (s2 << 2)); - s[6] = (unsigned char) (s2 >> 6); - s[7] = (unsigned char) ((s2 >> 14) | (s3 << 7)); - s[8] = (unsigned char) (s3 >> 1); - s[9] = (unsigned char) (s3 >> 9); - s[10] = (unsigned char) ((s3 >> 17) | (s4 << 4)); - s[11] = (unsigned char) (s4 >> 4); - s[12] = (unsigned char) (s4 >> 12); - s[13] = (unsigned char) ((s4 >> 20) | (s5 << 1)); - s[14] = (unsigned char) (s5 >> 7); - s[15] = (unsigned char) ((s5 >> 15) | (s6 << 6)); - s[16] = (unsigned char) (s6 >> 2); - s[17] = (unsigned char) (s6 >> 10); - s[18] = (unsigned char) ((s6 >> 18) | (s7 << 3)); - s[19] = (unsigned char) (s7 >> 5); - s[20] = (unsigned char) (s7 >> 13); - s[21] = (unsigned char) (s8 >> 0); - s[22] = (unsigned char) (s8 >> 8); - s[23] = (unsigned char) ((s8 >> 16) | (s9 << 5)); - s[24] = (unsigned char) (s9 >> 3); - s[25] = (unsigned char) (s9 >> 11); - s[26] = (unsigned char) ((s9 >> 19) | (s10 << 2)); - s[27] = (unsigned char) (s10 >> 6); - s[28] = (unsigned char) ((s10 >> 14) | (s11 << 7)); - s[29] = (unsigned char) (s11 >> 1); - s[30] = (unsigned char) (s11 >> 9); - s[31] = (unsigned char) (s11 >> 17); + s[0] = (unsigned char)(s0 >> 0); + s[1] = (unsigned char)(s0 >> 8); + s[2] = (unsigned char)((s0 >> 16) | (s1 << 5)); + s[3] = (unsigned char)(s1 >> 3); + s[4] = (unsigned char)(s1 >> 11); + s[5] = (unsigned char)((s1 >> 19) | (s2 << 2)); + s[6] = (unsigned char)(s2 >> 6); + s[7] = (unsigned char)((s2 >> 14) | (s3 << 7)); + s[8] = (unsigned char)(s3 >> 1); + s[9] = (unsigned char)(s3 >> 9); + s[10] = (unsigned char)((s3 >> 17) | (s4 << 4)); + s[11] = (unsigned char)(s4 >> 4); + s[12] = (unsigned char)(s4 >> 12); + s[13] = (unsigned char)((s4 >> 20) | (s5 << 1)); + s[14] = (unsigned char)(s5 >> 7); + s[15] = (unsigned char)((s5 >> 15) | (s6 << 6)); + s[16] = (unsigned char)(s6 >> 2); + s[17] = (unsigned char)(s6 >> 10); + s[18] = (unsigned char)((s6 >> 18) | (s7 << 3)); + s[19] = (unsigned char)(s7 >> 5); + s[20] = (unsigned char)(s7 >> 13); + s[21] = (unsigned char)(s8 >> 0); + s[22] = (unsigned char)(s8 >> 8); + s[23] = (unsigned char)((s8 >> 16) | (s9 << 5)); + s[24] = (unsigned char)(s9 >> 3); + s[25] = (unsigned char)(s9 >> 11); + s[26] = (unsigned char)((s9 >> 19) | (s10 << 2)); + s[27] = (unsigned char)(s10 >> 6); + s[28] = (unsigned char)((s10 >> 14) | (s11 << 7)); + s[29] = (unsigned char)(s11 >> 1); + s[30] = (unsigned char)(s11 >> 9); + s[31] = (unsigned char)(s11 >> 17); } - - /* Input: a[0]+256*a[1]+...+256^31*a[31] = a @@ -359,451 +361,463 @@ void sc_reduce(unsigned char *s) { where l = 2^252 + 27742317777372353535851937790883648493. */ -void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c) { - int64_t a0 = 2097151 & load_3(a); - int64_t a1 = 2097151 & (load_4(a + 2) >> 5); - int64_t a2 = 2097151 & (load_3(a + 5) >> 2); - int64_t a3 = 2097151 & (load_4(a + 7) >> 7); - int64_t a4 = 2097151 & (load_4(a + 10) >> 4); - int64_t a5 = 2097151 & (load_3(a + 13) >> 1); - int64_t a6 = 2097151 & (load_4(a + 15) >> 6); - int64_t a7 = 2097151 & (load_3(a + 18) >> 3); - int64_t a8 = 2097151 & load_3(a + 21); - int64_t a9 = 2097151 & (load_4(a + 23) >> 5); - int64_t a10 = 2097151 & (load_3(a + 26) >> 2); - int64_t a11 = (load_4(a + 28) >> 7); - int64_t b0 = 2097151 & load_3(b); - int64_t b1 = 2097151 & (load_4(b + 2) >> 5); - int64_t b2 = 2097151 & (load_3(b + 5) >> 2); - int64_t b3 = 2097151 & (load_4(b + 7) >> 7); - int64_t b4 = 2097151 & (load_4(b + 10) >> 4); - int64_t b5 = 2097151 & (load_3(b + 13) >> 1); - int64_t b6 = 2097151 & (load_4(b + 15) >> 6); - int64_t b7 = 2097151 & (load_3(b + 18) >> 3); - int64_t b8 = 2097151 & load_3(b + 21); - int64_t b9 = 2097151 & (load_4(b + 23) >> 5); - int64_t b10 = 2097151 & (load_3(b + 26) >> 2); - int64_t b11 = (load_4(b + 28) >> 7); - int64_t c0 = 2097151 & load_3(c); - int64_t c1 = 2097151 & (load_4(c + 2) >> 5); - int64_t c2 = 2097151 & (load_3(c + 5) >> 2); - int64_t c3 = 2097151 & (load_4(c + 7) >> 7); - int64_t c4 = 2097151 & (load_4(c + 10) >> 4); - int64_t c5 = 2097151 & (load_3(c + 13) >> 1); - int64_t c6 = 2097151 & (load_4(c + 15) >> 6); - int64_t c7 = 2097151 & (load_3(c + 18) >> 3); - int64_t c8 = 2097151 & load_3(c + 21); - int64_t c9 = 2097151 & (load_4(c + 23) >> 5); - int64_t c10 = 2097151 & (load_3(c + 26) >> 2); - int64_t c11 = (load_4(c + 28) >> 7); - int64_t s0; - int64_t s1; - int64_t s2; - int64_t s3; - int64_t s4; - int64_t s5; - int64_t s6; - int64_t s7; - int64_t s8; - int64_t s9; - int64_t s10; - int64_t s11; - int64_t s12; - int64_t s13; - int64_t s14; - int64_t s15; - int64_t s16; - int64_t s17; - int64_t s18; - int64_t s19; - int64_t s20; - int64_t s21; - int64_t s22; - int64_t s23; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - int64_t carry10; - int64_t carry11; - int64_t carry12; - int64_t carry13; - int64_t carry14; - int64_t carry15; - int64_t carry16; - int64_t carry17; - int64_t carry18; - int64_t carry19; - int64_t carry20; - int64_t carry21; - int64_t carry22; +void +sc_muladd( + unsigned char* s, const unsigned char* a, const unsigned char* b, + const unsigned char* c) { + int64_t a0 = 2097151 & load_3(a); + int64_t a1 = 2097151 & (load_4(a + 2) >> 5); + int64_t a2 = 2097151 & (load_3(a + 5) >> 2); + int64_t a3 = 2097151 & (load_4(a + 7) >> 7); + int64_t a4 = 2097151 & (load_4(a + 10) >> 4); + int64_t a5 = 2097151 & (load_3(a + 13) >> 1); + int64_t a6 = 2097151 & (load_4(a + 15) >> 6); + int64_t a7 = 2097151 & (load_3(a + 18) >> 3); + int64_t a8 = 2097151 & load_3(a + 21); + int64_t a9 = 2097151 & (load_4(a + 23) >> 5); + int64_t a10 = 2097151 & (load_3(a + 26) >> 2); + int64_t a11 = (load_4(a + 28) >> 7); + int64_t b0 = 2097151 & load_3(b); + int64_t b1 = 2097151 & (load_4(b + 2) >> 5); + int64_t b2 = 2097151 & (load_3(b + 5) >> 2); + int64_t b3 = 2097151 & (load_4(b + 7) >> 7); + int64_t b4 = 2097151 & (load_4(b + 10) >> 4); + int64_t b5 = 2097151 & (load_3(b + 13) >> 1); + int64_t b6 = 2097151 & (load_4(b + 15) >> 6); + int64_t b7 = 2097151 & (load_3(b + 18) >> 3); + int64_t b8 = 2097151 & load_3(b + 21); + int64_t b9 = 2097151 & (load_4(b + 23) >> 5); + int64_t b10 = 2097151 & (load_3(b + 26) >> 2); + int64_t b11 = (load_4(b + 28) >> 7); + int64_t c0 = 2097151 & load_3(c); + int64_t c1 = 2097151 & (load_4(c + 2) >> 5); + int64_t c2 = 2097151 & (load_3(c + 5) >> 2); + int64_t c3 = 2097151 & (load_4(c + 7) >> 7); + int64_t c4 = 2097151 & (load_4(c + 10) >> 4); + int64_t c5 = 2097151 & (load_3(c + 13) >> 1); + int64_t c6 = 2097151 & (load_4(c + 15) >> 6); + int64_t c7 = 2097151 & (load_3(c + 18) >> 3); + int64_t c8 = 2097151 & load_3(c + 21); + int64_t c9 = 2097151 & (load_4(c + 23) >> 5); + int64_t c10 = 2097151 & (load_3(c + 26) >> 2); + int64_t c11 = (load_4(c + 28) >> 7); + int64_t s0; + int64_t s1; + int64_t s2; + int64_t s3; + int64_t s4; + int64_t s5; + int64_t s6; + int64_t s7; + int64_t s8; + int64_t s9; + int64_t s10; + int64_t s11; + int64_t s12; + int64_t s13; + int64_t s14; + int64_t s15; + int64_t s16; + int64_t s17; + int64_t s18; + int64_t s19; + int64_t s20; + int64_t s21; + int64_t s22; + int64_t s23; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + int64_t carry10; + int64_t carry11; + int64_t carry12; + int64_t carry13; + int64_t carry14; + int64_t carry15; + int64_t carry16; + int64_t carry17; + int64_t carry18; + int64_t carry19; + int64_t carry20; + int64_t carry21; + int64_t carry22; + + s0 = c0 + a0 * b0; + s1 = c1 + a0 * b1 + a1 * b0; + s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0; + s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0; + s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0; + s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0; + s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0; + s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 + + a6 * b1 + a7 * b0; + s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 + + a6 * b2 + a7 * b1 + a8 * b0; + s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 + + a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0; + s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 + + a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0; + s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 + + a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0; + s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 + a7 * b5 + + a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1; + s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 + a8 * b5 + + a9 * b4 + a10 * b3 + a11 * b2; + s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 + a9 * b5 + + a10 * b4 + a11 * b3; + s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 + a10 * b5 + + a11 * b4; + s16 = a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5; + s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6; + s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7; + s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8; + s20 = a9 * b11 + a10 * b10 + a11 * b9; + s21 = a10 * b11 + a11 * b10; + s22 = a11 * b11; + s23 = 0; + carry0 = (s0 + (1 << 20)) >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry2 = (s2 + (1 << 20)) >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry4 = (s4 + (1 << 20)) >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry6 = (s6 + (1 << 20)) >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry12 = (s12 + (1 << 20)) >> 21; + s13 += carry12; + s12 -= carry12 << 21; + carry14 = (s14 + (1 << 20)) >> 21; + s15 += carry14; + s14 -= carry14 << 21; + carry16 = (s16 + (1 << 20)) >> 21; + s17 += carry16; + s16 -= carry16 << 21; + carry18 = (s18 + (1 << 20)) >> 21; + s19 += carry18; + s18 -= carry18 << 21; + carry20 = (s20 + (1 << 20)) >> 21; + s21 += carry20; + s20 -= carry20 << 21; + carry22 = (s22 + (1 << 20)) >> 21; + s23 += carry22; + s22 -= carry22 << 21; + carry1 = (s1 + (1 << 20)) >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry3 = (s3 + (1 << 20)) >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry5 = (s5 + (1 << 20)) >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry7 = (s7 + (1 << 20)) >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; + s12 += carry11; + s11 -= carry11 << 21; + carry13 = (s13 + (1 << 20)) >> 21; + s14 += carry13; + s13 -= carry13 << 21; + carry15 = (s15 + (1 << 20)) >> 21; + s16 += carry15; + s15 -= carry15 << 21; + carry17 = (s17 + (1 << 20)) >> 21; + s18 += carry17; + s17 -= carry17 << 21; + carry19 = (s19 + (1 << 20)) >> 21; + s20 += carry19; + s19 -= carry19 << 21; + carry21 = (s21 + (1 << 20)) >> 21; + s22 += carry21; + s21 -= carry21 << 21; + s11 += s23 * 666643; + s12 += s23 * 470296; + s13 += s23 * 654183; + s14 -= s23 * 997805; + s15 += s23 * 136657; + s16 -= s23 * 683901; + s23 = 0; + s10 += s22 * 666643; + s11 += s22 * 470296; + s12 += s22 * 654183; + s13 -= s22 * 997805; + s14 += s22 * 136657; + s15 -= s22 * 683901; + s22 = 0; + s9 += s21 * 666643; + s10 += s21 * 470296; + s11 += s21 * 654183; + s12 -= s21 * 997805; + s13 += s21 * 136657; + s14 -= s21 * 683901; + s21 = 0; + s8 += s20 * 666643; + s9 += s20 * 470296; + s10 += s20 * 654183; + s11 -= s20 * 997805; + s12 += s20 * 136657; + s13 -= s20 * 683901; + s20 = 0; + s7 += s19 * 666643; + s8 += s19 * 470296; + s9 += s19 * 654183; + s10 -= s19 * 997805; + s11 += s19 * 136657; + s12 -= s19 * 683901; + s19 = 0; + s6 += s18 * 666643; + s7 += s18 * 470296; + s8 += s18 * 654183; + s9 -= s18 * 997805; + s10 += s18 * 136657; + s11 -= s18 * 683901; + s18 = 0; + carry6 = (s6 + (1 << 20)) >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry12 = (s12 + (1 << 20)) >> 21; + s13 += carry12; + s12 -= carry12 << 21; + carry14 = (s14 + (1 << 20)) >> 21; + s15 += carry14; + s14 -= carry14 << 21; + carry16 = (s16 + (1 << 20)) >> 21; + s17 += carry16; + s16 -= carry16 << 21; + carry7 = (s7 + (1 << 20)) >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; + s12 += carry11; + s11 -= carry11 << 21; + carry13 = (s13 + (1 << 20)) >> 21; + s14 += carry13; + s13 -= carry13 << 21; + carry15 = (s15 + (1 << 20)) >> 21; + s16 += carry15; + s15 -= carry15 << 21; + s5 += s17 * 666643; + s6 += s17 * 470296; + s7 += s17 * 654183; + s8 -= s17 * 997805; + s9 += s17 * 136657; + s10 -= s17 * 683901; + s17 = 0; + s4 += s16 * 666643; + s5 += s16 * 470296; + s6 += s16 * 654183; + s7 -= s16 * 997805; + s8 += s16 * 136657; + s9 -= s16 * 683901; + s16 = 0; + s3 += s15 * 666643; + s4 += s15 * 470296; + s5 += s15 * 654183; + s6 -= s15 * 997805; + s7 += s15 * 136657; + s8 -= s15 * 683901; + s15 = 0; + s2 += s14 * 666643; + s3 += s14 * 470296; + s4 += s14 * 654183; + s5 -= s14 * 997805; + s6 += s14 * 136657; + s7 -= s14 * 683901; + s14 = 0; + s1 += s13 * 666643; + s2 += s13 * 470296; + s3 += s13 * 654183; + s4 -= s13 * 997805; + s5 += s13 * 136657; + s6 -= s13 * 683901; + s13 = 0; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = (s0 + (1 << 20)) >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry2 = (s2 + (1 << 20)) >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry4 = (s4 + (1 << 20)) >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry6 = (s6 + (1 << 20)) >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry1 = (s1 + (1 << 20)) >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry3 = (s3 + (1 << 20)) >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry5 = (s5 + (1 << 20)) >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry7 = (s7 + (1 << 20)) >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; + s12 += carry11; + s11 -= carry11 << 21; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = s0 >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry1 = s1 >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry2 = s2 >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry3 = s3 >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry4 = s4 >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry5 = s5 >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry6 = s6 >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry7 = s7 >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry8 = s8 >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry9 = s9 >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry10 = s10 >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry11 = s11 >> 21; + s12 += carry11; + s11 -= carry11 << 21; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = s0 >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry1 = s1 >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry2 = s2 >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry3 = s3 >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry4 = s4 >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry5 = s5 >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry6 = s6 >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry7 = s7 >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry8 = s8 >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry9 = s9 >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry10 = s10 >> 21; + s11 += carry10; + s10 -= carry10 << 21; - s0 = c0 + a0 * b0; - s1 = c1 + a0 * b1 + a1 * b0; - s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0; - s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0; - s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0; - s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0; - s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0; - s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 + a6 * b1 + a7 * b0; - s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 + a6 * b2 + a7 * b1 + a8 * b0; - s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 + a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0; - s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 + a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0; - s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 + a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0; - s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 + a7 * b5 + a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1; - s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 + a8 * b5 + a9 * b4 + a10 * b3 + a11 * b2; - s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 + a9 * b5 + a10 * b4 + a11 * b3; - s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 + a10 * b5 + a11 * b4; - s16 = a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5; - s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6; - s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7; - s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8; - s20 = a9 * b11 + a10 * b10 + a11 * b9; - s21 = a10 * b11 + a11 * b10; - s22 = a11 * b11; - s23 = 0; - carry0 = (s0 + (1 << 20)) >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry2 = (s2 + (1 << 20)) >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry4 = (s4 + (1 << 20)) >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry6 = (s6 + (1 << 20)) >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry8 = (s8 + (1 << 20)) >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry10 = (s10 + (1 << 20)) >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry12 = (s12 + (1 << 20)) >> 21; - s13 += carry12; - s12 -= carry12 << 21; - carry14 = (s14 + (1 << 20)) >> 21; - s15 += carry14; - s14 -= carry14 << 21; - carry16 = (s16 + (1 << 20)) >> 21; - s17 += carry16; - s16 -= carry16 << 21; - carry18 = (s18 + (1 << 20)) >> 21; - s19 += carry18; - s18 -= carry18 << 21; - carry20 = (s20 + (1 << 20)) >> 21; - s21 += carry20; - s20 -= carry20 << 21; - carry22 = (s22 + (1 << 20)) >> 21; - s23 += carry22; - s22 -= carry22 << 21; - carry1 = (s1 + (1 << 20)) >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry3 = (s3 + (1 << 20)) >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry5 = (s5 + (1 << 20)) >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry7 = (s7 + (1 << 20)) >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry9 = (s9 + (1 << 20)) >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry11 = (s11 + (1 << 20)) >> 21; - s12 += carry11; - s11 -= carry11 << 21; - carry13 = (s13 + (1 << 20)) >> 21; - s14 += carry13; - s13 -= carry13 << 21; - carry15 = (s15 + (1 << 20)) >> 21; - s16 += carry15; - s15 -= carry15 << 21; - carry17 = (s17 + (1 << 20)) >> 21; - s18 += carry17; - s17 -= carry17 << 21; - carry19 = (s19 + (1 << 20)) >> 21; - s20 += carry19; - s19 -= carry19 << 21; - carry21 = (s21 + (1 << 20)) >> 21; - s22 += carry21; - s21 -= carry21 << 21; - s11 += s23 * 666643; - s12 += s23 * 470296; - s13 += s23 * 654183; - s14 -= s23 * 997805; - s15 += s23 * 136657; - s16 -= s23 * 683901; - s23 = 0; - s10 += s22 * 666643; - s11 += s22 * 470296; - s12 += s22 * 654183; - s13 -= s22 * 997805; - s14 += s22 * 136657; - s15 -= s22 * 683901; - s22 = 0; - s9 += s21 * 666643; - s10 += s21 * 470296; - s11 += s21 * 654183; - s12 -= s21 * 997805; - s13 += s21 * 136657; - s14 -= s21 * 683901; - s21 = 0; - s8 += s20 * 666643; - s9 += s20 * 470296; - s10 += s20 * 654183; - s11 -= s20 * 997805; - s12 += s20 * 136657; - s13 -= s20 * 683901; - s20 = 0; - s7 += s19 * 666643; - s8 += s19 * 470296; - s9 += s19 * 654183; - s10 -= s19 * 997805; - s11 += s19 * 136657; - s12 -= s19 * 683901; - s19 = 0; - s6 += s18 * 666643; - s7 += s18 * 470296; - s8 += s18 * 654183; - s9 -= s18 * 997805; - s10 += s18 * 136657; - s11 -= s18 * 683901; - s18 = 0; - carry6 = (s6 + (1 << 20)) >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry8 = (s8 + (1 << 20)) >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry10 = (s10 + (1 << 20)) >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry12 = (s12 + (1 << 20)) >> 21; - s13 += carry12; - s12 -= carry12 << 21; - carry14 = (s14 + (1 << 20)) >> 21; - s15 += carry14; - s14 -= carry14 << 21; - carry16 = (s16 + (1 << 20)) >> 21; - s17 += carry16; - s16 -= carry16 << 21; - carry7 = (s7 + (1 << 20)) >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry9 = (s9 + (1 << 20)) >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry11 = (s11 + (1 << 20)) >> 21; - s12 += carry11; - s11 -= carry11 << 21; - carry13 = (s13 + (1 << 20)) >> 21; - s14 += carry13; - s13 -= carry13 << 21; - carry15 = (s15 + (1 << 20)) >> 21; - s16 += carry15; - s15 -= carry15 << 21; - s5 += s17 * 666643; - s6 += s17 * 470296; - s7 += s17 * 654183; - s8 -= s17 * 997805; - s9 += s17 * 136657; - s10 -= s17 * 683901; - s17 = 0; - s4 += s16 * 666643; - s5 += s16 * 470296; - s6 += s16 * 654183; - s7 -= s16 * 997805; - s8 += s16 * 136657; - s9 -= s16 * 683901; - s16 = 0; - s3 += s15 * 666643; - s4 += s15 * 470296; - s5 += s15 * 654183; - s6 -= s15 * 997805; - s7 += s15 * 136657; - s8 -= s15 * 683901; - s15 = 0; - s2 += s14 * 666643; - s3 += s14 * 470296; - s4 += s14 * 654183; - s5 -= s14 * 997805; - s6 += s14 * 136657; - s7 -= s14 * 683901; - s14 = 0; - s1 += s13 * 666643; - s2 += s13 * 470296; - s3 += s13 * 654183; - s4 -= s13 * 997805; - s5 += s13 * 136657; - s6 -= s13 * 683901; - s13 = 0; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = (s0 + (1 << 20)) >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry2 = (s2 + (1 << 20)) >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry4 = (s4 + (1 << 20)) >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry6 = (s6 + (1 << 20)) >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry8 = (s8 + (1 << 20)) >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry10 = (s10 + (1 << 20)) >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry1 = (s1 + (1 << 20)) >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry3 = (s3 + (1 << 20)) >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry5 = (s5 + (1 << 20)) >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry7 = (s7 + (1 << 20)) >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry9 = (s9 + (1 << 20)) >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry11 = (s11 + (1 << 20)) >> 21; - s12 += carry11; - s11 -= carry11 << 21; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = s0 >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry1 = s1 >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry2 = s2 >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry3 = s3 >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry4 = s4 >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry5 = s5 >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry6 = s6 >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry7 = s7 >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry8 = s8 >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry9 = s9 >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry10 = s10 >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry11 = s11 >> 21; - s12 += carry11; - s11 -= carry11 << 21; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = s0 >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry1 = s1 >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry2 = s2 >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry3 = s3 >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry4 = s4 >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry5 = s5 >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry6 = s6 >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry7 = s7 >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry8 = s8 >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry9 = s9 >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry10 = s10 >> 21; - s11 += carry10; - s10 -= carry10 << 21; - - s[0] = (unsigned char) (s0 >> 0); - s[1] = (unsigned char) (s0 >> 8); - s[2] = (unsigned char) ((s0 >> 16) | (s1 << 5)); - s[3] = (unsigned char) (s1 >> 3); - s[4] = (unsigned char) (s1 >> 11); - s[5] = (unsigned char) ((s1 >> 19) | (s2 << 2)); - s[6] = (unsigned char) (s2 >> 6); - s[7] = (unsigned char) ((s2 >> 14) | (s3 << 7)); - s[8] = (unsigned char) (s3 >> 1); - s[9] = (unsigned char) (s3 >> 9); - s[10] = (unsigned char) ((s3 >> 17) | (s4 << 4)); - s[11] = (unsigned char) (s4 >> 4); - s[12] = (unsigned char) (s4 >> 12); - s[13] = (unsigned char) ((s4 >> 20) | (s5 << 1)); - s[14] = (unsigned char) (s5 >> 7); - s[15] = (unsigned char) ((s5 >> 15) | (s6 << 6)); - s[16] = (unsigned char) (s6 >> 2); - s[17] = (unsigned char) (s6 >> 10); - s[18] = (unsigned char) ((s6 >> 18) | (s7 << 3)); - s[19] = (unsigned char) (s7 >> 5); - s[20] = (unsigned char) (s7 >> 13); - s[21] = (unsigned char) (s8 >> 0); - s[22] = (unsigned char) (s8 >> 8); - s[23] = (unsigned char) ((s8 >> 16) | (s9 << 5)); - s[24] = (unsigned char) (s9 >> 3); - s[25] = (unsigned char) (s9 >> 11); - s[26] = (unsigned char) ((s9 >> 19) | (s10 << 2)); - s[27] = (unsigned char) (s10 >> 6); - s[28] = (unsigned char) ((s10 >> 14) | (s11 << 7)); - s[29] = (unsigned char) (s11 >> 1); - s[30] = (unsigned char) (s11 >> 9); - s[31] = (unsigned char) (s11 >> 17); + s[0] = (unsigned char)(s0 >> 0); + s[1] = (unsigned char)(s0 >> 8); + s[2] = (unsigned char)((s0 >> 16) | (s1 << 5)); + s[3] = (unsigned char)(s1 >> 3); + s[4] = (unsigned char)(s1 >> 11); + s[5] = (unsigned char)((s1 >> 19) | (s2 << 2)); + s[6] = (unsigned char)(s2 >> 6); + s[7] = (unsigned char)((s2 >> 14) | (s3 << 7)); + s[8] = (unsigned char)(s3 >> 1); + s[9] = (unsigned char)(s3 >> 9); + s[10] = (unsigned char)((s3 >> 17) | (s4 << 4)); + s[11] = (unsigned char)(s4 >> 4); + s[12] = (unsigned char)(s4 >> 12); + s[13] = (unsigned char)((s4 >> 20) | (s5 << 1)); + s[14] = (unsigned char)(s5 >> 7); + s[15] = (unsigned char)((s5 >> 15) | (s6 << 6)); + s[16] = (unsigned char)(s6 >> 2); + s[17] = (unsigned char)(s6 >> 10); + s[18] = (unsigned char)((s6 >> 18) | (s7 << 3)); + s[19] = (unsigned char)(s7 >> 5); + s[20] = (unsigned char)(s7 >> 13); + s[21] = (unsigned char)(s8 >> 0); + s[22] = (unsigned char)(s8 >> 8); + s[23] = (unsigned char)((s8 >> 16) | (s9 << 5)); + s[24] = (unsigned char)(s9 >> 3); + s[25] = (unsigned char)(s9 >> 11); + s[26] = (unsigned char)((s9 >> 19) | (s10 << 2)); + s[27] = (unsigned char)(s10 >> 6); + s[28] = (unsigned char)((s10 >> 14) | (s11 << 7)); + s[29] = (unsigned char)(s11 >> 1); + s[30] = (unsigned char)(s11 >> 9); + s[31] = (unsigned char)(s11 >> 17); } diff --git a/bootrom/ed25519/sc.h b/bootrom/ed25519/sc.h index e29e7fa5a..7f212a7b6 100644 --- a/bootrom/ed25519/sc.h +++ b/bootrom/ed25519/sc.h @@ -6,7 +6,11 @@ The set of scalars is \Z/l where l = 2^252 + 27742317777372353535851937790883648493. */ -void sc_reduce(unsigned char *s); -void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c); +void +sc_reduce(unsigned char* s); +void +sc_muladd( + unsigned char* s, const unsigned char* a, const unsigned char* b, + const unsigned char* c); #endif diff --git a/bootrom/ed25519/sign.c b/bootrom/ed25519/sign.c index 4c651cbb5..311efbbc9 100644 --- a/bootrom/ed25519/sign.c +++ b/bootrom/ed25519/sign.c @@ -1,31 +1,32 @@ #include "ed25519.h" -#include "sha3/sha3.h" #include "ge.h" #include "sc.h" +#include "sha3/sha3.h" +void +ed25519_sign( + unsigned char* signature, const unsigned char* message, size_t message_len, + const unsigned char* public_key, const unsigned char* private_key) { + sha3_ctx_t hash; + unsigned char hram[64]; + unsigned char r[64]; + ge_p3 R; -void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key) { - sha3_ctx_t hash; - unsigned char hram[64]; - unsigned char r[64]; - ge_p3 R; - - - sha3_init(&hash, 64); - sha3_update(&hash, private_key + 32, 32); - sha3_update(&hash, message, message_len); - sha3_final(r, &hash); + sha3_init(&hash, 64); + sha3_update(&hash, private_key + 32, 32); + sha3_update(&hash, message, message_len); + sha3_final(r, &hash); - sc_reduce(r); - ge_scalarmult_base(&R, r); - ge_p3_tobytes(signature, &R); + sc_reduce(r); + ge_scalarmult_base(&R, r); + ge_p3_tobytes(signature, &R); - sha3_init(&hash, 64); - sha3_update(&hash, signature, 32); - sha3_update(&hash, public_key, 32); - sha3_update(&hash, message, message_len); - sha3_final(hram, &hash); + sha3_init(&hash, 64); + sha3_update(&hash, signature, 32); + sha3_update(&hash, public_key, 32); + sha3_update(&hash, message, message_len); + sha3_final(hram, &hash); - sc_reduce(hram); - sc_muladd(signature + 32, hram, private_key, r); + sc_reduce(hram); + sc_muladd(signature + 32, hram, private_key, r); } diff --git a/bootrom/ed25519/verify.c b/bootrom/ed25519/verify.c index 605c63c4e..98a73ed6f 100644 --- a/bootrom/ed25519/verify.c +++ b/bootrom/ed25519/verify.c @@ -1,77 +1,81 @@ #include "ed25519.h" -#include "sha3/sha3.h" #include "ge.h" #include "sc.h" +#include "sha3/sha3.h" -static int consttime_equal(const unsigned char *x, const unsigned char *y) { - unsigned char r = 0; +static int +consttime_equal(const unsigned char* x, const unsigned char* y) { + unsigned char r = 0; - r = x[0] ^ y[0]; - #define F(i) r |= x[i] ^ y[i] - F(1); - F(2); - F(3); - F(4); - F(5); - F(6); - F(7); - F(8); - F(9); - F(10); - F(11); - F(12); - F(13); - F(14); - F(15); - F(16); - F(17); - F(18); - F(19); - F(20); - F(21); - F(22); - F(23); - F(24); - F(25); - F(26); - F(27); - F(28); - F(29); - F(30); - F(31); - #undef F + r = x[0] ^ y[0]; +#define F(i) r |= x[i] ^ y[i] + F(1); + F(2); + F(3); + F(4); + F(5); + F(6); + F(7); + F(8); + F(9); + F(10); + F(11); + F(12); + F(13); + F(14); + F(15); + F(16); + F(17); + F(18); + F(19); + F(20); + F(21); + F(22); + F(23); + F(24); + F(25); + F(26); + F(27); + F(28); + F(29); + F(30); + F(31); +#undef F - return !r; + return !r; } -int ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key) { - unsigned char h[64]; - unsigned char checker[32]; - sha3_ctx_t hash; - ge_p3 A; - ge_p2 R; +int +ed25519_verify( + const unsigned char* signature, const unsigned char* message, + size_t message_len, const unsigned char* public_key) { + unsigned char h[64]; + unsigned char checker[32]; + sha3_ctx_t hash; + ge_p3 A; + ge_p2 R; + + if (signature[63] & 224) { + return 0; + } - if (signature[63] & 224) { - return 0; - } + if (ge_frombytes_negate_vartime(&A, public_key) != 0) { + return 0; + } - if (ge_frombytes_negate_vartime(&A, public_key) != 0) { - return 0; - } + sha3_init(&hash, 64); + sha3_update(&hash, signature, 32); + sha3_update(&hash, public_key, 32); + sha3_update(&hash, message, message_len); + sha3_final(h, &hash); - sha3_init(&hash, 64); - sha3_update(&hash, signature, 32); - sha3_update(&hash, public_key, 32); - sha3_update(&hash, message, message_len); - sha3_final(h, &hash); - - sc_reduce(h); - ge_double_scalarmult_vartime(&R, h, &A, signature + 32); - ge_tobytes(checker, &R); + sc_reduce(h); + ge_double_scalarmult_vartime(&R, h, &A, signature + 32); + ge_tobytes(checker, &R); - if (!consttime_equal(checker, signature)) { - return 0; - } + if (!consttime_equal(checker, signature)) { + return 0; + } - return 1; + return 1; } diff --git a/bootrom/sha3/sha3.c b/bootrom/sha3/sha3.c index 198a023bd..e6f89714d 100644 --- a/bootrom/sha3/sha3.c +++ b/bootrom/sha3/sha3.c @@ -8,158 +8,147 @@ // update the state with given number of rounds -void sha3_keccakf(uint64_t st[25]) -{ - // constants - const uint64_t keccakf_rndc[24] = { - 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, - 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, - 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, - 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, - 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, - 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, - 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, - 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 - }; - const int keccakf_rotc[24] = { - 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, - 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 - }; - const int keccakf_piln[24] = { - 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, - 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 - }; - - // variables - int i, j, r; - uint64_t t, bc[5]; +void +sha3_keccakf(uint64_t st[25]) { + // constants + const uint64_t keccakf_rndc[24] = { + 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, + 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, + 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, + 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, + 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, + 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, + 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, + 0x8000000000008080, 0x0000000080000001, 0x8000000080008008}; + const int keccakf_rotc[24] = {1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, + 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44}; + const int keccakf_piln[24] = {10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, + 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1}; + + // variables + int i, j, r; + uint64_t t, bc[5]; #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ - uint8_t *v; - - // endianess conversion. this is redundant on little-endian targets - for (i = 0; i < 25; i++) { - v = (uint8_t *) &st[i]; - st[i] = ((uint64_t) v[0]) | (((uint64_t) v[1]) << 8) | - (((uint64_t) v[2]) << 16) | (((uint64_t) v[3]) << 24) | - (((uint64_t) v[4]) << 32) | (((uint64_t) v[5]) << 40) | - (((uint64_t) v[6]) << 48) | (((uint64_t) v[7]) << 56); - } + uint8_t* v; + + // endianess conversion. this is redundant on little-endian targets + for (i = 0; i < 25; i++) { + v = (uint8_t*)&st[i]; + st[i] = ((uint64_t)v[0]) | (((uint64_t)v[1]) << 8) | + (((uint64_t)v[2]) << 16) | (((uint64_t)v[3]) << 24) | + (((uint64_t)v[4]) << 32) | (((uint64_t)v[5]) << 40) | + (((uint64_t)v[6]) << 48) | (((uint64_t)v[7]) << 56); + } #endif - // actual iteration - for (r = 0; r < KECCAKF_ROUNDS; r++) { - - // Theta - for (i = 0; i < 5; i++) - bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20]; - - for (i = 0; i < 5; i++) { - t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); - for (j = 0; j < 25; j += 5) - st[j + i] ^= t; - } - - // Rho Pi - t = st[1]; - for (i = 0; i < 24; i++) { - j = keccakf_piln[i]; - bc[0] = st[j]; - st[j] = ROTL64(t, keccakf_rotc[i]); - t = bc[0]; - } - - // Chi - for (j = 0; j < 25; j += 5) { - for (i = 0; i < 5; i++) - bc[i] = st[j + i]; - for (i = 0; i < 5; i++) - st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; - } - - // Iota - st[0] ^= keccakf_rndc[r]; + // actual iteration + for (r = 0; r < KECCAKF_ROUNDS; r++) { + // Theta + for (i = 0; i < 5; i++) + bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20]; + + for (i = 0; i < 5; i++) { + t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); + for (j = 0; j < 25; j += 5) st[j + i] ^= t; } -#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ - // endianess conversion. this is redundant on little-endian targets - for (i = 0; i < 25; i++) { - v = (uint8_t *) &st[i]; - t = st[i]; - v[0] = t & 0xFF; - v[1] = (t >> 8) & 0xFF; - v[2] = (t >> 16) & 0xFF; - v[3] = (t >> 24) & 0xFF; - v[4] = (t >> 32) & 0xFF; - v[5] = (t >> 40) & 0xFF; - v[6] = (t >> 48) & 0xFF; - v[7] = (t >> 56) & 0xFF; + // Rho Pi + t = st[1]; + for (i = 0; i < 24; i++) { + j = keccakf_piln[i]; + bc[0] = st[j]; + st[j] = ROTL64(t, keccakf_rotc[i]); + t = bc[0]; + } + + // Chi + for (j = 0; j < 25; j += 5) { + for (i = 0; i < 5; i++) bc[i] = st[j + i]; + for (i = 0; i < 5; i++) st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; } + + // Iota + st[0] ^= keccakf_rndc[r]; + } + +#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ + // endianess conversion. this is redundant on little-endian targets + for (i = 0; i < 25; i++) { + v = (uint8_t*)&st[i]; + t = st[i]; + v[0] = t & 0xFF; + v[1] = (t >> 8) & 0xFF; + v[2] = (t >> 16) & 0xFF; + v[3] = (t >> 24) & 0xFF; + v[4] = (t >> 32) & 0xFF; + v[5] = (t >> 40) & 0xFF; + v[6] = (t >> 48) & 0xFF; + v[7] = (t >> 56) & 0xFF; + } #endif } // Initialize the context for SHA3 -int sha3_init(sha3_ctx_t *c, int mdlen) -{ - int i; +int +sha3_init(sha3_ctx_t* c, int mdlen) { + int i; - for (i = 0; i < 25; i++) - c->st.q[i] = 0; - c->mdlen = mdlen; - c->rsiz = 200 - 2 * mdlen; - c->pt = 0; + for (i = 0; i < 25; i++) c->st.q[i] = 0; + c->mdlen = mdlen; + c->rsiz = 200 - 2 * mdlen; + c->pt = 0; - return 1; + return 1; } // update state with more data -int sha3_update(sha3_ctx_t *c, const void *data, size_t len) -{ - size_t i; - int j; - - j = c->pt; - for (i = 0; i < len; i++) { - c->st.b[j++] ^= ((const uint8_t *) data)[i]; - if (j >= c->rsiz) { - sha3_keccakf(c->st.q); - j = 0; - } +int +sha3_update(sha3_ctx_t* c, const void* data, size_t len) { + size_t i; + int j; + + j = c->pt; + for (i = 0; i < len; i++) { + c->st.b[j++] ^= ((const uint8_t*)data)[i]; + if (j >= c->rsiz) { + sha3_keccakf(c->st.q); + j = 0; } - c->pt = j; + } + c->pt = j; - return 1; + return 1; } // finalize and output a hash -int sha3_final(void *md, sha3_ctx_t *c) -{ - int i; +int +sha3_final(void* md, sha3_ctx_t* c) { + int i; - c->st.b[c->pt] ^= 0x06; - c->st.b[c->rsiz - 1] ^= 0x80; - sha3_keccakf(c->st.q); + c->st.b[c->pt] ^= 0x06; + c->st.b[c->rsiz - 1] ^= 0x80; + sha3_keccakf(c->st.q); - for (i = 0; i < c->mdlen; i++) { - ((uint8_t *) md)[i] = c->st.b[i]; - } + for (i = 0; i < c->mdlen; i++) { + ((uint8_t*)md)[i] = c->st.b[i]; + } - return 1; + return 1; } // compute a SHA-3 hash (md) of given byte length from "in" -void *sha3(const void *in, size_t inlen, void *md, int mdlen) -{ - sha3_ctx_t sha3; +void* +sha3(const void* in, size_t inlen, void* md, int mdlen) { + sha3_ctx_t sha3; - sha3_init(&sha3, mdlen); - sha3_update(&sha3, in, inlen); - sha3_final(md, &sha3); + sha3_init(&sha3, mdlen); + sha3_update(&sha3, in, inlen); + sha3_final(md, &sha3); - return md; + return md; } - diff --git a/bootrom/sha3/sha3.h b/bootrom/sha3/sha3.h index e0560f88b..e86976ad4 100644 --- a/bootrom/sha3/sha3.h +++ b/bootrom/sha3/sha3.h @@ -17,23 +17,27 @@ // state context typedef struct { - union { // state: - uint8_t b[200]; // 8-bit bytes - uint64_t q[25]; // 64-bit words - } st; - int pt, rsiz, mdlen; // these don't overflow + union { // state: + uint8_t b[200]; // 8-bit bytes + uint64_t q[25]; // 64-bit words + } st; + int pt, rsiz, mdlen; // these don't overflow } sha3_ctx_t; // Compression function. -void sha3_keccakf(uint64_t st[25]); +void +sha3_keccakf(uint64_t st[25]); // OpenSSL - like interfece -int sha3_init(sha3_ctx_t *c, int mdlen); // mdlen = hash output in bytes -int sha3_update(sha3_ctx_t *c, const void *data, size_t len); -int sha3_final(void *md, sha3_ctx_t *c); // digest goes to md +int +sha3_init(sha3_ctx_t* c, int mdlen); // mdlen = hash output in bytes +int +sha3_update(sha3_ctx_t* c, const void* data, size_t len); +int +sha3_final(void* md, sha3_ctx_t* c); // digest goes to md // compute a sha3 hash (md) of given byte length from "in" -void *sha3(const void *in, size_t inlen, void *md, int mdlen); +void* +sha3(const void* in, size_t inlen, void* md, int mdlen); #endif - diff --git a/bootrom/string.h b/bootrom/string.h index 37a216540..2bc17fe38 100644 --- a/bootrom/string.h +++ b/bootrom/string.h @@ -1,40 +1,37 @@ #ifndef __STRING_H__ #define __STRING_H__ -void* memcpy(void* dest, const void* src, size_t len) -{ +void* +memcpy(void* dest, const void* src, size_t len) { const char* s = src; - char *d = dest; + char* d = dest; - if ((((uintptr_t)dest | (uintptr_t)src) & (sizeof(uintptr_t)-1)) == 0) { - while ((void*)d < (dest + len - (sizeof(uintptr_t)-1))) { + if ((((uintptr_t)dest | (uintptr_t)src) & (sizeof(uintptr_t) - 1)) == 0) { + while ((void*)d < (dest + len - (sizeof(uintptr_t) - 1))) { *(uintptr_t*)d = *(const uintptr_t*)s; d += sizeof(uintptr_t); s += sizeof(uintptr_t); } } - while (d < (char*)(dest + len)) - *d++ = *s++; + while (d < (char*)(dest + len)) *d++ = *s++; return dest; } -void* memset(void* dest, int byte, size_t len) -{ - if ((((uintptr_t)dest | len) & (sizeof(uintptr_t)-1)) == 0) { +void* +memset(void* dest, int byte, size_t len) { + if ((((uintptr_t)dest | len) & (sizeof(uintptr_t) - 1)) == 0) { uintptr_t word = byte & 0xFF; word |= word << 8; word |= word << 16; word |= word << 16 << 16; - uintptr_t *d = dest; - while (d < (uintptr_t*)(dest + len)) - *d++ = word; + uintptr_t* d = dest; + while (d < (uintptr_t*)(dest + len)) *d++ = word; } else { - char *d = dest; - while (d < (char*)(dest + len)) - *d++ = byte; + char* d = dest; + while (d < (char*)(dest + len)) *d++ = byte; } return dest; } diff --git a/bootrom/test_dev_key.h b/bootrom/test_dev_key.h index ef4782d6c..f7610597b 100644 --- a/bootrom/test_dev_key.h +++ b/bootrom/test_dev_key.h @@ -1,19 +1,18 @@ -/* These are known device TESTING keys, use them for testing on platforms/qemu */ +/* These are known device TESTING keys, use them for testing on platforms/qemu + */ #warning Using TEST device root key. No integrity guarantee. static const unsigned char _sanctum_dev_secret_key[] = { - 0x40, 0xa0, 0x99, 0x47, 0x8c, 0xce, 0xfa, 0x3a, 0x06, 0x63, 0xab, 0xc9, - 0x5e, 0x7a, 0x1e, 0xc9, 0x54, 0xb4, 0xf5, 0xf6, 0x45, 0xba, 0xd8, 0x04, - 0xdb, 0x13, 0xe7, 0xd7, 0x82, 0x6c, 0x70, 0x73, 0x57, 0x6a, 0x9a, 0xb6, - 0x21, 0x60, 0xd9, 0xd1, 0xc6, 0xae, 0xdc, 0x29, 0x85, 0x2f, 0xb9, 0x60, - 0xee, 0x51, 0x32, 0x83, 0x5a, 0x16, 0x89, 0xec, 0x06, 0xa8, 0x72, 0x34, - 0x51, 0xaa, 0x0e, 0x4a -}; + 0x40, 0xa0, 0x99, 0x47, 0x8c, 0xce, 0xfa, 0x3a, 0x06, 0x63, 0xab, + 0xc9, 0x5e, 0x7a, 0x1e, 0xc9, 0x54, 0xb4, 0xf5, 0xf6, 0x45, 0xba, + 0xd8, 0x04, 0xdb, 0x13, 0xe7, 0xd7, 0x82, 0x6c, 0x70, 0x73, 0x57, + 0x6a, 0x9a, 0xb6, 0x21, 0x60, 0xd9, 0xd1, 0xc6, 0xae, 0xdc, 0x29, + 0x85, 0x2f, 0xb9, 0x60, 0xee, 0x51, 0x32, 0x83, 0x5a, 0x16, 0x89, + 0xec, 0x06, 0xa8, 0x72, 0x34, 0x51, 0xaa, 0x0e, 0x4a}; static const size_t _sanctum_dev_secret_key_len = 64; static const unsigned char _sanctum_dev_public_key[] = { - 0x0f, 0xaa, 0xd4, 0xff, 0x01, 0x17, 0x85, 0x83, 0xba, 0xa5, 0x88, 0x96, - 0x6f, 0x7c, 0x1f, 0xf3, 0x25, 0x64, 0xdd, 0x17, 0xd7, 0xdc, 0x2b, 0x46, - 0xcb, 0x50, 0xa8, 0x4a, 0x69, 0x27, 0x0b, 0x4c -}; + 0x0f, 0xaa, 0xd4, 0xff, 0x01, 0x17, 0x85, 0x83, 0xba, 0xa5, 0x88, + 0x96, 0x6f, 0x7c, 0x1f, 0xf3, 0x25, 0x64, 0xdd, 0x17, 0xd7, 0xdc, + 0x2b, 0x46, 0xcb, 0x50, 0xa8, 0x4a, 0x69, 0x27, 0x0b, 0x4c}; static const size_t _sanctum_dev_public_key_len = 32; diff --git a/bootrom/use_test_keys.h b/bootrom/use_test_keys.h index 13830ba54..ca5de015e 100644 --- a/bootrom/use_test_keys.h +++ b/bootrom/use_test_keys.h @@ -1,3 +1,7 @@ #include "test_dev_key.h" -memcpy(sanctum_dev_secret_key, _sanctum_dev_secret_key, _sanctum_dev_secret_key_len); -memcpy(sanctum_dev_public_key, _sanctum_dev_public_key, _sanctum_dev_public_key_len); +memcpy( + sanctum_dev_secret_key, _sanctum_dev_secret_key, + _sanctum_dev_secret_key_len); +memcpy( + sanctum_dev_public_key, _sanctum_dev_public_key, + _sanctum_dev_public_key_len); diff --git a/sdk/examples/attestation/host/attestor-runner.cpp b/sdk/examples/attestation/host/attestor-runner.cpp index 067c3c160..4fb129d8c 100644 --- a/sdk/examples/attestation/host/attestor-runner.cpp +++ b/sdk/examples/attestation/host/attestor-runner.cpp @@ -13,9 +13,8 @@ #include #include "host/keystone.h" -#include "verifier/report.h" - #include "verifier.h" +#include "verifier/report.h" int main(int argc, char** argv) { diff --git a/sdk/examples/attestation/host/host.h b/sdk/examples/attestation/host/host.h index 0ee19a94b..eedb8133a 100644 --- a/sdk/examples/attestation/host/host.h +++ b/sdk/examples/attestation/host/host.h @@ -55,30 +55,30 @@ class SharedBuffer { // The Host class mimicks a host interacting with the local enclave // and the remote verifier. class Host { -public: -Host( - const Keystone::Params& params, const std::string& eapp_file, - const std::string& rt_file) - : params_(params), eapp_file_(eapp_file), rt_file_(rt_file) {} - // Given a random nonce from the remote verifier, this method leaves - // it for the enclave to fetch, and returns the attestation report - // from the enclave to the verifier. - Report run(const std::string& nonce); + public: + Host( + const Keystone::Params& params, const std::string& eapp_file, + const std::string& rt_file) + : params_(params), eapp_file_(eapp_file), rt_file_(rt_file) {} + // Given a random nonce from the remote verifier, this method leaves + // it for the enclave to fetch, and returns the attestation report + // from the enclave to the verifier. + Report run(const std::string& nonce); -private: - struct RunData { - SharedBuffer shared_buffer; - const std::string& nonce; - std::unique_ptr report; - }; - static void dispatch_ocall(RunData& run_data); - static void print_buffer_wrapper(RunData& run_data); - static void print_value_wrapper(RunData& run_data); - static void copy_report_wrapper(RunData& run_data); - static void get_host_string_wrapper(RunData& run_data); - const Keystone::Params params_; - const std::string eapp_file_; - const std::string rt_file_; + private: + struct RunData { + SharedBuffer shared_buffer; + const std::string& nonce; + std::unique_ptr report; + }; + static void dispatch_ocall(RunData& run_data); + static void print_buffer_wrapper(RunData& run_data); + static void print_value_wrapper(RunData& run_data); + static void copy_report_wrapper(RunData& run_data); + static void get_host_string_wrapper(RunData& run_data); + const Keystone::Params params_; + const std::string eapp_file_; + const std::string rt_file_; }; #endif /* _ATTESTATION_HOST_H_ */ diff --git a/sdk/examples/attestation/host/verifier.h b/sdk/examples/attestation/host/verifier.h index f921553d9..abec258b4 100644 --- a/sdk/examples/attestation/host/verifier.h +++ b/sdk/examples/attestation/host/verifier.h @@ -17,7 +17,6 @@ #include "verifier/report.h" #include "verifier/test_dev_key.h" - class Verifier { public: Verifier( diff --git a/sdk/examples/tests/attestation/edge_wrapper.h b/sdk/examples/tests/attestation/edge_wrapper.h index e09b7caa0..42f82003d 100644 --- a/sdk/examples/tests/attestation/edge_wrapper.h +++ b/sdk/examples/tests/attestation/edge_wrapper.h @@ -5,10 +5,14 @@ #ifndef _EDGE_WRAPPER_H_ #define _EDGE_WRAPPER_H_ -void edge_init(); +void +edge_init(); -unsigned long ocall_print_buffer(char* data, size_t data_len); -void ocall_print_value(unsigned long val); +unsigned long +ocall_print_buffer(char* data, size_t data_len); +void +ocall_print_value(unsigned long val); -void ocall_copy_report(void* report, size_t len); +void +ocall_copy_report(void* report, size_t len); #endif /* _EDGE_WRAPPER_H_ */ diff --git a/sdk/examples/tests/data-sealing/data-sealing.h b/sdk/examples/tests/data-sealing/data-sealing.h index 58fcfc4a0..323492971 100644 --- a/sdk/examples/tests/data-sealing/data-sealing.h +++ b/sdk/examples/tests/data-sealing/data-sealing.h @@ -13,4 +13,5 @@ #define OCALL_PRINT_BUFFER 1 -unsigned long ocall_print_buffer(char *data, size_t data_len); +unsigned long +ocall_print_buffer(char* data, size_t data_len); diff --git a/sdk/examples/tests/edge_wrapper.cpp b/sdk/examples/tests/edge_wrapper.cpp index 73f2d7acb..6d6f8a01d 100644 --- a/sdk/examples/tests/edge_wrapper.cpp +++ b/sdk/examples/tests/edge_wrapper.cpp @@ -3,7 +3,9 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include "edge_wrapper.h" + #include + #include "verifier/report.h" /* Really all of this file should be autogenerated, that will happen eventually. */ diff --git a/sdk/examples/tests/edge_wrapper.h b/sdk/examples/tests/edge_wrapper.h index 212195092..c43ea7aa0 100644 --- a/sdk/examples/tests/edge_wrapper.h +++ b/sdk/examples/tests/edge_wrapper.h @@ -8,25 +8,34 @@ #include "edge/edge_call.h" #include "host/keystone.h" -typedef struct packaged_str{ +typedef struct packaged_str { unsigned long str_offset; size_t len; } packaged_str_t; typedef unsigned char byte; -int edge_init(Keystone::Enclave* enclave); +int +edge_init(Keystone::Enclave* enclave); -void print_buffer_wrapper(void* buffer); -unsigned long print_buffer(char* str); +void +print_buffer_wrapper(void* buffer); +unsigned long +print_buffer(char* str); -void print_value_wrapper(void* buffer); -void print_value(unsigned long val); +void +print_value_wrapper(void* buffer); +void +print_value(unsigned long val); -void copy_report_wrapper(void* buffer); -void copy_report(void* shared_buffer); +void +copy_report_wrapper(void* buffer); +void +copy_report(void* shared_buffer); -void get_host_string_wrapper(void* buffer); -const char* get_host_string(); +void +get_host_string_wrapper(void* buffer); +const char* +get_host_string(); #endif /* _EDGE_WRAPPER_H_ */ diff --git a/sdk/examples/tests/long-nop/nop.h b/sdk/examples/tests/long-nop/nop.h index 11c100622..262b301c3 100644 --- a/sdk/examples/tests/long-nop/nop.h +++ b/sdk/examples/tests/long-nop/nop.h @@ -1,9 +1,9 @@ #if __riscv_xlen == 64 -# define STORE sd -# define LOAD ld -# define LOG_REGBYTES 3 +#define STORE sd +#define LOAD ld +#define LOG_REGBYTES 3 #elif __riscv_xlen == 32 -# define STORE sw -# define LOAD lw -# define LOG_REGBYTES 2 +#define STORE sw +#define LOAD lw +#define LOG_REGBYTES 2 #endif diff --git a/sdk/examples/tests/test-runner.cpp b/sdk/examples/tests/test-runner.cpp index 02fb60c22..5cfcacd87 100644 --- a/sdk/examples/tests/test-runner.cpp +++ b/sdk/examples/tests/test-runner.cpp @@ -3,8 +3,10 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include + #include #include + #include "edge_wrapper.h" #include "host/keystone.h" #include "verifier/report.h" @@ -58,7 +60,8 @@ main(int argc, char** argv) { if (argc < 3 || argc > 8) { printf( "Usage: %s [--utm-size SIZE(K)] [--freemem-size " - "SIZE(K)] [--time] [--load-only] [--utm-ptr 0xPTR] [--retval EXPECTED]\n", + "SIZE(K)] [--time] [--load-only] [--utm-ptr 0xPTR] [--retval " + "EXPECTED]\n", argv[0]); return 0; } @@ -69,8 +72,8 @@ main(int argc, char** argv) { size_t untrusted_size = 2 * 1024 * 1024; size_t freemem_size = 48 * 1024 * 1024; uintptr_t utm_ptr = (uintptr_t)DEFAULT_UNTRUSTED_PTR; - bool retval_exist = false; - unsigned long retval = 0; + bool retval_exist = false; + unsigned long retval = 0; static struct option long_options[] = { {"time", no_argument, &self_timing, 1}, @@ -105,7 +108,7 @@ main(int argc, char** argv) { break; case 'r': retval_exist = true; - retval = atoi(optarg); + retval = atoi(optarg); break; } } @@ -137,7 +140,9 @@ main(int argc, char** argv) { if (!load_only) enclave.run(&encl_ret); if (retval_exist && encl_ret != retval) { - printf("[FAIL] enclave returned a wrong value (%d != %d)\r\n", encl_ret, retval); + printf( + "[FAIL] enclave returned a wrong value (%d != %d)\r\n", encl_ret, + retval); } if (self_timing) { diff --git a/sdk/examples/tests/untrusted/edge_wrapper.h b/sdk/examples/tests/untrusted/edge_wrapper.h index e959f0221..3f11bdb77 100644 --- a/sdk/examples/tests/untrusted/edge_wrapper.h +++ b/sdk/examples/tests/untrusted/edge_wrapper.h @@ -6,9 +6,13 @@ #define _EDGE_WRAPPER_H_ #include "edge/edge_call.h" -void edge_init(); +void +edge_init(); -unsigned long ocall_print_buffer(char* data, size_t data_len); -void ocall_print_value(unsigned long val); -void ocall_get_string(struct edge_data* retdata); +unsigned long +ocall_print_buffer(char* data, size_t data_len); +void +ocall_print_value(unsigned long val); +void +ocall_get_string(struct edge_data* retdata); #endif /* _EDGE_WRAPPER_H_ */ diff --git a/sdk/include/app/syscall.h b/sdk/include/app/syscall.h index d8bda798f..f9461b977 100644 --- a/sdk/include/app/syscall.h +++ b/sdk/include/app/syscall.h @@ -7,6 +7,7 @@ #include #include + #include "sealing.h" /* TODO We should be syncing these more explictly with the runtime defs */ diff --git a/sdk/include/edge/edge_syscall.h b/sdk/include/edge/edge_syscall.h index 80b550736..999eadc7a 100644 --- a/sdk/include/edge/edge_syscall.h +++ b/sdk/include/edge/edge_syscall.h @@ -1,15 +1,16 @@ #ifndef __EDGE_SYSCALL_H_ #define __EDGE_SYSCALL_H_ +#include +#include #include #include -#include -#include #include + #include "edge_call.h" #include "edge_common.h" -#include "syscall_nums.h" #include "sys/epoll.h" +#include "syscall_nums.h" #ifdef __cplusplus extern "C" { @@ -59,13 +60,13 @@ typedef struct sargs_SYS_epoll_create1 { int size; } sargs_SYS_epoll_create1; -typedef struct sargs_SYS_socket{ +typedef struct sargs_SYS_socket { int domain; int type; int protocol; } sargs_SYS_socket; -typedef struct sargs_SYS_setsockopt{ +typedef struct sargs_SYS_setsockopt { int socket; int level; int option_name; @@ -73,24 +74,24 @@ typedef struct sargs_SYS_setsockopt{ socklen_t option_len; } sargs_SYS_setsockopt; -typedef struct sargs_SYS_bind{ +typedef struct sargs_SYS_bind { int sockfd; struct sockaddr_storage addr; socklen_t addrlen; } sargs_SYS_bind; -typedef struct sargs_SYS_listen{ +typedef struct sargs_SYS_listen { int sockfd; int backlog; } sargs_SYS_listen; -typedef struct sargs_SYS_accept{ +typedef struct sargs_SYS_accept { int sockfd; struct sockaddr_storage addr; socklen_t addrlen; } sargs_SYS_accept; -typedef struct sargs_SYS_epoll_ctl{ +typedef struct sargs_SYS_epoll_ctl { int epfd; int op; int fd; @@ -109,32 +110,30 @@ typedef struct sargs_SYS_getcwd { char buf[]; } sargs_SYS_getcwd; -typedef struct sargs_SYS_chdir{ +typedef struct sargs_SYS_chdir { char path[0]; } sargs_SYS_chdir; - -typedef struct sargs_SYS_epoll_pwait{ +typedef struct sargs_SYS_epoll_pwait { int epfd; struct epoll_event events; int maxevents; int timeout; } sargs_SYS_epoll_pwait; - -typedef struct sargs_SYS_getpeername{ +typedef struct sargs_SYS_getpeername { int sockfd; struct sockaddr_storage addr; socklen_t addrlen; } sargs_SYS_getpeername; -typedef struct sargs_SYS_getsockname{ +typedef struct sargs_SYS_getsockname { int sockfd; struct sockaddr addr; socklen_t addrlen; } sargs_SYS_getsockname; -typedef struct sargs_SYS_renameat2{ +typedef struct sargs_SYS_renameat2 { int olddirfd; char oldpath[128]; int newdirfd; @@ -142,9 +141,7 @@ typedef struct sargs_SYS_renameat2{ unsigned int flags; } sargs_SYS_renameat2; - - -typedef struct sargs_SYS_umask{ +typedef struct sargs_SYS_umask { mode_t mask; } sargs_SYS_umask; @@ -166,44 +163,44 @@ typedef struct sargs_SYS_fstat { } sargs_SYS_fstat; typedef struct sargs_SYS_pselect { - int nfds; - int readfds_is_null; - int writefds_is_null; - int exceptfds_is_null; - int timeout_is_null; - int sigmask_is_null; - fd_set readfds; - fd_set writefds; - fd_set exceptfds; - struct timespec timeout; - sigset_t sigmask; + int nfds; + int readfds_is_null; + int writefds_is_null; + int exceptfds_is_null; + int timeout_is_null; + int sigmask_is_null; + fd_set readfds; + fd_set writefds; + fd_set exceptfds; + struct timespec timeout; + sigset_t sigmask; } sargs_SYS_pselect; typedef struct sargs_SYS_recvfrom { - int sockfd; - size_t len; - int flags; - int src_addr_is_null; - struct sockaddr src_addr; - socklen_t addrlen; - char buf[]; + int sockfd; + size_t len; + int flags; + int src_addr_is_null; + struct sockaddr src_addr; + socklen_t addrlen; + char buf[]; } sargs_SYS_recvfrom; typedef struct sargs_SYS_sendto { - int sockfd; - size_t len; - int flags; - int dest_addr_is_null; - struct sockaddr dest_addr; - socklen_t addrlen; - char buf[]; + int sockfd; + size_t len; + int flags; + int dest_addr_is_null; + struct sockaddr dest_addr; + socklen_t addrlen; + char buf[]; } sargs_SYS_sendto; typedef struct sargs_SYS_sendfile { - int out_fd; - size_t in_fd; + int out_fd; + size_t in_fd; int offset_is_null; - off_t offset; + off_t offset; size_t count; } sargs_SYS_sendfile; diff --git a/sdk/src/host/ElfFile.cpp b/sdk/src/host/ElfFile.cpp index fe983ad94..2fe69f832 100644 --- a/sdk/src/host/ElfFile.cpp +++ b/sdk/src/host/ElfFile.cpp @@ -3,8 +3,10 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include "ElfFile.hpp" + #include #include + #include namespace Keystone { diff --git a/sdk/src/host/Enclave.cpp b/sdk/src/host/Enclave.cpp index b3cd2f263..39b562b5a 100644 --- a/sdk/src/host/Enclave.cpp +++ b/sdk/src/host/Enclave.cpp @@ -3,6 +3,7 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include "Enclave.hpp" + #include #include #include @@ -67,7 +68,7 @@ Enclave::initStack(std::uintptr_t start, std::size_t size, bool is_rt) { }; std::uintptr_t high_addr = ROUND_UP(start, PAGE_BITS); std::uintptr_t va_start_stk = ROUND_DOWN((high_addr - size), PAGE_BITS); - int stk_pages = (high_addr - va_start_stk) / PAGE_SIZE; + int stk_pages = (high_addr - va_start_stk) / PAGE_SIZE; for (int i = 0; i < stk_pages; i++) { if (!pMemory->allocPage( @@ -114,8 +115,8 @@ Enclave::loadElf(ElfFile* elf) { std::uintptr_t start = elf->getProgramHeaderVaddr(i); std::uintptr_t file_end = start + elf->getProgramHeaderFileSize(i); std::uintptr_t memory_end = start + elf->getProgramHeaderMemorySize(i); - char* src = reinterpret_cast(elf->getProgramSegment(i)); - std::uintptr_t va = start; + char* src = reinterpret_cast(elf->getProgramSegment(i)); + std::uintptr_t va = start; /* FIXME: This is a temporary fix for loading iozone binary * which has a page-misaligned program header. */ diff --git a/sdk/src/host/KeystoneDevice.cpp b/sdk/src/host/KeystoneDevice.cpp index 777380265..4238152fa 100644 --- a/sdk/src/host/KeystoneDevice.cpp +++ b/sdk/src/host/KeystoneDevice.cpp @@ -3,6 +3,7 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include "KeystoneDevice.hpp" + #include namespace Keystone { @@ -38,8 +39,8 @@ KeystoneDevice::initUTM(std::size_t size) { Error KeystoneDevice::finalize( - std::uintptr_t runtimePhysAddr, std::uintptr_t eappPhysAddr, std::uintptr_t freePhysAddr, - struct runtime_params_t params) { + std::uintptr_t runtimePhysAddr, std::uintptr_t eappPhysAddr, + std::uintptr_t freePhysAddr, struct runtime_params_t params) { struct keystone_ioctl_create_enclave encl; encl.eid = eid; encl.runtime_paddr = runtimePhysAddr; @@ -153,8 +154,8 @@ MockKeystoneDevice::initUTM(std::size_t size) { Error MockKeystoneDevice::finalize( - std::uintptr_t runtimePhysAddr, std::uintptr_t eappPhysAddr, std::uintptr_t freePhysAddr, - struct runtime_params_t params) { + std::uintptr_t runtimePhysAddr, std::uintptr_t eappPhysAddr, + std::uintptr_t freePhysAddr, struct runtime_params_t params) { return Error::Success; } diff --git a/sdk/src/host/Memory.cpp b/sdk/src/host/Memory.cpp index 3e96b81e0..c585790ef 100644 --- a/sdk/src/host/Memory.cpp +++ b/sdk/src/host/Memory.cpp @@ -3,6 +3,7 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include "Memory.hpp" + #include #include @@ -104,7 +105,7 @@ Memory::allocPage(std::uintptr_t va, std::uintptr_t src, unsigned int mode) { pte* Memory::__ept_continue_walk_create(std::uintptr_t addr, pte* pte) { std::uint64_t free_ppn = ppn(epmFreeList); - *pte = ptd_create(free_ppn); + *pte = ptd_create(free_ppn); epmFreeList += PAGE_SIZE; return __ept_walk_create(addr); } @@ -164,8 +165,9 @@ Memory::epmAllocVspace(std::uintptr_t addr, std::size_t num_pages) { linear at-most-once paddr mappings, and then hashing valid pages */ int Memory::validateAndHashEpm( - hash_ctx_t* hash_ctx, int level, pte* tb, std::uintptr_t vaddr, int contiguous, - std::uintptr_t* runtime_max_seen, std::uintptr_t* user_max_seen) { + hash_ctx_t* hash_ctx, int level, pte* tb, std::uintptr_t vaddr, + int contiguous, std::uintptr_t* runtime_max_seen, + std::uintptr_t* user_max_seen) { pte* walk; int i; @@ -177,7 +179,8 @@ Memory::validateAndHashEpm( continue; } std::uintptr_t vpn; - std::uintptr_t phys_addr = (pte_val(*walk) >> PTE_PPN_SHIFT) << RISCV_PGSHIFT; + std::uintptr_t phys_addr = (pte_val(*walk) >> PTE_PPN_SHIFT) + << RISCV_PGSHIFT; /* Check for blatently invalid mappings */ int map_in_epm = (phys_addr >= startAddr && phys_addr < startAddr + epmSize); diff --git a/sdk/src/verifier/Report.cpp b/sdk/src/verifier/Report.cpp index 253e081f5..cb94201d2 100644 --- a/sdk/src/verifier/Report.cpp +++ b/sdk/src/verifier/Report.cpp @@ -8,6 +8,7 @@ #include #include #include + #include "ed25519/ed25519.h" using json11::Json; @@ -123,12 +124,12 @@ Report::printPretty() { byte* Report::getEnclaveHash() { - return report.enclave.hash; + return report.enclave.hash; } byte* Report::getSmHash() { - return report.sm.hash; + return report.sm.hash; } int diff --git a/sdk/src/verifier/json11.cpp b/sdk/src/verifier/json11.cpp index f7cd5047c..e9003e1ca 100644 --- a/sdk/src/verifier/json11.cpp +++ b/sdk/src/verifier/json11.cpp @@ -20,125 +20,136 @@ */ #include "json11.h" + #include #include -#include #include +#include #include namespace json11 { static const int max_depth = 200; -using std::string; -using std::vector; -using std::map; -using std::make_shared; using std::initializer_list; +using std::make_shared; +using std::map; using std::move; +using std::string; +using std::vector; /* Helper for representing null - just a do-nothing struct, plus comparison * operators so the helpers in JsonValue work. We can't use nullptr_t because * it may not be orderable. */ struct NullStruct { - bool operator==(NullStruct) const { return true; } - bool operator<(NullStruct) const { return false; } + bool operator==(NullStruct) const { return true; } + bool operator<(NullStruct) const { return false; } }; /* * * * * * * * * * * * * * * * * * * * * Serialization */ -static void dump(NullStruct, string &out) { +static void +dump(NullStruct, string& out) { + out += "null"; +} + +static void +dump(double value, string& out) { + if (std::isfinite(value)) { + char buf[32]; + snprintf(buf, sizeof buf, "%.17g", value); + out += buf; + } else { out += "null"; + } } -static void dump(double value, string &out) { - if (std::isfinite(value)) { - char buf[32]; - snprintf(buf, sizeof buf, "%.17g", value); - out += buf; - } else { - out += "null"; - } +static void +dump(int value, string& out) { + char buf[32]; + snprintf(buf, sizeof buf, "%d", value); + out += buf; } -static void dump(int value, string &out) { - char buf[32]; - snprintf(buf, sizeof buf, "%d", value); - out += buf; +static void +dump(bool value, string& out) { + out += value ? "true" : "false"; } -static void dump(bool value, string &out) { - out += value ? "true" : "false"; -} - -static void dump(const string &value, string &out) { - out += '"'; - for (size_t i = 0; i < value.length(); i++) { - const char ch = value[i]; - if (ch == '\\') { - out += "\\\\"; - } else if (ch == '"') { - out += "\\\""; - } else if (ch == '\b') { - out += "\\b"; - } else if (ch == '\f') { - out += "\\f"; - } else if (ch == '\n') { - out += "\\n"; - } else if (ch == '\r') { - out += "\\r"; - } else if (ch == '\t') { - out += "\\t"; - } else if (static_cast(ch) <= 0x1f) { - char buf[8]; - snprintf(buf, sizeof buf, "\\u%04x", ch); - out += buf; - } else if (static_cast(ch) == 0xe2 && static_cast(value[i+1]) == 0x80 - && static_cast(value[i+2]) == 0xa8) { - out += "\\u2028"; - i += 2; - } else if (static_cast(ch) == 0xe2 && static_cast(value[i+1]) == 0x80 - && static_cast(value[i+2]) == 0xa9) { - out += "\\u2029"; - i += 2; - } else { - out += ch; - } +static void +dump(const string& value, string& out) { + out += '"'; + for (size_t i = 0; i < value.length(); i++) { + const char ch = value[i]; + if (ch == '\\') { + out += "\\\\"; + } else if (ch == '"') { + out += "\\\""; + } else if (ch == '\b') { + out += "\\b"; + } else if (ch == '\f') { + out += "\\f"; + } else if (ch == '\n') { + out += "\\n"; + } else if (ch == '\r') { + out += "\\r"; + } else if (ch == '\t') { + out += "\\t"; + } else if (static_cast(ch) <= 0x1f) { + char buf[8]; + snprintf(buf, sizeof buf, "\\u%04x", ch); + out += buf; + } else if ( + static_cast(ch) == 0xe2 && + static_cast(value[i + 1]) == 0x80 && + static_cast(value[i + 2]) == 0xa8) { + out += "\\u2028"; + i += 2; + } else if ( + static_cast(ch) == 0xe2 && + static_cast(value[i + 1]) == 0x80 && + static_cast(value[i + 2]) == 0xa9) { + out += "\\u2029"; + i += 2; + } else { + out += ch; } - out += '"'; + } + out += '"'; } -static void dump(const Json::array &values, string &out) { - bool first = true; - out += "["; - for (const auto &value : values) { - if (!first) - out += ", "; - value.dump(out); - first = false; - } - out += "]"; -} - -static void dump(const Json::object &values, string &out) { - bool first = true; - out += "{"; - for (const auto &kv : values) { - if (!first) - out += ", "; - dump(kv.first, out); - out += ": "; - kv.second.dump(out); - first = false; - } - out += "}"; +static void +dump(const Json::array& values, string& out) { + bool first = true; + out += "["; + for (const auto& value : values) { + if (!first) out += ", "; + value.dump(out); + first = false; + } + out += "]"; +} + +static void +dump(const Json::object& values, string& out) { + bool first = true; + out += "{"; + for (const auto& kv : values) { + if (!first) out += ", "; + dump(kv.first, out); + out += ": "; + kv.second.dump(out); + first = false; + } + out += "}"; } -void Json::dump(string &out) const { - m_ptr->dump(out); +void +Json::dump(string& out) const { + m_ptr->dump(out); } /* * * * * * * * * * * * * * * * * * * * @@ -147,174 +158,245 @@ void Json::dump(string &out) const { template class Value : public JsonValue { -protected: - - // Constructors - explicit Value(const T &value) : m_value(value) {} - explicit Value(T &&value) : m_value(move(value)) {} - - // Get type tag - Json::Type type() const override { - return tag; - } - - // Comparisons - bool equals(const JsonValue * other) const override { - return m_value == static_cast *>(other)->m_value; - } - bool less(const JsonValue * other) const override { - return m_value < static_cast *>(other)->m_value; - } - - const T m_value; - void dump(string &out) const override { json11::dump(m_value, out); } + protected: + // Constructors + explicit Value(const T& value) : m_value(value) {} + explicit Value(T&& value) : m_value(move(value)) {} + + // Get type tag + Json::Type type() const override { return tag; } + + // Comparisons + bool equals(const JsonValue* other) const override { + return m_value == static_cast*>(other)->m_value; + } + bool less(const JsonValue* other) const override { + return m_value < static_cast*>(other)->m_value; + } + + const T m_value; + void dump(string& out) const override { json11::dump(m_value, out); } }; class JsonDouble final : public Value { - double number_value() const override { return m_value; } - int int_value() const override { return static_cast(m_value); } - bool equals(const JsonValue * other) const override { return m_value == other->number_value(); } - bool less(const JsonValue * other) const override { return m_value < other->number_value(); } -public: - explicit JsonDouble(double value) : Value(value) {} + double number_value() const override { return m_value; } + int int_value() const override { return static_cast(m_value); } + bool equals(const JsonValue* other) const override { + return m_value == other->number_value(); + } + bool less(const JsonValue* other) const override { + return m_value < other->number_value(); + } + + public: + explicit JsonDouble(double value) : Value(value) {} }; class JsonInt final : public Value { - double number_value() const override { return m_value; } - int int_value() const override { return m_value; } - bool equals(const JsonValue * other) const override { return m_value == other->number_value(); } - bool less(const JsonValue * other) const override { return m_value < other->number_value(); } -public: - explicit JsonInt(int value) : Value(value) {} + double number_value() const override { return m_value; } + int int_value() const override { return m_value; } + bool equals(const JsonValue* other) const override { + return m_value == other->number_value(); + } + bool less(const JsonValue* other) const override { + return m_value < other->number_value(); + } + + public: + explicit JsonInt(int value) : Value(value) {} }; class JsonBoolean final : public Value { - bool bool_value() const override { return m_value; } -public: - explicit JsonBoolean(bool value) : Value(value) {} + bool bool_value() const override { return m_value; } + + public: + explicit JsonBoolean(bool value) : Value(value) {} }; class JsonString final : public Value { - const string &string_value() const override { return m_value; } -public: - explicit JsonString(const string &value) : Value(value) {} - explicit JsonString(string &&value) : Value(move(value)) {} + const string& string_value() const override { return m_value; } + + public: + explicit JsonString(const string& value) : Value(value) {} + explicit JsonString(string&& value) : Value(move(value)) {} }; class JsonArray final : public Value { - const Json::array &array_items() const override { return m_value; } - const Json & operator[](size_t i) const override; -public: - explicit JsonArray(const Json::array &value) : Value(value) {} - explicit JsonArray(Json::array &&value) : Value(move(value)) {} + const Json::array& array_items() const override { return m_value; } + const Json& operator[](size_t i) const override; + + public: + explicit JsonArray(const Json::array& value) : Value(value) {} + explicit JsonArray(Json::array&& value) : Value(move(value)) {} }; class JsonObject final : public Value { - const Json::object &object_items() const override { return m_value; } - const Json & operator[](const string &key) const override; -public: - explicit JsonObject(const Json::object &value) : Value(value) {} - explicit JsonObject(Json::object &&value) : Value(move(value)) {} + const Json::object& object_items() const override { return m_value; } + const Json& operator[](const string& key) const override; + + public: + explicit JsonObject(const Json::object& value) : Value(value) {} + explicit JsonObject(Json::object&& value) : Value(move(value)) {} }; class JsonNull final : public Value { -public: - JsonNull() : Value({}) {} + public: + JsonNull() : Value({}) {} }; /* * * * * * * * * * * * * * * * * * * * * Static globals - static-init-safe */ struct Statics { - const std::shared_ptr null = make_shared(); - const std::shared_ptr t = make_shared(true); - const std::shared_ptr f = make_shared(false); - const string empty_string; - const vector empty_vector; - const map empty_map; - Statics() {} + const std::shared_ptr null = make_shared(); + const std::shared_ptr t = make_shared(true); + const std::shared_ptr f = make_shared(false); + const string empty_string; + const vector empty_vector; + const map empty_map; + Statics() {} }; -static const Statics & statics() { - static const Statics s {}; - return s; +static const Statics& +statics() { + static const Statics s{}; + return s; } -static const Json & static_null() { - // This has to be separate, not in Statics, because Json() accesses statics().null. - static const Json json_null; - return json_null; +static const Json& +static_null() { + // This has to be separate, not in Statics, because Json() accesses + // statics().null. + static const Json json_null; + return json_null; } /* * * * * * * * * * * * * * * * * * * * * Constructors */ -Json::Json() noexcept : m_ptr(statics().null) {} -Json::Json(std::nullptr_t) noexcept : m_ptr(statics().null) {} -Json::Json(double value) : m_ptr(make_shared(value)) {} -Json::Json(int value) : m_ptr(make_shared(value)) {} -Json::Json(bool value) : m_ptr(value ? statics().t : statics().f) {} -Json::Json(const string &value) : m_ptr(make_shared(value)) {} -Json::Json(string &&value) : m_ptr(make_shared(move(value))) {} -Json::Json(const char * value) : m_ptr(make_shared(value)) {} -Json::Json(const Json::array &values) : m_ptr(make_shared(values)) {} -Json::Json(Json::array &&values) : m_ptr(make_shared(move(values))) {} -Json::Json(const Json::object &values) : m_ptr(make_shared(values)) {} -Json::Json(Json::object &&values) : m_ptr(make_shared(move(values))) {} +Json::Json() noexcept : m_ptr(statics().null) {} +Json::Json(std::nullptr_t) noexcept : m_ptr(statics().null) {} +Json::Json(double value) : m_ptr(make_shared(value)) {} +Json::Json(int value) : m_ptr(make_shared(value)) {} +Json::Json(bool value) : m_ptr(value ? statics().t : statics().f) {} +Json::Json(const string& value) : m_ptr(make_shared(value)) {} +Json::Json(string&& value) : m_ptr(make_shared(move(value))) {} +Json::Json(const char* value) : m_ptr(make_shared(value)) {} +Json::Json(const Json::array& values) : m_ptr(make_shared(values)) {} +Json::Json(Json::array&& values) + : m_ptr(make_shared(move(values))) {} +Json::Json(const Json::object& values) + : m_ptr(make_shared(values)) {} +Json::Json(Json::object&& values) + : m_ptr(make_shared(move(values))) {} /* * * * * * * * * * * * * * * * * * * * * Accessors */ -Json::Type Json::type() const { return m_ptr->type(); } -double Json::number_value() const { return m_ptr->number_value(); } -int Json::int_value() const { return m_ptr->int_value(); } -bool Json::bool_value() const { return m_ptr->bool_value(); } -const string & Json::string_value() const { return m_ptr->string_value(); } -const vector & Json::array_items() const { return m_ptr->array_items(); } -const map & Json::object_items() const { return m_ptr->object_items(); } -const Json & Json::operator[] (size_t i) const { return (*m_ptr)[i]; } -const Json & Json::operator[] (const string &key) const { return (*m_ptr)[key]; } - -double JsonValue::number_value() const { return 0; } -int JsonValue::int_value() const { return 0; } -bool JsonValue::bool_value() const { return false; } -const string & JsonValue::string_value() const { return statics().empty_string; } -const vector & JsonValue::array_items() const { return statics().empty_vector; } -const map & JsonValue::object_items() const { return statics().empty_map; } -const Json & JsonValue::operator[] (size_t) const { return static_null(); } -const Json & JsonValue::operator[] (const string &) const { return static_null(); } - -const Json & JsonObject::operator[] (const string &key) const { - auto iter = m_value.find(key); - return (iter == m_value.end()) ? static_null() : iter->second; -} -const Json & JsonArray::operator[] (size_t i) const { - if (i >= m_value.size()) return static_null(); - else return m_value[i]; +Json::Type +Json::type() const { + return m_ptr->type(); +} +double +Json::number_value() const { + return m_ptr->number_value(); +} +int +Json::int_value() const { + return m_ptr->int_value(); +} +bool +Json::bool_value() const { + return m_ptr->bool_value(); +} +const string& +Json::string_value() const { + return m_ptr->string_value(); +} +const vector& +Json::array_items() const { + return m_ptr->array_items(); +} +const map& +Json::object_items() const { + return m_ptr->object_items(); +} +const Json& +Json::operator[](size_t i) const { + return (*m_ptr)[i]; +} +const Json& +Json::operator[](const string& key) const { + return (*m_ptr)[key]; +} + +double +JsonValue::number_value() const { + return 0; +} +int +JsonValue::int_value() const { + return 0; +} +bool +JsonValue::bool_value() const { + return false; +} +const string& +JsonValue::string_value() const { + return statics().empty_string; +} +const vector& +JsonValue::array_items() const { + return statics().empty_vector; +} +const map& +JsonValue::object_items() const { + return statics().empty_map; +} +const Json& +JsonValue::operator[](size_t) const { + return static_null(); +} +const Json& +JsonValue::operator[](const string&) const { + return static_null(); +} + +const Json& +JsonObject::operator[](const string& key) const { + auto iter = m_value.find(key); + return (iter == m_value.end()) ? static_null() : iter->second; +} +const Json& +JsonArray::operator[](size_t i) const { + if (i >= m_value.size()) + return static_null(); + else + return m_value[i]; } /* * * * * * * * * * * * * * * * * * * * * Comparison */ -bool Json::operator== (const Json &other) const { - if (m_ptr == other.m_ptr) - return true; - if (m_ptr->type() != other.m_ptr->type()) - return false; +bool +Json::operator==(const Json& other) const { + if (m_ptr == other.m_ptr) return true; + if (m_ptr->type() != other.m_ptr->type()) return false; - return m_ptr->equals(other.m_ptr.get()); + return m_ptr->equals(other.m_ptr.get()); } -bool Json::operator< (const Json &other) const { - if (m_ptr == other.m_ptr) - return false; - if (m_ptr->type() != other.m_ptr->type()) - return m_ptr->type() < other.m_ptr->type(); +bool +Json::operator<(const Json& other) const { + if (m_ptr == other.m_ptr) return false; + if (m_ptr->type() != other.m_ptr->type()) + return m_ptr->type() < other.m_ptr->type(); - return m_ptr->less(other.m_ptr.get()); + return m_ptr->less(other.m_ptr.get()); } /* * * * * * * * * * * * * * * * * * * * @@ -325,18 +407,20 @@ bool Json::operator< (const Json &other) const { * * Format char c suitable for printing in an error message. */ -static inline string esc(char c) { - char buf[12]; - if (static_cast(c) >= 0x20 && static_cast(c) <= 0x7f) { - snprintf(buf, sizeof buf, "'%c' (%d)", c, c); - } else { - snprintf(buf, sizeof buf, "(%d)", c); - } - return string(buf); +static inline string +esc(char c) { + char buf[12]; + if (static_cast(c) >= 0x20 && static_cast(c) <= 0x7f) { + snprintf(buf, sizeof buf, "'%c' (%d)", c, c); + } else { + snprintf(buf, sizeof buf, "(%d)", c); + } + return string(buf); } -static inline bool in_range(long x, long lower, long upper) { - return (x >= lower && x <= upper); +static inline bool +in_range(long x, long lower, long upper) { + return (x >= lower && x <= upper); } namespace { @@ -345,444 +429,419 @@ namespace { * Object that tracks all state of an in-progress parse. */ struct JsonParser final { - - /* State - */ - const string &str; - size_t i; - string &err; - bool failed; - const JsonParse strategy; - - /* fail(msg, err_ret = Json()) - * - * Mark this parse as failed. - */ - Json fail(string &&msg) { - return fail(move(msg), Json()); - } - - template - T fail(string &&msg, const T err_ret) { - if (!failed) - err = std::move(msg); - failed = true; - return err_ret; - } - - /* consume_whitespace() - * - * Advance until the current character is non-whitespace. - */ - void consume_whitespace() { - while (str[i] == ' ' || str[i] == '\r' || str[i] == '\n' || str[i] == '\t') - i++; - } - - /* consume_comment() - * - * Advance comments (c-style inline and multiline). - */ - bool consume_comment() { - bool comment_found = false; - if (str[i] == '/') { + /* State + */ + const string& str; + size_t i; + string& err; + bool failed; + const JsonParse strategy; + + /* fail(msg, err_ret = Json()) + * + * Mark this parse as failed. + */ + Json fail(string&& msg) { return fail(move(msg), Json()); } + + template + T fail(string&& msg, const T err_ret) { + if (!failed) err = std::move(msg); + failed = true; + return err_ret; + } + + /* consume_whitespace() + * + * Advance until the current character is non-whitespace. + */ + void consume_whitespace() { + while (str[i] == ' ' || str[i] == '\r' || str[i] == '\n' || str[i] == '\t') + i++; + } + + /* consume_comment() + * + * Advance comments (c-style inline and multiline). + */ + bool consume_comment() { + bool comment_found = false; + if (str[i] == '/') { + i++; + if (i == str.size()) + return fail("unexpected end of input after start of comment", false); + if (str[i] == '/') { // inline comment i++; - if (i == str.size()) - return fail("unexpected end of input after start of comment", false); - if (str[i] == '/') { // inline comment + // advance until next line, or end of input + while (i < str.size() && str[i] != '\n') { i++; - // advance until next line, or end of input - while (i < str.size() && str[i] != '\n') { - i++; - } - comment_found = true; } - else if (str[i] == '*') { // multiline comment + comment_found = true; + } else if (str[i] == '*') { // multiline comment + i++; + if (i > str.size() - 2) + return fail( + "unexpected end of input inside multi-line comment", false); + // advance until closing tokens + while (!(str[i] == '*' && str[i + 1] == '/')) { i++; - if (i > str.size()-2) - return fail("unexpected end of input inside multi-line comment", false); - // advance until closing tokens - while (!(str[i] == '*' && str[i+1] == '/')) { - i++; - if (i > str.size()-2) - return fail( + if (i > str.size() - 2) + return fail( "unexpected end of input inside multi-line comment", false); - } - i += 2; - comment_found = true; } - else - return fail("malformed comment", false); - } - return comment_found; + i += 2; + comment_found = true; + } else + return fail("malformed comment", false); + } + return comment_found; + } + + /* consume_garbage() + * + * Advance until the current character is non-whitespace and non-comment. + */ + void consume_garbage() { + consume_whitespace(); + if (strategy == JsonParse::COMMENTS) { + bool comment_found = false; + do { + comment_found = consume_comment(); + if (failed) return; + consume_whitespace(); + } while (comment_found); + } + } + + /* get_next_token() + * + * Return the next non-whitespace character. If the end of the input is + * reached, flag an error and return 0. + */ + char get_next_token() { + consume_garbage(); + if (failed) return (char)0; + if (i == str.size()) return fail("unexpected end of input", (char)0); + + return str[i++]; + } + + /* encode_utf8(pt, out) + * + * Encode pt as UTF-8 and add it to out. + */ + void encode_utf8(long pt, string& out) { + if (pt < 0) return; + + if (pt < 0x80) { + out += static_cast(pt); + } else if (pt < 0x800) { + out += static_cast((pt >> 6) | 0xC0); + out += static_cast((pt & 0x3F) | 0x80); + } else if (pt < 0x10000) { + out += static_cast((pt >> 12) | 0xE0); + out += static_cast(((pt >> 6) & 0x3F) | 0x80); + out += static_cast((pt & 0x3F) | 0x80); + } else { + out += static_cast((pt >> 18) | 0xF0); + out += static_cast(((pt >> 12) & 0x3F) | 0x80); + out += static_cast(((pt >> 6) & 0x3F) | 0x80); + out += static_cast((pt & 0x3F) | 0x80); } + } + + /* parse_string() + * + * Parse a string, starting at the current position. + */ + string parse_string() { + string out; + long last_escaped_codepoint = -1; + while (true) { + if (i == str.size()) return fail("unexpected end of input in string", ""); + + char ch = str[i++]; + + if (ch == '"') { + encode_utf8(last_escaped_codepoint, out); + return out; + } - /* consume_garbage() - * - * Advance until the current character is non-whitespace and non-comment. - */ - void consume_garbage() { - consume_whitespace(); - if(strategy == JsonParse::COMMENTS) { - bool comment_found = false; - do { - comment_found = consume_comment(); - if (failed) return; - consume_whitespace(); - } - while(comment_found); + if (in_range(ch, 0, 0x1f)) + return fail("unescaped " + esc(ch) + " in string", ""); + + // The usual case: non-escaped characters + if (ch != '\\') { + encode_utf8(last_escaped_codepoint, out); + last_escaped_codepoint = -1; + out += ch; + continue; } - } - /* get_next_token() - * - * Return the next non-whitespace character. If the end of the input is reached, - * flag an error and return 0. - */ - char get_next_token() { - consume_garbage(); - if (failed) return (char)0; - if (i == str.size()) - return fail("unexpected end of input", (char)0); - - return str[i++]; - } + // Handle escapes + if (i == str.size()) return fail("unexpected end of input in string", ""); - /* encode_utf8(pt, out) - * - * Encode pt as UTF-8 and add it to out. - */ - void encode_utf8(long pt, string & out) { - if (pt < 0) - return; - - if (pt < 0x80) { - out += static_cast(pt); - } else if (pt < 0x800) { - out += static_cast((pt >> 6) | 0xC0); - out += static_cast((pt & 0x3F) | 0x80); - } else if (pt < 0x10000) { - out += static_cast((pt >> 12) | 0xE0); - out += static_cast(((pt >> 6) & 0x3F) | 0x80); - out += static_cast((pt & 0x3F) | 0x80); - } else { - out += static_cast((pt >> 18) | 0xF0); - out += static_cast(((pt >> 12) & 0x3F) | 0x80); - out += static_cast(((pt >> 6) & 0x3F) | 0x80); - out += static_cast((pt & 0x3F) | 0x80); - } - } + ch = str[i++]; - /* parse_string() - * - * Parse a string, starting at the current position. - */ - string parse_string() { - string out; - long last_escaped_codepoint = -1; - while (true) { - if (i == str.size()) - return fail("unexpected end of input in string", ""); - - char ch = str[i++]; - - if (ch == '"') { - encode_utf8(last_escaped_codepoint, out); - return out; - } - - if (in_range(ch, 0, 0x1f)) - return fail("unescaped " + esc(ch) + " in string", ""); - - // The usual case: non-escaped characters - if (ch != '\\') { - encode_utf8(last_escaped_codepoint, out); - last_escaped_codepoint = -1; - out += ch; - continue; - } - - // Handle escapes - if (i == str.size()) - return fail("unexpected end of input in string", ""); - - ch = str[i++]; - - if (ch == 'u') { - // Extract 4-byte escape sequence - string esc = str.substr(i, 4); - // Explicitly check length of the substring. The following loop - // relies on std::string returning the terminating NUL when - // accessing str[length]. Checking here reduces brittleness. - if (esc.length() < 4) { - return fail("bad \\u escape: " + esc, ""); - } - for (size_t j = 0; j < 4; j++) { - if (!in_range(esc[j], 'a', 'f') && !in_range(esc[j], 'A', 'F') - && !in_range(esc[j], '0', '9')) - return fail("bad \\u escape: " + esc, ""); - } - - long codepoint = strtol(esc.data(), nullptr, 16); - - // JSON specifies that characters outside the BMP shall be encoded as a pair - // of 4-hex-digit \u escapes encoding their surrogate pair components. Check - // whether we're in the middle of such a beast: the previous codepoint was an - // escaped lead (high) surrogate, and this is a trail (low) surrogate. - if (in_range(last_escaped_codepoint, 0xD800, 0xDBFF) - && in_range(codepoint, 0xDC00, 0xDFFF)) { - // Reassemble the two surrogate pairs into one astral-plane character, per - // the UTF-16 algorithm. - encode_utf8((((last_escaped_codepoint - 0xD800) << 10) - | (codepoint - 0xDC00)) + 0x10000, out); - last_escaped_codepoint = -1; - } else { - encode_utf8(last_escaped_codepoint, out); - last_escaped_codepoint = codepoint; - } - - i += 4; - continue; - } - - encode_utf8(last_escaped_codepoint, out); - last_escaped_codepoint = -1; - - if (ch == 'b') { - out += '\b'; - } else if (ch == 'f') { - out += '\f'; - } else if (ch == 'n') { - out += '\n'; - } else if (ch == 'r') { - out += '\r'; - } else if (ch == 't') { - out += '\t'; - } else if (ch == '"' || ch == '\\' || ch == '/') { - out += ch; - } else { - return fail("invalid escape character " + esc(ch), ""); - } + if (ch == 'u') { + // Extract 4-byte escape sequence + string esc = str.substr(i, 4); + // Explicitly check length of the substring. The following loop + // relies on std::string returning the terminating NUL when + // accessing str[length]. Checking here reduces brittleness. + if (esc.length() < 4) { + return fail("bad \\u escape: " + esc, ""); + } + for (size_t j = 0; j < 4; j++) { + if (!in_range(esc[j], 'a', 'f') && !in_range(esc[j], 'A', 'F') && + !in_range(esc[j], '0', '9')) + return fail("bad \\u escape: " + esc, ""); } - } - /* parse_number() - * - * Parse a double. - */ - Json parse_number() { - size_t start_pos = i; - - if (str[i] == '-') - i++; - - // Integer part - if (str[i] == '0') { - i++; - if (in_range(str[i], '0', '9')) - return fail("leading 0s not permitted in numbers"); - } else if (in_range(str[i], '1', '9')) { - i++; - while (in_range(str[i], '0', '9')) - i++; + long codepoint = strtol(esc.data(), nullptr, 16); + + // JSON specifies that characters outside the BMP shall be encoded as a + // pair of 4-hex-digit \u escapes encoding their surrogate pair + // components. Check whether we're in the middle of such a beast: the + // previous codepoint was an escaped lead (high) surrogate, and this is + // a trail (low) surrogate. + if (in_range(last_escaped_codepoint, 0xD800, 0xDBFF) && + in_range(codepoint, 0xDC00, 0xDFFF)) { + // Reassemble the two surrogate pairs into one astral-plane character, + // per the UTF-16 algorithm. + encode_utf8( + (((last_escaped_codepoint - 0xD800) << 10) | + (codepoint - 0xDC00)) + + 0x10000, + out); + last_escaped_codepoint = -1; } else { - return fail("invalid " + esc(str[i]) + " in number"); + encode_utf8(last_escaped_codepoint, out); + last_escaped_codepoint = codepoint; } - if (str[i] != '.' && str[i] != 'e' && str[i] != 'E' - && (i - start_pos) <= static_cast(std::numeric_limits::digits10)) { - return std::atoi(str.c_str() + start_pos); - } + i += 4; + continue; + } + + encode_utf8(last_escaped_codepoint, out); + last_escaped_codepoint = -1; + + if (ch == 'b') { + out += '\b'; + } else if (ch == 'f') { + out += '\f'; + } else if (ch == 'n') { + out += '\n'; + } else if (ch == 'r') { + out += '\r'; + } else if (ch == 't') { + out += '\t'; + } else if (ch == '"' || ch == '\\' || ch == '/') { + out += ch; + } else { + return fail("invalid escape character " + esc(ch), ""); + } + } + } + + /* parse_number() + * + * Parse a double. + */ + Json parse_number() { + size_t start_pos = i; + + if (str[i] == '-') i++; + + // Integer part + if (str[i] == '0') { + i++; + if (in_range(str[i], '0', '9')) + return fail("leading 0s not permitted in numbers"); + } else if (in_range(str[i], '1', '9')) { + i++; + while (in_range(str[i], '0', '9')) i++; + } else { + return fail("invalid " + esc(str[i]) + " in number"); + } - // Decimal part - if (str[i] == '.') { - i++; - if (!in_range(str[i], '0', '9')) - return fail("at least one digit required in fractional part"); + if (str[i] != '.' && str[i] != 'e' && str[i] != 'E' && + (i - start_pos) <= + static_cast(std::numeric_limits::digits10)) { + return std::atoi(str.c_str() + start_pos); + } - while (in_range(str[i], '0', '9')) - i++; - } + // Decimal part + if (str[i] == '.') { + i++; + if (!in_range(str[i], '0', '9')) + return fail("at least one digit required in fractional part"); - // Exponent part - if (str[i] == 'e' || str[i] == 'E') { - i++; + while (in_range(str[i], '0', '9')) i++; + } - if (str[i] == '+' || str[i] == '-') - i++; + // Exponent part + if (str[i] == 'e' || str[i] == 'E') { + i++; - if (!in_range(str[i], '0', '9')) - return fail("at least one digit required in exponent"); + if (str[i] == '+' || str[i] == '-') i++; - while (in_range(str[i], '0', '9')) - i++; - } + if (!in_range(str[i], '0', '9')) + return fail("at least one digit required in exponent"); - return std::strtod(str.c_str() + start_pos, nullptr); + while (in_range(str[i], '0', '9')) i++; } - /* expect(str, res) - * - * Expect that 'str' starts at the character that was just read. If it does, advance - * the input and return res. If not, flag an error. - */ - Json expect(const string &expected, Json res) { - assert(i != 0); - i--; - if (str.compare(i, expected.length(), expected) == 0) { - i += expected.length(); - return res; - } else { - return fail("parse error: expected " + expected + ", got " + str.substr(i, expected.length())); - } + return std::strtod(str.c_str() + start_pos, nullptr); + } + + /* expect(str, res) + * + * Expect that 'str' starts at the character that was just read. If it does, + * advance the input and return res. If not, flag an error. + */ + Json expect(const string& expected, Json res) { + assert(i != 0); + i--; + if (str.compare(i, expected.length(), expected) == 0) { + i += expected.length(); + return res; + } else { + return fail( + "parse error: expected " + expected + ", got " + + str.substr(i, expected.length())); + } + } + + /* parse_json() + * + * Parse a JSON object. + */ + Json parse_json(int depth) { + if (depth > max_depth) { + return fail("exceeded maximum nesting depth"); } - /* parse_json() - * - * Parse a JSON object. - */ - Json parse_json(int depth) { - if (depth > max_depth) { - return fail("exceeded maximum nesting depth"); - } + char ch = get_next_token(); + if (failed) return Json(); - char ch = get_next_token(); - if (failed) - return Json(); + if (ch == '-' || (ch >= '0' && ch <= '9')) { + i--; + return parse_number(); + } - if (ch == '-' || (ch >= '0' && ch <= '9')) { - i--; - return parse_number(); - } + if (ch == 't') return expect("true", true); - if (ch == 't') - return expect("true", true); + if (ch == 'f') return expect("false", false); - if (ch == 'f') - return expect("false", false); + if (ch == 'n') return expect("null", Json()); - if (ch == 'n') - return expect("null", Json()); + if (ch == '"') return parse_string(); - if (ch == '"') - return parse_string(); + if (ch == '{') { + map data; + ch = get_next_token(); + if (ch == '}') return data; - if (ch == '{') { - map data; - ch = get_next_token(); - if (ch == '}') - return data; + while (1) { + if (ch != '"') return fail("expected '\"' in object, got " + esc(ch)); - while (1) { - if (ch != '"') - return fail("expected '\"' in object, got " + esc(ch)); + string key = parse_string(); + if (failed) return Json(); - string key = parse_string(); - if (failed) - return Json(); + ch = get_next_token(); + if (ch != ':') return fail("expected ':' in object, got " + esc(ch)); - ch = get_next_token(); - if (ch != ':') - return fail("expected ':' in object, got " + esc(ch)); + data[std::move(key)] = parse_json(depth + 1); + if (failed) return Json(); - data[std::move(key)] = parse_json(depth + 1); - if (failed) - return Json(); + ch = get_next_token(); + if (ch == '}') break; + if (ch != ',') return fail("expected ',' in object, got " + esc(ch)); - ch = get_next_token(); - if (ch == '}') - break; - if (ch != ',') - return fail("expected ',' in object, got " + esc(ch)); + ch = get_next_token(); + } + return data; + } - ch = get_next_token(); - } - return data; - } + if (ch == '[') { + vector data; + ch = get_next_token(); + if (ch == ']') return data; - if (ch == '[') { - vector data; - ch = get_next_token(); - if (ch == ']') - return data; - - while (1) { - i--; - data.push_back(parse_json(depth + 1)); - if (failed) - return Json(); - - ch = get_next_token(); - if (ch == ']') - break; - if (ch != ',') - return fail("expected ',' in list, got " + esc(ch)); - - ch = get_next_token(); - (void)ch; - } - return data; - } + while (1) { + i--; + data.push_back(parse_json(depth + 1)); + if (failed) return Json(); + + ch = get_next_token(); + if (ch == ']') break; + if (ch != ',') return fail("expected ',' in list, got " + esc(ch)); - return fail("expected value, got " + esc(ch)); + ch = get_next_token(); + (void)ch; + } + return data; } + + return fail("expected value, got " + esc(ch)); + } }; -}//namespace { +} // namespace -Json Json::parse(const string &in, string &err, JsonParse strategy) { - JsonParser parser { in, 0, err, false, strategy }; - Json result = parser.parse_json(0); +Json +Json::parse(const string& in, string& err, JsonParse strategy) { + JsonParser parser{in, 0, err, false, strategy}; + Json result = parser.parse_json(0); - // Check for any trailing garbage - parser.consume_garbage(); - if (parser.failed) - return Json(); - if (parser.i != in.size()) - return parser.fail("unexpected trailing " + esc(in[parser.i])); + // Check for any trailing garbage + parser.consume_garbage(); + if (parser.failed) return Json(); + if (parser.i != in.size()) + return parser.fail("unexpected trailing " + esc(in[parser.i])); - return result; + return result; } // Documented in json11.hpp -vector Json::parse_multi(const string &in, - std::string::size_type &parser_stop_pos, - string &err, - JsonParse strategy) { - JsonParser parser { in, 0, err, false, strategy }; - parser_stop_pos = 0; - vector json_vec; - while (parser.i != in.size() && !parser.failed) { - json_vec.push_back(parser.parse_json(0)); - if (parser.failed) - break; - - // Check for another object - parser.consume_garbage(); - if (parser.failed) - break; - parser_stop_pos = parser.i; - } - return json_vec; +vector +Json::parse_multi( + const string& in, std::string::size_type& parser_stop_pos, string& err, + JsonParse strategy) { + JsonParser parser{in, 0, err, false, strategy}; + parser_stop_pos = 0; + vector json_vec; + while (parser.i != in.size() && !parser.failed) { + json_vec.push_back(parser.parse_json(0)); + if (parser.failed) break; + + // Check for another object + parser.consume_garbage(); + if (parser.failed) break; + parser_stop_pos = parser.i; + } + return json_vec; } /* * * * * * * * * * * * * * * * * * * * * Shape-checking */ -bool Json::has_shape(const shape & types, string & err) const { - if (!is_object()) { - err = "expected JSON object, got " + dump(); - return false; - } - - for (auto & item : types) { - if ((*this)[item.first].type() != item.second) { - err = "bad type for " + item.first + " in " + dump(); - return false; - } +bool +Json::has_shape(const shape& types, string& err) const { + if (!is_object()) { + err = "expected JSON object, got " + dump(); + return false; + } + + for (auto& item : types) { + if ((*this)[item.first].type() != item.second) { + err = "bad type for " + item.first + " in " + dump(); + return false; } + } - return true; + return true; } -} // namespace json11 +} // namespace json11 diff --git a/sdk/tests/keystone_test.cpp b/sdk/tests/keystone_test.cpp index 03dd0da0d..bac0ef441 100644 --- a/sdk/tests/keystone_test.cpp +++ b/sdk/tests/keystone_test.cpp @@ -4,8 +4,10 @@ //------------------------------------------------------------------------------ #include #include + #include #include + #include "gtest/gtest.h" #define EYRIE_RT "eyrie-rt" diff --git a/sm/plat/generic/include/platform_override.h b/sm/plat/generic/include/platform_override.h index e55da2517..fb1586ec4 100644 --- a/sm/plat/generic/include/platform_override.h +++ b/sm/plat/generic/include/platform_override.h @@ -10,24 +10,23 @@ #ifndef __PLATFORM_OVERRIDE_H__ #define __PLATFORM_OVERRIDE_H__ -#include #include +#include struct platform_override { - const struct fdt_match *match_table; - u64 (*features)(const struct fdt_match *match); - u64 (*tlbr_flush_limit)(const struct fdt_match *match); - int (*early_init)(bool cold_boot, const struct fdt_match *match); - int (*final_init)(bool cold_boot, const struct fdt_match *match); - void (*early_exit)(const struct fdt_match *match); - void (*final_exit)(const struct fdt_match *match); - int (*fdt_fixup)(void *fdt, const struct fdt_match *match); - int (*vendor_ext_check)(long extid, const struct fdt_match *match); - int (*vendor_ext_provider)(long extid, long funcid, - const struct sbi_trap_regs *regs, - unsigned long *out_value, - struct sbi_trap_info *out_trap, - const struct fdt_match *match); + const struct fdt_match* match_table; + u64 (*features)(const struct fdt_match* match); + u64 (*tlbr_flush_limit)(const struct fdt_match* match); + int (*early_init)(bool cold_boot, const struct fdt_match* match); + int (*final_init)(bool cold_boot, const struct fdt_match* match); + void (*early_exit)(const struct fdt_match* match); + void (*final_exit)(const struct fdt_match* match); + int (*fdt_fixup)(void* fdt, const struct fdt_match* match); + int (*vendor_ext_check)(long extid, const struct fdt_match* match); + int (*vendor_ext_provider)( + long extid, long funcid, const struct sbi_trap_regs* regs, + unsigned long* out_value, struct sbi_trap_info* out_trap, + const struct fdt_match* match); }; #endif diff --git a/sm/plat/generic/platform.c b/sm/plat/generic/platform.c index 0a22ebde6..8765c31b8 100644 --- a/sm/plat/generic/platform.c +++ b/sm/plat/generic/platform.c @@ -17,45 +17,44 @@ #include #include #include +#include #include #include +#include #include #include -#include -#include + #include "sm.h" /* List of platform override modules generated at compile time */ -extern const struct platform_override *platform_override_modules[]; +extern const struct platform_override* platform_override_modules[]; extern unsigned long platform_override_modules_size; -static const struct platform_override *generic_plat = NULL; -static const struct fdt_match *generic_plat_match = NULL; +static const struct platform_override* generic_plat = NULL; +static const struct fdt_match* generic_plat_match = NULL; -static void fw_platform_lookup_special(void *fdt, int root_offset) -{ - int pos, noff; - const struct platform_override *plat; - const struct fdt_match *match; +static void +fw_platform_lookup_special(void* fdt, int root_offset) { + int pos, noff; + const struct platform_override* plat; + const struct fdt_match* match; - for (pos = 0; pos < platform_override_modules_size; pos++) { - plat = platform_override_modules[pos]; - if (!plat->match_table) - continue; + for (pos = 0; pos < platform_override_modules_size; pos++) { + plat = platform_override_modules[pos]; + if (!plat->match_table) continue; - noff = fdt_find_match(fdt, -1, plat->match_table, &match); - if (noff < 0) - continue; + noff = fdt_find_match(fdt, -1, plat->match_table, &match); + if (noff < 0) continue; - generic_plat = plat; - generic_plat_match = match; - break; - } + generic_plat = plat; + generic_plat_match = match; + break; + } } extern struct sbi_platform platform; -static bool platform_has_mlevel_imsic = false; -static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 }; +static bool platform_has_mlevel_imsic = false; +static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = {0}; /* * The fw_platform_init() function is called very early on the boot HART @@ -70,209 +69,190 @@ static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 }; * FDT is unchanged (or FDT is modified in-place) then fw_platform_init() * can always return the original FDT location (i.e. 'arg1') unmodified. */ -unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1, - unsigned long arg2, unsigned long arg3, - unsigned long arg4) -{ - const char *model; - void *fdt = (void *)arg1; - u32 hartid, hart_count = 0; - int rc, root_offset, cpus_offset, cpu_offset, len; +unsigned long +fw_platform_init( + unsigned long arg0, unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4) { + const char* model; + void* fdt = (void*)arg1; + u32 hartid, hart_count = 0; + int rc, root_offset, cpus_offset, cpu_offset, len; - root_offset = fdt_path_offset(fdt, "/"); - if (root_offset < 0) - goto fail; + root_offset = fdt_path_offset(fdt, "/"); + if (root_offset < 0) goto fail; - fw_platform_lookup_special(fdt, root_offset); + fw_platform_lookup_special(fdt, root_offset); - model = fdt_getprop(fdt, root_offset, "model", &len); - if (model) - sbi_strncpy(platform.name, model, sizeof(platform.name) - 1); + model = fdt_getprop(fdt, root_offset, "model", &len); + if (model) sbi_strncpy(platform.name, model, sizeof(platform.name) - 1); - if (generic_plat && generic_plat->features) - platform.features = generic_plat->features(generic_plat_match); + if (generic_plat && generic_plat->features) + platform.features = generic_plat->features(generic_plat_match); - cpus_offset = fdt_path_offset(fdt, "/cpus"); - if (cpus_offset < 0) - goto fail; + cpus_offset = fdt_path_offset(fdt, "/cpus"); + if (cpus_offset < 0) goto fail; - fdt_for_each_subnode(cpu_offset, fdt, cpus_offset) { - rc = fdt_parse_hart_id(fdt, cpu_offset, &hartid); - if (rc) - continue; + fdt_for_each_subnode(cpu_offset, fdt, cpus_offset) { + rc = fdt_parse_hart_id(fdt, cpu_offset, &hartid); + if (rc) continue; - if (SBI_HARTMASK_MAX_BITS <= hartid) - continue; + if (SBI_HARTMASK_MAX_BITS <= hartid) continue; - if (!fdt_node_is_enabled(fdt, cpu_offset)) - continue; + if (!fdt_node_is_enabled(fdt, cpu_offset)) continue; - generic_hart_index2id[hart_count++] = hartid; - } + generic_hart_index2id[hart_count++] = hartid; + } - platform.hart_count = hart_count; + platform.hart_count = hart_count; - platform_has_mlevel_imsic = fdt_check_imsic_mlevel(fdt); + platform_has_mlevel_imsic = fdt_check_imsic_mlevel(fdt); - /* Return original FDT pointer */ - return arg1; + /* Return original FDT pointer */ + return arg1; fail: - while (1) - wfi(); + while (1) wfi(); } -static int generic_nascent_init(void) -{ - if (platform_has_mlevel_imsic) - imsic_local_irqchip_init(); - return 0; +static int +generic_nascent_init(void) { + if (platform_has_mlevel_imsic) imsic_local_irqchip_init(); + return 0; } -static int generic_early_init(bool cold_boot) -{ - if (!generic_plat || !generic_plat->early_init) - return 0; +static int +generic_early_init(bool cold_boot) { + if (!generic_plat || !generic_plat->early_init) return 0; - return generic_plat->early_init(cold_boot, generic_plat_match); + return generic_plat->early_init(cold_boot, generic_plat_match); } -static int generic_final_init(bool cold_boot) -{ - void *fdt; - int rc; +static int +generic_final_init(bool cold_boot) { + void* fdt; + int rc; - if (cold_boot) - fdt_reset_init(); + if (cold_boot) fdt_reset_init(); - if (generic_plat && generic_plat->final_init) { - rc = generic_plat->final_init(cold_boot, generic_plat_match); - if (rc) - return rc; - } + if (generic_plat && generic_plat->final_init) { + rc = generic_plat->final_init(cold_boot, generic_plat_match); + if (rc) return rc; + } - sm_init(cold_boot); + sm_init(cold_boot); - if (!cold_boot) - return 0; + if (!cold_boot) return 0; - fdt = fdt_get_address(); + fdt = fdt_get_address(); - fdt_cpu_fixup(fdt); - fdt_fixups(fdt); - fdt_domain_fixup(fdt); + fdt_cpu_fixup(fdt); + fdt_fixups(fdt); + fdt_domain_fixup(fdt); - if (generic_plat && generic_plat->fdt_fixup) { - rc = generic_plat->fdt_fixup(fdt, generic_plat_match); - if (rc) - return rc; - } + if (generic_plat && generic_plat->fdt_fixup) { + rc = generic_plat->fdt_fixup(fdt, generic_plat_match); + if (rc) return rc; + } - return 0; + return 0; } -static int generic_vendor_ext_check(long extid) -{ - if (generic_plat && generic_plat->vendor_ext_check) - return generic_plat->vendor_ext_check(extid, - generic_plat_match); +static int +generic_vendor_ext_check(long extid) { + if (generic_plat && generic_plat->vendor_ext_check) + return generic_plat->vendor_ext_check(extid, generic_plat_match); - return 0; + return 0; } -static int generic_vendor_ext_provider(long extid, long funcid, - const struct sbi_trap_regs *regs, - unsigned long *out_value, - struct sbi_trap_info *out_trap) -{ - if (generic_plat && generic_plat->vendor_ext_provider) { - return generic_plat->vendor_ext_provider(extid, funcid, regs, - out_value, out_trap, - generic_plat_match); - } - - return SBI_ENOTSUPP; +static int +generic_vendor_ext_provider( + long extid, long funcid, const struct sbi_trap_regs* regs, + unsigned long* out_value, struct sbi_trap_info* out_trap) { + if (generic_plat && generic_plat->vendor_ext_provider) { + return generic_plat->vendor_ext_provider( + extid, funcid, regs, out_value, out_trap, generic_plat_match); + } + + return SBI_ENOTSUPP; } -static void generic_early_exit(void) -{ - if (generic_plat && generic_plat->early_exit) - generic_plat->early_exit(generic_plat_match); +static void +generic_early_exit(void) { + if (generic_plat && generic_plat->early_exit) + generic_plat->early_exit(generic_plat_match); } -static void generic_final_exit(void) -{ - if (generic_plat && generic_plat->final_exit) - generic_plat->final_exit(generic_plat_match); +static void +generic_final_exit(void) { + if (generic_plat && generic_plat->final_exit) + generic_plat->final_exit(generic_plat_match); } -static int generic_domains_init(void) -{ - return fdt_domains_populate(fdt_get_address()); +static int +generic_domains_init(void) { + return fdt_domains_populate(fdt_get_address()); } -static u64 generic_tlbr_flush_limit(void) -{ - if (generic_plat && generic_plat->tlbr_flush_limit) - return generic_plat->tlbr_flush_limit(generic_plat_match); - return SBI_PLATFORM_TLB_RANGE_FLUSH_LIMIT_DEFAULT; +static u64 +generic_tlbr_flush_limit(void) { + if (generic_plat && generic_plat->tlbr_flush_limit) + return generic_plat->tlbr_flush_limit(generic_plat_match); + return SBI_PLATFORM_TLB_RANGE_FLUSH_LIMIT_DEFAULT; } -static int generic_pmu_init(void) -{ - return fdt_pmu_setup(fdt_get_address()); +static int +generic_pmu_init(void) { + return fdt_pmu_setup(fdt_get_address()); } -static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx, - uint64_t data) -{ - uint64_t evt_val = 0; - - /* data is valid only for raw events and is equal to event selector */ - if (event_idx == SBI_PMU_EVENT_RAW_IDX) - evt_val = data; - else { - /** - * Generic platform follows the SBI specification recommendation - * i.e. zero extended event_idx is used as mhpmevent value for - * hardware general/cache events if platform does't define one. - */ - evt_val = fdt_pmu_get_select_value(event_idx); - if (!evt_val) - evt_val = (uint64_t)event_idx; - } - - return evt_val; +static uint64_t +generic_pmu_xlate_to_mhpmevent(uint32_t event_idx, uint64_t data) { + uint64_t evt_val = 0; + + /* data is valid only for raw events and is equal to event selector */ + if (event_idx == SBI_PMU_EVENT_RAW_IDX) + evt_val = data; + else { + /** + * Generic platform follows the SBI specification recommendation + * i.e. zero extended event_idx is used as mhpmevent value for + * hardware general/cache events if platform does't define one. + */ + evt_val = fdt_pmu_get_select_value(event_idx); + if (!evt_val) evt_val = (uint64_t)event_idx; + } + + return evt_val; } const struct sbi_platform_operations platform_ops = { - .nascent_init = generic_nascent_init, - .early_init = generic_early_init, - .final_init = generic_final_init, - .early_exit = generic_early_exit, - .final_exit = generic_final_exit, - .domains_init = generic_domains_init, - .console_init = fdt_serial_init, - .irqchip_init = fdt_irqchip_init, - .irqchip_exit = fdt_irqchip_exit, - .ipi_init = fdt_ipi_init, - .ipi_exit = fdt_ipi_exit, - .pmu_init = generic_pmu_init, - .pmu_xlate_to_mhpmevent = generic_pmu_xlate_to_mhpmevent, - .get_tlbr_flush_limit = generic_tlbr_flush_limit, - .timer_init = fdt_timer_init, - .timer_exit = fdt_timer_exit, - .vendor_ext_check = generic_vendor_ext_check, - .vendor_ext_provider = generic_vendor_ext_provider, + .nascent_init = generic_nascent_init, + .early_init = generic_early_init, + .final_init = generic_final_init, + .early_exit = generic_early_exit, + .final_exit = generic_final_exit, + .domains_init = generic_domains_init, + .console_init = fdt_serial_init, + .irqchip_init = fdt_irqchip_init, + .irqchip_exit = fdt_irqchip_exit, + .ipi_init = fdt_ipi_init, + .ipi_exit = fdt_ipi_exit, + .pmu_init = generic_pmu_init, + .pmu_xlate_to_mhpmevent = generic_pmu_xlate_to_mhpmevent, + .get_tlbr_flush_limit = generic_tlbr_flush_limit, + .timer_init = fdt_timer_init, + .timer_exit = fdt_timer_exit, + .vendor_ext_check = generic_vendor_ext_check, + .vendor_ext_provider = generic_vendor_ext_provider, }; struct sbi_platform platform = { - .opensbi_version = OPENSBI_VERSION, - .platform_version = SBI_PLATFORM_VERSION(0x0, 0x01), - .name = "Generic", - .features = SBI_PLATFORM_DEFAULT_FEATURES, - .hart_count = SBI_HARTMASK_MAX_BITS, - .hart_index2id = generic_hart_index2id, - .hart_stack_size = SBI_PLATFORM_DEFAULT_HART_STACK_SIZE, - .platform_ops_addr = (unsigned long)&platform_ops -}; + .opensbi_version = OPENSBI_VERSION, + .platform_version = SBI_PLATFORM_VERSION(0x0, 0x01), + .name = "Generic", + .features = SBI_PLATFORM_DEFAULT_FEATURES, + .hart_count = SBI_HARTMASK_MAX_BITS, + .hart_index2id = generic_hart_index2id, + .hart_stack_size = SBI_PLATFORM_DEFAULT_HART_STACK_SIZE, + .platform_ops_addr = (unsigned long)&platform_ops}; diff --git a/sm/plat/generic/sifive_fu540.c b/sm/plat/generic/sifive_fu540.c index 08f7bfc40..41d421347 100644 --- a/sm/plat/generic/sifive_fu540.c +++ b/sm/plat/generic/sifive_fu540.c @@ -8,40 +8,40 @@ */ #include -#include #include +#include -static u64 sifive_fu540_tlbr_flush_limit(const struct fdt_match *match) -{ - /* - * The sfence.vma by virtual address does not work on - * SiFive FU540 so we return remote TLB flush limit as zero. - */ - return 0; +static u64 +sifive_fu540_tlbr_flush_limit(const struct fdt_match* match) { + /* + * The sfence.vma by virtual address does not work on + * SiFive FU540 so we return remote TLB flush limit as zero. + */ + return 0; } -static int sifive_fu540_fdt_fixup(void *fdt, const struct fdt_match *match) -{ - /* - * SiFive Freedom U540 has an erratum that prevents S-mode software - * to access a PMP protected region using 1GB page table mapping, so - * always add the no-map attribute on this platform. - */ - fdt_reserved_memory_nomap_fixup(fdt); +static int +sifive_fu540_fdt_fixup(void* fdt, const struct fdt_match* match) { + /* + * SiFive Freedom U540 has an erratum that prevents S-mode software + * to access a PMP protected region using 1GB page table mapping, so + * always add the no-map attribute on this platform. + */ + fdt_reserved_memory_nomap_fixup(fdt); - return 0; + return 0; } static const struct fdt_match sifive_fu540_match[] = { - { .compatible = "sifive,fu540" }, - { .compatible = "sifive,fu540g" }, - { .compatible = "sifive,fu540-c000" }, - { .compatible = "sifive,hifive-unleashed-a00" }, - { }, + {.compatible = "sifive,fu540"}, + {.compatible = "sifive,fu540g"}, + {.compatible = "sifive,fu540-c000"}, + {.compatible = "sifive,hifive-unleashed-a00"}, + {}, }; const struct platform_override sifive_fu540 = { - .match_table = sifive_fu540_match, - .tlbr_flush_limit = sifive_fu540_tlbr_flush_limit, - .fdt_fixup = sifive_fu540_fdt_fixup, + .match_table = sifive_fu540_match, + .tlbr_flush_limit = sifive_fu540_tlbr_flush_limit, + .fdt_fixup = sifive_fu540_fdt_fixup, }; diff --git a/sm/plat/mpfs/clocks/hw_mss_clks.h b/sm/plat/mpfs/clocks/hw_mss_clks.h index 90c2f4099..c38b65b26 100644 --- a/sm/plat/mpfs/clocks/hw_mss_clks.h +++ b/sm/plat/mpfs/clocks/hw_mss_clks.h @@ -1,73 +1,70 @@ /******************************************************************************* * Copyright 2019-2020 Microchip FPGA Embedded Systems Solutions. - * + * * SPDX-License-Identifier: MIT - * + * * @file hw_mss_clks.h * @author Microchip-FPGA Embedded Systems Solutions - * + * * Generated using Libero version: 1.0 * Libero design name: ICICLE_MSS * MPFS part number used in design: MPFS250T_ES * Date generated by Libero: 11-16-2020_19:07:30 * Format version of XML description: 0.3.8 * PolarFire SoC Configuration Generator version: 0.4.1 - * + * * Note 1: This file should not be edited. If you need to modify a parameter, * without going through the Libero flow or editing the associated xml file, * the following method is recommended: * 1. edit the file platform//config//software//mpfs_hal//mss_sw_config.h - * 2. define the value you want to override there. (Note: There is a + * 2. define the value you want to override there. (Note: There is a * commented example in mss_sw_config.h) - * Note 2: The definition in mss_sw_config.h takes precedence, as - * mss_sw_config.h is included prior to the hw_mss_clks.h in the hal + * Note 2: The definition in mss_sw_config.h takes precedence, as + * mss_sw_config.h is included prior to the hw_mss_clks.h in the hal * (see platform//mpfs_hal//mss_hal.h) * - */ + */ #ifndef HW_MSS_CLKS_H_ #define HW_MSS_CLKS_H_ - #ifdef __cplusplus -extern "C" { +extern "C" { #endif -#if !defined (LIBERO_SETTING_MSS_EXT_SGMII_REF_CLK) -/*Ref Clock rate in MHz */ -#define LIBERO_SETTING_MSS_EXT_SGMII_REF_CLK 125000000 - /* MSS_EXT_SGMII_REF_CLK [0:32] RW value= 125000000 */ +#if !defined(LIBERO_SETTING_MSS_EXT_SGMII_REF_CLK) +/*Ref Clock rate in MHz */ +#define LIBERO_SETTING_MSS_EXT_SGMII_REF_CLK 125000000 +/* MSS_EXT_SGMII_REF_CLK [0:32] RW value= 125000000 */ #endif -#if !defined (LIBERO_SETTING_MSS_COREPLEX_CPU_CLK) -/*CPU Clock rate in MHz */ -#define LIBERO_SETTING_MSS_COREPLEX_CPU_CLK 600000000 - /* MSS_COREPLEX_CPU_CLK [0:32] RW value= 600000000 */ +#if !defined(LIBERO_SETTING_MSS_COREPLEX_CPU_CLK) +/*CPU Clock rate in MHz */ +#define LIBERO_SETTING_MSS_COREPLEX_CPU_CLK 600000000 +/* MSS_COREPLEX_CPU_CLK [0:32] RW value= 600000000 */ #endif -#if !defined (LIBERO_SETTING_MSS_SYSTEM_CLK) -/*System Clock rate in MHz static power. */ -#define LIBERO_SETTING_MSS_SYSTEM_CLK 600000000 - /* MSS_SYSTEM_CLK [0:32] RW value= 600000000 */ +#if !defined(LIBERO_SETTING_MSS_SYSTEM_CLK) +/*System Clock rate in MHz static power. */ +#define LIBERO_SETTING_MSS_SYSTEM_CLK 600000000 +/* MSS_SYSTEM_CLK [0:32] RW value= 600000000 */ #endif -#if !defined (LIBERO_SETTING_MSS_RTC_TOGGLE_CLK) -/*RTC toggle Clock rate in MHz static power. */ -#define LIBERO_SETTING_MSS_RTC_TOGGLE_CLK 1000000 - /* MSS_RTC_TOGGLE_CLK [0:32] RW value= 1000000 */ +#if !defined(LIBERO_SETTING_MSS_RTC_TOGGLE_CLK) +/*RTC toggle Clock rate in MHz static power. */ +#define LIBERO_SETTING_MSS_RTC_TOGGLE_CLK 1000000 +/* MSS_RTC_TOGGLE_CLK [0:32] RW value= 1000000 */ #endif -#if !defined (LIBERO_SETTING_MSS_AXI_CLK) -/*AXI Clock rate in MHz static power. */ -#define LIBERO_SETTING_MSS_AXI_CLK 300000000 - /* MSS_AXI_CLK [0:32] RW value= 300000000 */ +#if !defined(LIBERO_SETTING_MSS_AXI_CLK) +/*AXI Clock rate in MHz static power. */ +#define LIBERO_SETTING_MSS_AXI_CLK 300000000 +/* MSS_AXI_CLK [0:32] RW value= 300000000 */ #endif -#if !defined (LIBERO_SETTING_MSS_APB_AHB_CLK) -/*AXI Clock rate in MHz static power. */ -#define LIBERO_SETTING_MSS_APB_AHB_CLK 150000000 - /* MSS_APB_AHB_CLK [0:32] RW value= 150000000 */ +#if !defined(LIBERO_SETTING_MSS_APB_AHB_CLK) +/*AXI Clock rate in MHz static power. */ +#define LIBERO_SETTING_MSS_APB_AHB_CLK 150000000 +/* MSS_APB_AHB_CLK [0:32] RW value= 150000000 */ #endif #ifdef __cplusplus } #endif - #endif /* #ifdef HW_MSS_CLKS_H_ */ - diff --git a/sm/plat/mpfs/config.h b/sm/plat/mpfs/config.h index b5623a072..babd66899 100644 --- a/sm/plat/mpfs/config.h +++ b/sm/plat/mpfs/config.h @@ -10,5 +10,5 @@ #define mHSS_DEBUG_PRINTF(...) #define CRLF "\r\n" -#define CR "\r" -#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) +#define CR "\r" +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/sm/plat/mpfs/csr_helper.c b/sm/plat/mpfs/csr_helper.c index c77105d85..44f451959 100644 --- a/sm/plat/mpfs/csr_helper.c +++ b/sm/plat/mpfs/csr_helper.c @@ -12,27 +12,27 @@ * \brief CSR Helper */ -#include "config.h" #include "csr_helper.h" -#include "mpfs_reg_map.h" - #include -HSSTicks_t CSR_GetTickCount(void) -{ - HSSTicks_t tickCount; +#include "config.h" +#include "mpfs_reg_map.h" + +HSSTicks_t +CSR_GetTickCount(void) { + HSSTicks_t tickCount; - tickCount = mHSS_CSR_READ(mcycle); + tickCount = mHSS_CSR_READ(mcycle); - return tickCount; + return tickCount; } -HSSTicks_t CSR_GetTime(void) -{ - HSSTicks_t time; +HSSTicks_t +CSR_GetTime(void) { + HSSTicks_t time; - time = mHSS_ReadRegU64(CLINT, MTIME); + time = mHSS_ReadRegU64(CLINT, MTIME); - return time; + return time; } diff --git a/sm/plat/mpfs/csr_helper.h b/sm/plat/mpfs/csr_helper.h index 25bd8ad57..940e139ea 100644 --- a/sm/plat/mpfs/csr_helper.h +++ b/sm/plat/mpfs/csr_helper.h @@ -38,29 +38,30 @@ extern "C" { #endif +#include #include "config.h" -#include typedef uint64_t HSSTicks_t; #if IS_ENABLED(CONFIG_OPENSBI) -# include "sbi/riscv_asm.h" -# include "sbi/sbi_bitops.h" -# include "sbi/sbi_hart.h" -# include "sbi/sbi_init.h" -# include "sbi/sbi_scratch.h" -# define mHSS_CSR_READ csr_read -# define mHSS_CSR_WRITE csr_write +#include "sbi/riscv_asm.h" +#include "sbi/sbi_bitops.h" +#include "sbi/sbi_hart.h" +#include "sbi/sbi_init.h" +#include "sbi/sbi_scratch.h" +#define mHSS_CSR_READ csr_read +#define mHSS_CSR_WRITE csr_write #else -# include "encoding.h" -# define mHSS_CSR_READ read_csr -# define mHSS_CSR_WRITE write_csr +#include "encoding.h" +#define mHSS_CSR_READ read_csr +#define mHSS_CSR_WRITE write_csr #endif +HSSTicks_t +CSR_GetTickCount(void); -HSSTicks_t CSR_GetTickCount(void); - -HSSTicks_t CSR_GetTime(void); +HSSTicks_t +CSR_GetTime(void); #ifdef __cplusplus } diff --git a/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services.c b/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services.c index 5f80c0f48..2011bb0e3 100644 --- a/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services.c +++ b/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services.c @@ -10,6 +10,7 @@ * SVN $Date$ */ #include "mss_sys_services.h" + #include "mss_sys_services_regs.h" // #include "mpfs_hal/mss_hal.h" // #include "mss_assert.h" @@ -23,27 +24,27 @@ extern "C" { /******************************************************************************* * Null buffer constant definition */ -#define NULL_BUFFER (( uint8_t* ) 0) - -/*-------------------------------------------------------------------------*//** - System service response offset - ============================ - The following constants are used to specify the offset in the mailbox where - the service response is written by the system controller after service - execution. -*/ -#define MSS_SYS_COMMON_RET_OFFSET 0u -#define MSS_SYS_DIGITAL_SIG_RET_OFFSET 48u -#define MSS_SYS_SECURE_NVM_READ_RET_OFFSET 16u -#define MSS_SYS_PUF_EMULATION_RET_OFFSET 20u -#define MSS_SYS_DIGEST_CHECK_RET_OFFSET 4u -#define MSS_SYS_GENERATE_OTP_RET_OFFSET 20u +#define NULL_BUFFER ((uint8_t*)0) + +/*-------------------------------------------------------------------------*/ /** + System service response offset + ============================ + The following constants are used to specify the offset in the mailbox where + the service response is written by the system controller after service + execution. + */ +#define MSS_SYS_COMMON_RET_OFFSET 0u +#define MSS_SYS_DIGITAL_SIG_RET_OFFSET 48u +#define MSS_SYS_SECURE_NVM_READ_RET_OFFSET 16u +#define MSS_SYS_PUF_EMULATION_RET_OFFSET 20u +#define MSS_SYS_DIGEST_CHECK_RET_OFFSET 4u +#define MSS_SYS_GENERATE_OTP_RET_OFFSET 20u /******************************************************************************* * Global variables declarations */ volatile uint8_t g_message_received = 0u; -uint8_t g_service_mode = 0u; +uint8_t g_service_mode = 0u; uint8_t* gp_int_service_response; uint16_t g_int_service_response_size; @@ -59,1840 +60,1220 @@ mss_sys_service_handler_t mss_sys_interrupt_handler; /******************************************************************************* * Local function declarations. */ -static uint16_t execute_ss_polling_mode -( - uint8_t cmd_opcode, - uint8_t* cmd_data, - uint16_t cmd_data_size, - uint8_t* p_response, - uint16_t response_size, - uint16_t mb_offset, - uint16_t response_offset -); - -static uint16_t execute_ss_interrupt_mode -( - uint8_t cmd_opcode, - uint8_t* cmd_data, - uint16_t cmd_data_size, - uint8_t* p_response, - uint16_t response_size, - uint16_t mb_offset, - uint16_t response_offset -); - -static uint16_t request_system_service -( - uint8_t cmd_opcode, - uint8_t* cmd_data, - uint16_t cmd_data_size, - uint8_t* p_response, - uint16_t response_size, - uint16_t mb_offset, - uint16_t response_offset -); +static uint16_t +execute_ss_polling_mode( + uint8_t cmd_opcode, uint8_t* cmd_data, uint16_t cmd_data_size, + uint8_t* p_response, uint16_t response_size, uint16_t mb_offset, + uint16_t response_offset); + +static uint16_t +execute_ss_interrupt_mode( + uint8_t cmd_opcode, uint8_t* cmd_data, uint16_t cmd_data_size, + uint8_t* p_response, uint16_t response_size, uint16_t mb_offset, + uint16_t response_offset); + +static uint16_t +request_system_service( + uint8_t cmd_opcode, uint8_t* cmd_data, uint16_t cmd_data_size, + uint8_t* p_response, uint16_t response_size, uint16_t mb_offset, + uint16_t response_offset); /*----------------------------------------------------------------------------- Public Functions -----------------------------------------------------------------------------*/ -/***************************************************************************//** - * MSS_SYS_get_serial_number() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_get_serial_number() + * See "mss_sysservices.h" for details of how to use this function. + */ void -MSS_SYS_select_service_mode -( +MSS_SYS_select_service_mode( uint8_t sys_service_mode, - mss_sys_service_handler_t mss_sys_service_interrupt_handler -) -{ - g_service_mode = sys_service_mode; - mss_sys_interrupt_handler = mss_sys_service_interrupt_handler; + mss_sys_service_handler_t mss_sys_service_interrupt_handler) { + g_service_mode = sys_service_mode; + mss_sys_interrupt_handler = mss_sys_service_interrupt_handler; } - -/***************************************************************************//** - * MSS_SYS_get_serial_number() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_get_serial_number() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_get_serial_number -( - uint8_t * p_serial_number, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_SERIAL_NUMBER_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_serial_number, - (uint16_t)MSS_SYS_SERIAL_NUMBER_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_SERIAL_NUMBER_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_serial_number, - (uint16_t)MSS_SYS_SERIAL_NUMBER_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_get_serial_number(uint8_t* p_serial_number, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_SERIAL_NUMBER_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_serial_number, + (uint16_t)MSS_SYS_SERIAL_NUMBER_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_SERIAL_NUMBER_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_serial_number, + (uint16_t)MSS_SYS_SERIAL_NUMBER_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * SYS_get_user_code() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_get_user_code() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_get_user_code -( - uint8_t * p_user_code, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_USERCODE_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_user_code, - (uint16_t)MSS_SYS_USERCODE_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_USERCODE_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_user_code, - (uint16_t)MSS_SYS_USERCODE_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_get_user_code(uint8_t* p_user_code, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_USERCODE_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_user_code, + (uint16_t)MSS_SYS_USERCODE_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_USERCODE_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_user_code, + (uint16_t)MSS_SYS_USERCODE_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * SYS_get_design_info() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_get_design_info() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_get_design_info -( - uint8_t * p_design_info, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_DESIGN_INFO_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_design_info, - (uint16_t)MSS_SYS_DESIGN_INFO_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_DESIGN_INFO_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_design_info, - (uint16_t)MSS_SYS_DESIGN_INFO_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_get_design_info(uint8_t* p_design_info, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_DESIGN_INFO_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_design_info, + (uint16_t)MSS_SYS_DESIGN_INFO_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_DESIGN_INFO_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_design_info, + (uint16_t)MSS_SYS_DESIGN_INFO_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * SYS_get_device_certificate() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_get_device_certificate() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_get_device_certificate -( - uint8_t * p_device_certificate, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_DEVICE_CERTIFICATE_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_device_certificate, - (uint16_t)MSS_SYS_DEVICE_CERTIFICATE_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_DEVICE_CERTIFICATE_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_device_certificate, - (uint16_t)MSS_SYS_DEVICE_CERTIFICATE_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_get_device_certificate( + uint8_t* p_device_certificate, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_DEVICE_CERTIFICATE_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_device_certificate, + (uint16_t)MSS_SYS_DEVICE_CERTIFICATE_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_DEVICE_CERTIFICATE_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_device_certificate, + (uint16_t)MSS_SYS_DEVICE_CERTIFICATE_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * SYS_read_digest() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_read_digest() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_read_digest -( - uint8_t * p_digest, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_READ_DIGEST_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_digest, - (uint16_t)MSS_SYS_READ_DIGEST_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_READ_DIGEST_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_digest, - (uint16_t)MSS_SYS_READ_DIGEST_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_read_digest(uint8_t* p_digest, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_READ_DIGEST_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_digest, + (uint16_t)MSS_SYS_READ_DIGEST_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_READ_DIGEST_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_digest, + (uint16_t)MSS_SYS_READ_DIGEST_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * SYS_query_security() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_query_security() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_query_security -( - uint8_t * p_security_locks, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t idx=0; - uint8_t buf[36] = {0}; - - /*Actual QUERY_SECURITY_RESP_LEN is 9 but CoreSysService_PF IP needs number - of words instead of number of bytes to be written to or read from MailBox*/ - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_QUERY_SECURITY_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - buf, - (uint16_t)(MSS_SYS_QUERY_SECURITY_RESP_LEN + 3u), - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_QUERY_SECURITY_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - buf, - (uint16_t)(MSS_SYS_QUERY_SECURITY_RESP_LEN + 3u), - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - for (idx = 0u; idx < MSS_SYS_QUERY_SECURITY_RESP_LEN; idx++) - { - *(p_security_locks + idx) = buf[idx]; - } - - return status; +MSS_SYS_query_security(uint8_t* p_security_locks, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t idx = 0; + uint8_t buf[36] = {0}; + + /*Actual QUERY_SECURITY_RESP_LEN is 9 but CoreSysService_PF IP needs number + of words instead of number of bytes to be written to or read from MailBox*/ + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_QUERY_SECURITY_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, buf, + (uint16_t)(MSS_SYS_QUERY_SECURITY_RESP_LEN + 3u), mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_QUERY_SECURITY_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, buf, + (uint16_t)(MSS_SYS_QUERY_SECURITY_RESP_LEN + 3u), mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + + for (idx = 0u; idx < MSS_SYS_QUERY_SECURITY_RESP_LEN; idx++) { + *(p_security_locks + idx) = buf[idx]; + } + + return status; } -/***************************************************************************//** - * SYS_read_debug_info() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_read_debug_info() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_read_debug_info -( - uint8_t * p_debug_info, - uint16_t mb_offset -) -{ - - uint16_t status = MSS_SYS_PARAM_ERR; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_READ_DEBUG_INFO_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_debug_info, - (uint16_t)MSS_SYS_READ_DEBUG_INFO_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_READ_DEBUG_INFO_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_debug_info, - (uint16_t)MSS_SYS_READ_DEBUG_INFO_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_read_debug_info(uint8_t* p_debug_info, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_READ_DEBUG_INFO_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_debug_info, + (uint16_t)MSS_SYS_READ_DEBUG_INFO_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_READ_DEBUG_INFO_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_debug_info, + (uint16_t)MSS_SYS_READ_DEBUG_INFO_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/**************************************************************************//** - * SYS_read_envm_param() - * See "mss_sysservices.h" for details of how to use this function. - */ +/**************************************************************************/ /** + * SYS_read_envm_param() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_read_envm_parameter -( - uint8_t * p_envm_param, - uint16_t mb_offset -) -{ - - uint16_t status = MSS_SYS_PARAM_ERR; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_READ_ENVM_PARAM_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_envm_param, - (uint16_t)MSS_SYS_READ_ENVM_PARAM_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_READ_ENVM_PARAM_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_envm_param, - (uint16_t)MSS_SYS_READ_ENVM_PARAM_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_read_envm_parameter(uint8_t* p_envm_param, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_READ_ENVM_PARAM_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_envm_param, + (uint16_t)MSS_SYS_READ_ENVM_PARAM_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_READ_ENVM_PARAM_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_envm_param, + (uint16_t)MSS_SYS_READ_ENVM_PARAM_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * SYS_puf_emulation_service() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_puf_emulation_service() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_puf_emulation_service -( - uint8_t * p_challenge, - uint8_t op_type, - uint8_t* p_response, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[20] = {0x00}; - uint8_t index = 0u; - - /* Frame the data required for mailbox */ - mb_format[index] = op_type; - - for (index = 4u; index < 20u; index++) - { - mb_format[index] = p_challenge[index - 4u]; - } - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_PUF_EMULATION_SERVICE_REQUEST_CMD, - mb_format, - (uint16_t)MSS_SYS_PUF_EMULATION_SERVICE_CMD_LEN, - p_response, - (uint16_t)MSS_SYS_PUF_EMULATION_SERVICE_RESP_LEN, - mb_offset, - (uint16_t)MSS_SYS_PUF_EMULATION_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_PUF_EMULATION_SERVICE_REQUEST_CMD, - mb_format, - (uint16_t)MSS_SYS_PUF_EMULATION_SERVICE_CMD_LEN, - p_response, - (uint16_t)MSS_SYS_PUF_EMULATION_SERVICE_RESP_LEN, - mb_offset, - (uint16_t)MSS_SYS_PUF_EMULATION_RET_OFFSET); - } - - return status; +MSS_SYS_puf_emulation_service( + uint8_t* p_challenge, uint8_t op_type, uint8_t* p_response, + uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[20] = {0x00}; + uint8_t index = 0u; + + /* Frame the data required for mailbox */ + mb_format[index] = op_type; + + for (index = 4u; index < 20u; index++) { + mb_format[index] = p_challenge[index - 4u]; + } + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_PUF_EMULATION_SERVICE_REQUEST_CMD, mb_format, + (uint16_t)MSS_SYS_PUF_EMULATION_SERVICE_CMD_LEN, p_response, + (uint16_t)MSS_SYS_PUF_EMULATION_SERVICE_RESP_LEN, mb_offset, + (uint16_t)MSS_SYS_PUF_EMULATION_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_PUF_EMULATION_SERVICE_REQUEST_CMD, mb_format, + (uint16_t)MSS_SYS_PUF_EMULATION_SERVICE_CMD_LEN, p_response, + (uint16_t)MSS_SYS_PUF_EMULATION_SERVICE_RESP_LEN, mb_offset, + (uint16_t)MSS_SYS_PUF_EMULATION_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * SYS_digital_signature_service() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_digital_signature_service() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_digital_signature_service -( - uint8_t* p_hash, - uint8_t format, - uint8_t* p_response, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - - if (format == MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_REQUEST_CMD) - { - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode - ((uint8_t)MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_REQUEST_CMD, - p_hash, - (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN, - p_response, - (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_RESP_SIZE, - mb_offset, - (uint16_t)MSS_SYS_DIGITAL_SIG_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode - ((uint8_t)MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_REQUEST_CMD, - p_hash, - (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN, - p_response, - (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_RESP_SIZE, - mb_offset, - (uint16_t)MSS_SYS_DIGITAL_SIG_RET_OFFSET); - } - } - - else - { - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode - ((uint8_t)MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_REQUEST_CMD, - p_hash, - (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN, - p_response, - (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_RESP_SIZE, - mb_offset, - (uint16_t)MSS_SYS_DIGITAL_SIG_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode - ((uint8_t)MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_REQUEST_CMD, - p_hash, - (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN, - p_response, - (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_RESP_SIZE, - mb_offset, - (uint16_t)MSS_SYS_DIGITAL_SIG_RET_OFFSET); - } - } - - return status; +MSS_SYS_digital_signature_service( + uint8_t* p_hash, uint8_t format, uint8_t* p_response, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + + if (format == MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_REQUEST_CMD) { + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_REQUEST_CMD, p_hash, + (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN, p_response, + (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_RESP_SIZE, mb_offset, + (uint16_t)MSS_SYS_DIGITAL_SIG_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_REQUEST_CMD, p_hash, + (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN, p_response, + (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_RESP_SIZE, mb_offset, + (uint16_t)MSS_SYS_DIGITAL_SIG_RET_OFFSET); + } + } + + else { + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_REQUEST_CMD, p_hash, + (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN, p_response, + (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_RESP_SIZE, mb_offset, + (uint16_t)MSS_SYS_DIGITAL_SIG_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_REQUEST_CMD, p_hash, + (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN, p_response, + (uint16_t)MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_RESP_SIZE, mb_offset, + (uint16_t)MSS_SYS_DIGITAL_SIG_RET_OFFSET); + } + } + + return status; } -/***************************************************************************//** - * SYS_secure_nvm_write() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_secure_nvm_write() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_secure_nvm_write -( - uint8_t format, - uint8_t snvm_module, - uint8_t* p_data, - uint8_t* p_user_key, - uint16_t mb_offset -) -{ - uint8_t frame[256] = {0x00}; - uint8_t* p_frame = &frame[0]; - uint16_t index = 0; - uint16_t status = MSS_SYS_PARAM_ERR; - - ASSERT(!(NULL_BUFFER == p_data)); - ASSERT(!(NULL_BUFFER == p_user_key)); - ASSERT(!(snvm_module >= 221u)); - - *p_frame = snvm_module; /*SNVMADDR - SNVM module*/ - p_frame += 4; /* Next 3 bytes RESERVED - For alignment */ - - /* Copy user key and send the command/data to mailbox. */ - if ((format == MSS_SYS_SNVM_AUTHEN_TEXT_REQUEST_CMD) || - (format == MSS_SYS_SNVM_AUTHEN_CIPHERTEXT_REQUEST_CMD)) - { - /* Copy user data */ - for (index = 0u; index < (MSS_SYS_AUTHENTICATED_TEXT_DATA_LEN - - MSS_SYS_USER_SECRET_KEY_LEN); index++) - { - *p_frame = p_data[index]; - p_frame++; - } - - /* Copy user key */ - for (index = 0u; index < MSS_SYS_USER_SECRET_KEY_LEN; index++) - { - *p_frame = p_user_key[index]; - p_frame++; - } - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - format, - &frame[0], - (uint16_t)MSS_SYS_AUTHENTICATED_TEXT_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - format, - &frame[0], - (uint16_t)MSS_SYS_AUTHENTICATED_TEXT_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - } - else - { - /* Copy user data */ - for (index = 0u; index < (MSS_SYS_NON_AUTHENTICATED_TEXT_DATA_LEN - 4u); - index++) - { - *(p_frame+index) = p_data[index]; - } - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - format, - &frame[0], - (uint16_t)MSS_SYS_NON_AUTHENTICATED_TEXT_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - format, - &frame[0], - (uint16_t)MSS_SYS_NON_AUTHENTICATED_TEXT_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } +MSS_SYS_secure_nvm_write( + uint8_t format, uint8_t snvm_module, uint8_t* p_data, uint8_t* p_user_key, + uint16_t mb_offset) { + uint8_t frame[256] = {0x00}; + uint8_t* p_frame = &frame[0]; + uint16_t index = 0; + uint16_t status = MSS_SYS_PARAM_ERR; + + ASSERT(!(NULL_BUFFER == p_data)); + ASSERT(!(NULL_BUFFER == p_user_key)); + ASSERT(!(snvm_module >= 221u)); + + *p_frame = snvm_module; /*SNVMADDR - SNVM module*/ + p_frame += 4; /* Next 3 bytes RESERVED - For alignment */ + + /* Copy user key and send the command/data to mailbox. */ + if ((format == MSS_SYS_SNVM_AUTHEN_TEXT_REQUEST_CMD) || + (format == MSS_SYS_SNVM_AUTHEN_CIPHERTEXT_REQUEST_CMD)) { + /* Copy user data */ + for (index = 0u; index < (MSS_SYS_AUTHENTICATED_TEXT_DATA_LEN - + MSS_SYS_USER_SECRET_KEY_LEN); + index++) { + *p_frame = p_data[index]; + p_frame++; } - return status; + /* Copy user key */ + for (index = 0u; index < MSS_SYS_USER_SECRET_KEY_LEN; index++) { + *p_frame = p_user_key[index]; + p_frame++; + } + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + format, &frame[0], (uint16_t)MSS_SYS_AUTHENTICATED_TEXT_DATA_LEN, + NULL_BUFFER, MSS_SYS_NO_RESPONSE_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + format, &frame[0], (uint16_t)MSS_SYS_AUTHENTICATED_TEXT_DATA_LEN, + NULL_BUFFER, MSS_SYS_NO_RESPONSE_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + } else { + /* Copy user data */ + for (index = 0u; index < (MSS_SYS_NON_AUTHENTICATED_TEXT_DATA_LEN - 4u); + index++) { + *(p_frame + index) = p_data[index]; + } + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + format, &frame[0], (uint16_t)MSS_SYS_NON_AUTHENTICATED_TEXT_DATA_LEN, + NULL_BUFFER, MSS_SYS_NO_RESPONSE_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + format, &frame[0], (uint16_t)MSS_SYS_NON_AUTHENTICATED_TEXT_DATA_LEN, + NULL_BUFFER, MSS_SYS_NO_RESPONSE_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + } + + return status; } -/***************************************************************************//** - * SYS_secure_nvm_read() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_secure_nvm_read() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_secure_nvm_read -( - uint8_t snvm_module, - uint8_t* p_user_key, - uint8_t* p_admin, - uint8_t* p_data, - uint16_t data_len, - uint16_t mb_offset -) -{ - /* Frame the message. */ - uint8_t frame[16] = {0x00u}; - uint8_t* p_frame = &frame[0]; - uint16_t index = 0u; - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t response[256] = {0x00}; - - ASSERT(!(NULL_BUFFER == p_data)); - ASSERT(!(NULL_BUFFER == p_admin)); - ASSERT(!(snvm_module > 221u)); - - ASSERT((data_len == 236u) || (data_len == 252u)); - - *p_frame = snvm_module; /*SNVMADDR - SNVM module*/ - p_frame += 4u; /* RESERVED - For alignment */ - - /* Copy user key */ - if (236u == data_len) - { - for (index = 0u; index < 12u; index++) - { - ASSERT(p_user_key != NULL_BUFFER); - *p_frame = p_user_key[index]; - p_frame++; - } - } - else - { - p_frame += 12u; - } - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_SNVM_READ_REQUEST_CMD, - &frame[0], - (uint16_t)MSS_SYS_SECURE_NVM_READ_DATA_LEN, - response, - (data_len + 4u), - mb_offset, - (uint16_t)MSS_SYS_SECURE_NVM_READ_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_SNVM_READ_REQUEST_CMD, - &frame[0], - (uint16_t)MSS_SYS_SECURE_NVM_READ_DATA_LEN, - response, - (data_len + 4u), - mb_offset, - (uint16_t)MSS_SYS_SECURE_NVM_READ_RET_OFFSET); - } - - if (MSS_SYS_SUCCESS == status) - { - for (index = 0u; index < 4u; index++) - { - *(p_admin+index) = (uint32_t)response[index]; - } - - /* Copy data into user buffer. */ - for (index = 4u; index < (data_len + 4u); index++) - { - *(p_data + (index - 4u)) = response[index]; - } - } - else - { - ; - } - - return status; +MSS_SYS_secure_nvm_read( + uint8_t snvm_module, uint8_t* p_user_key, uint8_t* p_admin, uint8_t* p_data, + uint16_t data_len, uint16_t mb_offset) { + /* Frame the message. */ + uint8_t frame[16] = {0x00u}; + uint8_t* p_frame = &frame[0]; + uint16_t index = 0u; + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t response[256] = {0x00}; + + ASSERT(!(NULL_BUFFER == p_data)); + ASSERT(!(NULL_BUFFER == p_admin)); + ASSERT(!(snvm_module > 221u)); + + ASSERT((data_len == 236u) || (data_len == 252u)); + + *p_frame = snvm_module; /*SNVMADDR - SNVM module*/ + p_frame += 4u; /* RESERVED - For alignment */ + + /* Copy user key */ + if (236u == data_len) { + for (index = 0u; index < 12u; index++) { + ASSERT(p_user_key != NULL_BUFFER); + *p_frame = p_user_key[index]; + p_frame++; + } + } else { + p_frame += 12u; + } + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_SNVM_READ_REQUEST_CMD, &frame[0], + (uint16_t)MSS_SYS_SECURE_NVM_READ_DATA_LEN, response, (data_len + 4u), + mb_offset, (uint16_t)MSS_SYS_SECURE_NVM_READ_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_SNVM_READ_REQUEST_CMD, &frame[0], + (uint16_t)MSS_SYS_SECURE_NVM_READ_DATA_LEN, response, (data_len + 4u), + mb_offset, (uint16_t)MSS_SYS_SECURE_NVM_READ_RET_OFFSET); + } + + if (MSS_SYS_SUCCESS == status) { + for (index = 0u; index < 4u; index++) { + *(p_admin + index) = (uint32_t)response[index]; + } + + /* Copy data into user buffer. */ + for (index = 4u; index < (data_len + 4u); index++) { + *(p_data + (index - 4u)) = response[index]; + } + } else { + ; + } + + return status; } -/***************************************************************************//** - * SYS_nonce_service() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * SYS_nonce_service() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_nonce_service -( - uint8_t * p_nonce, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_NONCE_SERVICE_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_nonce, - (uint16_t)MSS_SYS_NONCE_SERVICE_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_NONCE_SERVICE_REQUEST_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - p_nonce, - (uint16_t)MSS_SYS_NONCE_SERVICE_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_nonce_service(uint8_t* p_nonce, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_NONCE_SERVICE_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_nonce, + (uint16_t)MSS_SYS_NONCE_SERVICE_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_NONCE_SERVICE_REQUEST_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, p_nonce, + (uint16_t)MSS_SYS_NONCE_SERVICE_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_execute_uic_script() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_execute_uic_script() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_execute_uic_script -( - uint8_t src_periph_type, - uint32_t periph_address, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t input_data[8]; - uint32_t l_periph_addr = periph_address; - - if (src_periph_type == MSS_SYS_UIC_SOURCE_PERIPH_SNVM) - { - l_periph_addr &= 0x000000FFu; /*only first 8 bits are valid*/ - } - else if ((src_periph_type == MSS_SYS_UIC_SOURCE_PERIPH_NONAUTHEN_SPIFLASH )|| - (src_periph_type == MSS_SYS_UIC_SOURCE_PERIPH_AUTHEN_SPIFLASH )) - { - l_periph_addr &= 0xFFFFFFFFu; /*only first 24 or 32 bits are valid*/ - } - else if (src_periph_type == MSS_SYS_UIC_SOURCE_PERIPH_UPROM) - { - l_periph_addr &= 0x000000FFu; /*only first 8 bits are valid*/ - l_periph_addr = (l_periph_addr << 14u); - } - else - { - return status; - } - - *(uint32_t*)input_data = l_periph_addr; - input_data[4] = src_periph_type; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_UIC_EXECUTE_SCRIPT_CMD, - &input_data[0], - (uint16_t)MSS_SYS_EXECUTE_UIC_SCRIPT_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_UIC_EXECUTE_SCRIPT_CMD, - &input_data[0], - (uint16_t)MSS_SYS_EXECUTE_UIC_SCRIPT_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - +MSS_SYS_execute_uic_script( + uint8_t src_periph_type, uint32_t periph_address, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t input_data[8]; + uint32_t l_periph_addr = periph_address; + + if (src_periph_type == MSS_SYS_UIC_SOURCE_PERIPH_SNVM) { + l_periph_addr &= 0x000000FFu; /*only first 8 bits are valid*/ + } else if ( + (src_periph_type == MSS_SYS_UIC_SOURCE_PERIPH_NONAUTHEN_SPIFLASH) || + (src_periph_type == MSS_SYS_UIC_SOURCE_PERIPH_AUTHEN_SPIFLASH)) { + l_periph_addr &= 0xFFFFFFFFu; /*only first 24 or 32 bits are valid*/ + } else if (src_periph_type == MSS_SYS_UIC_SOURCE_PERIPH_UPROM) { + l_periph_addr &= 0x000000FFu; /*only first 8 bits are valid*/ + l_periph_addr = (l_periph_addr << 14u); + } else { return status; + } + + *(uint32_t*)input_data = l_periph_addr; + input_data[4] = src_periph_type; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_UIC_EXECUTE_SCRIPT_CMD, &input_data[0], + (uint16_t)MSS_SYS_EXECUTE_UIC_SCRIPT_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_UIC_EXECUTE_SCRIPT_CMD, &input_data[0], + (uint16_t)MSS_SYS_EXECUTE_UIC_SCRIPT_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_authenticate_uic_bitstream() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_authenticate_uic_bitstream() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_authenticate_uic_bitstream -( - uint32_t spi_flash_address, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint32_t l_spi_flash_address = spi_flash_address; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_CMD, - (uint8_t* )&l_spi_flash_address, - (uint16_t)MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_CMD, - (uint8_t* )&l_spi_flash_address, - (uint16_t)MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_authenticate_uic_bitstream( + uint32_t spi_flash_address, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint32_t l_spi_flash_address = spi_flash_address; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_CMD, + (uint8_t*)&l_spi_flash_address, + (uint16_t)MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_CMD, + (uint8_t*)&l_spi_flash_address, + (uint16_t)MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_authenticate_bitstream() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_authenticate_bitstream() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_authenticate_bitstream -( - uint32_t spi_flash_address, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint32_t l_spi_flash_address = spi_flash_address; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_BITSTREAM_AUTHENTICATE_CMD, - (uint8_t* )&l_spi_flash_address, - (uint16_t)MSS_SYS_BITSTREAM_AUTHENTICATE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_BITSTREAM_AUTHENTICATE_CMD, - (uint8_t* )&l_spi_flash_address, - (uint16_t)MSS_SYS_BITSTREAM_AUTHENTICATE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_authenticate_bitstream(uint32_t spi_flash_address, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint32_t l_spi_flash_address = spi_flash_address; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_BITSTREAM_AUTHENTICATE_CMD, + (uint8_t*)&l_spi_flash_address, + (uint16_t)MSS_SYS_BITSTREAM_AUTHENTICATE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_BITSTREAM_AUTHENTICATE_CMD, + (uint8_t*)&l_spi_flash_address, + (uint16_t)MSS_SYS_BITSTREAM_AUTHENTICATE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_authenticate_iap_image() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_authenticate_iap_image() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_authenticate_iap_image -( - uint32_t spi_idx -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - - ASSERT(!(spi_idx == 1u)); - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_BITSTREAM_AUTHENTICATE_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - (uint16_t)spi_idx, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_BITSTREAM_AUTHENTICATE_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - (uint16_t)spi_idx, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_authenticate_iap_image(uint32_t spi_idx) { + uint16_t status = MSS_SYS_PARAM_ERR; + + ASSERT(!(spi_idx == 1u)); + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_BITSTREAM_AUTHENTICATE_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, NULL_BUFFER, MSS_SYS_NO_RESPONSE_LEN, + (uint16_t)spi_idx, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_BITSTREAM_AUTHENTICATE_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, NULL_BUFFER, MSS_SYS_NO_RESPONSE_LEN, + (uint16_t)spi_idx, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_digest_check() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_digest_check() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_digest_check -( - uint32_t options, - uint8_t* digesterr, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint32_t l_options = options; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_DIGEST_CHECK_CMD, - (uint8_t* )&l_options, - (uint16_t)MSS_SYS_DIGEST_CHECK_DATA_LEN, - digesterr, - (uint16_t)MSS_SYS_DIGEST_CHECK_SERVICE_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_DIGEST_CHECK_CMD, - (uint8_t* )&l_options, - (uint16_t)MSS_SYS_DIGEST_CHECK_DATA_LEN, - digesterr, - (uint16_t)MSS_SYS_DIGEST_CHECK_SERVICE_RESP_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_digest_check(uint32_t options, uint8_t* digesterr, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint32_t l_options = options; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_DIGEST_CHECK_CMD, (uint8_t*)&l_options, + (uint16_t)MSS_SYS_DIGEST_CHECK_DATA_LEN, digesterr, + (uint16_t)MSS_SYS_DIGEST_CHECK_SERVICE_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_DIGEST_CHECK_CMD, (uint8_t*)&l_options, + (uint16_t)MSS_SYS_DIGEST_CHECK_DATA_LEN, digesterr, + (uint16_t)MSS_SYS_DIGEST_CHECK_SERVICE_RESP_LEN, mb_offset, + MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_execute_iap() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_execute_iap() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_execute_iap -( - uint8_t iap_cmd, - uint32_t spiaddr -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint32_t l_spiaddr = spiaddr; - - if ((MSS_SYS_IAP_PROGRAM_BY_SPIIDX_CMD == iap_cmd) - || (MSS_SYS_IAP_VERIFY_BY_SPIIDX_CMD == iap_cmd)) - { - ASSERT(!(1u == spiaddr)); - } - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)iap_cmd, - (uint8_t*)&l_spiaddr, - MSS_SYS_IAP_SERVICE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - (uint16_t)spiaddr, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)iap_cmd, - (uint8_t*)&l_spiaddr, - MSS_SYS_IAP_SERVICE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - (uint16_t)spiaddr, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_execute_iap(uint8_t iap_cmd, uint32_t spiaddr) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint32_t l_spiaddr = spiaddr; + + if ((MSS_SYS_IAP_PROGRAM_BY_SPIIDX_CMD == iap_cmd) || + (MSS_SYS_IAP_VERIFY_BY_SPIIDX_CMD == iap_cmd)) { + ASSERT(!(1u == spiaddr)); + } + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)iap_cmd, (uint8_t*)&l_spiaddr, MSS_SYS_IAP_SERVICE_DATA_LEN, + NULL_BUFFER, MSS_SYS_NO_RESPONSE_LEN, (uint16_t)spiaddr, + MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)iap_cmd, (uint8_t*)&l_spiaddr, MSS_SYS_IAP_SERVICE_DATA_LEN, + NULL_BUFFER, MSS_SYS_NO_RESPONSE_LEN, (uint16_t)spiaddr, + MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_spi_copy() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_spi_copy() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_spi_copy -( - uint64_t mss_dest_addr, - uint32_t mss_spi_flash, - uint32_t n_bytes, - uint8_t options, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[17]; - - *(uint64_t *)mb_format = mss_dest_addr; - *(uint32_t *)(mb_format + 8u) = mss_spi_flash; - *(uint32_t *)(mb_format + 12u) = n_bytes; - mb_format[16] = options; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_SPI_COPY_CMD, - mb_format, - (uint16_t)MSS_SYS_SPI_COPY_MAILBOX_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_SPI_COPY_CMD, - mb_format, - (uint16_t)MSS_SYS_SPI_COPY_MAILBOX_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_spi_copy( + uint64_t mss_dest_addr, uint32_t mss_spi_flash, uint32_t n_bytes, + uint8_t options, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[17]; + + *(uint64_t*)mb_format = mss_dest_addr; + *(uint32_t*)(mb_format + 8u) = mss_spi_flash; + *(uint32_t*)(mb_format + 12u) = n_bytes; + mb_format[16] = options; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_SPI_COPY_CMD, mb_format, + (uint16_t)MSS_SYS_SPI_COPY_MAILBOX_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_SPI_COPY_CMD, mb_format, + (uint16_t)MSS_SYS_SPI_COPY_MAILBOX_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_debug_read_probe() - * See "mss_sysservices.h" for details of how to use this function. - */ - uint16_t - MSS_SYS_debug_read_probe -( - uint8_t ipseg_addr, - uint8_t iprow_addr, - uint8_t *prdata, - uint16_t mb_offset, - uint8_t resp_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[2]; - uint16_t service_data = 0u; - uint8_t l_resp_offset = resp_offset; - - service_data = iprow_addr; - service_data = service_data << 6u; - - service_data = service_data + ipseg_addr; - - *(uint16_t*)mb_format = service_data; - - l_resp_offset = (4u + (4u * l_resp_offset)); - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_PROBE_READ_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_PROBE_READ_SERVICE_DATA_LEN, - prdata, - (uint16_t)MSS_SYS_PROBE_READ_SERVICE_RESP_LEN, - mb_offset, - (uint16_t)l_resp_offset); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_PROBE_READ_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_PROBE_READ_SERVICE_DATA_LEN, - prdata, - (uint16_t)MSS_SYS_PROBE_READ_SERVICE_RESP_LEN, - mb_offset, - (uint16_t)l_resp_offset); - } - - return status; - } - -/***************************************************************************//** - * MSS_SYS_debug_write_probe() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_debug_read_probe() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_debug_write_probe -( - uint8_t prb_addr, - uint8_t ipseg_addr, - uint8_t iprow_addr, - uint32_t pwmask, - uint32_t pwdata, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[12] = {0}; - - /* Local variable to store the combination of iprow_addr, ipseg_addr and - * prb_addr*/ - uint32_t service_data = 0u; - - service_data = iprow_addr; - service_data = service_data << 12u; - - uint16_t temp = ipseg_addr; - temp = temp << 6u; - temp += prb_addr; - - service_data = service_data + temp; - - *(uint32_t *)mb_format = service_data; - *(uint32_t *)(mb_format + 4u) = pwmask; - *(uint32_t *)(mb_format + 8u) = pwdata; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_PROBE_WRITE_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_PROBE_WRITE_SERVICE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_PROBE_WRITE_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_PROBE_WRITE_SERVICE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_debug_read_probe( + uint8_t ipseg_addr, uint8_t iprow_addr, uint8_t* prdata, uint16_t mb_offset, + uint8_t resp_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[2]; + uint16_t service_data = 0u; + uint8_t l_resp_offset = resp_offset; + + service_data = iprow_addr; + service_data = service_data << 6u; + + service_data = service_data + ipseg_addr; + + *(uint16_t*)mb_format = service_data; + + l_resp_offset = (4u + (4u * l_resp_offset)); + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_PROBE_READ_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_PROBE_READ_SERVICE_DATA_LEN, prdata, + (uint16_t)MSS_SYS_PROBE_READ_SERVICE_RESP_LEN, mb_offset, + (uint16_t)l_resp_offset); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_PROBE_READ_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_PROBE_READ_SERVICE_DATA_LEN, prdata, + (uint16_t)MSS_SYS_PROBE_READ_SERVICE_RESP_LEN, mb_offset, + (uint16_t)l_resp_offset); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_debug_live_probe() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_debug_write_probe() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_debug_live_probe -( - uint8_t x_addr, - uint8_t y_addr, - uint8_t ipseg_addr, - uint8_t iprow_addr, - uint8_t clear, - uint8_t ioen, - uint16_t mb_offset, - uint8_t service_cmd -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[6] = {0}; - uint32_t service_data = 0u; - - uint16_t channel_addr = 0u; - uint16_t probe_addr = 0u; - - channel_addr = y_addr; - channel_addr = (channel_addr << 5u) + x_addr; - - probe_addr = iprow_addr; - probe_addr = (probe_addr << 6u) + ipseg_addr; - - service_data = probe_addr; - service_data = (service_data << 11u) + channel_addr; - - *(uint32_t*)mb_format = service_data; - mb_format[4] = clear; - mb_format[5] = ioen; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - service_cmd, - mb_format, - (uint16_t)MSS_SYS_LIVE_PROBE_DEBUG_SERVICE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - service_cmd, - mb_format, - (uint16_t)MSS_SYS_LIVE_PROBE_DEBUG_SERVICE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_debug_write_probe( + uint8_t prb_addr, uint8_t ipseg_addr, uint8_t iprow_addr, uint32_t pwmask, + uint32_t pwdata, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[12] = {0}; + + /* Local variable to store the combination of iprow_addr, ipseg_addr and + * prb_addr*/ + uint32_t service_data = 0u; + + service_data = iprow_addr; + service_data = service_data << 12u; + + uint16_t temp = ipseg_addr; + temp = temp << 6u; + temp += prb_addr; + + service_data = service_data + temp; + + *(uint32_t*)mb_format = service_data; + *(uint32_t*)(mb_format + 4u) = pwmask; + *(uint32_t*)(mb_format + 8u) = pwdata; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_PROBE_WRITE_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_PROBE_WRITE_SERVICE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_PROBE_WRITE_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_PROBE_WRITE_SERVICE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_debug_select_mem() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_debug_live_probe() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_debug_select_mem -( - uint8_t ipblk_addr, - uint8_t ipseg_addr, - uint8_t iprow_addr, - uint8_t memtype, - uint8_t memlock_mode, - uint16_t timeout, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[6] = {0}; - uint16_t service_data = 0u; - - service_data = iprow_addr; - - uint16_t temp = ipseg_addr; - temp = ((temp << 3u) + ipblk_addr); - service_data = ((temp << 9u) + temp); - - *(uint16_t *)mb_format = service_data; - mb_format[2] = memtype; - mb_format[3] = memlock_mode; - *(uint16_t*)(mb_format + 4u) = timeout; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_MEM_SELECT_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_MEM_SELECT_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_MEM_SELECT_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_MEM_SELECT_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_debug_live_probe( + uint8_t x_addr, uint8_t y_addr, uint8_t ipseg_addr, uint8_t iprow_addr, + uint8_t clear, uint8_t ioen, uint16_t mb_offset, uint8_t service_cmd) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[6] = {0}; + uint32_t service_data = 0u; + + uint16_t channel_addr = 0u; + uint16_t probe_addr = 0u; + + channel_addr = y_addr; + channel_addr = (channel_addr << 5u) + x_addr; + + probe_addr = iprow_addr; + probe_addr = (probe_addr << 6u) + ipseg_addr; + + service_data = probe_addr; + service_data = (service_data << 11u) + channel_addr; + + *(uint32_t*)mb_format = service_data; + mb_format[4] = clear; + mb_format[5] = ioen; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + service_cmd, mb_format, + (uint16_t)MSS_SYS_LIVE_PROBE_DEBUG_SERVICE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + service_cmd, mb_format, + (uint16_t)MSS_SYS_LIVE_PROBE_DEBUG_SERVICE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } - -/***************************************************************************//** - * MSS_SYS_debug_read_mem() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_debug_select_mem() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_debug_read_mem -( - uint16_t mem_addr, - uint16_t n_words, - uint64_t mss_addr, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[16] = {0}; - - *(uint16_t*)(mb_format) = mem_addr; - *(uint16_t*)(mb_format + 2u) = n_words; - *(uint64_t*)(mb_format + 8u) = mss_addr; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_MEM_READ_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_MEM_READ_WRITE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_MEM_READ_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_MEM_READ_WRITE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; - } - +MSS_SYS_debug_select_mem( + uint8_t ipblk_addr, uint8_t ipseg_addr, uint8_t iprow_addr, uint8_t memtype, + uint8_t memlock_mode, uint16_t timeout, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[6] = {0}; + uint16_t service_data = 0u; + + service_data = iprow_addr; + + uint16_t temp = ipseg_addr; + temp = ((temp << 3u) + ipblk_addr); + service_data = ((temp << 9u) + temp); + + *(uint16_t*)mb_format = service_data; + mb_format[2] = memtype; + mb_format[3] = memlock_mode; + *(uint16_t*)(mb_format + 4u) = timeout; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_MEM_SELECT_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_MEM_SELECT_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_MEM_SELECT_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_MEM_SELECT_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; +} -/***************************************************************************//** - * MSS_SYS_debug_write_mem() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_debug_read_mem() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_debug_write_mem -( - uint16_t mem_addr, - uint16_t n_words, - uint64_t mss_addr, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[16] = {0}; - - *(uint16_t*)(mb_format) = mem_addr; - *(uint16_t*)(mb_format + 2u) = n_words; - *(uint64_t*)(mb_format + 8u) = mss_addr; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_MEM_WRITE_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_MEM_READ_WRITE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_MEM_WRITE_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_MEM_READ_WRITE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_debug_read_mem( + uint16_t mem_addr, uint16_t n_words, uint64_t mss_addr, + uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[16] = {0}; + + *(uint16_t*)(mb_format) = mem_addr; + *(uint16_t*)(mb_format + 2u) = n_words; + *(uint64_t*)(mb_format + 8u) = mss_addr; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_MEM_READ_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_MEM_READ_WRITE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_MEM_READ_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_MEM_READ_WRITE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_debug_read_apb() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_debug_write_mem() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_debug_read_apb -( - uint32_t apb_addr, - uint8_t apb_wsize, - uint16_t max_bytes, - uint64_t mss_addr, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[24] = {0}; - - *(uint32_t *)mb_format = apb_addr; - mb_format[5] = apb_wsize; - *(uint16_t *)(mb_format + 8u) = max_bytes; - *(uint64_t *)(mb_format + 16u) = mss_addr; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_APB_READ_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_APB_SERVICE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_APB_READ_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_APB_SERVICE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_debug_write_mem( + uint16_t mem_addr, uint16_t n_words, uint64_t mss_addr, + uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[16] = {0}; + + *(uint16_t*)(mb_format) = mem_addr; + *(uint16_t*)(mb_format + 2u) = n_words; + *(uint64_t*)(mb_format + 8u) = mss_addr; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_MEM_WRITE_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_MEM_READ_WRITE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_MEM_WRITE_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_MEM_READ_WRITE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_debug_write_apb() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_debug_read_apb() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_debug_write_apb -( - uint32_t apb_addr, - uint8_t apb_wsize, - uint16_t max_bytes, - uint64_t mss_addr, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[24] = {0}; - - *(uint32_t *)mb_format = apb_addr; - mb_format[5] = apb_wsize; - *(uint16_t *)(mb_format + 8u) = max_bytes; - *(uint64_t *)(mb_format + 16u) = mss_addr; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_APB_WRITE_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_APB_SERVICE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_APB_WRITE_DEBUG_CMD, - mb_format, - (uint16_t)MSS_SYS_APB_SERVICE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_debug_read_apb( + uint32_t apb_addr, uint8_t apb_wsize, uint16_t max_bytes, uint64_t mss_addr, + uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[24] = {0}; + + *(uint32_t*)mb_format = apb_addr; + mb_format[5] = apb_wsize; + *(uint16_t*)(mb_format + 8u) = max_bytes; + *(uint64_t*)(mb_format + 16u) = mss_addr; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_APB_READ_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_APB_SERVICE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_APB_READ_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_APB_SERVICE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_debug_fabric_snapshot() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_debug_write_apb() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_debug_fabric_snapshot -( - uint32_t port_addr, - uint8_t apb_fast_write, - uint16_t mb_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[5]={0}; - - *(uint32_t *)mb_format = port_addr; - mb_format[4] = apb_fast_write; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_DEBUG_SNAPSHOT_CMD, - mb_format, - (uint16_t)MSS_SYS_DEBUG_SNAPSHOT_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_DEBUG_SNAPSHOT_CMD, - mb_format, - (uint16_t)MSS_SYS_DEBUG_SNAPSHOT_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - MSS_SYS_COMMON_RET_OFFSET); - } - - return status; +MSS_SYS_debug_write_apb( + uint32_t apb_addr, uint8_t apb_wsize, uint16_t max_bytes, uint64_t mss_addr, + uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[24] = {0}; + + *(uint32_t*)mb_format = apb_addr; + mb_format[5] = apb_wsize; + *(uint16_t*)(mb_format + 8u) = max_bytes; + *(uint64_t*)(mb_format + 16u) = mss_addr; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_APB_WRITE_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_APB_SERVICE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_APB_WRITE_DEBUG_CMD, mb_format, + (uint16_t)MSS_SYS_APB_SERVICE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_otp_generate() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_debug_fabric_snapshot() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_otp_generate -( - uint8_t keymode, - uint8_t* n_user, - uint8_t* n_fpga, - uint16_t mb_offset, - uint16_t resp_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[20] = {0}; - uint8_t index = 0u; - - mb_format[index] = keymode; - - for (index = 0u; index < 16u; index++ ) - { - mb_format[index + 4u] = *(n_user + index); - } - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_GENERATE_OTP_CMD, - mb_format, - (uint16_t)MSS_SYS_GENERATE_OTP_DATA_LEN, - n_fpga, - (uint16_t)MSS_SYS_GENERATE_OTP_RESP_LEN, - mb_offset, - resp_offset); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_GENERATE_OTP_CMD, - mb_format, - (uint16_t)MSS_SYS_GENERATE_OTP_DATA_LEN, - n_fpga, - (uint16_t)MSS_SYS_GENERATE_OTP_RESP_LEN, - mb_offset, - resp_offset); - } - - return status; +MSS_SYS_debug_fabric_snapshot( + uint32_t port_addr, uint8_t apb_fast_write, uint16_t mb_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[5] = {0}; + + *(uint32_t*)mb_format = port_addr; + mb_format[4] = apb_fast_write; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_DEBUG_SNAPSHOT_CMD, mb_format, + (uint16_t)MSS_SYS_DEBUG_SNAPSHOT_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_DEBUG_SNAPSHOT_CMD, mb_format, + (uint16_t)MSS_SYS_DEBUG_SNAPSHOT_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, MSS_SYS_COMMON_RET_OFFSET); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_otp_match() - * See "mss_sysservices.h" for details of how to use this function. - */ -uint16_t MSS_SYS_otp_match -( - uint8_t * user_id, - uint8_t * validator, - uint8_t * otp, - uint16_t mb_offset, - uint16_t resp_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[80] = {0}; - uint8_t index = 0u; - - for (index = 0u; index < 80u; index++) - { - if (index < 16u) - { - mb_format[index] = user_id[index]; - } - if ((index > 15u) && (index < 48u)) - { - mb_format[index] = validator[index - 16u]; - } - if (index > 47u) - { - mb_format[index] = otp[index - 48u]; - } - } - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_MATCH_OTP_CMD, - mb_format, - (uint16_t)MSS_SYS_MATCH_OTP_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - resp_offset); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_MATCH_OTP_CMD, - mb_format, - (uint16_t)MSS_SYS_MATCH_OTP_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - resp_offset); - } - - return status; +/***************************************************************************/ /** + * MSS_SYS_otp_generate() + * See "mss_sysservices.h" for details of how to use this function. + */ +uint16_t +MSS_SYS_otp_generate( + uint8_t keymode, uint8_t* n_user, uint8_t* n_fpga, uint16_t mb_offset, + uint16_t resp_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[20] = {0}; + uint8_t index = 0u; + + mb_format[index] = keymode; + + for (index = 0u; index < 16u; index++) { + mb_format[index + 4u] = *(n_user + index); + } + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_GENERATE_OTP_CMD, mb_format, + (uint16_t)MSS_SYS_GENERATE_OTP_DATA_LEN, n_fpga, + (uint16_t)MSS_SYS_GENERATE_OTP_RESP_LEN, mb_offset, resp_offset); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_GENERATE_OTP_CMD, mb_format, + (uint16_t)MSS_SYS_GENERATE_OTP_DATA_LEN, n_fpga, + (uint16_t)MSS_SYS_GENERATE_OTP_RESP_LEN, mb_offset, resp_offset); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_unlock_debug_passcode() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_otp_match() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_unlock_debug_passcode -( - uint8_t* cmd_data, - uint16_t mb_offset, - uint16_t resp_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - //uint8_t mb_format[32] = {0}; - //uint8_t index = 0u; - - //for (index = 0u; index < 32u; index++) - //{ - // mb_format[index] = cmd_data[index]; - //} - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_UNLOCK_DEBUG_PASSCODE, - cmd_data, - (uint16_t)MSS_SYS_UNLOCK_DEBUG_PASSCODE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - resp_offset); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_UNLOCK_DEBUG_PASSCODE, - cmd_data, - (uint16_t)MSS_SYS_UNLOCK_DEBUG_PASSCODE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - resp_offset); - } - - return status; +MSS_SYS_otp_match( + uint8_t* user_id, uint8_t* validator, uint8_t* otp, uint16_t mb_offset, + uint16_t resp_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[80] = {0}; + uint8_t index = 0u; + + for (index = 0u; index < 80u; index++) { + if (index < 16u) { + mb_format[index] = user_id[index]; + } + if ((index > 15u) && (index < 48u)) { + mb_format[index] = validator[index - 16u]; + } + if (index > 47u) { + mb_format[index] = otp[index - 48u]; + } + } + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_MATCH_OTP_CMD, mb_format, + (uint16_t)MSS_SYS_MATCH_OTP_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, resp_offset); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_MATCH_OTP_CMD, mb_format, + (uint16_t)MSS_SYS_MATCH_OTP_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, resp_offset); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_one_way_passcode() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_unlock_debug_passcode() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_one_way_passcode -( - uint8_t* msg_id, - uint8_t* validator, - uint8_t keymode, - uint8_t* dsn, - uint8_t* hash, - uint8_t* plaintext_passcode, - uint8_t* hwm, - uint16_t mb_offset, - uint16_t resp_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - uint8_t mb_format[480] = {0}; - uint16_t index = 0; - for (index = 0u; index < 480u; index++) - { - if ( index < 16u) - { - mb_format[index] = msg_id[index]; - } - if ((index > 15u) && (index < 48u)) - { - mb_format[index] = validator[index - 16]; - } - if ( index == 51u) - { - mb_format[index] = keymode; - } - if ((index > 67u) && (index < 84u)) - { - mb_format[index] = dsn[index - 68]; - } - if ((index > 351u) && (index < 384u)) - { - mb_format[index] = hash[index - 352]; - } - if ((index > 383u) && (index < 416u)) - { - mb_format[index] = plaintext_passcode[index - 384]; - } - if ((index > 415u) && (index < 432u)) - { - mb_format[index] = hwm[index]; - } - } +MSS_SYS_unlock_debug_passcode( + uint8_t* cmd_data, uint16_t mb_offset, uint16_t resp_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + // uint8_t mb_format[32] = {0}; + // uint8_t index = 0u; + + // for (index = 0u; index < 32u; index++) + //{ + // mb_format[index] = cmd_data[index]; + // } + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_UNLOCK_DEBUG_PASSCODE, cmd_data, + (uint16_t)MSS_SYS_UNLOCK_DEBUG_PASSCODE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, resp_offset); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_UNLOCK_DEBUG_PASSCODE, cmd_data, + (uint16_t)MSS_SYS_UNLOCK_DEBUG_PASSCODE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, resp_offset); + } + + return status; +} - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_ONE_WAY_PASSCODE_CMD, - mb_format, - (uint16_t)MSS_SYS_ONE_WAY_PASSCODE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - resp_offset); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_ONE_WAY_PASSCODE_CMD, - mb_format, - (uint16_t)MSS_SYS_ONE_WAY_PASSCODE_DATA_LEN, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - resp_offset); - } +/***************************************************************************/ /** + * MSS_SYS_one_way_passcode() + * See "mss_sysservices.h" for details of how to use this function. + */ +uint16_t +MSS_SYS_one_way_passcode( + uint8_t* msg_id, uint8_t* validator, uint8_t keymode, uint8_t* dsn, + uint8_t* hash, uint8_t* plaintext_passcode, uint8_t* hwm, + uint16_t mb_offset, uint16_t resp_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + uint8_t mb_format[480] = {0}; + uint16_t index = 0; + for (index = 0u; index < 480u; index++) { + if (index < 16u) { + mb_format[index] = msg_id[index]; + } + if ((index > 15u) && (index < 48u)) { + mb_format[index] = validator[index - 16]; + } + if (index == 51u) { + mb_format[index] = keymode; + } + if ((index > 67u) && (index < 84u)) { + mb_format[index] = dsn[index - 68]; + } + if ((index > 351u) && (index < 384u)) { + mb_format[index] = hash[index - 352]; + } + if ((index > 383u) && (index < 416u)) { + mb_format[index] = plaintext_passcode[index - 384]; + } + if ((index > 415u) && (index < 432u)) { + mb_format[index] = hwm[index]; + } + } + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_ONE_WAY_PASSCODE_CMD, mb_format, + (uint16_t)MSS_SYS_ONE_WAY_PASSCODE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, resp_offset); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_ONE_WAY_PASSCODE_CMD, mb_format, + (uint16_t)MSS_SYS_ONE_WAY_PASSCODE_DATA_LEN, NULL_BUFFER, + MSS_SYS_NO_RESPONSE_LEN, mb_offset, resp_offset); + } + + return status; +} - return status; +/***************************************************************************/ /** + * MSS_SYS_debug_terminate() + * See "mss_sysservices.h" for details of how to use this function. + */ +uint16_t +MSS_SYS_debug_terminate(uint16_t mb_offset, uint16_t resp_offset) { + uint16_t status = MSS_SYS_PARAM_ERR; + + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + status = execute_ss_interrupt_mode( + (uint8_t)MSS_SYS_TERMINATE_DEBUG_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, NULL_BUFFER, MSS_SYS_NO_RESPONSE_LEN, + mb_offset, resp_offset); + } else { + status = execute_ss_polling_mode( + (uint8_t)MSS_SYS_TERMINATE_DEBUG_CMD, NULL_BUFFER, + MSS_SYS_WITHOUT_CMD_DATA, NULL_BUFFER, MSS_SYS_NO_RESPONSE_LEN, + mb_offset, resp_offset); + } + + return status; } -/***************************************************************************//** - * MSS_SYS_debug_terminate() - * See "mss_sysservices.h" for details of how to use this function. - */ +/***************************************************************************/ /** + * MSS_SYS_read_response() + * See "mss_sysservices.h" for details of how to use this function. + */ uint16_t -MSS_SYS_debug_terminate -( - uint16_t mb_offset, - uint16_t resp_offset -) -{ - uint16_t status = MSS_SYS_PARAM_ERR; - - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - status = execute_ss_interrupt_mode( - (uint8_t)MSS_SYS_TERMINATE_DEBUG_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - resp_offset); - } - else - { - status = execute_ss_polling_mode( - (uint8_t)MSS_SYS_TERMINATE_DEBUG_CMD, - NULL_BUFFER, - MSS_SYS_WITHOUT_CMD_DATA, - NULL_BUFFER, - MSS_SYS_NO_RESPONSE_LEN, - mb_offset, - resp_offset); - } +MSS_SYS_read_response(void) { + uint16_t response_limit = 0u; + uint32_t idx; + uint16_t status = MSS_SYS_PARAM_ERR; - return status; -} + if (g_message_interrupt_counter > 0u) { + g_message_interrupt_counter = 0u; -/***************************************************************************//** - * MSS_SYS_read_response() - * See "mss_sysservices.h" for details of how to use this function. - */ -uint16_t MSS_SYS_read_response -( - void -) -{ - uint16_t response_limit = 0u; - uint32_t idx; - uint16_t status = MSS_SYS_PARAM_ERR; - - if (g_message_interrupt_counter > 0u) - { - g_message_interrupt_counter = 0u; - - if (g_int_service_response_size > 0u) - { - response_limit = g_int_service_response_size + - g_int_service_response_offset; - - for (idx = g_int_service_response_offset; idx < response_limit; idx++) - { - gp_int_service_response[idx - g_int_service_response_offset] = - *((uint8_t *)MSS_SCBMAILBOX + idx); - } - } - - /* Read the status returned by System Controller*/ - status = ((MSS_SCBCTRL->SERVICES_SR & SCBCTRL_SERVICESSR_STATUS_MASK) >> - SCBCTRL_SERVICESSR_STATUS); + if (g_int_service_response_size > 0u) { + response_limit = + g_int_service_response_size + g_int_service_response_offset; + + for (idx = g_int_service_response_offset; idx < response_limit; idx++) { + gp_int_service_response[idx - g_int_service_response_offset] = + *((uint8_t*)MSS_SCBMAILBOX + idx); + } } - return status; + /* Read the status returned by System Controller*/ + status = + ((MSS_SCBCTRL->SERVICES_SR & SCBCTRL_SERVICESSR_STATUS_MASK) >> + SCBCTRL_SERVICESSR_STATUS); + } + + return status; } -/***************************************************************************//** - Internal functions. -*/ +/***************************************************************************/ /** + Internal functions. + */ /* * This function requests the system service to the system controller. It will @@ -1900,124 +1281,102 @@ uint16_t MSS_SYS_read_response * required for that service. * */ -static uint16_t request_system_service -( - uint8_t cmd_opcode, - uint8_t* cmd_data, - uint16_t cmd_data_size, - uint8_t* p_response, - uint16_t response_size, - uint16_t mb_offset, +static uint16_t +request_system_service( + uint8_t cmd_opcode, uint8_t* cmd_data, uint16_t cmd_data_size, + uint8_t* p_response, uint16_t response_size, uint16_t mb_offset, uint16_t response_offset -) -{ - uint32_t idx; - uint16_t ss_command = 0u; - uint32_t* word_buf ; - uint8_t* byte_buf ; - uint8_t byte_off; - uint8_t byte_index; - uint32_t * mailbox_reg; - uint32_t mailbox_val = 0u; - - if (MSS_SCBCTRL->SERVICES_SR & SCBCTRL_SERVICESSR_BUSY_MASK) - { - /*System controller is busy with executing service*/ - return MSS_SYS_BUSY; - } - - /*Code for MSS_SYS_PARAM_ERR is not implemented with this version of driver.*/ - - *MSS_SCBMESSAGE_INT = 0x0u; /*clear message_int reg*/ - - if (g_service_mode == MSS_SYS_SERVICE_INTERRUPT_MODE) - { - gp_int_service_response = (uint8_t*)p_response; - g_int_service_response_offset = response_offset; - g_int_service_response_size = response_size; - } - - if (cmd_data_size > 0u) - { - word_buf = (uint32_t*)cmd_data; - - /* Write the user data into mail box. */ - for (idx = 0u; idx < (cmd_data_size / 4u); idx++) - { - *(MSS_SCBMAILBOX + idx) = word_buf[idx]; - } - - if ((cmd_data_size % 4u) > 0u) - { - byte_off = (((cmd_data_size / 4u) * 4u)); - byte_buf = (uint8_t*)(cmd_data + byte_off); - - mailbox_reg = (MSS_SCBMAILBOX + idx); - mailbox_val = *mailbox_reg; - - for (byte_index = 0u; byte_index < (cmd_data_size % 4u); - byte_index++) - { - mailbox_val &= ~(0xffu << (byte_index * 8u)); - mailbox_val |= (byte_buf[byte_index] << (byte_index * 8u)); - } - *mailbox_reg = mailbox_val; - } - } - - /*Form the SS command: bit 0to6 is the opcode, bit 7to15 is the Mailbox - offset For some services this field has another meaning. - (e.g. for IAP bit-stream auth. it means spi_idx)*/ - ss_command = ((mb_offset << 7u) | (cmd_opcode & 0x7Fu)); - - /*Interrupt based implementation of services */ - if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) - { - MSS_SCBCTRL->SERVICES_CR = (((ss_command << SCBCTRL_SERVICESCR_COMMAND) - & SCBCTRL_SERVICESCR_COMMAND_MASK) | - SCBCTRL_SERVICESCR_REQ_MASK | - SCBCTRL_SERVICESSR_NOTIFY_MASK); - } - else - { - MSS_SCBCTRL->SERVICES_CR = (((ss_command << SCBCTRL_SERVICESCR_COMMAND) - & SCBCTRL_SERVICESCR_COMMAND_MASK) | - SCBCTRL_SERVICESCR_REQ_MASK); - - } - - /*Service requested successfully*/ - return MSS_SYS_SUCCESS; +) { + uint32_t idx; + uint16_t ss_command = 0u; + uint32_t* word_buf; + uint8_t* byte_buf; + uint8_t byte_off; + uint8_t byte_index; + uint32_t* mailbox_reg; + uint32_t mailbox_val = 0u; + + if (MSS_SCBCTRL->SERVICES_SR & SCBCTRL_SERVICESSR_BUSY_MASK) { + /*System controller is busy with executing service*/ + return MSS_SYS_BUSY; + } + + /*Code for MSS_SYS_PARAM_ERR is not implemented with this version of driver.*/ + + *MSS_SCBMESSAGE_INT = 0x0u; /*clear message_int reg*/ + + if (g_service_mode == MSS_SYS_SERVICE_INTERRUPT_MODE) { + gp_int_service_response = (uint8_t*)p_response; + g_int_service_response_offset = response_offset; + g_int_service_response_size = response_size; + } + + if (cmd_data_size > 0u) { + word_buf = (uint32_t*)cmd_data; + + /* Write the user data into mail box. */ + for (idx = 0u; idx < (cmd_data_size / 4u); idx++) { + *(MSS_SCBMAILBOX + idx) = word_buf[idx]; + } + + if ((cmd_data_size % 4u) > 0u) { + byte_off = (((cmd_data_size / 4u) * 4u)); + byte_buf = (uint8_t*)(cmd_data + byte_off); + + mailbox_reg = (MSS_SCBMAILBOX + idx); + mailbox_val = *mailbox_reg; + + for (byte_index = 0u; byte_index < (cmd_data_size % 4u); byte_index++) { + mailbox_val &= ~(0xffu << (byte_index * 8u)); + mailbox_val |= (byte_buf[byte_index] << (byte_index * 8u)); + } + *mailbox_reg = mailbox_val; + } + } + + /*Form the SS command: bit 0to6 is the opcode, bit 7to15 is the Mailbox + offset For some services this field has another meaning. + (e.g. for IAP bit-stream auth. it means spi_idx)*/ + ss_command = ((mb_offset << 7u) | (cmd_opcode & 0x7Fu)); + + /*Interrupt based implementation of services */ + if (MSS_SYS_SERVICE_INTERRUPT_MODE == g_service_mode) { + MSS_SCBCTRL->SERVICES_CR = + (((ss_command << SCBCTRL_SERVICESCR_COMMAND) & + SCBCTRL_SERVICESCR_COMMAND_MASK) | + SCBCTRL_SERVICESCR_REQ_MASK | SCBCTRL_SERVICESSR_NOTIFY_MASK); + } else { + MSS_SCBCTRL->SERVICES_CR = + (((ss_command << SCBCTRL_SERVICESCR_COMMAND) & + SCBCTRL_SERVICESCR_COMMAND_MASK) | + SCBCTRL_SERVICESCR_REQ_MASK); + } + + /*Service requested successfully*/ + return MSS_SYS_SUCCESS; } /* - * This function executes the SS command in interrupt mode. If Mailbox input data - * is required by the service, the call to request_system_service() function will - * first load it from cmd_data into the Mailbox. The response of the service is - * not read by this function as it depends on message interrupt. Application - * will have to read the response of service by calling MSS_SYS_read_response(), - * only after interrupt occurs. + * This function executes the SS command in interrupt mode. If Mailbox input + * data is required by the service, the call to request_system_service() + * function will first load it from cmd_data into the Mailbox. The response of + * the service is not read by this function as it depends on message interrupt. + * Application will have to read the response of service by calling + * MSS_SYS_read_response(), only after interrupt occurs. */ -static uint16_t execute_ss_interrupt_mode -( - uint8_t cmd_opcode, - uint8_t* cmd_data, - uint16_t cmd_data_size, - uint8_t* p_response, - uint16_t response_size, - uint16_t mb_offset, - uint16_t response_offset -) -{ - - uint16_t status; - status = request_system_service(cmd_opcode, cmd_data, cmd_data_size, - p_response, response_size, mb_offset, - response_offset); - - return status; - } +static uint16_t +execute_ss_interrupt_mode( + uint8_t cmd_opcode, uint8_t* cmd_data, uint16_t cmd_data_size, + uint8_t* p_response, uint16_t response_size, uint16_t mb_offset, + uint16_t response_offset) { + uint16_t status; + status = request_system_service( + cmd_opcode, cmd_data, cmd_data_size, p_response, response_size, mb_offset, + response_offset); + + return status; +} /* * This function executes the SS command in polling mode. If Mailbox input data @@ -2026,92 +1385,75 @@ static uint16_t execute_ss_interrupt_mode * service requires the response data to be read from mailbox, it will read the * mailbox contents and store it in p_response buffer. */ -static uint16_t execute_ss_polling_mode -( - uint8_t cmd_opcode, - uint8_t* cmd_data, - uint16_t cmd_data_size, - uint8_t* p_response, - uint16_t response_size, - uint16_t mb_offset, - uint16_t response_offset -) -{ - uint32_t idx; - uint16_t status = 0u; - uint16_t response_limit = 0u; - uint8_t* response_buf; - - status = request_system_service(cmd_opcode, cmd_data, cmd_data_size, - p_response,response_size, mb_offset, - response_offset); - - if (status == MSS_SYS_SUCCESS) - { - /**REQ bit will remain set till the system controller starts - * processing command. Since DRI is slow interface, we are waiting - * here to make sure System controller has started processing - * command*/ - while (SCBCTRL_SERVICESCR_REQ_MASK == (MSS_SCBCTRL->SERVICES_CR & - SCBCTRL_SERVICESCR_REQ_MASK)) - { - ; - } - - /*Once system controller starts processing command The busy bit will - * go 1. Make sure that service is complete i.e. BUSY bit is gone 0*/ - while (SCBCTRL_SERVICESSR_BUSY_MASK == (MSS_SCBCTRL->SERVICES_SR & - SCBCTRL_SERVICESSR_BUSY_MASK)) - { - ; - } - - if (response_size > 0u) - { - response_limit = response_size + response_offset; - response_buf = (uint8_t*)p_response; - - for (idx = response_offset; idx < response_limit; idx++) - { - response_buf[idx - response_offset] = - *((uint8_t *)MSS_SCBMAILBOX + idx); - } - } - - /*Read the status returned by System Controller*/ - status = ((MSS_SCBCTRL->SERVICES_SR & SCBCTRL_SERVICESSR_STATUS_MASK) >> - SCBCTRL_SERVICESSR_STATUS); - } - else - { - status = MSS_SYS_BUSY; - } - - return status; +static uint16_t +execute_ss_polling_mode( + uint8_t cmd_opcode, uint8_t* cmd_data, uint16_t cmd_data_size, + uint8_t* p_response, uint16_t response_size, uint16_t mb_offset, + uint16_t response_offset) { + uint32_t idx; + uint16_t status = 0u; + uint16_t response_limit = 0u; + uint8_t* response_buf; + + status = request_system_service( + cmd_opcode, cmd_data, cmd_data_size, p_response, response_size, mb_offset, + response_offset); + + if (status == MSS_SYS_SUCCESS) { + /**REQ bit will remain set till the system controller starts + * processing command. Since DRI is slow interface, we are waiting + * here to make sure System controller has started processing + * command*/ + while (SCBCTRL_SERVICESCR_REQ_MASK == + (MSS_SCBCTRL->SERVICES_CR & SCBCTRL_SERVICESCR_REQ_MASK)) { + ; + } + + /*Once system controller starts processing command The busy bit will + * go 1. Make sure that service is complete i.e. BUSY bit is gone 0*/ + while (SCBCTRL_SERVICESSR_BUSY_MASK == + (MSS_SCBCTRL->SERVICES_SR & SCBCTRL_SERVICESSR_BUSY_MASK)) { + ; + } + + if (response_size > 0u) { + response_limit = response_size + response_offset; + response_buf = (uint8_t*)p_response; + + for (idx = response_offset; idx < response_limit; idx++) { + response_buf[idx - response_offset] = *((uint8_t*)MSS_SCBMAILBOX + idx); + } + } + + /*Read the status returned by System Controller*/ + status = + ((MSS_SCBCTRL->SERVICES_SR & SCBCTRL_SERVICESSR_STATUS_MASK) >> + SCBCTRL_SERVICESSR_STATUS); + } else { + status = MSS_SYS_BUSY; + } + + return status; } -/***************************************************************************//** - * Interrupt service routine triggered by message interrupt. - * This routine will call handler function which will read the service response - * in interrupt mode of operation. - */ +/***************************************************************************/ /** + * Interrupt service routine triggered by message interrupt. + * This routine will call handler function which will read the service response + * in interrupt mode of operation. + */ uint8_t -g5c_message_plic_IRQHandler -( - void -) -{ - g_message_interrupt_counter++; - - volatile uint32_t reg = *MSS_SCBMESSAGE; /*read message reg.*/ - reg = *MSS_SCBMESSAGE_INT; - *MSS_SCBMESSAGE_INT = 0x0u; /*clear message_int reg*/ - reg = *MSS_SCBMESSAGE_INT; - (void)reg; // reference to avoid compiler warning - - mss_sys_interrupt_handler(); - - return 0; +g5c_message_plic_IRQHandler(void) { + g_message_interrupt_counter++; + + volatile uint32_t reg = *MSS_SCBMESSAGE; /*read message reg.*/ + reg = *MSS_SCBMESSAGE_INT; + *MSS_SCBMESSAGE_INT = 0x0u; /*clear message_int reg*/ + reg = *MSS_SCBMESSAGE_INT; + (void)reg; // reference to avoid compiler warning + + mss_sys_interrupt_handler(); + + return 0; } #ifdef __cplusplus diff --git a/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services.h b/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services.h index b1e3f8d9b..2e36049c9 100644 --- a/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services.h +++ b/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services.h @@ -163,11 +163,11 @@ All the service execution functions return the 16-bit status returned by system controller on executing the given service. A zero value indicates the successful execution of that service. A non-zero value indicates an error code - representing the type of error that was encountered while executing the service. - Irrespective of the mode, if the controller is busy executing the previous - service the function will exit with the MSS_SYS_BUSY return value. The error - codes are different for each service. See individual function descriptions to - know the meaning of the error code for each service. + representing the type of error that was encountered while executing the + service. Irrespective of the mode, if the controller is busy executing the + previous service the function will exit with the MSS_SYS_BUSY return value. + The error codes are different for each service. See individual function + descriptions to know the meaning of the error code for each service. */ #ifndef MSS_SYS_SERVICES_H_ @@ -181,678 +181,681 @@ extern "C" { /*--------------------------------Public constants----------------------------*/ -/*-------------------------------------------------------------------------*//** - System services Generic constants - ============================ +/*-------------------------------------------------------------------------*/ /** + System services Generic constants + ============================ - These constants are used to communicate the outcome of a system services - request. These status codes are used across all types of services. The - following table lists the system service driver generic constants. + These constants are used to communicate the outcome of a system services + request. These status codes are used across all types of services. The + following table lists the system service driver generic constants. - MSS_SYS_SUCCESS - System service executed successfully. + MSS_SYS_SUCCESS + System service executed successfully. - MSS_SYS_BUSY - system controller is busy executing system service which was initiated using - its AMBA interface. + MSS_SYS_BUSY + system controller is busy executing system service which was initiated + using its AMBA interface. - MSS_SYS_PARAM_ERR - System service cannot be executed as one or more parameters are not as - expected by this driver. + MSS_SYS_PARAM_ERR + System service cannot be executed as one or more parameters are not as + expected by this driver. -*/ -#define MSS_SYS_SUCCESS 0u -#define MSS_SYS_BUSY 0xEFu -#define MSS_SYS_PARAM_ERR 0xFFu + */ +#define MSS_SYS_SUCCESS 0u +#define MSS_SYS_BUSY 0xEFu +#define MSS_SYS_PARAM_ERR 0xFFu -/*-------------------------------------------------------------------------*//** - System service execution mode macros - ============================ +/*-------------------------------------------------------------------------*/ /** + System service execution mode macros + ============================ - The following defines are used to select whether to execute services in - interrupt mode or polling mode. - */ + The following defines are used to select whether to execute services in + interrupt mode or polling mode. + */ /* Parameter used in MSS_SYS_service_mode() function * to execute the services in interrupt mode */ -#define MSS_SYS_SERVICE_INTERRUPT_MODE 1u +#define MSS_SYS_SERVICE_INTERRUPT_MODE 1u /* Parameter used in MSS_SYS_service_mode() function * to execute the services in polling mode */ -#define MSS_SYS_SERVICE_POLLING_MODE 0u - -/*-------------------------------------------------------------------------*//** - System service error codes - ============================ - - The following constants list the success/error code for each system service. -*/ - -/*-------------------------------------------------------------------------*//** - Device Certificate Service error codes - - MSS_SYS_DCF_DEVICE_MISMATCH - Public key or FSN do not match device - - MSS_SYS_DCF_INVALID_SIGNATURE - Certificate signature is invalid - - MSS_SYS_DCF_SYSTEM_ERROR - PUF or storage failure -*/ -#define MSS_SYS_DCF_DEVICE_MISMATCH 1u -#define MSS_SYS_DCF_INVALID_SIGNATURE 2u -#define MSS_SYS_DCF_SYSTEM_ERROR 3u - -/*------------------------------------------------------------------------*//** - Read ENVM parameters service error codes - - MSS_SYS_ENVM_DIGEST_ERROR - Page digest mismatches. Parameter values still returned - */ -#define MSS_SYS_ENVM_DIGEST_ERROR 1u - -/*-------------------------------------------------------------------------*//** - Execute UIC script and UIC bitstream authentication error codes - - EXECUTE_UIC_SPI_MAX_FRAME_ERR - Maximum number for Frames have been exceeded during SPI UIC execution - - EXECUTE_UIC_POLL_TIMEOUT - Timeout occurred during the Poll instruction. - - EXECUTE_UIC_SPI_AUTHEN_ERR - Authentication error occurred during UIC SPI Authenticated mode - - EXECUTE_UIC_SPI_DECRYPT_ERR - Decryption error occurred during UIC SPI Authenticated mode - - EXECUTE_UIC_SPI_NOTMASTER_ERR - SPI isn’t set as the master +#define MSS_SYS_SERVICE_POLLING_MODE 0u - EXECUTE_UIC_FABRIC_APB_ERR - A Fabric APB Error was detected during UIC execution +/*-------------------------------------------------------------------------*/ /** + System service error codes + ============================ - EXECUTE_UIC_SCB_ERR - A SCB Error was detected during UIC execution - - EXECUTE_UIC_PNVM_ENCRYPT_ERR - An Encrypted SNVM page was detected during UIC execution - - EXECUTE_UIC_ADDR_OUTOFRANGE_ERR - An illegal script address was detected during UIC execution - - EXECUTE_UIC_JUMP_MAX_ERR - The maximum number of Jump executions was exceeded. Current max is 1000. - - EXECUTE_UIC_UNEXPECTED_FORMAT_ERR - Fields within the instruction that were expected to be all 0 were not. - - EXECUTE_UIC_SCRIPT_TIMEOUT_ERR - UIC Script took longer than the specified UIC_SCRIPT_TIMEOUT - parameter (in seconds) - -*/ -#define MSS_SYS_EXECUTE_UIC_SUCCESS 0u -#define MSS_SYS_EXECUTE_UIC_SPI_MAX_FRAME_ERR 1u -#define MSS_SYS_EXECUTE_UIC_POLL_TIMEOUT 2u -#define MSS_SYS_EXECUTE_UIC_SPI_AUTHEN_ERR 3u -#define MSS_SYS_EXECUTE_UIC_SPI_DECRYPT_ERR 4u -#define MSS_SYS_EXECUTE_UIC_SPI_NOTMASTER_ERR 5u -#define MSS_SYS_EXECUTE_UIC_FABRIC_APB_ERR 6u -#define MSS_SYS_EXECUTE_UIC_SCB_ERR 7u -#define MSS_SYS_EXECUTE_UIC_PNVM_ENCRYPT_ERR 8u -#define MSS_SYS_EXECUTE_UIC_ADDR_OUTOFRANGE_ERR 9u -#define MSS_SYS_EXECUTE_UIC_JUMP_MAX_ERR 10u -#define MSS_SYS_EXECUTE_UIC_UNEXPECTED_FORMAT_ERR 11u -#define MSS_SYS_EXECUTE_UIC_SCRIPT_TIMEOUT_ERR 12u - -/*-------------------------------------------------------------------------*//** - bitstream authentication and IAP bitstream authentication error codes - - BSTREAM_AUTH_CHAINING_MISMATCH_ERR - Validator or hash chaining mismatch. Incorrectly constructed bitstream or - wrong key used. - - BSTREAM_AUTH_UNEXPECTED_DATA_ERR - Unexpected data received. - Additional data received after end of EOB component + The following constants list the success/error code for each system service. + */ - BSTREAM_AUTH_INVALID_ENCRY_KEY_ERR - Invalid/corrupt encryption key. - The requested key mode is disabled or the key could not be read/reconstructed +/*-------------------------------------------------------------------------*/ /** + Device Certificate Service error codes - BSTREAM_AUTH_INVALID_HEADER_ERR - Invalid component header + MSS_SYS_DCF_DEVICE_MISMATCH + Public key or FSN do not match device - BSTREAM_AUTH_BACK_LEVEL_NOT_SATISFIED_ERR - Back level not satisfied + MSS_SYS_DCF_INVALID_SIGNATURE + Certificate signature is invalid - BSTREAM_AUTH_ILLEGAL_BITSTREAM_MODE_ERR - Illegal bitstream mode. - Requested bitstream mode is disabled by user security + MSS_SYS_DCF_SYSTEM_ERROR + PUF or storage failure + */ +#define MSS_SYS_DCF_DEVICE_MISMATCH 1u +#define MSS_SYS_DCF_INVALID_SIGNATURE 2u +#define MSS_SYS_DCF_SYSTEM_ERROR 3u - BSTREAM_AUTH_DNS_BINDING_MISMATCH_ERR - DSN binding mismatch +/*------------------------------------------------------------------------*/ /** + Read ENVM parameters service error codes - BSTREAM_AUTH_ILLEGAL_COMPONENT_SEQUENCE_ERR - Illegal component sequence + MSS_SYS_ENVM_DIGEST_ERROR + Page digest mismatches. Parameter values still returned + */ +#define MSS_SYS_ENVM_DIGEST_ERROR 1u - BSTREAM_AUTH_INSUFF_DEVICE_CAPAB_ERR - Insufficient device capabilities +/*-------------------------------------------------------------------------*/ /** + Execute UIC script and UIC bitstream authentication error codes - BSTREAM_AUTH_INCORRECT_DEVICEID_ERR - Incorrect DEVICEID + EXECUTE_UIC_SPI_MAX_FRAME_ERR + Maximum number for Frames have been exceeded during SPI UIC execution - BSTREAM_AUTH_PROTOCOL_VERSION_ERR - Unsupported bitstream protocol version (regeneration required) + EXECUTE_UIC_POLL_TIMEOUT + Timeout occurred during the Poll instruction. - BSTREAM_AUTH_VERIFY_ERR - Verify not permitted on this bitstream + EXECUTE_UIC_SPI_AUTHEN_ERR + Authentication error occurred during UIC SPI Authenticated mode - BSTREAM_AUTH_INVALID_DEV_CERT_ERR - Invalid Device Certificate. - Device SCAC is invalid or not present + EXECUTE_UIC_SPI_DECRYPT_ERR + Decryption error occurred during UIC SPI Authenticated mode - BSTREAM_AUTH_INVALID_DIB_ERR - Invalid DIB + EXECUTE_UIC_SPI_NOTMASTER_ERR + SPI isn’t set as the master - BSTREAM_AUTH_SPI_NOT_MASTER_ERR - Device not in SPI Master Mode. - Error may occur only when bitstream is executed through IAP mode + EXECUTE_UIC_FABRIC_APB_ERR + A Fabric APB Error was detected during UIC execution - BSTREAM_AUTH_AUTOIAP_NO_VALID_IMAGE_ERR - No valid images found. - Error may occur when bitstream is executed through Auto Update mode. - Occurs when No valid image pointers are found. + EXECUTE_UIC_SCB_ERR + A SCB Error was detected during UIC execution - BSTREAM_AUTH_INDEXIAP_NO_VALID_IMAGE_ERR - No valid images found. - Error may occur when bitstream is executed through IAP mode via Index Mode. - Occurs when No valid image pointers are found. + EXECUTE_UIC_PNVM_ENCRYPT_ERR + An Encrypted SNVM page was detected during UIC execution - BSTREAM_AUTH_NEWER_DESIGN_VERSION_ERR - Programmed design version is newer than AutoUpdate image found. - Error may occur when bitstream is executed through Auto Update mode + EXECUTE_UIC_ADDR_OUTOFRANGE_ERR + An illegal script address was detected during UIC execution - BSTREAM_AUTH_INVALID_IMAGE_ERR - Selected image was invalid and no recovery was performed due to valid design - in device. - Error may occur only when bitstream is executed through Auto Update or IAP - mode (This error is here for completeness but only can be observed by - running the READ_DEBUG_INFO instruction and looking at IAP Error code field) + EXECUTE_UIC_JUMP_MAX_ERR + The maximum number of Jump executions was exceeded. Current max is 1000. - BSTREAM_AUTH_IMAGE_PROGRAM_FAILED_ERR - Selected and Recovery image failed to program. - Error may occur only when bitstream is executed through Auto Update or - IAP mode - (This error is here for completeness but only can be observed by running the - READ_DEBUG_INFO instruction and looking at IAP Error code field) + EXECUTE_UIC_UNEXPECTED_FORMAT_ERR + Fields within the instruction that were expected to be all 0 were not. - BSTREAM_AUTH_ABORT_ERR - Abort. - Non-bitstream instruction executed during bitstream loading. + EXECUTE_UIC_SCRIPT_TIMEOUT_ERR + UIC Script took longer than the specified UIC_SCRIPT_TIMEOUT + parameter (in seconds) - BSTREAM_AUTH_NVMVERIFY_ERR - Fabric/UFS verification failed (min or weak limit) + */ +#define MSS_SYS_EXECUTE_UIC_SUCCESS 0u +#define MSS_SYS_EXECUTE_UIC_SPI_MAX_FRAME_ERR 1u +#define MSS_SYS_EXECUTE_UIC_POLL_TIMEOUT 2u +#define MSS_SYS_EXECUTE_UIC_SPI_AUTHEN_ERR 3u +#define MSS_SYS_EXECUTE_UIC_SPI_DECRYPT_ERR 4u +#define MSS_SYS_EXECUTE_UIC_SPI_NOTMASTER_ERR 5u +#define MSS_SYS_EXECUTE_UIC_FABRIC_APB_ERR 6u +#define MSS_SYS_EXECUTE_UIC_SCB_ERR 7u +#define MSS_SYS_EXECUTE_UIC_PNVM_ENCRYPT_ERR 8u +#define MSS_SYS_EXECUTE_UIC_ADDR_OUTOFRANGE_ERR 9u +#define MSS_SYS_EXECUTE_UIC_JUMP_MAX_ERR 10u +#define MSS_SYS_EXECUTE_UIC_UNEXPECTED_FORMAT_ERR 11u +#define MSS_SYS_EXECUTE_UIC_SCRIPT_TIMEOUT_ERR 12u + +/*-------------------------------------------------------------------------*/ /** + bitstream authentication and IAP bitstream authentication error codes + + BSTREAM_AUTH_CHAINING_MISMATCH_ERR + Validator or hash chaining mismatch. Incorrectly constructed bitstream or + wrong key used. + + BSTREAM_AUTH_UNEXPECTED_DATA_ERR + Unexpected data received. + Additional data received after end of EOB component + + BSTREAM_AUTH_INVALID_ENCRY_KEY_ERR + Invalid/corrupt encryption key. + The requested key mode is disabled or the key could not be + read/reconstructed + + BSTREAM_AUTH_INVALID_HEADER_ERR + Invalid component header + + BSTREAM_AUTH_BACK_LEVEL_NOT_SATISFIED_ERR + Back level not satisfied + + BSTREAM_AUTH_ILLEGAL_BITSTREAM_MODE_ERR + Illegal bitstream mode. + Requested bitstream mode is disabled by user security + + BSTREAM_AUTH_DNS_BINDING_MISMATCH_ERR + DSN binding mismatch + + BSTREAM_AUTH_ILLEGAL_COMPONENT_SEQUENCE_ERR + Illegal component sequence + + BSTREAM_AUTH_INSUFF_DEVICE_CAPAB_ERR + Insufficient device capabilities + + BSTREAM_AUTH_INCORRECT_DEVICEID_ERR + Incorrect DEVICEID + + BSTREAM_AUTH_PROTOCOL_VERSION_ERR + Unsupported bitstream protocol version (regeneration required) + + BSTREAM_AUTH_VERIFY_ERR + Verify not permitted on this bitstream + + BSTREAM_AUTH_INVALID_DEV_CERT_ERR + Invalid Device Certificate. + Device SCAC is invalid or not present + + BSTREAM_AUTH_INVALID_DIB_ERR + Invalid DIB + + BSTREAM_AUTH_SPI_NOT_MASTER_ERR + Device not in SPI Master Mode. + Error may occur only when bitstream is executed through IAP mode + + BSTREAM_AUTH_AUTOIAP_NO_VALID_IMAGE_ERR + No valid images found. + Error may occur when bitstream is executed through Auto Update mode. + Occurs when No valid image pointers are found. + + BSTREAM_AUTH_INDEXIAP_NO_VALID_IMAGE_ERR + No valid images found. + Error may occur when bitstream is executed through IAP mode via Index Mode. + Occurs when No valid image pointers are found. + + BSTREAM_AUTH_NEWER_DESIGN_VERSION_ERR + Programmed design version is newer than AutoUpdate image found. + Error may occur when bitstream is executed through Auto Update mode + + BSTREAM_AUTH_INVALID_IMAGE_ERR + Selected image was invalid and no recovery was performed due to valid + design in device. Error may occur only when bitstream is executed through + Auto Update or IAP mode (This error is here for completeness but only can be + observed by running the READ_DEBUG_INFO instruction and looking at IAP Error + code field) + + BSTREAM_AUTH_IMAGE_PROGRAM_FAILED_ERR + Selected and Recovery image failed to program. + Error may occur only when bitstream is executed through Auto Update or + IAP mode + (This error is here for completeness but only can be observed by running + the READ_DEBUG_INFO instruction and looking at IAP Error code field) + + BSTREAM_AUTH_ABORT_ERR + Abort. + Non-bitstream instruction executed during bitstream loading. + + BSTREAM_AUTH_NVMVERIFY_ERR + Fabric/UFS verification failed (min or weak limit) - BSTREAM_AUTH_PROTECTED_ERR - Device security prevented modification of non-volatile memory + BSTREAM_AUTH_PROTECTED_ERR + Device security prevented modification of non-volatile memory - BSTREAM_AUTH_NOTENA - Programming mode not enabled + BSTREAM_AUTH_NOTENA + Programming mode not enabled - BSTREAM_AUTH_PNVMVERIFY - pNVM verify operation failed + BSTREAM_AUTH_PNVMVERIFY + pNVM verify operation failed - BSTREAM_AUTH_SYSTEM - System hardware error (PUF or DRBG) + BSTREAM_AUTH_SYSTEM + System hardware error (PUF or DRBG) - BSTREAM_AUTH_BADCOMPONENT - An internal error was detected in a component payload + BSTREAM_AUTH_BADCOMPONENT + An internal error was detected in a component payload - BSTREAM_AUTH_HVPROGERR - HV programming subsystem failure (pump failure) + BSTREAM_AUTH_HVPROGERR + HV programming subsystem failure (pump failure) - BSTREAM_AUTH_HVSTATE - HV programming subsystem in unexpected state (internal error) - */ -#define MSS_SYS_BSTREAM_AUTH_CHAINING_MISMATCH_ERR 1u -#define MSS_SYS_BSTREAM_AUTH_UNEXPECTED_DATA_ERR 2u -#define MSS_SYS_BSTREAM_AUTH_INVALID_ENCRY_KEY_ERR 3u -#define MSS_SYS_BSTREAM_AUTH_INVALID_HEADER_ERR 4u -#define MSS_SYS_BSTREAM_AUTH_BACK_LEVEL_NOT_SATISFIED_ERR 5u -#define MSS_SYS_BSTREAM_AUTH_ILLEGAL_BITSTREAM_MODE_ERR 6u -#define MSS_SYS_BSTREAM_AUTH_DNS_BINDING_MISMATCH_ERR 7u -#define MSS_SYS_BSTREAM_AUTH_ILLEGAL_COMPONENT_SEQUENCE_ERR 8u -#define MSS_SYS_BSTREAM_AUTH_INSUFF_DEVICE_CAPAB_ERR 9u -#define MSS_SYS_BSTREAM_AUTH_INCORRECT_DEVICEID_ERR 10u -#define MSS_SYS_BSTREAM_AUTH_PROTOCOL_VERSION_ERR 11u -#define MSS_SYS_BSTREAM_AUTH_VERIFY_ERR 12u -#define MSS_SYS_BSTREAM_AUTH_INVALID_DEV_CERT_ERR 13u -#define MSS_SYS_BSTREAM_AUTH_INVALID_DIB_ERR 14u -#define MSS_SYS_BSTREAM_AUTH_SPI_NOT_MASTER_ERR 21u -#define MSS_SYS_BSTREAM_AUTH_AUTOIAP_NO_VALID_IMAGE_ERR 22u -#define MSS_SYS_BSTREAM_AUTH_INDEXIAP_NO_VALID_IMAGE_ERR 23u -#define MSS_SYS_BSTREAM_AUTH_NEWER_DESIGN_VERSION_ERR 24u + BSTREAM_AUTH_HVSTATE + HV programming subsystem in unexpected state (internal error) + */ +#define MSS_SYS_BSTREAM_AUTH_CHAINING_MISMATCH_ERR 1u +#define MSS_SYS_BSTREAM_AUTH_UNEXPECTED_DATA_ERR 2u +#define MSS_SYS_BSTREAM_AUTH_INVALID_ENCRY_KEY_ERR 3u +#define MSS_SYS_BSTREAM_AUTH_INVALID_HEADER_ERR 4u +#define MSS_SYS_BSTREAM_AUTH_BACK_LEVEL_NOT_SATISFIED_ERR 5u +#define MSS_SYS_BSTREAM_AUTH_ILLEGAL_BITSTREAM_MODE_ERR 6u +#define MSS_SYS_BSTREAM_AUTH_DNS_BINDING_MISMATCH_ERR 7u +#define MSS_SYS_BSTREAM_AUTH_ILLEGAL_COMPONENT_SEQUENCE_ERR 8u +#define MSS_SYS_BSTREAM_AUTH_INSUFF_DEVICE_CAPAB_ERR 9u +#define MSS_SYS_BSTREAM_AUTH_INCORRECT_DEVICEID_ERR 10u +#define MSS_SYS_BSTREAM_AUTH_PROTOCOL_VERSION_ERR 11u +#define MSS_SYS_BSTREAM_AUTH_VERIFY_ERR 12u +#define MSS_SYS_BSTREAM_AUTH_INVALID_DEV_CERT_ERR 13u +#define MSS_SYS_BSTREAM_AUTH_INVALID_DIB_ERR 14u +#define MSS_SYS_BSTREAM_AUTH_SPI_NOT_MASTER_ERR 21u +#define MSS_SYS_BSTREAM_AUTH_AUTOIAP_NO_VALID_IMAGE_ERR 22u +#define MSS_SYS_BSTREAM_AUTH_INDEXIAP_NO_VALID_IMAGE_ERR 23u +#define MSS_SYS_BSTREAM_AUTH_NEWER_DESIGN_VERSION_ERR 24u /*25 Reserved*/ -#define MSS_SYS_BSTREAM_AUTH_INVALID_IMAGE_ERR 26u -#define MSS_SYS_BSTREAM_AUTH_IMAGE_PROGRAM_FAILED_ERR 27u -#define MSS_SYS_BSTREAM_AUTH_ABORT_ERR 127u -#define MSS_SYS_BSTREAM_AUTH_NVMVERIFY_ERR 128u -#define MSS_SYS_BSTREAM_AUTH_PROTECTED_ERR 129u -#define MSS_SYS_BSTREAM_AUTH_NOTENA 130u -#define MSS_SYS_BSTREAM_AUTH_PNVMVERIFY 131u -#define MSS_SYS_BSTREAM_AUTH_SYSTEM 132u -#define MSS_SYS_BSTREAM_AUTH_BADCOMPONENT 133u -#define MSS_SYS_BSTREAM_AUTH_HVPROGERR 134u -#define MSS_SYS_BSTREAM_AUTH_HVSTATE 135u - -/*-------------------------------------------------------------------------*//** - Digital Signature Service error code - - DIGITAL_SIGNATURE_FEK_FAILURE_ERROR - Error retrieving FEK - - DIGITAL_SIGNATURE_DRBG_ERROR - Failed to generate nonce - - DIGITAL_SIGNATURE_ECDSA_ERROR - ECDSA failed -*/ -#define MSS_SYS_DIGITAL_SIGNATURE_FEK_FAILURE_ERROR 0x01u -#define MSS_SYS_DIGITAL_SIGNATURE_DRBG_ERROR 0x02u -#define MSS_SYS_DIGITAL_SIGNATURE_ECDSA_ERROR 0x03u - -/*-------------------------------------------------------------------------*//** - Secure NVM write error codes - - SNVM_WRITE_INVALID_SNVMADDR - Illegal page address +#define MSS_SYS_BSTREAM_AUTH_INVALID_IMAGE_ERR 26u +#define MSS_SYS_BSTREAM_AUTH_IMAGE_PROGRAM_FAILED_ERR 27u +#define MSS_SYS_BSTREAM_AUTH_ABORT_ERR 127u +#define MSS_SYS_BSTREAM_AUTH_NVMVERIFY_ERR 128u +#define MSS_SYS_BSTREAM_AUTH_PROTECTED_ERR 129u +#define MSS_SYS_BSTREAM_AUTH_NOTENA 130u +#define MSS_SYS_BSTREAM_AUTH_PNVMVERIFY 131u +#define MSS_SYS_BSTREAM_AUTH_SYSTEM 132u +#define MSS_SYS_BSTREAM_AUTH_BADCOMPONENT 133u +#define MSS_SYS_BSTREAM_AUTH_HVPROGERR 134u +#define MSS_SYS_BSTREAM_AUTH_HVSTATE 135u + +/*-------------------------------------------------------------------------*/ /** + Digital Signature Service error code + + DIGITAL_SIGNATURE_FEK_FAILURE_ERROR + Error retrieving FEK + + DIGITAL_SIGNATURE_DRBG_ERROR + Failed to generate nonce + + DIGITAL_SIGNATURE_ECDSA_ERROR + ECDSA failed + */ +#define MSS_SYS_DIGITAL_SIGNATURE_FEK_FAILURE_ERROR 0x01u +#define MSS_SYS_DIGITAL_SIGNATURE_DRBG_ERROR 0x02u +#define MSS_SYS_DIGITAL_SIGNATURE_ECDSA_ERROR 0x03u - SNVM_WRITE_FAILURE - PNVM program/verify failed +/*-------------------------------------------------------------------------*/ /** + Secure NVM write error codes - SNVM_WRITE_SYSTEM_ERROR - PUF or storage failure + SNVM_WRITE_INVALID_SNVMADDR + Illegal page address - SNVM_WRITE_NOT_PERMITTED - Write is not permitted -*/ -#define MSS_SYS_SNVM_WRITE_INVALID_SNVMADDR 1u -#define MSS_SYS_SNVM_WRITE_FAILURE 2u -#define MSS_SYS_SNVM_WRITE_SYSTEM_ERROR 3u -#define MSS_SYS_SNVM_WRITE_NOT_PERMITTED 4u + SNVM_WRITE_FAILURE + PNVM program/verify failed -/*-------------------------------------------------------------------------*//** - Secure NVM read error codes + SNVM_WRITE_SYSTEM_ERROR + PUF or storage failure - SNVM_READ_INVALID_SNVMADDR - Illegal page address + SNVM_WRITE_NOT_PERMITTED + Write is not permitted + */ +#define MSS_SYS_SNVM_WRITE_INVALID_SNVMADDR 1u +#define MSS_SYS_SNVM_WRITE_FAILURE 2u +#define MSS_SYS_SNVM_WRITE_SYSTEM_ERROR 3u +#define MSS_SYS_SNVM_WRITE_NOT_PERMITTED 4u - SNVM_READ_AUTHENTICATION_FAILURE - Storage corrupt or incorrect USK +/*-------------------------------------------------------------------------*/ /** + Secure NVM read error codes - SNVM_READ_SYSTEM_ERROR - PUF or storage failure -*/ -#define MSS_SYS_SNVM_READ_INVALID_SNVMADDR 1u -#define MSS_SYS_SNVM_READ_AUTHENTICATION_FAILURE 2u -#define MSS_SYS_SNVM_READ_SYSTEM_ERROR 3u + SNVM_READ_INVALID_SNVMADDR + Illegal page address -/*-------------------------------------------------------------------------*//** - PUF emulation service error codes + SNVM_READ_AUTHENTICATION_FAILURE + Storage corrupt or incorrect USK - MSS_SYS_PUF_EMU_INTERNAL_ERR - Internal error + SNVM_READ_SYSTEM_ERROR + PUF or storage failure */ -#define MSS_SYS_PUF_EMU_INTERNAL_ERR 1u +#define MSS_SYS_SNVM_READ_INVALID_SNVMADDR 1u +#define MSS_SYS_SNVM_READ_AUTHENTICATION_FAILURE 2u +#define MSS_SYS_SNVM_READ_SYSTEM_ERROR 3u -/*-------------------------------------------------------------------------*//** - Nonce Service Error Codes +/*-------------------------------------------------------------------------*/ /** + PUF emulation service error codes - MSS_SYS_NONCE_PUK_FETCH_ERROR - Error fetching PUK + MSS_SYS_PUF_EMU_INTERNAL_ERR + Internal error + */ +#define MSS_SYS_PUF_EMU_INTERNAL_ERR 1u - MSS_SYS_NONCE_SEED_GEN_ERROR - Error generating seed -*/ -#define MSS_SYS_NONCE_PUK_FETCH_ERROR 1u -#define MSS_SYS_NONCE_SEED_GEN_ERROR 2u +/*-------------------------------------------------------------------------*/ /** + Nonce Service Error Codes -/*-------------------------------------------------------------------------*//** - Digest Check service error code + MSS_SYS_NONCE_PUK_FETCH_ERROR + Error fetching PUK - MSS_SYS_DIGEST_CHECK_DIGESTERR - Digest mismatch occurred -*/ -#define MSS_SYS_DIGEST_CHECK_DIGESTERR 1u + MSS_SYS_NONCE_SEED_GEN_ERROR + Error generating seed + */ +#define MSS_SYS_NONCE_PUK_FETCH_ERROR 1u +#define MSS_SYS_NONCE_SEED_GEN_ERROR 2u -/*-------------------------------------------------------------------------*//** - SPI COPY SERVICE error codes +/*-------------------------------------------------------------------------*/ /** + Digest Check service error code - MSS_SYS_SPI_MASTER_MODE_ERR - Device is not configured for master mode + MSS_SYS_DIGEST_CHECK_DIGESTERR + Digest mismatch occurred + */ +#define MSS_SYS_DIGEST_CHECK_DIGESTERR 1u - MSS_SYS_SPI_AXI_ERR - AXI error -*/ -#define MSS_SYS_SPI_MASTER_MODE_ERR 1u -#define MSS_SYS_SPI_AXI_ERR 2u +/*-------------------------------------------------------------------------*/ /** + SPI COPY SERVICE error codes -/*-------------------------------------------------------------------------*//** - Probe services error codes + MSS_SYS_SPI_MASTER_MODE_ERR + Device is not configured for master mode - MSS_SYS_PROBE_SECERR - The operation was blocked by device security. This will occur if the - permanent debug lock UP_DEBUG is set or the user software debug lock - SWL_DEBUG is active or the device is in the virgin state. No data is read - and PRDATA is invalid. + MSS_SYS_SPI_AXI_ERR + AXI error */ -#define MSS_SYS_PROBE_SECERR 1u - -/*-------------------------------------------------------------------------*//** - MEM Services error codes +#define MSS_SYS_SPI_MASTER_MODE_ERR 1u +#define MSS_SYS_SPI_AXI_ERR 2u - MSS_SYS_MEM_SECERR - The operation was blocked by device security. - This will occur if the permanent debug lock UP_DEBUG is set or the user - software debug lock SWL_DEBUG is active or the device is in the virgin state. +/*-------------------------------------------------------------------------*/ /** + Probe services error codes - MSS_SYS_MEM_TIMEOUTERR - Timeout occurred. - - MSS_SYS_MEM_LOCKERR - Target memory failed to lock -*/ -#define MSS_SYS_MEM_SECERR 1u -#define MSS_SYS_MEM_TIMEOUTERR 2u -#define MSS_SYS_MEM_LOCKERR 3u + MSS_SYS_PROBE_SECERR + The operation was blocked by device security. This will occur if the + permanent debug lock UP_DEBUG is set or the user software debug lock + SWL_DEBUG is active or the device is in the virgin state. No data is read + and PRDATA is invalid. + */ +#define MSS_SYS_PROBE_SECERR 1u -/*-------------------------------------------------------------------------*//** - APB services error codes +/*-------------------------------------------------------------------------*/ /** + MEM Services error codes - MSS_SYS_APB_SECERR - The operation was blocked by device security. - This will occur if the permanent debug lock UP_DEBUG is set or the user - software debug lock SWL_DEBUG is active or the device is in the virgin state. + MSS_SYS_MEM_SECERR + The operation was blocked by device security. + This will occur if the permanent debug lock UP_DEBUG is set or the user + software debug lock SWL_DEBUG is active or the device is in the virgin state. - MSS_SYS_APB_SLVERR - The addressed fabric APB peripheral generated a SLVERR response to the bus - transaction. + MSS_SYS_MEM_TIMEOUTERR + Timeout occurred. - MSS_SYS_APB_TIMEOUT - The addressed fabric APB peripheral failed to respond before the user-defined - APB timeout or the fabric power is not on. -*/ -#define MSS_SYS_APB_SECERR 1u -#define MSS_SYS_APB_SLVERR 2u -#define MSS_SYS_APB_TIMEOUT 3u + MSS_SYS_MEM_LOCKERR + Target memory failed to lock + */ +#define MSS_SYS_MEM_SECERR 1u +#define MSS_SYS_MEM_TIMEOUTERR 2u +#define MSS_SYS_MEM_LOCKERR 3u -/*-------------------------------------------------------------------------*//** - Debug snapshot service error codes +/*-------------------------------------------------------------------------*/ /** + APB services error codes - MSS_SYS_DEBUG_SNAPSHOT_SECERR + MSS_SYS_APB_SECERR The operation was blocked by device security. This will occur if the permanent debug lock UP_DEBUG is set or the user software debug lock SWL_DEBUG is active or the device is in the virgin state. - MSS_SYS_DEBUG_SNAPSHOT_BUSERR - A bus error occurred and the snapshot was aborted. This may occur if: - • the fabric power is off, or - • the fabric APB slave flagged an error, or - • the fabric APB slave was too slow to assert PREADY -*/ -#define MSS_SYS_DEBUG_SNAPSHOT_SECERR 1u -#define MSS_SYS_DEBUG_SNAPSHOT_BUSERR 2u + MSS_SYS_APB_SLVERR + The addressed fabric APB peripheral generated a SLVERR response to the bus + transaction. -/*-------------------------------------------------------------------------*//** - GENERATE OTP SERVICE + MSS_SYS_APB_TIMEOUT + The addressed fabric APB peripheral failed to respond before the user-defined + APB timeout or the fabric power is not on. + */ +#define MSS_SYS_APB_SECERR 1u +#define MSS_SYS_APB_SLVERR 2u +#define MSS_SYS_APB_TIMEOUT 3u + +/*-------------------------------------------------------------------------*/ /** + Debug snapshot service error codes + + MSS_SYS_DEBUG_SNAPSHOT_SECERR + The operation was blocked by device security. + This will occur if the permanent debug lock UP_DEBUG is set or the user + software debug lock SWL_DEBUG is active or the device is in the virgin + state. + + MSS_SYS_DEBUG_SNAPSHOT_BUSERR + A bus error occurred and the snapshot was aborted. This may occur if: + • the fabric power is off, or + • the fabric APB slave flagged an error, or + • the fabric APB slave was too slow to assert PREADY + */ +#define MSS_SYS_DEBUG_SNAPSHOT_SECERR 1u +#define MSS_SYS_DEBUG_SNAPSHOT_BUSERR 2u - MSS_SYS_SECERR - Operation is blocked by device security +/*-------------------------------------------------------------------------*/ /** + GENERATE OTP SERVICE - MSS_SYS_PROTOCOLERR - Invalid key provided -*/ -#define MSS_SYS_GENERATE_OTP_SECERR 1u -#define MSS_SYS_GENERATE_OTP_PROTOCOLERR 2u + MSS_SYS_SECERR + Operation is blocked by device security -/*-------------------------------------------------------------------------*//** - MATCH OTP SERVICE + MSS_SYS_PROTOCOLERR + Invalid key provided + */ +#define MSS_SYS_GENERATE_OTP_SECERR 1u +#define MSS_SYS_GENERATE_OTP_PROTOCOLERR 2u - MSS_SYS_PROTOCOLERR - Keymode not supported. +/*-------------------------------------------------------------------------*/ /** + MATCH OTP SERVICE - MSS_SYS_MATCH_OTP_MISMATCHERR - Calculated validator mismatch. -*/ -#define MSS_SYS_MATCH_OTP_PROTOCOLERR 1u -#define MSS_SYS_MATCH_OTP_MISMATCHERR 2u + MSS_SYS_PROTOCOLERR + Keymode not supported. -/*-------------------------------------------------------------------------*//** - Unlock debug passcode service error codes + MSS_SYS_MATCH_OTP_MISMATCHERR + Calculated validator mismatch. + */ +#define MSS_SYS_MATCH_OTP_PROTOCOLERR 1u +#define MSS_SYS_MATCH_OTP_MISMATCHERR 2u - MSS_SYS_UNLOCK_DEBUG_PASSCODE_SECERR - The operation was blocked by device security. - Occurs if the lock UL_PLAINTEXT is active or the permanent lock UP_DPK is set. +/*-------------------------------------------------------------------------*/ /** + Unlock debug passcode service error codes - MSS_SYS_UNLOCK_DEBUG_PASSCODE_ERR - If the unlock operation fails for any reason then the tamper event - PASSCODE_FAIL is generated and all unlocked passcodes are re-locked. -*/ -#define MSS_SYS_UNLOCK_DEBUG_PASSCODE_SECERR 1u -#define MSS_SYS_UNLOCK_DEBUG_PASSCODE_ERR 2u + MSS_SYS_UNLOCK_DEBUG_PASSCODE_SECERR + The operation was blocked by device security. + Occurs if the lock UL_PLAINTEXT is active or the permanent lock UP_DPK is + set. -/*-------------------------------------------------------------------------*//** - One way passcode service error codes + MSS_SYS_UNLOCK_DEBUG_PASSCODE_ERR + If the unlock operation fails for any reason then the tamper event + PASSCODE_FAIL is generated and all unlocked passcodes are re-locked. + */ +#define MSS_SYS_UNLOCK_DEBUG_PASSCODE_SECERR 1u +#define MSS_SYS_UNLOCK_DEBUG_PASSCODE_ERR 2u - MSS_SYS_OWP_OWPERR - If the unlock operation fails for any reason then the tamper event - PASSCODE_FAIL is generated and all unlocked passcodes are re-locked. -*/ -#define MSS_SYS_OWP_OWPERR 1u +/*-------------------------------------------------------------------------*/ /** + One way passcode service error codes + + MSS_SYS_OWP_OWPERR + If the unlock operation fails for any reason then the tamper event + PASSCODE_FAIL is generated and all unlocked passcodes are re-locked. + */ +#define MSS_SYS_OWP_OWPERR 1u -/*-------------------------------------------------------------------------*//** - System service response data length - ============================ +/*-------------------------------------------------------------------------*/ /** + System service response data length + ============================ - The following constants can be used to indicate the length of the data that - is written into the mailbox by the system controller in response to the - service being requested. + The following constants can be used to indicate the length of the data that + is written into the mailbox by the system controller in response to the + service being requested. - MSS_SYS_NO_RESPONSE_LEN - This constant is used to indicate that system controller does not return any - mailbox data for the service which is being requested + MSS_SYS_NO_RESPONSE_LEN + This constant is used to indicate that system controller does not return + any mailbox data for the service which is being requested - MSS_SYS_SERIAL_NUMBER_RESP_LEN - Response length serial number service + MSS_SYS_SERIAL_NUMBER_RESP_LEN + Response length serial number service - MSS_SYS_USERCODE_RESP_LEN - Response length for Usercode service + MSS_SYS_USERCODE_RESP_LEN + Response length for Usercode service - MSS_SYS_DESIGN_INFO_RESP_LEN - Response length for Design info service + MSS_SYS_DESIGN_INFO_RESP_LEN + Response length for Design info service - MSS_SYS_DEVICE_CERTIFICATE_RESP_LEN - Response length for Device certificate service + MSS_SYS_DEVICE_CERTIFICATE_RESP_LEN + Response length for Device certificate service - MSS_SYS_READ_DIGEST_RESP_LEN - Response length Read digest service + MSS_SYS_READ_DIGEST_RESP_LEN + Response length Read digest service - MSS_SYS_QUERY_SECURITY_RESP_LEN - Response length Query security service + MSS_SYS_QUERY_SECURITY_RESP_LEN + Response length Query security service - MSS_SYS_READ_DEBUG_INFO_RESP_LEN - Response length Read debug info service + MSS_SYS_READ_DEBUG_INFO_RESP_LEN + Response length Read debug info service - MSS_SYS_NONCE_SERVICE_RESP_LEN - Response length Nonce service + MSS_SYS_NONCE_SERVICE_RESP_LEN + Response length Nonce service - MSS_SYS_READ_ENVM_PARAM_RESP_LEN - Response length Read eNVM parameters service + MSS_SYS_READ_ENVM_PARAM_RESP_LEN + Response length Read eNVM parameters service - MSS_SYS_PROBE_READ_SERVICE_RESP_LEN - Response length Probe read service + MSS_SYS_PROBE_READ_SERVICE_RESP_LEN + Response length Probe read service - MSS_SYS_GENERATE_OTP_RESP_LEN - Response length Generate OTP service + MSS_SYS_GENERATE_OTP_RESP_LEN + Response length Generate OTP service - MSS_SYS_PUF_EMULATION_SERVICE_RESP_LEN - Response length PUF emulation service + MSS_SYS_PUF_EMULATION_SERVICE_RESP_LEN + Response length PUF emulation service - MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_RESP_SIZE - Response length for digital signature service raw format + MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_RESP_SIZE + Response length for digital signature service raw format - MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_RESP_SIZE - Response length for digital signature service DER format -*/ -#define MSS_SYS_NO_RESPONSE_LEN 0u -#define MSS_SYS_SERIAL_NUMBER_RESP_LEN 16u -#define MSS_SYS_USERCODE_RESP_LEN 4u -#define MSS_SYS_DESIGN_INFO_RESP_LEN 36u -#define MSS_SYS_DEVICE_CERTIFICATE_RESP_LEN 1024u -#define MSS_SYS_READ_DIGEST_RESP_LEN 544u -#define MSS_SYS_QUERY_SECURITY_RESP_LEN 33u -#define MSS_SYS_READ_DEBUG_INFO_RESP_LEN 94u -#define MSS_SYS_NONCE_SERVICE_RESP_LEN 32u -#define MSS_SYS_READ_ENVM_PARAM_RESP_LEN 256u -#define MSS_SYS_PUF_EMULATION_SERVICE_RESP_LEN 32u -#define MSS_SYS_DIGEST_CHECK_SERVICE_RESP_LEN 4u -#define MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_RESP_SIZE 96u -#define MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_RESP_SIZE 104u -#define MSS_SYS_USER_SECRET_KEY_LEN 12u -#define MSS_SYS_PROBE_READ_SERVICE_RESP_LEN 4u -#define MSS_SYS_GENERATE_OTP_RESP_LEN 16u + MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_RESP_SIZE + Response length for digital signature service DER format + */ +#define MSS_SYS_NO_RESPONSE_LEN 0u +#define MSS_SYS_SERIAL_NUMBER_RESP_LEN 16u +#define MSS_SYS_USERCODE_RESP_LEN 4u +#define MSS_SYS_DESIGN_INFO_RESP_LEN 36u +#define MSS_SYS_DEVICE_CERTIFICATE_RESP_LEN 1024u +#define MSS_SYS_READ_DIGEST_RESP_LEN 544u +#define MSS_SYS_QUERY_SECURITY_RESP_LEN 33u +#define MSS_SYS_READ_DEBUG_INFO_RESP_LEN 94u +#define MSS_SYS_NONCE_SERVICE_RESP_LEN 32u +#define MSS_SYS_READ_ENVM_PARAM_RESP_LEN 256u +#define MSS_SYS_PUF_EMULATION_SERVICE_RESP_LEN 32u +#define MSS_SYS_DIGEST_CHECK_SERVICE_RESP_LEN 4u +#define MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_RESP_SIZE 96u +#define MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_RESP_SIZE 104u +#define MSS_SYS_USER_SECRET_KEY_LEN 12u +#define MSS_SYS_PROBE_READ_SERVICE_RESP_LEN 4u +#define MSS_SYS_GENERATE_OTP_RESP_LEN 16u /*-------------------------Private constants--------------------------------*/ -/*-------------------------------------------------------------------------*//** - Service request command opcodes - ============================ +/*-------------------------------------------------------------------------*/ /** + Service request command opcodes + ============================ - The following constants can be used as parameter value of the functions to - indicate the system service command opcode. - */ + The following constants can be used as parameter value of the functions to + indicate the system service command opcode. + */ -/*-------------------------------------------------------------------------*//** - Device and design information services request command opcodes +/*-------------------------------------------------------------------------*/ /** + Device and design information services request command opcodes + */ +#define MSS_SYS_SERIAL_NUMBER_REQUEST_CMD 0x00u +#define MSS_SYS_USERCODE_REQUEST_CMD 0x01u +#define MSS_SYS_DESIGN_INFO_REQUEST_CMD 0x02u +#define MSS_SYS_DEVICE_CERTIFICATE_REQUEST_CMD 0x03u +#define MSS_SYS_READ_DIGEST_REQUEST_CMD 0x04u +#define MSS_SYS_QUERY_SECURITY_REQUEST_CMD 0x05u +#define MSS_SYS_READ_DEBUG_INFO_REQUEST_CMD 0x06u +#define MSS_SYS_READ_ENVM_PARAM_REQUEST_CMD 0x07u + +/*-------------------------------------------------------------------------*/ /** + Design services request command opcodes */ -#define MSS_SYS_SERIAL_NUMBER_REQUEST_CMD 0x00u -#define MSS_SYS_USERCODE_REQUEST_CMD 0x01u -#define MSS_SYS_DESIGN_INFO_REQUEST_CMD 0x02u -#define MSS_SYS_DEVICE_CERTIFICATE_REQUEST_CMD 0x03u -#define MSS_SYS_READ_DIGEST_REQUEST_CMD 0x04u -#define MSS_SYS_QUERY_SECURITY_REQUEST_CMD 0x05u -#define MSS_SYS_READ_DEBUG_INFO_REQUEST_CMD 0x06u -#define MSS_SYS_READ_ENVM_PARAM_REQUEST_CMD 0x07u - -/*-------------------------------------------------------------------------*//** - Design services request command opcodes -*/ -#define MSS_SYS_BITSTREAM_AUTHENTICATE_CMD 0x23u -#define MSS_SYS_IAP_BITSTREAM_AUTHENTICATE_CMD 0x22u -#define MSS_SYS_UIC_EXECUTE_SCRIPT_CMD 0x24u -#define MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_CMD 0x25u +#define MSS_SYS_BITSTREAM_AUTHENTICATE_CMD 0x23u +#define MSS_SYS_IAP_BITSTREAM_AUTHENTICATE_CMD 0x22u +#define MSS_SYS_UIC_EXECUTE_SCRIPT_CMD 0x24u +#define MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_CMD 0x25u -/*-------------------------------------------------------------------------*//** - Data security services request command opcodes -*/ -#define MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_REQUEST_CMD 0x19u -#define MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_REQUEST_CMD 0x1Au -#define MSS_SYS_SNVM_NON_AUTHEN_TEXT_REQUEST_CMD 0x10u -#define MSS_SYS_SNVM_AUTHEN_TEXT_REQUEST_CMD 0x11u -#define MSS_SYS_SNVM_AUTHEN_CIPHERTEXT_REQUEST_CMD 0x12u -#define MSS_SYS_SNVM_READ_REQUEST_CMD 0x18u -#define MSS_SYS_PUF_EMULATION_SERVICE_REQUEST_CMD 0x20u -#define MSS_SYS_NONCE_SERVICE_REQUEST_CMD 0x21u - -/*-------------------------------------------------------------------------*//** - Fabric services request command opcodes -*/ -#define MSS_SYS_DIGEST_CHECK_CMD 0x47u -#define MSS_SYS_IAP_PROGRAM_BY_SPIIDX_CMD 0x42u -#define MSS_SYS_IAP_VERIFY_BY_SPIIDX_CMD 0x44u -#define MSS_SYS_IAP_PROGRAM_BY_SPIADDR_CMD 0x43u -#define MSS_SYS_IAP_VERIFY_BY_SPIADDR_CMD 0x45u -#define MSS_SYS_IAP_AUTOUPDATE_CMD 0x46u - -/*-------------------------------------------------------------------------*//** - MSS services request command opcodes -*/ -#define MSS_SYS_SPI_COPY_CMD 0X50U -#define MSS_SYS_PROBE_READ_DEBUG_CMD 0X70U -#define MSS_SYS_PROBE_WRITE_DEBUG_CMD 0X71U -#define MSS_SYS_LIVE_PROBE_A_DEBUG_CMD 0X72U -#define MSS_SYS_LIVE_PROBE_B_DEBUG_CMD 0X73U -#define MSS_SYS_MEM_SELECT_DEBUG_CMD 0X74U -#define MSS_SYS_MEM_READ_DEBUG_CMD 0X75U -#define MSS_SYS_MEM_WRITE_DEBUG_CMD 0X76U -#define MSS_SYS_APB_READ_DEBUG_CMD 0X77U -#define MSS_SYS_APB_WRITE_DEBUG_CMD 0X78U -#define MSS_SYS_DEBUG_SNAPSHOT_CMD 0X79U -#define MSS_SYS_GENERATE_OTP_CMD 0X7AU -#define MSS_SYS_MATCH_OTP_CMD 0X7BU -#define MSS_SYS_UNLOCK_DEBUG_PASSCODE 0X7CU -#define MSS_SYS_ONE_WAY_PASSCODE_CMD 0X7DU -#define MSS_SYS_TERMINATE_DEBUG_CMD 0X7EU - -/*-------------------------------------------------------------------------*//** - System service mailbox data length - ============================ - - The following constants are used to specify the mailbox data length of each - service for the service that is being requested. -*/ +/*-------------------------------------------------------------------------*/ /** + Data security services request command opcodes + */ +#define MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_REQUEST_CMD 0x19u +#define MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_REQUEST_CMD 0x1Au +#define MSS_SYS_SNVM_NON_AUTHEN_TEXT_REQUEST_CMD 0x10u +#define MSS_SYS_SNVM_AUTHEN_TEXT_REQUEST_CMD 0x11u +#define MSS_SYS_SNVM_AUTHEN_CIPHERTEXT_REQUEST_CMD 0x12u +#define MSS_SYS_SNVM_READ_REQUEST_CMD 0x18u +#define MSS_SYS_PUF_EMULATION_SERVICE_REQUEST_CMD 0x20u +#define MSS_SYS_NONCE_SERVICE_REQUEST_CMD 0x21u + +/*-------------------------------------------------------------------------*/ /** + Fabric services request command opcodes + */ +#define MSS_SYS_DIGEST_CHECK_CMD 0x47u +#define MSS_SYS_IAP_PROGRAM_BY_SPIIDX_CMD 0x42u +#define MSS_SYS_IAP_VERIFY_BY_SPIIDX_CMD 0x44u +#define MSS_SYS_IAP_PROGRAM_BY_SPIADDR_CMD 0x43u +#define MSS_SYS_IAP_VERIFY_BY_SPIADDR_CMD 0x45u +#define MSS_SYS_IAP_AUTOUPDATE_CMD 0x46u + +/*-------------------------------------------------------------------------*/ /** + MSS services request command opcodes + */ +#define MSS_SYS_SPI_COPY_CMD 0X50U +#define MSS_SYS_PROBE_READ_DEBUG_CMD 0X70U +#define MSS_SYS_PROBE_WRITE_DEBUG_CMD 0X71U +#define MSS_SYS_LIVE_PROBE_A_DEBUG_CMD 0X72U +#define MSS_SYS_LIVE_PROBE_B_DEBUG_CMD 0X73U +#define MSS_SYS_MEM_SELECT_DEBUG_CMD 0X74U +#define MSS_SYS_MEM_READ_DEBUG_CMD 0X75U +#define MSS_SYS_MEM_WRITE_DEBUG_CMD 0X76U +#define MSS_SYS_APB_READ_DEBUG_CMD 0X77U +#define MSS_SYS_APB_WRITE_DEBUG_CMD 0X78U +#define MSS_SYS_DEBUG_SNAPSHOT_CMD 0X79U +#define MSS_SYS_GENERATE_OTP_CMD 0X7AU +#define MSS_SYS_MATCH_OTP_CMD 0X7BU +#define MSS_SYS_UNLOCK_DEBUG_PASSCODE 0X7CU +#define MSS_SYS_ONE_WAY_PASSCODE_CMD 0X7DU +#define MSS_SYS_TERMINATE_DEBUG_CMD 0X7EU + +/*-------------------------------------------------------------------------*/ /** + System service mailbox data length + ============================ + + The following constants are used to specify the mailbox data length of each + service for the service that is being requested. + */ /* This constant is used for the services where no mailbox input data is * required */ -#define MSS_SYS_WITHOUT_CMD_DATA 0u +#define MSS_SYS_WITHOUT_CMD_DATA 0u -#define MSS_SYS_PUF_EMULATION_SERVICE_CMD_LEN 20u -#define MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN 48u +#define MSS_SYS_PUF_EMULATION_SERVICE_CMD_LEN 20u +#define MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN 48u /*SNVMADDR + RESERVED + PT*/ -#define MSS_SYS_AUTHENTICATED_TEXT_DATA_LEN 252u +#define MSS_SYS_AUTHENTICATED_TEXT_DATA_LEN 252u /*SNVMADDR + RESERVED + PT + USK*/ -#define MSS_SYS_NON_AUTHENTICATED_TEXT_DATA_LEN 256u - -#define MSS_SYS_SECURE_NVM_READ_DATA_LEN 16u -#define MSS_SYS_EXECUTE_UIC_SCRIPT_DATA_LEN 8u -#define MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_DATA_LEN 4u -#define MSS_SYS_BITSTREAM_AUTHENTICATE_DATA_LEN 4u -#define MSS_SYS_DIGEST_CHECK_DATA_LEN 4u -#define MSS_SYS_IAP_SERVICE_DATA_LEN 4u -#define MSS_SYS_SPI_COPY_MAILBOX_DATA_LEN 17u -#define MSS_SYS_PROBE_READ_SERVICE_DATA_LEN 2u -#define MSS_SYS_PROBE_WRITE_SERVICE_DATA_LEN 11u -#define MSS_SYS_LIVE_PROBE_DEBUG_SERVICE_DATA_LEN 6u -#define MSS_SYS_MEM_SELECT_DATA_LEN 6u -#define MSS_SYS_MEM_READ_WRITE_DATA_LEN 12u -#define MSS_SYS_APB_SERVICE_DATA_LEN 24u -#define MSS_SYS_DEBUG_SNAPSHOT_DATA_LEN 5u -#define MSS_SYS_GENERATE_OTP_DATA_LEN 20u -#define MSS_SYS_MATCH_OTP_DATA_LEN 80u -#define MSS_SYS_UNLOCK_DEBUG_PASSCODE_DATA_LEN 32u -#define MSS_SYS_ONE_WAY_PASSCODE_DATA_LEN 480u - -/*-------------------------------------------------------------------------*//** - System Services mailbox data constants - ============================ - */ +#define MSS_SYS_NON_AUTHENTICATED_TEXT_DATA_LEN 256u + +#define MSS_SYS_SECURE_NVM_READ_DATA_LEN 16u +#define MSS_SYS_EXECUTE_UIC_SCRIPT_DATA_LEN 8u +#define MSS_SYS_UIC_BITSTREAM_AUTHENTICATE_DATA_LEN 4u +#define MSS_SYS_BITSTREAM_AUTHENTICATE_DATA_LEN 4u +#define MSS_SYS_DIGEST_CHECK_DATA_LEN 4u +#define MSS_SYS_IAP_SERVICE_DATA_LEN 4u +#define MSS_SYS_SPI_COPY_MAILBOX_DATA_LEN 17u +#define MSS_SYS_PROBE_READ_SERVICE_DATA_LEN 2u +#define MSS_SYS_PROBE_WRITE_SERVICE_DATA_LEN 11u +#define MSS_SYS_LIVE_PROBE_DEBUG_SERVICE_DATA_LEN 6u +#define MSS_SYS_MEM_SELECT_DATA_LEN 6u +#define MSS_SYS_MEM_READ_WRITE_DATA_LEN 12u +#define MSS_SYS_APB_SERVICE_DATA_LEN 24u +#define MSS_SYS_DEBUG_SNAPSHOT_DATA_LEN 5u +#define MSS_SYS_GENERATE_OTP_DATA_LEN 20u +#define MSS_SYS_MATCH_OTP_DATA_LEN 80u +#define MSS_SYS_UNLOCK_DEBUG_PASSCODE_DATA_LEN 32u +#define MSS_SYS_ONE_WAY_PASSCODE_DATA_LEN 480u + +/*-------------------------------------------------------------------------*/ /** + System Services mailbox data constants + ============================ + */ /* KEY MODE for Generate OTP service KM_USER_KEY1 USER Key 1 KM_USER_KEY2 USER Key 2 KM_FACTORY_KEY FK Diversified by UID */ -#define MSS_SYS_KM_USER_KEY1 3u -#define MSS_SYS_KM_USER_KEY2 4u -#define MSS_SYS_KM_FACTORY_KEY 7u +#define MSS_SYS_KM_USER_KEY1 3u +#define MSS_SYS_KM_USER_KEY2 4u +#define MSS_SYS_KM_FACTORY_KEY 7u /*Digest Check Input options DIGEST_CHECK_FABRIC @@ -894,40 +897,40 @@ extern "C" { DIGEST_CHECK_SYS Carry out digest check on Factory and Factory Key Segments. */ -#define MSS_SYS_DIGEST_CHECK_FABRIC (0x01<<0x00u) -#define MSS_SYS_DIGEST_CHECK_CC (0x01<<0x01u) -#define MSS_SYS_DIGEST_CHECK_SNVM (0x01<<0x02u) -#define MSS_SYS_DIGEST_CHECK_UL (0x01<<0x03u) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST0 (0x01<<0x04u) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST1 (0x01<<0x05u) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST2 (0x01<<0x06u) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST3 (0x01<<0x07u) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST4 (0x01<<0x08u) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST5 (0x01<<0x09u) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST6 (0x01<<0x0au) -#define MSS_SYS_DIGEST_CHECK_UPERM (0x01<<0x0bu) -#define MSS_SYS_DIGEST_CHECK_SYS (0x01<<0x0cu) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST7 (0x01<<0x0du) -#define MSS_SYS_DIGEST_CHECK_ENVM (0x01<<0x0eu) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST8 (0x01<<0x0fu) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST9 (0x01<<0x10u) -#define MSS_SYS_DIGEST_CHECK_UKDIGEST10 (0x01<<0x11u) - -/*-------------------------------------------------------------------------*//** - Mailbox ECC status - Provides ECC status when the mailbox is read. The values are as follows: - 00: No ECC errors detected, data is correct. - 01: Exactly one bit erred and has been corrected. - 10: Exactly two bits erred, no correction performed. - 11: Reserved. -*/ -#define MSS_SYS_MBOX_ECC_NO_ERROR_MASK 0x00u -#define MSS_SYS_MBOX_ONEBIT_ERROR_CORRECTED_MASK 0x40u -#define MSS_SYS_MBOX_TWOBIT_ERROR_MASK 0xC0u +#define MSS_SYS_DIGEST_CHECK_FABRIC (0x01 << 0x00u) +#define MSS_SYS_DIGEST_CHECK_CC (0x01 << 0x01u) +#define MSS_SYS_DIGEST_CHECK_SNVM (0x01 << 0x02u) +#define MSS_SYS_DIGEST_CHECK_UL (0x01 << 0x03u) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST0 (0x01 << 0x04u) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST1 (0x01 << 0x05u) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST2 (0x01 << 0x06u) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST3 (0x01 << 0x07u) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST4 (0x01 << 0x08u) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST5 (0x01 << 0x09u) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST6 (0x01 << 0x0au) +#define MSS_SYS_DIGEST_CHECK_UPERM (0x01 << 0x0bu) +#define MSS_SYS_DIGEST_CHECK_SYS (0x01 << 0x0cu) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST7 (0x01 << 0x0du) +#define MSS_SYS_DIGEST_CHECK_ENVM (0x01 << 0x0eu) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST8 (0x01 << 0x0fu) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST9 (0x01 << 0x10u) +#define MSS_SYS_DIGEST_CHECK_UKDIGEST10 (0x01 << 0x11u) + +/*-------------------------------------------------------------------------*/ /** + Mailbox ECC status + Provides ECC status when the mailbox is read. The values are as follows: + 00: No ECC errors detected, data is correct. + 01: Exactly one bit erred and has been corrected. + 10: Exactly two bits erred, no correction performed. + 11: Reserved. + */ +#define MSS_SYS_MBOX_ECC_NO_ERROR_MASK 0x00u +#define MSS_SYS_MBOX_ONEBIT_ERROR_CORRECTED_MASK 0x40u +#define MSS_SYS_MBOX_TWOBIT_ERROR_MASK 0xC0u -/*-------------------------------------------------------------------------*//** - * Options for system services -*/ +/*-------------------------------------------------------------------------*/ /** + * Options for system services + */ /*Execute UIC script source peripheral options UIC_SOURCE_PERIPH_UPROM @@ -942,2262 +945,1987 @@ extern "C" { UIC_SOURCE_PERIPH_AUTHEN_SPIFLASH Execute UIC from SPI flash (Authenticated) */ -#define MSS_SYS_UIC_SOURCE_PERIPH_UPROM 0x01u -#define MSS_SYS_UIC_SOURCE_PERIPH_NONAUTHEN_SPIFLASH 0x02u -#define MSS_SYS_UIC_SOURCE_PERIPH_SNVM 0x03u -#define MSS_SYS_UIC_SOURCE_PERIPH_AUTHEN_SPIFLASH 0x06u +#define MSS_SYS_UIC_SOURCE_PERIPH_UPROM 0x01u +#define MSS_SYS_UIC_SOURCE_PERIPH_NONAUTHEN_SPIFLASH 0x02u +#define MSS_SYS_UIC_SOURCE_PERIPH_SNVM 0x03u +#define MSS_SYS_UIC_SOURCE_PERIPH_AUTHEN_SPIFLASH 0x06u /* Permitted key modes for one way Pass-code service * *NS -- Not Supported */ -#define KM_INIT_FACTORY 0x00u/*NS*/ -#define KM_ZERO_RECOVERY 0x01u/*NS*/ -#define KM_DEFAULT_KEY 0x02u -#define KM_USER_KEY1 0x03u -#define KM_USER_KEY2 0x04u -#define KM_AUTH_CODE 0x06u/*NS*/ -#define KM_FACTORY_KEY 0x07u -#define KM_FACTORY_EC 0x08u/*NS*/ -#define KM_FACTORY_EC_E 0x09u/*NS*/ -#define KM_USER_EC 0x12u/*NS*/ -#define KM_USER_EC_E 0x13u/*NS*/ - -/*-------------------------------------------------------------------------*//** - Callback function handler - The callback handler is used by the application to indicate the user about - the event of interrupt when the driver is configured to execute the system - services in interrupt mode. - The callback function handler is is registered to the MSS system service - driver through the call to MSS_SYS_select_service_mode() function. - The actual name of callback function handler is not important. User can select - any name. - */ +#define KM_INIT_FACTORY 0x00u /*NS*/ +#define KM_ZERO_RECOVERY 0x01u /*NS*/ +#define KM_DEFAULT_KEY 0x02u +#define KM_USER_KEY1 0x03u +#define KM_USER_KEY2 0x04u +#define KM_AUTH_CODE 0x06u /*NS*/ +#define KM_FACTORY_KEY 0x07u +#define KM_FACTORY_EC 0x08u /*NS*/ +#define KM_FACTORY_EC_E 0x09u /*NS*/ +#define KM_USER_EC 0x12u /*NS*/ +#define KM_USER_EC_E 0x13u /*NS*/ + +/*-------------------------------------------------------------------------*/ /** + Callback function handler + The callback handler is used by the application to indicate the user about + the event of interrupt when the driver is configured to execute the system + services in interrupt mode. + The callback function handler is is registered to the MSS system service + driver through the call to MSS_SYS_select_service_mode() function. + The actual name of callback function handler is not important. User can + select any name. + */ typedef void (*mss_sys_service_handler_t)(void); -/*-------------------------------------------------------------------------*//** - The function MSS_SYS_read_response() is used to read the response after - execution of system service in interrupt mode only. For polling mode call to - MSS_SYS_read_response is not required, as the drive performs the response - read operation. - @param - This function does not have any parameters. - @return - This function returns the status code returned by the system controller - for requested service. - - Example: - @code - status = MSS_SYS_read_response(); - - @endcode - */ +/*-------------------------------------------------------------------------*/ /** + The function MSS_SYS_read_response() is used to read the response after + execution of system service in interrupt mode only. For polling mode call to + MSS_SYS_read_response is not required, as the drive performs the response + read operation. + @param + This function does not have any parameters. + @return + This function returns the status code returned by the system + controller for requested service. + + Example: + @code + status = MSS_SYS_read_response(); + + @endcode + */ uint16_t -MSS_SYS_read_response -( - void -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_service_mode() function is for user to configure system service - execution in polling mode or interrupt mode. This function also registers the - callback handler to the driver which will be called when message interrupt - occurs. - - @param sys_service_mode - User can decide whether to execute the service in polling - mode or interrupt mode. - Example: - MSS_SYS_SERVICE_INTERRUPT_MODE - MSS_SYS_SERVICE_POLLING_MODE - - @param mss_sys_service_interrupt_handler - Callback function to the application. This function is - invoked when message interrupt occurs. - - @return - This function does not return any value. - - Example: - @code - MSS_SYS_service_mode(MSS_SYS_SERVICE_POLLING_MODE, - mss_sys_service_interrupt_handler); - @endcode -*/ +MSS_SYS_read_response(void); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_service_mode() function is for user to configure system service + execution in polling mode or interrupt mode. This function also registers the + callback handler to the driver which will be called when message interrupt + occurs. + + @param sys_service_mode + User can decide whether to execute the service in polling + mode or interrupt mode. + Example: + MSS_SYS_SERVICE_INTERRUPT_MODE + MSS_SYS_SERVICE_POLLING_MODE + + @param mss_sys_service_interrupt_handler + Callback function to the application. This function is + invoked when message interrupt occurs. + + @return + This function does not return any value. + + Example: + @code + MSS_SYS_service_mode(MSS_SYS_SERVICE_POLLING_MODE, + mss_sys_service_interrupt_handler); + @endcode + */ void -MSS_SYS_select_service_mode -( +MSS_SYS_select_service_mode( uint8_t sys_service_mode, - mss_sys_service_handler_t mss_sys_service_interrupt_handler -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_get_serial_number() function fetches the 128-bit Device Serial - Number (DSN). This function is non-blocking in the interrupt mode , in that, - it will exit immediately after requesting the service. In polling mode, it - becomes a blocking function. It will block until the the service is completed - and a response is received from the system controller. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param p_serial_number - The p_serial_number parameter is a pointer to a buffer - in which the data returned by system controller will be - copied. - - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns the status code returned by the - system controller for this service. A '0' status code means - that the service was executed successfully. - - | STATUS | Description | Note | - |--------|----------------|-----------------------------| - | 0 | Success | | - | 1 | Error | DSN could not be read | -*/ + mss_sys_service_handler_t mss_sys_service_interrupt_handler); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_get_serial_number() function fetches the 128-bit Device Serial + Number (DSN). This function is non-blocking in the interrupt mode , in that, + it will exit immediately after requesting the service. In polling mode, it + becomes a blocking function. It will block until the the service is completed + and a response is received from the system controller. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param p_serial_number + The p_serial_number parameter is a pointer to a buffer + in which the data returned by system controller will be + copied. + + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns the status code returned by the + system controller for this service. A '0' status code means + that the service was executed successfully. + + | STATUS | Description | Note | + |--------|----------------|-----------------------------| + | 0 | Success | | + | 1 | Error | DSN could not be read | + */ uint16_t -MSS_SYS_get_serial_number -( - uint8_t * p_serial_number, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The function MSS_SYS_get_user_code() is used to execute "USERCODE" system - service. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param p_user_code - The p_user_code parameter is a pointer to a buffer - in which the data returned by system controller will be - copied. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description Note | - |--------|------------------| - | 0 | Success | -*/ +MSS_SYS_get_serial_number(uint8_t* p_serial_number, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The function MSS_SYS_get_user_code() is used to execute "USERCODE" system + service. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param p_user_code + The p_user_code parameter is a pointer to a buffer + in which the data returned by system controller will be + copied. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description Note | + |--------|------------------| + | 0 | Success | + */ uint16_t -MSS_SYS_get_user_code -( - uint8_t * p_user_code, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The function MSS_SYS_get_design_info() is used to execute "Get Design Info" - system service. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param p_design_info The p_design_info parameter is a pointer to a buffer - in which the data returned by system controller will be - copied. Total size of debug information is 76 bytes. - Below listed fields in the 76 bytes information are - "reserved bytes". They do not represent meaningful - information and can be ignored. - From offset 3 (size 1) - From offset 18 (size 1) - From offset 37 (size 4) - From offset 42 (size 2) - From offset 50 (size 2) - From offset 65 (size 7) - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description Note | - |--------|------------------| - | 0 | Success | +MSS_SYS_get_user_code(uint8_t* p_user_code, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The function MSS_SYS_get_design_info() is used to execute "Get Design Info" + system service. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param p_design_info The p_design_info parameter is a pointer to a buffer + in which the data returned by system controller will + be copied. Total size of debug information is 76 bytes. Below listed fields + in the 76 bytes information are "reserved bytes". They do not represent + meaningful information and can be ignored. From offset 3 (size 1) From offset + 18 (size 1) From offset 37 (size 4) From offset 42 (size 2) From offset 50 + (size 2) From offset 65 (size 7) + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description Note | + |--------|------------------| + | 0 | Success | -*/ + */ uint16_t -MSS_SYS_get_design_info -( - uint8_t * p_design_info, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The function MSS_SYS_get_device_certificate() is used to execute "Get Device - Certificate" system service. - - @param p_device_certificate The p_device_certificate parameter is a pointer - to a buffer in which the data returned by the - system controller will be copied. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description | Note - |----------|-------------------|------------------------------------------ - | 0 | Success |Certificate is valid & consistent with - | | |device - | 1 | Signature invalid |Certificate signature is invalid - | 2 | Device mismatch |Public key or FSN do not match device - | 3 | System error |PUF or storage failure -*/ +MSS_SYS_get_design_info(uint8_t* p_design_info, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The function MSS_SYS_get_device_certificate() is used to execute "Get Device + Certificate" system service. + + @param p_device_certificate The p_device_certificate parameter is a pointer + to a buffer in which the data returned by the + system controller will be copied. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description | Note + |----------|-------------------|------------------------------------------ + | 0 | Success |Certificate is valid & consistent with + | | |device + | 1 | Signature invalid |Certificate signature is invalid + | 2 | Device mismatch |Public key or FSN do not match device + | 3 | System error |PUF or storage failure + */ uint16_t -MSS_SYS_get_device_certificate -( - uint8_t * p_device_certificate, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The function MSS_SYS_read_digest() is used to execute "Read Digest" system - service. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param p_digest The p_digest parameter is a pointer to a buffer - in which the data returned by system controller will be - copied. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description Note | - |--------|------------------| - | 0 | Success | -*/ +MSS_SYS_get_device_certificate( + uint8_t* p_device_certificate, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The function MSS_SYS_read_digest() is used to execute "Read Digest" system + service. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param p_digest The p_digest parameter is a pointer to a buffer + in which the data returned by system controller will be + copied. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description Note | + |--------|------------------| + | 0 | Success | + */ uint16_t -MSS_SYS_read_digest -( - uint8_t * p_digest, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The function MSS_SYS_query_security() is used to execute "Query Security" - system service. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param p_security_locks The p_security_locks parameter is a pointer to a buffer - in which the data returned by system controller will be - copied. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description Note | - |--------|------------------| - | 0 | Success | -*/ +MSS_SYS_read_digest(uint8_t* p_digest, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The function MSS_SYS_query_security() is used to execute "Query Security" + system service. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param p_security_locks The p_security_locks parameter is a pointer to a + buffer in which the data returned by system controller will be copied. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description Note | + |--------|------------------| + | 0 | Success | + */ uint16_t -MSS_SYS_query_security -( - uint8_t * p_security_locks, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The function MSS_SYS_read_debug_info() is used to execute "Read Debug info" - system service. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param p_debug_info The p_debug_info parameter is a pointer to a buffer - in which the data returned by system controller will be - copied. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description Note | - |--------|------------------| - | 0 | Success | -*/ +MSS_SYS_query_security(uint8_t* p_security_locks, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The function MSS_SYS_read_debug_info() is used to execute "Read Debug info" + system service. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param p_debug_info The p_debug_info parameter is a pointer to a buffer + in which the data returned by system controller will be + copied. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description Note | + |--------|------------------| + | 0 | Success | + */ uint16_t -MSS_SYS_read_debug_info -( - uint8_t * p_debug_info, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The function MSS_SYS_read_envm_parameter() is used to retrieve all parameters - needed for eNVM operation and programming. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param p_envm_param - The p_envm_param parameter specifies the the user buffer - which will be accumulated with envm parameters after the - service completes execution. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description | Note | - |--------|----------------|--------------------------------| - | 0 | Success | | - | 1 | Digest Error |Page digest mismatches. | - | | |Parameter values still returned.| -*/ +MSS_SYS_read_debug_info(uint8_t* p_debug_info, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The function MSS_SYS_read_envm_parameter() is used to retrieve all parameters + needed for eNVM operation and programming. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param p_envm_param + The p_envm_param parameter specifies the the user buffer + which will be accumulated with envm parameters after the + service completes execution. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description | Note | + |--------|----------------|--------------------------------| + | 0 | Success | | | 1 | Digest Error + |Page digest mismatches. | | | |Parameter + values still returned.| + */ uint16_t -MSS_SYS_read_envm_parameter -( - uint8_t * p_envm_param, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_execute_uic_script() function is used to execute UCI script - service. This service allows the user to invoke a UIC script stored in any of - the available non-volatile memory sources. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param src_periph_type - The src_periph_type parameter specifies the type of - non-volatile memory in which the UIC script is stored. - Below is the list of all available peripheral options. - - SRC Location - 0 Reserved - 1 PROM - 2 SPI flash (Not Authenticated) - 3 SNVM - 4 Reserved - 5 Reserved - 6 SPI flash (Authenticated) - 7 Reserved - @param periph_address - The periph_address parameter specifies the address within the - selected non-volatile memory where the UIC script is stored. - The address format is different for different peripherals. - Below is the list of peripherals and corresponding addresses. - - uPROM memory -- IP Segment/Block Address - SNVM memory -- SNVM Module number. - SPI FLash (Authenticated or NonAuthenticated) - 24 or 32 bit - address. - - This function will adjust the provided value to fit into the - format expected by system controller. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description | - |---------|---------------------------------| - | 0 | Successful completion | - | 1 | SPI Max Frame Error | - | 2 | Poll Time out | - | 3 | SPI Authentication Error | - | 4 | SPI Decryption Error | - | 5 | SPI Not Master Error | - | 6 | Fabric APB Error | - | 7 | SCB Error | - | 8 | PNVM Encrypted Error | - | 9 | Address out of Range Error | - | 10 | Jump Max Error | - | 11 | Unexpected Format Error | - | 12 | Script Time out Error | -*/ +MSS_SYS_read_envm_parameter(uint8_t* p_envm_param, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_execute_uic_script() function is used to execute UCI script + service. This service allows the user to invoke a UIC script stored in any of + the available non-volatile memory sources. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param src_periph_type + The src_periph_type parameter specifies the type of + non-volatile memory in which the UIC script is stored. + Below is the list of all available peripheral options. + + SRC Location + 0 Reserved + 1 PROM + 2 SPI flash (Not Authenticated) + 3 SNVM + 4 Reserved + 5 Reserved + 6 SPI flash (Authenticated) + 7 Reserved + @param periph_address + The periph_address parameter specifies the address within + the selected non-volatile memory where the UIC script is stored. The address + format is different for different peripherals. Below is the list of + peripherals and corresponding addresses. + + uPROM memory -- IP Segment/Block Address + SNVM memory -- SNVM Module number. + SPI FLash (Authenticated or NonAuthenticated) - 24 or 32 + bit address. + + This function will adjust the provided value to fit into + the format expected by system controller. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description | + |---------|---------------------------------| + | 0 | Successful completion | + | 1 | SPI Max Frame Error | + | 2 | Poll Time out | + | 3 | SPI Authentication Error | + | 4 | SPI Decryption Error | + | 5 | SPI Not Master Error | + | 6 | Fabric APB Error | + | 7 | SCB Error | + | 8 | PNVM Encrypted Error | + | 9 | Address out of Range Error | + | 10 | Jump Max Error | + | 11 | Unexpected Format Error | + | 12 | Script Time out Error | + */ uint16_t -MSS_SYS_execute_uic_script -( - uint8_t src_periph_type, - uint32_t periph_address, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_authenticate_uic_bitstream() function is used to authenticate - the UIC Bitstream which is located in SPI through a system service routine. - This service is applicable to UIC scripts stored in SPI Flash memory only. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param spi_flash_address - The spi_flash_address parameter specifies the address within - SPI Flash memory where the UIC script is stored. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description | - |---------|---------------------------------| - | 0 | Successful completion | - | 1 | SPI Max Frame Error | - | 2 | Poll Time out | - | 3 | SPI Authentication Error | - | 4 | SPI Decryption Error | - | 5 | SPI Not Master Error | - | 6 | Fabric APB Error | - | 7 | SCB Error | - | 8 | PNVM Encrypted Error | - | 9 | Address out of Range Error | - | 10 | Jump Max Error | - | 11 | Unexpected Format Error | - | 12 | Script Time out Error | +MSS_SYS_execute_uic_script( + uint8_t src_periph_type, uint32_t periph_address, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_authenticate_uic_bitstream() function is used to authenticate + the UIC Bitstream which is located in SPI through a system service routine. + This service is applicable to UIC scripts stored in SPI Flash memory only. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param spi_flash_address + The spi_flash_address parameter specifies the address within + SPI Flash memory where the UIC script is stored. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description | + |---------|---------------------------------| + | 0 | Successful completion | + | 1 | SPI Max Frame Error | + | 2 | Poll Time out | + | 3 | SPI Authentication Error | + | 4 | SPI Decryption Error | + | 5 | SPI Not Master Error | + | 6 | Fabric APB Error | + | 7 | SCB Error | + | 8 | PNVM Encrypted Error | + | 9 | Address out of Range Error | + | 10 | Jump Max Error | + | 11 | Unexpected Format Error | + | 12 | Script Time out Error | -*/ + */ uint16_t -MSS_SYS_authenticate_uic_bitstream -( - uint32_t spi_flash_address, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_authenticate_bitstream() function is used to authenticate - the Bitstream which is located in SPI through a system service routine. Prior - to using the IAP service, it may be required to first validate the new - bitstream before committing the device to reprogramming, thus avoiding the - need to invoke recovery procedures if the bitstream is invalid. - - This service is applicable to bitstreams stored in SPI Flash memory only. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param spi_flash_address - The spi_flash_address parameter specifies the address within - SPI Flash memory where the bit-stream is stored. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description | - |----------|-----------------------------------------------| - | 0 | No error | - | 1 | Validator or hash chaining mismatch | - | 2 | Unexpected data received | - | 3 | Invalid/corrupt encryption key | - | 4 | Invalid component header | - | 5 | Back level not satisfied | - | 6 | Illegal bitstream mode | - | 7 | DSN binding mismatch | - | 8 | Illegal component sequence | - | 9 | Insufficient device capabilities | - | 10 | Incorrect DEVICEID | - | 11 | Unsupported bitstream protocol version | - | | (regeneration required) | - | 12 | Verify not permitted on this bitstream | - | 13 | Invalid Device Certificate | - | 14 | Invalid DIB | - | 21 | Device not in SPI Master Mode | - | 22 | No valid images found | - | 23 | No valid images found | - | 24 | Programmed design version is newer than Auto | - | | Update image found | - | 25 | Reserved | - | 26 | Selected image was invalid and no recovery | - | | was performed due to valid design in device | - | 27 | Selected and Recovery image failed to program| - | 127 | Abort | - | 128 | NVMVERIFY | - | 129 | PROTECTED | - | 130 | NOTENA | - | 131 | PNVMVERIFY | - | 132 | SYSTEM | - | 133 | BADCOMPONENT | - | 134 | HVPROGERR | - | 135 | HVSTATE | -*/ +MSS_SYS_authenticate_uic_bitstream( + uint32_t spi_flash_address, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_authenticate_bitstream() function is used to authenticate + the Bitstream which is located in SPI through a system service routine. Prior + to using the IAP service, it may be required to first validate the new + bitstream before committing the device to reprogramming, thus avoiding the + need to invoke recovery procedures if the bitstream is invalid. + + This service is applicable to bitstreams stored in SPI Flash memory only. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param spi_flash_address + The spi_flash_address parameter specifies the address + within SPI Flash memory where the bit-stream is stored. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description | + |----------|-----------------------------------------------| + | 0 | No error | | 1 | Validator or hash + chaining mismatch | | 2 | Unexpected data received | | 3 + | Invalid/corrupt encryption key | | 4 | Invalid + component header | | 5 | Back level not satisfied + | | 6 | Illegal bitstream mode | | 7 | + DSN binding mismatch | | 8 | Illegal + component sequence | | 9 | Insufficient device + capabilities | | 10 | Incorrect DEVICEID | | 11 | + Unsupported bitstream protocol version | | | (regeneration + required) | | 12 | Verify not permitted on this + bitstream | | 13 | Invalid Device Certificate | | 14 | + Invalid DIB | | 21 | Device not in + SPI Master Mode | | 22 | No valid images found | | 23 + | No valid images found | | 24 | Programmed + design version is newer than Auto | | | Update image found | | 25 + | Reserved | | 26 | Selected + image was invalid and no recovery | | | was performed due to + valid design in device | | 27 | Selected and Recovery image failed to + program| | 127 | Abort | | 128 + | NVMVERIFY | | 129 | PROTECTED | + | 130 | NOTENA | | 131 | PNVMVERIFY | | 132 + | SYSTEM | | 133 | BADCOMPONENT + | | 134 | HVPROGERR | | 135 | + HVSTATE | + */ uint16_t -MSS_SYS_authenticate_bitstream -( - uint32_t spi_flash_address, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_authenticate_iap_image() function is used to authenticate - the IAP image which is located in SPI through a system service routine. The - service checks the image descriptor and the referenced bitstream and optional - initialization data. If the image is authenticated successfully, then the - image is guaranteed to be valid when used by an IAP function. - - This service is applicable to bitstreams stored in SPI Flash memory only. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param spi_idx - The spi_idx parameter specifies the index in the SPI directory to - be used where the IAP bit-stream is stored. - - Note: To support recovery SPI_IDX=1 should be an empty slot - and the recovery image should be located in SPI_IDX=0. Since - SPI_IDX=1 should be an empty slot it shouldn’t be passed into - the system service. - @return - The MSS_SYS_authenticate_iap_image function returns - one of following status codes. The status code indicates - the success/failure status of the service execution. - - | STATUS | Description | - |----------|-----------------------------------------------| - | 0 | No error | - | 1 | Validator or hash chaining mismatch | - | 2 | Unexpected data received | - | 3 | Invalid/corrupt encryption key | - | 4 | Invalid component header | - | 5 | Back level not satisfied | - | 6 | Illegal bitstream mode | - | 7 | DSN binding mismatch | - | 8 | Illegal component sequence | - | 9 | Insufficient device capabilities | - | 10 | Incorrect DEVICEID | - | 11 | Unsupported bitstream protocol version | - | | (regeneration required) | - | 12 | Verify not permitted on this bitstream | - | 13 | Invalid Device Certificate | - | 14 | Invalid DIB | - | 21 | Device not in SPI Master Mode | - | 22 | No valid images found | - | 23 | No valid images found | - | 24 | Programmed design version is newer than Auto | - | | Update image found | - | 25 | Reserved | - | 26 | Selected image was invalid and no recovery | - | | was performed due to valid design in device | - | 27 | Selected and Recovery image failed to program| - | 127 | Abort | - | 128 | NVMVERIFY | - | 129 | PROTECTED | - | 130 | NOTENA | - | 131 | PNVMVERIFY | - | 132 | SYSTEM | - | 133 | BADCOMPONENT | - | 134 | HVPROGERR | - | 135 | HVSTATE | -*/ +MSS_SYS_authenticate_bitstream(uint32_t spi_flash_address, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_authenticate_iap_image() function is used to authenticate + the IAP image which is located in SPI through a system service routine. The + service checks the image descriptor and the referenced bitstream and optional + initialization data. If the image is authenticated successfully, then the + image is guaranteed to be valid when used by an IAP function. + + This service is applicable to bitstreams stored in SPI Flash memory only. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param spi_idx + The spi_idx parameter specifies the index in the SPI + directory to be used where the IAP bit-stream is stored. + + Note: To support recovery SPI_IDX=1 should be an empty slot + and the recovery image should be located in SPI_IDX=0. + Since SPI_IDX=1 should be an empty slot it shouldn’t be passed into the + system service. + @return + The MSS_SYS_authenticate_iap_image function returns + one of following status codes. The status code indicates + the success/failure status of the service execution. + + | STATUS | Description | + |----------|-----------------------------------------------| + | 0 | No error | | 1 | Validator or hash + chaining mismatch | | 2 | Unexpected data received | | 3 + | Invalid/corrupt encryption key | | 4 | Invalid + component header | | 5 | Back level not satisfied + | | 6 | Illegal bitstream mode | | 7 | + DSN binding mismatch | | 8 | Illegal + component sequence | | 9 | Insufficient device + capabilities | | 10 | Incorrect DEVICEID | | 11 | + Unsupported bitstream protocol version | | | (regeneration + required) | | 12 | Verify not permitted on this + bitstream | | 13 | Invalid Device Certificate | | 14 | + Invalid DIB | | 21 | Device not in + SPI Master Mode | | 22 | No valid images found | | 23 + | No valid images found | | 24 | Programmed + design version is newer than Auto | | | Update image found | | 25 + | Reserved | | 26 | Selected + image was invalid and no recovery | | | was performed due to + valid design in device | | 27 | Selected and Recovery image failed to + program| | 127 | Abort | | 128 + | NVMVERIFY | | 129 | PROTECTED | + | 130 | NOTENA | | 131 | PNVMVERIFY | | 132 + | SYSTEM | | 133 | BADCOMPONENT + | | 134 | HVPROGERR | | 135 | + HVSTATE | + */ uint16_t -MSS_SYS_authenticate_iap_image -( - uint32_t spi_idx -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_puf_emulation_service() function accept a challenge comprising a - 8-bit optype and 128-bit challenge and return a 256-bit response unique to - the given challenge and the device. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param p_challenge - The p_challenge parameter specifies the 128-bit challenge - to be used to generate the unique 256-bits unique - response. - @param op_type - The op_type parameter specifies the operational parameter - to be used to generate the unique 256-bits unique - response. - @param p_response - The p_response parameter is a pointer to a buffer in - which the data returned i.e. response by system controller - will be copied. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description - |--------|-----------------| - | 0 | SUCCESS | - | 1 | INTERNAL ERROR| - | | | -*/ +MSS_SYS_authenticate_iap_image(uint32_t spi_idx); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_puf_emulation_service() function accept a challenge comprising a + 8-bit optype and 128-bit challenge and return a 256-bit response unique to + the given challenge and the device. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param p_challenge + The p_challenge parameter specifies the 128-bit challenge + to be used to generate the unique 256-bits unique + response. + @param op_type + The op_type parameter specifies the operational parameter + to be used to generate the unique 256-bits unique + response. + @param p_response + The p_response parameter is a pointer to a buffer in + which the data returned i.e. response by system controller + will be copied. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description + |--------|-----------------| + | 0 | SUCCESS | + | 1 | INTERNAL ERROR| + | | | + */ uint16_t -MSS_SYS_puf_emulation_service -( - uint8_t * p_challenge, - uint8_t op_type, - uint8_t* p_response, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_digital_signature_service() function is used to generate P-384 - ECDSA signature based on SHA384 hash value. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param p_hash - The p_hash parameter is a pointer to the buffer which - contain the 48 bytes SH384 Hash value(input value). - @param format - The format parameter specifies the output format of - generated SIGNATURE field. The different types of output - signature formats are as follow: - - DIGITAL_SIGNATURE_RAW_FORMAT - - DIGITAL_SIGNATURE_DER_FORMAT - @param p_response - The p_response parameter is a pointer to a buffer which - contain the generated ECDSA signature. The field may be - 96 bytes or 104 bytes depend upon the output format. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description | - |-------|--------------------------------------| - | 0 | Success | - | 1 | FEK Failure Error retrieving FEK | - | 2 | DRBG Error Failed to generate nonce | - | 3 | ECDSA Error ECDSA failed | +MSS_SYS_puf_emulation_service( + uint8_t* p_challenge, uint8_t op_type, uint8_t* p_response, + uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_digital_signature_service() function is used to generate P-384 + ECDSA signature based on SHA384 hash value. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param p_hash + The p_hash parameter is a pointer to the buffer which + contain the 48 bytes SH384 Hash value(input value). + @param format + The format parameter specifies the output format of + generated SIGNATURE field. The different types of output + signature formats are as follow: + - DIGITAL_SIGNATURE_RAW_FORMAT + - DIGITAL_SIGNATURE_DER_FORMAT + @param p_response + The p_response parameter is a pointer to a buffer which + contain the generated ECDSA signature. The field may be + 96 bytes or 104 bytes depend upon the output format. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description | + |-------|--------------------------------------| + | 0 | Success | + | 1 | FEK Failure Error retrieving FEK | + | 2 | DRBG Error Failed to generate nonce | + | 3 | ECDSA Error ECDSA failed | -*/ + */ uint16_t -MSS_SYS_digital_signature_service -( - uint8_t* p_hash, - uint8_t format, - uint8_t* p_response, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_secure_nvm_write() function is used to provide write access/write the - data in the sNVM region. Data can be stored in the following format: - - Non-authenticated plaintext, - - Authenticated plaintext - - Authenticated ciphertext - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param format - The format parameter specifies the format used to write - data in sNVM region. The different type of text formats - are as follow: - - NON_AUTHENTICATED_PLAINTEXT_FORMAT - - AUTHENTICATED_PLAINTEXT_FORMAT - - AUTHENTICATED_CIPHERTEXT_FORMAT - @param snvm_module - The snvm_module parameter specifies the the sNVM module - in which the data need to be written. - @param p_data - The p_data parameter is a pointer to a buffer which - contains the data to be stored in sNVM region. The data length - to be written is if fixed depending on the format parameter. - If NON_AUTHENTICATED_PLAINTEXT_FORMAT is selected then you - can write 252 bytes in the sNVM module. For other two formats - the data length is 236 bytes. - @param p_user_key - The p_user_key parameter is a pointer to a buffer which - contain the 96-bit key USK (user secret key). This user - secret key will enhance the security when authentication - is used.(i.e. When Authenticated plaintext and - Authenticated ciphertext format is selected). - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description Note | - |--------|-------------------------------------------------| - | 0 | Success | - | 1 | Invalid SNVMADDR Illegal page address | - | 2 | Write failure PNVM program/verify failed | - | 3 | System error PUF or storage failure | - | 4 | Write Not Permitted ROMFLAG is set | - | 5 | Access failure Write Access from either Fabric| - | | or MSS was blocked (PolarFire SoC only) | -*/ +MSS_SYS_digital_signature_service( + uint8_t* p_hash, uint8_t format, uint8_t* p_response, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_secure_nvm_write() function is used to provide write access/write + the data in the sNVM region. Data can be stored in the following format: + - Non-authenticated plaintext, + - Authenticated plaintext + - Authenticated ciphertext + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param format + The format parameter specifies the format used to write + data in sNVM region. The different type of text formats + are as follow: + - NON_AUTHENTICATED_PLAINTEXT_FORMAT + - AUTHENTICATED_PLAINTEXT_FORMAT + - AUTHENTICATED_CIPHERTEXT_FORMAT + @param snvm_module + The snvm_module parameter specifies the the sNVM module + in which the data need to be written. + @param p_data + The p_data parameter is a pointer to a buffer which + contains the data to be stored in sNVM region. The data + length to be written is if fixed depending on the format parameter. If + NON_AUTHENTICATED_PLAINTEXT_FORMAT is selected then you can write 252 bytes + in the sNVM module. For other two formats the data length is 236 bytes. + @param p_user_key + The p_user_key parameter is a pointer to a buffer which + contain the 96-bit key USK (user secret key). This user + secret key will enhance the security when authentication + is used.(i.e. When Authenticated plaintext and + Authenticated ciphertext format is selected). + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description Note | + |--------|-------------------------------------------------| + | 0 | Success | | 1 | Invalid SNVMADDR Illegal + page address | | 2 | Write failure PNVM program/verify failed | + | 3 | System error PUF or storage failure | | 4 + | Write Not Permitted ROMFLAG is set | | 5 | Access + failure Write Access from either Fabric| | | or MSS was blocked + (PolarFire SoC only) | + */ uint16_t -MSS_SYS_secure_nvm_write -( - uint8_t format, - uint8_t snvm_module, - uint8_t* p_data, - uint8_t* p_user_key, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_secure_nvm_read() function is used to read data present in sNVM - region. User should provide USK key, if the data was programmed using - authentication. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param snvm_module - The snvm_module parameter specifies the sNVM module - from which the data need to be read. - @param p_user_key - The p_user_key parameter is a pointer to a buffer which - contain the 96-bit key USK (user secret key). User should - provide same secret key which is previously used for - authentication while writing data in sNVM region. - @param p_admin - The p_admin parameter is a pointer to the buffer where - the output page admin data will be stored. The page admin - data is 4 bytes long. - @param p_data - The p_data parameter is a pointer to a buffer which - contains the data read from sNVM region. User should - provide the buffer large enough to store the read data. - @param data_len - The data_len parameter specifies the number of bytes to be - read from sNVM. - The application should know whether the data written in the - chose sNVM module was previously stored using Authentication - or not. - The data_len should be 236 bytes, for authenticated data, - for not authenticated data the data_len should be 252 bytes. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description Note | - |--------|-------------------------------------------------| - | 0 | Success | - | 1 | Invalid SNVMADDR Illegal page address | - | 2 | Write failure PNVM program/verify failed | - | 3 | System error PUF or storage failure | - | 4 | Write Not Permitted ROMFLAG is set | - | 5 | Access failure Write Access from either Fabric| - | | or MSS was blocked (PolarFire SoC only) | -*/ +MSS_SYS_secure_nvm_write( + uint8_t format, uint8_t snvm_module, uint8_t* p_data, uint8_t* p_user_key, + uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_secure_nvm_read() function is used to read data present in sNVM + region. User should provide USK key, if the data was programmed using + authentication. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param snvm_module + The snvm_module parameter specifies the sNVM module + from which the data need to be read. + @param p_user_key + The p_user_key parameter is a pointer to a buffer which + contain the 96-bit key USK (user secret key). User should + provide same secret key which is previously used for + authentication while writing data in sNVM region. + @param p_admin + The p_admin parameter is a pointer to the buffer where + the output page admin data will be stored. The page admin + data is 4 bytes long. + @param p_data + The p_data parameter is a pointer to a buffer which + contains the data read from sNVM region. User should + provide the buffer large enough to store the read data. + @param data_len + The data_len parameter specifies the number of bytes to be + read from sNVM. + The application should know whether the data written in the + chose sNVM module was previously stored using + Authentication or not. The data_len should be 236 bytes, for authenticated + data, for not authenticated data the data_len should be 252 bytes. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description Note | + |--------|-------------------------------------------------| + | 0 | Success | | 1 | Invalid SNVMADDR Illegal + page address | | 2 | Write failure PNVM program/verify failed | + | 3 | System error PUF or storage failure | | 4 + | Write Not Permitted ROMFLAG is set | | 5 | Access + failure Write Access from either Fabric| | | or MSS was blocked + (PolarFire SoC only) | + */ uint16_t -MSS_SYS_secure_nvm_read -( - uint8_t snvm_module, - uint8_t* p_user_key, - uint8_t* p_admin, - uint8_t* p_data, - uint16_t data_len, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The function MSS_SYS_nonce_service() is used to issue "Nonce Service" system - service to the system controller. - - @param p_nonce - The p_nonce parameter is a pointer to a buffer - in which the data returned by system controller will be - copied. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return This function returns the status code returned by the - system controller for this service. A '0' status code means - that the service was executed successfully. - - | STATUS | Description | - |------------|------------------------------------------| - | 0 | Success completion (exit) | - | 1 | Error fetching PUK | - | 2 | Error generating seed | -*/ +MSS_SYS_secure_nvm_read( + uint8_t snvm_module, uint8_t* p_user_key, uint8_t* p_admin, uint8_t* p_data, + uint16_t data_len, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The function MSS_SYS_nonce_service() is used to issue "Nonce Service" system + service to the system controller. + + @param p_nonce + The p_nonce parameter is a pointer to a buffer + in which the data returned by system controller will be + copied. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return This function returns the status code returned by the + system controller for this service. A '0' status code means + that the service was executed successfully. + + | STATUS | Description | + |------------|------------------------------------------| + | 0 | Success completion (exit) | + | 1 | Error fetching PUK | + | 2 | Error generating seed | + */ uint16_t -MSS_SYS_nonce_service -( - uint8_t * p_nonce, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_digest_check() function is used to Recalculates and compares - digests of selected non-volatile memories. - - This service is applicable to bitstream stored in SPI Flash memory only. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param options - The options parameter specifies the digest check options which - indicate the area on which the digest check should be performed. - Below is the list of options. You can OR these options to indicate - to perform digest check on multiple segments. - - | Options[i] | Description | - |-------------|---------------------------------------------| - | 0x01 | Fabric digest | - | 0x02 | Fabric Configuration (CC) segment | - | 0x04 | ROM digest in SNVM segment | - | 0x08 | UL segment | - | 0x10 | UKDIGEST0 in User Key segment | - | 0x20 | UKDIGEST1 in User Key segment | - | 0x40 | UKDIGEST2 in User Key segment (UPK1) | - | 0x80 | UKDIGEST3 in User Key segment (UK1) | - | 0x100 | UKDIGEST4 in User Key segment (DPK) | - | 0x200 | UKDIGEST5 in User Key segment (UPK2) | - | 0x400 | UKDIGEST6 in User Key segment (UK2) | - | 0x800 | UFS Permanent lock (UPERM) segment | - | 0x1000 | Factory and Factory Key Segments. | - | 0x2000 | UKDIGEST7 in User Key segment (HWM) | - | 0x4000 | ENVMDIGEST | - | 0x8000 | UKDIGEST8 for MSS Boot Info | - | 0x10000 | SNVM_RW_ACCESS_MAP Digest | - | 0x20000 | SBIC revocation digest | - - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @param digesterr - The digesterr parameter specifies the set bit in case of - DIGESTERR. - - | DIGESTERR[i]| Description | - |-------------|---------------------------------------------| - | 0x01 | Fabric digest | - | 0x02 | Fabric Configuration (CC) segment | - | 0x04 | ROM digest in SNVM segment | - | 0x08 | UL segment | - | 0x10 | UKDIGEST0 in User Key segment | - | 0x20 | UKDIGEST1 in User Key segment | - | 0x40 | UKDIGEST2 in User Key segment (UPK1) | - | 0x80 | UKDIGEST3 in User Key segment (UK1) | - | 0x100 | UKDIGEST4 in User Key segment (DPK) | - | 0x200 | UKDIGEST5 in User Key segment (UPK2) | - | 0x400 | UKDIGEST6 in User Key segment (UK2) | - | 0x800 | UFS Permanent lock (UPERM) segment | - | 0x1000 | Factory and Factory Key Segments. | - | 0x2000 | UKDIGEST7 in User Key segment (HWM) | - | 0x4000 | ENVMDIGEST | - | 0x8000 | UKDIGEST8 for MSS Boot Info | - | 0x10000 | SNVM_RW_ACCESS_MAP Digest | - | 0x20000 | SBIC revocation digest | - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS DIGESTERR[i] | Description | - |---------------------|----------------------------------------| - | 1 or 0 |1 is returned if any of DIGESTERR bits | - | |are set | -*/ +MSS_SYS_nonce_service(uint8_t* p_nonce, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_digest_check() function is used to Recalculates and compares + digests of selected non-volatile memories. + + This service is applicable to bitstream stored in SPI Flash memory only. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param options + The options parameter specifies the digest check options which + indicate the area on which the digest check should be performed. + Below is the list of options. You can OR these options to + indicate to perform digest check on multiple segments. + + | Options[i] | Description | + |-------------|---------------------------------------------| + | 0x01 | Fabric digest | + | 0x02 | Fabric Configuration (CC) segment | + | 0x04 | ROM digest in SNVM segment | + | 0x08 | UL segment | + | 0x10 | UKDIGEST0 in User Key segment | + | 0x20 | UKDIGEST1 in User Key segment | + | 0x40 | UKDIGEST2 in User Key segment (UPK1) | + | 0x80 | UKDIGEST3 in User Key segment (UK1) | + | 0x100 | UKDIGEST4 in User Key segment (DPK) | + | 0x200 | UKDIGEST5 in User Key segment (UPK2) | + | 0x400 | UKDIGEST6 in User Key segment (UK2) | + | 0x800 | UFS Permanent lock (UPERM) segment | + | 0x1000 | Factory and Factory Key Segments. | + | 0x2000 | UKDIGEST7 in User Key segment (HWM) | + | 0x4000 | ENVMDIGEST | + | 0x8000 | UKDIGEST8 for MSS Boot Info | + | 0x10000 | SNVM_RW_ACCESS_MAP Digest | + | 0x20000 | SBIC revocation digest | + + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @param digesterr + The digesterr parameter specifies the set bit in case of + DIGESTERR. + + | DIGESTERR[i]| Description | + |-------------|---------------------------------------------| + | 0x01 | Fabric digest | + | 0x02 | Fabric Configuration (CC) segment | + | 0x04 | ROM digest in SNVM segment | + | 0x08 | UL segment | + | 0x10 | UKDIGEST0 in User Key segment | + | 0x20 | UKDIGEST1 in User Key segment | + | 0x40 | UKDIGEST2 in User Key segment (UPK1) | + | 0x80 | UKDIGEST3 in User Key segment (UK1) | + | 0x100 | UKDIGEST4 in User Key segment (DPK) | + | 0x200 | UKDIGEST5 in User Key segment (UPK2) | + | 0x400 | UKDIGEST6 in User Key segment (UK2) | + | 0x800 | UFS Permanent lock (UPERM) segment | + | 0x1000 | Factory and Factory Key Segments. | + | 0x2000 | UKDIGEST7 in User Key segment (HWM) | + | 0x4000 | ENVMDIGEST | + | 0x8000 | UKDIGEST8 for MSS Boot Info | + | 0x10000 | SNVM_RW_ACCESS_MAP Digest | + | 0x20000 | SBIC revocation digest | + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS DIGESTERR[i] | Description | + |---------------------|----------------------------------------| + | 1 or 0 |1 is returned if any of DIGESTERR bits | + | |are set | + */ uint16_t -MSS_SYS_digest_check -( - uint32_t options, - uint8_t* digesterr, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_execute_iap() function is used to IAP service. The IAP service - allows the user to reprogram the device without the need for an external - master. The user design writes the bitstream to be programmed into a SPI Flash - connected to the SPI port. When the service is invoked, the System Controller - automatically reads the bitstream from the SPI flash and programs the device. - The service allows the image to be executed in either VERIFY or PROGRAM modes. - Another option for IAP is to perform the auto-update sequence. In this case - the newest image of the first two images in the SPI directory is chosen to be - programmed. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param iap_cmd - The iap_cmd parameter specifies the specific IAP command which - depends upon VERIFY or PROGRAM modes and the SPI address method. - - iap_cmd Description - IAP_PROGRAM_BY_SPIIDX_CMD IAP program. - IAP_VERIFY_BY_SPIIDX_CMD Fabric Configuration (CC) segment - IAP_PROGRAM_BY_SPIADDR_CMD ROM digest in SNVM segment - IAP_VERIFY_BY_SPIADDR_CMD UL segment - IAP_AUTOUPDATE_CMD UKDIGEST0 in User Key segment - @param spiaddr - The spiaddr parameter specifies the either the either the index - in the SPI directory or the SPI address in the SPI Flash memory. - Below is the list of the possible meaning of spiaddr parameter - in accordance with the iap_cmd parameter. - - iap_cmd spiaddr - IAP_PROGRAM_BY_SPIIDX_CMD Index in the SPI directory. - IAP_VERIFY_BY_SPIIDX_CMD Index in the SPI directory. - IAP_PROGRAM_BY_SPIADDR_CMD SPI address in the SPI Flash memory - IAP_VERIFY_BY_SPIADDR_CMD SPI address in the SPI Flash memory - IAP_AUTOUPDATE_CMD spiaddr is ignored as No index/ - address required for this command. - - Note: For the IAP services with command IAP_PROGRAM_BY_SPIIDX_CMD and - IAP_VERIFY_BY_SPIIDX_CMD To support recovery SPI_IDX=1 should be an - empty slot and the recovery image should be located in SPI_IDX=0. - Since SPI_IDX=1 should be an empty slot it shouldn’t be passed into - the system service. - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description | - |----------|-----------------------------------------------| - | 0 | No error | - | 1 | Validator or hash chaining mismatch | - | 2 | Unexpected data received | - | 3 | Invalid/corrupt encryption key | - | 4 | Invalid component header | - | 5 | Back level not satisfied | - | 6 | Illegal bitstream mode | - | 7 | DSN binding mismatch | - | 8 | Illegal component sequence | - | 9 | Insufficient device capabilities | - | 10 | Incorrect DEVICEID | - | 11 | Unsupported bitstream protocol version | - | | (regeneration required) | - | 12 | Verify not permitted on this bitstream | - | 13 | Invalid Device Certificate | - | 14 | Invalid DIB | - | 21 | Device not in SPI Master Mode | - | 22 | No valid images found | - | 23 | No valid images found | - | 24 | Programmed design version is newer than Auto | - | | Update image found | - | 25 | Reserved | - | 26 | Selected image was invalid and no recovery | - | | was performed due to valid design in device | - | 27 | Selected and Recovery image failed to program| - | 127 | Abort | - | 128 | NVMVERIFY | - | 129 | PROTECTED | - | 130 | NOTENA | - | 131 | PNVMVERIFY | - | 132 | SYSTEM | - | 133 | BADCOMPONENT | - | 134 | HVPROGERR | - | 135 | HVSTATE | -*/ +MSS_SYS_digest_check(uint32_t options, uint8_t* digesterr, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_execute_iap() function is used to IAP service. The IAP service + allows the user to reprogram the device without the need for an external + master. The user design writes the bitstream to be programmed into a SPI + Flash connected to the SPI port. When the service is invoked, the System + Controller automatically reads the bitstream from the SPI flash and programs + the device. The service allows the image to be executed in either VERIFY or + PROGRAM modes. Another option for IAP is to perform the auto-update sequence. + In this case the newest image of the first two images in the SPI directory is + chosen to be programmed. This function is non-blocking in the interrupt mode + , in that, it will exit immediately after requesting the service. In polling + mode, it becomes a blocking function. It will block until the the service is + completed and a response is received from the system controller. + + @param iap_cmd + The iap_cmd parameter specifies the specific IAP command which + depends upon VERIFY or PROGRAM modes and the SPI address method. + + iap_cmd Description + IAP_PROGRAM_BY_SPIIDX_CMD IAP program. + IAP_VERIFY_BY_SPIIDX_CMD Fabric Configuration (CC) segment + IAP_PROGRAM_BY_SPIADDR_CMD ROM digest in SNVM segment + IAP_VERIFY_BY_SPIADDR_CMD UL segment + IAP_AUTOUPDATE_CMD UKDIGEST0 in User Key segment + @param spiaddr + The spiaddr parameter specifies the either the either the index + in the SPI directory or the SPI address in the SPI Flash memory. + Below is the list of the possible meaning of spiaddr parameter + in accordance with the iap_cmd parameter. + + iap_cmd spiaddr + IAP_PROGRAM_BY_SPIIDX_CMD Index in the SPI directory. + IAP_VERIFY_BY_SPIIDX_CMD Index in the SPI directory. + IAP_PROGRAM_BY_SPIADDR_CMD SPI address in the SPI Flash + memory IAP_VERIFY_BY_SPIADDR_CMD SPI address in the SPI Flash memory + IAP_AUTOUPDATE_CMD spiaddr is ignored as No index/ + address required for this + command. + + Note: For the IAP services with command IAP_PROGRAM_BY_SPIIDX_CMD and + IAP_VERIFY_BY_SPIIDX_CMD To support recovery SPI_IDX=1 should be an + empty slot and the recovery image should be located in SPI_IDX=0. + Since SPI_IDX=1 should be an empty slot it shouldn’t be passed into + the system service. + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description | + |----------|-----------------------------------------------| + | 0 | No error | | 1 | Validator or hash + chaining mismatch | | 2 | Unexpected data received | | 3 + | Invalid/corrupt encryption key | | 4 | Invalid + component header | | 5 | Back level not satisfied + | | 6 | Illegal bitstream mode | | 7 | + DSN binding mismatch | | 8 | Illegal + component sequence | | 9 | Insufficient device + capabilities | | 10 | Incorrect DEVICEID | | 11 | + Unsupported bitstream protocol version | | | (regeneration + required) | | 12 | Verify not permitted on this + bitstream | | 13 | Invalid Device Certificate | | 14 | + Invalid DIB | | 21 | Device not in + SPI Master Mode | | 22 | No valid images found | | 23 + | No valid images found | | 24 | Programmed + design version is newer than Auto | | | Update image found | | 25 + | Reserved | | 26 | Selected + image was invalid and no recovery | | | was performed due to + valid design in device | | 27 | Selected and Recovery image failed to + program| | 127 | Abort | | 128 + | NVMVERIFY | | 129 | PROTECTED | + | 130 | NOTENA | | 131 | PNVMVERIFY | | 132 + | SYSTEM | | 133 | BADCOMPONENT + | | 134 | HVPROGERR | | 135 | + HVSTATE | + */ uint16_t -MSS_SYS_execute_iap -( - uint8_t iap_cmd, - uint32_t spiaddr -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_spi_copy() function allows data to be copied from the system - controller SPI flash to MSS memory. The SPI SCK frequency is specified by a - user-defined option allowing for a maximum SCK frequency of 80MHz. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param mss_dest_addr - The 64-bit mss_dest_addr parameter specifies the destination - address in MSS where system controller copies data from SPI - flash. - @param mss_spi_flash - The 32-bit mss_spi_flash parameter specifies the source - address of data to be copied in MSS. - @param n_bytes - The n_bytes parameter specifies the number of bytes to - transfer. - @param options - The 8 bit options parameter specifies the SPI clk - divider configuration. - - OPTIONS[i] Name Description - 1:0 CLKDIV SPI clock divider configuration. - 0=80MHz, 1=40MHz, - 2=20MHz, 3=13.33MHz - - 7:2 RESERVED Reserved for future use - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS |Description | - |----------|---------------------------------------------| - | 0 | Success | - | 1 | Device not configured for master mode | - | 2 | AXI Error | -*/ +MSS_SYS_execute_iap(uint8_t iap_cmd, uint32_t spiaddr); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_spi_copy() function allows data to be copied from the system + controller SPI flash to MSS memory. The SPI SCK frequency is specified by a + user-defined option allowing for a maximum SCK frequency of 80MHz. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param mss_dest_addr + The 64-bit mss_dest_addr parameter specifies the + destination address in MSS where system controller copies data from SPI + flash. + @param mss_spi_flash + The 32-bit mss_spi_flash parameter specifies the source + address of data to be copied in MSS. + @param n_bytes + The n_bytes parameter specifies the number of bytes to + transfer. + @param options + The 8 bit options parameter specifies the SPI clk + divider configuration. + + OPTIONS[i] Name Description + 1:0 CLKDIV SPI clock divider configuration. + 0=80MHz, 1=40MHz, + 2=20MHz, 3=13.33MHz + + 7:2 RESERVED Reserved for future use + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS |Description | + |----------|---------------------------------------------| + | 0 | Success | + | 1 | Device not configured for master mode | + | 2 | AXI Error | + */ uint16_t -MSS_SYS_spi_copy -( - uint64_t mss_dest_addr, - uint32_t mss_spi_flash, - uint32_t n_bytes, - uint8_t options, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_debug_read_probe() function will read the content of a - probe module (59 x 18b words). - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - Note: The IPROWADDR & IPSEGADDR addresses are not incremented as the - associated address space is not contiguous. If PRBADDR is 63 it will - wrap back to 0. - - @param ipseg_addr - The ipseg_addr parameter specifies the probe segment - address. - @param iprow_addr - The iprow_addr parameter specifies the probe row address. - ipseg_addr and iprow_addr parameters specifies the target - address of probe module. - @param prdata - The prdata parameter specifies the read data for probe - word i(0 to 58) within the probe module. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @param resp_offset - The resp_offset parameter specifies the offset of the - start of Mailbox response where the data received from - the service will be available. - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description | | - |---------|---------------|-------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by | - | | | device security. | -*/ +MSS_SYS_spi_copy( + uint64_t mss_dest_addr, uint32_t mss_spi_flash, uint32_t n_bytes, + uint8_t options, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_debug_read_probe() function will read the content of a + probe module (59 x 18b words). + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + Note: The IPROWADDR & IPSEGADDR addresses are not incremented as the + associated address space is not contiguous. If PRBADDR is 63 it will + wrap back to 0. + + @param ipseg_addr + The ipseg_addr parameter specifies the probe segment + address. + @param iprow_addr + The iprow_addr parameter specifies the probe row address. + ipseg_addr and iprow_addr parameters specifies the target + address of probe module. + @param prdata + The prdata parameter specifies the read data for probe + word i(0 to 58) within the probe module. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @param resp_offset + The resp_offset parameter specifies the offset of the + start of Mailbox response where the data received from + the service will be available. + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description | | + |---------|---------------|-------------------------------| + | 0 | Success | | + | 1 | SECERR | The operation was blocked by | + | | | device security. | + */ uint16_t -MSS_SYS_debug_read_probe -( - uint8_t ipseg_addr, - uint8_t iprow_addr, - uint8_t *prdata, - uint16_t mb_offset, - uint8_t resp_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_debug_write_probe() function will writes up to 18 bits of - data to selected probe address. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param prb_addr - The prb_addr parameter specifies the probe address. - @param ipseg_addr - The ipseg_addr parameter specifies the probe segment - address. - @param iprow_addr - The iprow_addr parameter specifies the probe row address. - prb_addr, ipseg_addr and iprow_addr parameters specifies - the target address of one of the 59 words within a probe - module. - @param pwmask - The pwmask parameter specifies the which of the 18 bits of - pwdata shall be written to selected probe module. - @param pwdata - The pwdata parameter specifies the value to be written on - selected probe registers. - Example: If PWMASK[i] is ‘1’ then probe register i will - be written to the value specified by PWDATA[i]. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description | | - |---------|---------------|-------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by | - | | | device security. | -*/ +MSS_SYS_debug_read_probe( + uint8_t ipseg_addr, uint8_t iprow_addr, uint8_t* prdata, uint16_t mb_offset, + uint8_t resp_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_debug_write_probe() function will writes up to 18 bits of + data to selected probe address. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param prb_addr + The prb_addr parameter specifies the probe address. + @param ipseg_addr + The ipseg_addr parameter specifies the probe segment + address. + @param iprow_addr + The iprow_addr parameter specifies the probe row address. + prb_addr, ipseg_addr and iprow_addr parameters specifies + the target address of one of the 59 words within a probe + module. + @param pwmask + The pwmask parameter specifies the which of the 18 bits of + pwdata shall be written to selected probe module. + @param pwdata + The pwdata parameter specifies the value to be written on + selected probe registers. + Example: If PWMASK[i] is ‘1’ then probe register i will + be written to the value specified by PWDATA[i]. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description | | + |---------|---------------|-------------------------------| + | 0 | Success | | + | 1 | SECERR | The operation was blocked by | + | | | device security. | + */ uint16_t -MSS_SYS_debug_write_probe -( - uint8_t prb_addr, - uint8_t ipseg_addr, - uint8_t iprow_addr, - uint32_t pwmask, - uint32_t pwdata, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_debug_live_probe() function will configures channel a or - b of the live probe system. A live probe is enabled by writing a local - address register within one of the probe segment modules. Each probe segment - module generates its own local channel a live probe outputs which are - combined by OR chains to generate a chip-level live probe channel a signal. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - Note: - When configuring channel a, channel b is not affected and vice versa. - - Live probes are intentionally not cleared by JTAG reset. - They remain in effect until either manually disabled or the device is - reset. - - @param x_addr - The parameter x_addr specifies the x co-ordinate within - target probe module. - @param y_addr - The parameter y_addr specifies the y co-ordinate within - the target probe module. - @param ipseg_addr - The ipseg_addr parameter specifies the probe segment - address. - @param iprow_addr - The iprow_addr parameter specifies the probe row address. - ipseg_addr and iprow_addr parameters specifies the target - address of probe module. - @param clear - The clear parameter is used to clear the configurations of - local channels a or b. If CLEAR is ‘1’, all local channel - x (the applicable channel a or b) configurations are - cleared before applying the new configuration - @param ioen - The ioen parameter is used to activate the probe output - pad. If IOEN is ‘1’ then the corresponding live probe - output pad is activated. Note that setting IOEN to ‘0’ - does not disable the internal live probe configuration. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @param service_cmd - The service_cmd parameter specifies the channel(channel - a or b) selected by the user. User have to provide one of - the predefined macros to select the channel for live probe - debug operation. - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description | | - |---------|---------------|-------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by | - | | | device security. | -*/ +MSS_SYS_debug_write_probe( + uint8_t prb_addr, uint8_t ipseg_addr, uint8_t iprow_addr, uint32_t pwmask, + uint32_t pwdata, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_debug_live_probe() function will configures channel a or + b of the live probe system. A live probe is enabled by writing a local + address register within one of the probe segment modules. Each probe segment + module generates its own local channel a live probe outputs which are + combined by OR chains to generate a chip-level live probe channel a signal. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + Note: - When configuring channel a, channel b is not affected and vice versa. + - Live probes are intentionally not cleared by JTAG reset. + They remain in effect until either manually disabled or the device is + reset. + + @param x_addr + The parameter x_addr specifies the x co-ordinate within + target probe module. + @param y_addr + The parameter y_addr specifies the y co-ordinate within + the target probe module. + @param ipseg_addr + The ipseg_addr parameter specifies the probe segment + address. + @param iprow_addr + The iprow_addr parameter specifies the probe row address. + ipseg_addr and iprow_addr parameters specifies the target + address of probe module. + @param clear + The clear parameter is used to clear the configurations of + local channels a or b. If CLEAR is ‘1’, all local channel + x (the applicable channel a or b) configurations are + cleared before applying the new configuration + @param ioen + The ioen parameter is used to activate the probe output + pad. If IOEN is ‘1’ then the corresponding live probe + output pad is activated. Note that setting IOEN to ‘0’ + does not disable the internal live probe configuration. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @param service_cmd + The service_cmd parameter specifies the channel(channel + a or b) selected by the user. User have to provide one of + the predefined macros to select the channel for live probe + debug operation. + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description | | + |---------|---------------|-------------------------------| + | 0 | Success | | + | 1 | SECERR | The operation was blocked by | + | | | device security. | + */ uint16_t -MSS_SYS_debug_live_probe -( - uint8_t x_addr, - uint8_t y_addr, - uint8_t ipseg_addr, - uint8_t iprow_addr, - uint8_t clear, - uint8_t ioen, - uint16_t mb_offset, - uint8_t service_cmd -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_debug_select_mem() function will specifies a target - fabric memory to be accessed by the MEM read & MEM write services. - A handshake mechanism is used to request access to the target memory. The - memory lock may be acquired immediately allowing multiple read/write - operations to be performed as one logical transaction or the lock may be - acquired and released by individual read/write operations. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param ipblk_addr - The ipblk_addr parameter specifies the block address of - fabric memory. - @param ipseg_addr - The ipseg_addr parameter specifies the segment address. - @param iprow_addr - The iprow_addr parameter specifies the row address of - fabric memory to be accessed by MEM read and MEM write - services. - @param memtype - The memtype parameter specifies the type of fabric - memory to be used for MEM read and write services. - - MEMTYPE Peripheral MEMSIZE(words) Access Width - 0 LSRAM x1 16384 1 - 1 LSRAM x2 8192 2 - 2 LSRAM x5 4096 5 - 3 LSRAM x10 2048 10 - 4 LSRAM x20 1024 20 - 5 µRAM 64 12 - 6 µPROM 256 9 - 7 LSRAM x20 1024 20 - @param memlock_mode - The memlock_mode parameter specifies the the memory - lock states for supported MEMLOCKMODE values. - @param timeout - When a lock is requested we must consider a scenario - where the user design may not complete the request - handshake. To prevent the firmware from waiting - indefinitely, the user must specify a timeout after - which time the handshake is aborted. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description | | - |---------|---------------|-------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by | - | | | device security. | - | 2 | TIMEOUTERR | Timeout occurred. | - | 3 | LOCKERR | Target memory failed to lock | -*/ +MSS_SYS_debug_live_probe( + uint8_t x_addr, uint8_t y_addr, uint8_t ipseg_addr, uint8_t iprow_addr, + uint8_t clear, uint8_t ioen, uint16_t mb_offset, uint8_t service_cmd); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_debug_select_mem() function will specifies a target + fabric memory to be accessed by the MEM read & MEM write services. + A handshake mechanism is used to request access to the target memory. The + memory lock may be acquired immediately allowing multiple read/write + operations to be performed as one logical transaction or the lock may be + acquired and released by individual read/write operations. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param ipblk_addr + The ipblk_addr parameter specifies the block address of + fabric memory. + @param ipseg_addr + The ipseg_addr parameter specifies the segment address. + @param iprow_addr + The iprow_addr parameter specifies the row address of + fabric memory to be accessed by MEM read and MEM write + services. + @param memtype + The memtype parameter specifies the type of fabric + memory to be used for MEM read and write services. + + MEMTYPE Peripheral MEMSIZE(words) Access Width + 0 LSRAM x1 16384 1 + 1 LSRAM x2 8192 2 + 2 LSRAM x5 4096 5 + 3 LSRAM x10 2048 10 + 4 LSRAM x20 1024 20 + 5 µRAM 64 12 + 6 µPROM 256 9 + 7 LSRAM x20 1024 20 + @param memlock_mode + The memlock_mode parameter specifies the the memory + lock states for supported MEMLOCKMODE values. + @param timeout + When a lock is requested we must consider a scenario + where the user design may not complete the request + handshake. To prevent the firmware from waiting + indefinitely, the user must specify a timeout after + which time the handshake is aborted. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description | | + |---------|---------------|-------------------------------| + | 0 | Success | | + | 1 | SECERR | The operation was blocked by | + | | | device security. | + | 2 | TIMEOUTERR | Timeout occurred. | + | 3 | LOCKERR | Target memory failed to lock | + */ uint16_t -MSS_SYS_debug_select_mem -( - uint8_t ipblk_addr, - uint8_t ipseg_addr, - uint8_t iprow_addr, - uint8_t memtype, - uint8_t memlock_mode, - uint16_t timeout, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_debug_read_mem() function provides an interface to read - data from the memory peripheral that is specified. A handshake mechanism is - used to request access to the target memory. The memory lock may be acquired - immediately allowing multiple read/write operations to be performed as one - logical transaction. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param mem_addr - The mem_addr parameter sets the target address within the - currently selected memory peripheral for subsequent - mem write & mem read instructions. - @param n_words - The n_words parameter value depends on memtype. The - maximum limit is the size of memory. - @param mss_addr - The mss_addr parameter specifies the MSS RAM area where - to copy the MEM Read data to. Note that all accesses will - be done with MSS User privileges. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description | | - |---------|---------------|-------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by | - | | | device security. | - | 2 | TIMEOUTERR | Timeout occurred. | - | 3 | LOCKERR | Target memory failed to lock | -*/ +MSS_SYS_debug_select_mem( + uint8_t ipblk_addr, uint8_t ipseg_addr, uint8_t iprow_addr, uint8_t memtype, + uint8_t memlock_mode, uint16_t timeout, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_debug_read_mem() function provides an interface to read + data from the memory peripheral that is specified. A handshake mechanism is + used to request access to the target memory. The memory lock may be acquired + immediately allowing multiple read/write operations to be performed as one + logical transaction. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param mem_addr + The mem_addr parameter sets the target address within the + currently selected memory peripheral for subsequent + mem write & mem read instructions. + @param n_words + The n_words parameter value depends on memtype. The + maximum limit is the size of memory. + @param mss_addr + The mss_addr parameter specifies the MSS RAM area where + to copy the MEM Read data to. Note that all accesses will + be done with MSS User privileges. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description | | + |---------|---------------|-------------------------------| + | 0 | Success | | + | 1 | SECERR | The operation was blocked by | + | | | device security. | + | 2 | TIMEOUTERR | Timeout occurred. | + | 3 | LOCKERR | Target memory failed to lock | + */ uint16_t -MSS_SYS_debug_read_mem -( - uint16_t mem_addr, - uint16_t n_words, - uint64_t mss_addr, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_debug_write_mem() function provides an interface to write - data from the memory peripheral that is specified. A handshake mechanism is - used to request access to the target memory. The memory lock may be acquired - immediately allowing multiple read/write operations to be performed as one - logical transaction. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param mem_addr - The mem_addr parameter sets the target address within the - currently selected memory peripheral for subsequent - mem write & mem read instructions. - @param n_words - The n_words parameter value depends on memtype. The - maximum limit is the size of memory. - @param mss_addr - The mss_addr parameter specifies the MSS RAM area where - to copy the MEM Read data to. Note that all accesses will - be done with MSS User privileges. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description | | - |---------|---------------|-------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by | - | | | device security. | - | 2 | TIMEOUTERR | Timeout occurred. | - | 3 | LOCKERR | Target memory failed to lock | -*/ +MSS_SYS_debug_read_mem( + uint16_t mem_addr, uint16_t n_words, uint64_t mss_addr, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_debug_write_mem() function provides an interface to write + data from the memory peripheral that is specified. A handshake mechanism is + used to request access to the target memory. The memory lock may be acquired + immediately allowing multiple read/write operations to be performed as one + logical transaction. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param mem_addr + The mem_addr parameter sets the target address within the + currently selected memory peripheral for subsequent + mem write & mem read instructions. + @param n_words + The n_words parameter value depends on memtype. The + maximum limit is the size of memory. + @param mss_addr + The mss_addr parameter specifies the MSS RAM area where + to copy the MEM Read data to. Note that all accesses will + be done with MSS User privileges. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description | | + |---------|---------------|-------------------------------| + | 0 | Success | | + | 1 | SECERR | The operation was blocked by | + | | | device security. | + | 2 | TIMEOUTERR | Timeout occurred. | + | 3 | LOCKERR | Target memory failed to lock | + */ uint16_t -MSS_SYS_debug_write_mem -( - uint16_t mem_addr, - uint16_t n_words, - uint64_t mss_addr, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_debug_read_apb() function reads a specified number of bytes - from the fabric APB bus to the specified MSS RAM area. The operation makes - the required number of read transactions using the selected transaction size, - APBDWSIZE. - The addressed fabric peripheral may generate an error or fail to respond - within a user-defined window, in which case any subsequent transfers are - aborted and corresponding error flags are returned. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param apb_addr - The apb_addr parameter specifies the target address and - transfer size for the apb write & apb read operations. - @param apb_wsize - The apb_wsize parameter specifies the data transfer size - to be used by the apb write & apb read operations. - @param max_bytes - The max_bytes parameter is used in calculation specified - number of bytes from the fabric APB bus to the Shared - Buffer. - NBYTES = MAXBYTES + 1 - @param mss_addr - The mss_addr parameter specifies the MSS RAM area where - to copy the MEM Read data to. Note that all accesses will - be done with MSS User privileges. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description| | - |---------|------------|-------------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by device | - | | | security. | - | 2 | SLVERR | The addressed fabric APB peripheral | - | | | generated a SLVERR response to the | - | | | bus transaction. | - | 3 | TIMEOUT | The addressed fabric APB peripheral | - | | | failed to respond before the | - | | | user-defined APB timeout or the | - | | | fabric power is not on. | -*/ +MSS_SYS_debug_write_mem( + uint16_t mem_addr, uint16_t n_words, uint64_t mss_addr, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_debug_read_apb() function reads a specified number of bytes + from the fabric APB bus to the specified MSS RAM area. The operation makes + the required number of read transactions using the selected transaction size, + APBDWSIZE. + The addressed fabric peripheral may generate an error or fail to respond + within a user-defined window, in which case any subsequent transfers are + aborted and corresponding error flags are returned. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param apb_addr + The apb_addr parameter specifies the target address and + transfer size for the apb write & apb read operations. + @param apb_wsize + The apb_wsize parameter specifies the data transfer size + to be used by the apb write & apb read operations. + @param max_bytes + The max_bytes parameter is used in calculation specified + number of bytes from the fabric APB bus to the Shared + Buffer. + NBYTES = MAXBYTES + 1 + @param mss_addr + The mss_addr parameter specifies the MSS RAM area where + to copy the MEM Read data to. Note that all accesses will + be done with MSS User privileges. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description| | + |---------|------------|-------------------------------------| + | 0 | Success | | | 1 | SECERR | The + operation was blocked by device | | | | security. | | 2 | + SLVERR | The addressed fabric APB peripheral | | | | + generated a SLVERR response to the | | | | bus + transaction. | | 3 | TIMEOUT | The addressed + fabric APB peripheral | | | | failed to respond before the + | | | | user-defined APB timeout or the | | | + | fabric power is not on. | + */ uint16_t -MSS_SYS_debug_read_apb -( - uint32_t apb_addr, - uint8_t apb_wsize, - uint16_t max_bytes, - uint64_t mss_addr, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_debug_write_apb() function writes bytes of data to the - current fabric APB address as specified by APBADDR. The addressed fabric - peripheral may generate an error or fail to respond within a user-defined - window, in which case the corresponding error flags are returned. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param apb_addr - The apb_addr parameter specifies the target address and - transfer size for the apb write & apb read operations. - @param apb_wsize - The apb_wsize parameter specifies the data transfer size - to be used by the apb write & apb read operations. - @param max_bytes - The max_bytes parameter is used in calculation specified - number of bytes from the fabric APB bus to the Shared - Buffer. - NBYTES = MAXBYTES + 1 - @param mss_addr - The mss_addr parameter specifies the MSS RAM area where - to copy the MEM Read data to. Note that all accesses will - be done with MSS User privileges. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description| | - |---------|------------|-------------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by device | - | | | security. | - | 2 | SLVERR | The addressed fabric APB peripheral | - | | | generated a SLVERR response to the | - | | | bus transaction. | - | 3 | TIMEOUT | The addressed fabric APB peripheral | - | | | failed to respond before the | - | | | user-defined APB timeout or the | - | | | fabric power is not on. | -*/ +MSS_SYS_debug_read_apb( + uint32_t apb_addr, uint8_t apb_wsize, uint16_t max_bytes, uint64_t mss_addr, + uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_debug_write_apb() function writes bytes of data to the + current fabric APB address as specified by APBADDR. The addressed fabric + peripheral may generate an error or fail to respond within a user-defined + window, in which case the corresponding error flags are returned. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param apb_addr + The apb_addr parameter specifies the target address and + transfer size for the apb write & apb read operations. + @param apb_wsize + The apb_wsize parameter specifies the data transfer size + to be used by the apb write & apb read operations. + @param max_bytes + The max_bytes parameter is used in calculation specified + number of bytes from the fabric APB bus to the Shared + Buffer. + NBYTES = MAXBYTES + 1 + @param mss_addr + The mss_addr parameter specifies the MSS RAM area where + to copy the MEM Read data to. Note that all accesses will + be done with MSS User privileges. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description| | + |---------|------------|-------------------------------------| + | 0 | Success | | | 1 | SECERR | The + operation was blocked by device | | | | security. | | 2 | + SLVERR | The addressed fabric APB peripheral | | | | + generated a SLVERR response to the | | | | bus + transaction. | | 3 | TIMEOUT | The addressed + fabric APB peripheral | | | | failed to respond before the + | | | | user-defined APB timeout or the | | | + | fabric power is not on. | + */ uint16_t -MSS_SYS_debug_write_apb -( - uint32_t apb_addr, - uint8_t apb_wsize, - uint16_t max_bytes, - uint64_t mss_addr, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_debug_fabric_snapshot() function will service generates a - snapshot of the volatile fabric content. Data is read from each LSRAM, µRAM - and probe module and copied to the fabric APB debug port. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param port_addr - The port_addr parameter sets the address of the APB port - to be used for bulk access debug instructions which are - used in conjunction with Microsemi fabric debug IP. - The debug port is a single location on the fabric APB - bus through which debug data is streamed. - @param apb_fast_write - The apb_fast_write parameter specifies whether to use - the fast apb protocol. If apb_fast_write is ‘1’ then, - during write transfers, the fast APB protocol is used - and the address range is limited to port_addr[15:2] and - port_addr[28:16] is ignored. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description| | - |---------|------------|-------------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by device | - | | | security. | - | 2 | BUSERR | Bus error occurred and the snapshot | - | | | was aborted. | -*/ +MSS_SYS_debug_write_apb( + uint32_t apb_addr, uint8_t apb_wsize, uint16_t max_bytes, uint64_t mss_addr, + uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_debug_fabric_snapshot() function will service generates a + snapshot of the volatile fabric content. Data is read from each LSRAM, µRAM + and probe module and copied to the fabric APB debug port. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param port_addr + The port_addr parameter sets the address of the APB port + to be used for bulk access debug instructions which are + used in conjunction with Microsemi fabric debug IP. + The debug port is a single location on the fabric APB + bus through which debug data is streamed. + @param apb_fast_write + The apb_fast_write parameter specifies whether to use + the fast apb protocol. If apb_fast_write is ‘1’ then, + during write transfers, the fast APB protocol is used + and the address range is limited to port_addr[15:2] and + port_addr[28:16] is ignored. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description| | + |---------|------------|-------------------------------------| + | 0 | Success | | | 1 | SECERR | The + operation was blocked by device | | | | security. | | 2 | + BUSERR | Bus error occurred and the snapshot | | | | + was aborted. | + */ uint16_t -MSS_SYS_debug_fabric_snapshot -( - uint32_t port_addr, - uint8_t apb_fast_write, - uint16_t mb_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_otp_generate() function is used to set up the device to - The receive a one-time passcode. A 128-bit nonce, NFPGA, is generated and - The stored in volatile memory for later use in the rest of the protocol. - The A 128-bit user nonce, NUSER, is supplied by the user. - This service only unlocks the software debug lock SWL_DEBUG. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param keymode - keymode parameter specifies the key mode to be used to - transport the encrypted passcode. - The KEYMODE parameter is not checked for validity until the - MATCH OTP service is executed. Both PCTYPE and KEYMODE are - stored in volatile memory for use by the MATCH OTP service. - - Supported values for KEYMODE are shown below. - PCTYPE KEYMODE Key Mode KROOT Note - 1 3 KM_USER_KEY1 UK1 User key 1 - 1 4 KM_USER_KEY2 UK2 User key 2 - 1 7 KM_FACTORY_KEY DFK FK diversified by UID - @param n_user - The n_user parameter specifies the user nonce, is supplied - by the user. - @param n_fpga - The n_fpga parameter specifies the 128-bit nonce, NFPGA, is - generated and stored in volatile memory for later use in the - rest of the protocol. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @param ret_offset - The ret_offset parameter specifies the offset of the - start of Mailbox response where the data received from - the service will be available. - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - If any part of the service fails, then all unlocked - passcodes are re-locked and the tamper event - PASSCODE_FAIL is generated. - - | STATUS | Description| | - |---------|------------|-------------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by device | - | | | security. | - | 2 | PROTOCOLERR| If an invalid key mode is specified | - | | | fails then the returned nonce is | - | | | 0^128, the protocol is aborted and | - | | | the tamper event PASSCODE_FAIL is | - | | | generated. | -*/ +MSS_SYS_debug_fabric_snapshot( + uint32_t port_addr, uint8_t apb_fast_write, uint16_t mb_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_otp_generate() function is used to set up the device to + The receive a one-time passcode. A 128-bit nonce, NFPGA, is generated and + The stored in volatile memory for later use in the rest of the protocol. + The A 128-bit user nonce, NUSER, is supplied by the user. + This service only unlocks the software debug lock SWL_DEBUG. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param keymode + keymode parameter specifies the key mode to be used to + transport the encrypted passcode. + The KEYMODE parameter is not checked for validity until the + MATCH OTP service is executed. Both PCTYPE and KEYMODE are + stored in volatile memory for use by the MATCH OTP service. + + Supported values for KEYMODE are shown below. + PCTYPE KEYMODE Key Mode KROOT Note + 1 3 KM_USER_KEY1 UK1 User key 1 + 1 4 KM_USER_KEY2 UK2 User key 2 + 1 7 KM_FACTORY_KEY DFK FK diversified by + UID + @param n_user + The n_user parameter specifies the user nonce, is supplied + by the user. + @param n_fpga + The n_fpga parameter specifies the 128-bit nonce, NFPGA, is + generated and stored in volatile memory for later use in + the rest of the protocol. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @param ret_offset + The ret_offset parameter specifies the offset of the + start of Mailbox response where the data received from + the service will be available. + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + If any part of the service fails, then all unlocked + passcodes are re-locked and the tamper event + PASSCODE_FAIL is generated. + + | STATUS | Description| | + |---------|------------|-------------------------------------| + | 0 | Success | | | 1 | SECERR | The + operation was blocked by device | | | | security. | | 2 | + PROTOCOLERR| If an invalid key mode is specified | | | | + fails then the returned nonce is | | | | 0^128, the + protocol is aborted and | | | | the tamper event + PASSCODE_FAIL is | | | | generated. | + */ uint16_t -MSS_SYS_otp_generate -( - uint8_t keymode, - uint8_t* n_user, - uint8_t* n_fpga, - uint16_t mb_offset, - uint16_t resp_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_otp_match() function is the second part of the one-time - passcode protocol. Before using this service the GENERATE OTP service must - first be used to obtain a nonce, NFPGA, from the device. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param user_id - The UID parameter is only used if the KEYMODE used for - the GENERATE OTP service was KEYMODE_FACTORY_KEY and the - passcode was not the Factory Passcode. - @param validator - The 256-bit validator parameter store the validator key. - @param otp - The otp parameter stores the otp value from generate otp - service. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @param resp_offset - The resp_offset parameter specifies the offset from the - start of Mailbox response where the data received from - the service will be available. - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS| Description | - |------|-----------------| - | 0 | Success | - | 1 | PROTOCOLERR | - | 2 | MISMATCHERR | -*/ +MSS_SYS_otp_generate( + uint8_t keymode, uint8_t* n_user, uint8_t* n_fpga, uint16_t mb_offset, + uint16_t resp_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_otp_match() function is the second part of the one-time + passcode protocol. Before using this service the GENERATE OTP service must + first be used to obtain a nonce, NFPGA, from the device. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param user_id + The UID parameter is only used if the KEYMODE used for + the GENERATE OTP service was KEYMODE_FACTORY_KEY and the + passcode was not the Factory Passcode. + @param validator + The 256-bit validator parameter store the validator key. + @param otp + The otp parameter stores the otp value from generate otp + service. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @param resp_offset + The resp_offset parameter specifies the offset from the + start of Mailbox response where the data received from + the service will be available. + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS| Description | + |------|-----------------| + | 0 | Success | + | 1 | PROTOCOLERR | + | 2 | MISMATCHERR | + */ uint16_t -MSS_SYS_otp_match -( - uint8_t * user_id, - uint8_t * validator, - uint8_t * otp, - uint16_t mb_offset, - uint16_t resp_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_unlock_debug_passcode() function will Attempt to match - the user debug pass code using the key loaded into the mailbox. If the match - is successful the software debug lock SWL_DEBUG is temporarily inactive. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param cmd_data - The parameter cmd_data specifies the device's debug - passcode (DPK), configured by the user via bitstream. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @param ret_offset - The ret_offset parameter specifies the offset from the - start of Mailbox response where the data received from - the service will be available. - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description| | - |---------|------------|-------------------------------------| - | 0 | Success | | - | 1 | SECERR | The operation was blocked by device | - | | | security. | - | 2 | PROTOCOLERR| If the unlock operation fail for any| - | | | reason, then the tamper event | - | | | PASSCODE_FAIL is generated. | - - If any part of the service fails, then all unlocked passcodes are re-locked - and the tamper event PASSCODE_FAIL is generated. -*/ +MSS_SYS_otp_match( + uint8_t* user_id, uint8_t* validator, uint8_t* otp, uint16_t mb_offset, + uint16_t resp_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_unlock_debug_passcode() function will Attempt to match + the user debug pass code using the key loaded into the mailbox. If the match + is successful the software debug lock SWL_DEBUG is temporarily inactive. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param cmd_data + The parameter cmd_data specifies the device's debug + passcode (DPK), configured by the user via bitstream. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @param ret_offset + The ret_offset parameter specifies the offset from the + start of Mailbox response where the data received from + the service will be available. + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description| | + |---------|------------|-------------------------------------| + | 0 | Success | | | 1 | SECERR | The + operation was blocked by device | | | | security. | | 2 | + PROTOCOLERR| If the unlock operation fail for any| | | | + reason, then the tamper event | | | | PASSCODE_FAIL + is generated. | + + If any part of the service fails, then all unlocked passcodes are re-locked + and the tamper event PASSCODE_FAIL is generated. + */ uint16_t -MSS_SYS_unlock_debug_passcode -( - uint8_t* cmd_data, - uint16_t mb_offset, - uint16_t resp_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_one_way_passcode() function is used to provide a - mechanism for overriding the software debug lock SWL_DEBUG without requiring - any interaction with an external intelligence. - The following conditions must be met for the OWP to proceed and write the - payload HWM to the device: - • HWM stored in the device must be valid - • OWP passcode matches - • Payload HWM is greater than the HWM stored in the device - After HWM is written the OWP is successful and SWL_DEBUG is unlocked. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param msg_id - The msg_id parameter stores the value of message ID. - @param validator - The 256-bit validator parameter store the validator key. - @param keymode - The Keymode parameter specifies the permitted keymodes for - OWP service. - - KEYID Key Mode Permitted - 0 KM_INIT_FACTORY No - 1 KM_ZERO_RECOVERY No - 2 KM_DEFAULT_KEY Yes - 3 KM_USER_KEY1 Yes - 4 KM_USER_KEY2 Yes - 5 - - 6 KM_AUTH_CODE No - 7 KM_FACTORY_KEY Yes - 8 KM_FACTORY_EC No - 9 KM_FACTORY_EC_E No - 10 - - 11 - - 12 KM_USER_EC No - 13 KM_USER_EC_E No - 14 - - 15 - - - @param dsn - The dsn parameter stores the value of device serial number. - @param hash - The hash parameter stores 256-bit hash value. - - @param plaintext_passcode - The plaintext_passcode parameter stores the passcode value. - @param hwm - The hwm parameter stores the high water mark value. - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @param ret_offset - The ret_offset parameter specifies the offset from the - start of Mailbox response where the data received from - the service will be available. - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - | STATUS | Description| | - |---------|------------|-------------------------------------| - | 0 | Success | | - | 1 | OWPERR | If the unlock operation fail for any| - | | | reason, then the tamper event | - | | | PASSCODE_FAIL is generated. | - - If any part of the service fails, then all unlocked passcodes are re-locked - and the tamper event PASSCODE_FAIL is generated. -*/ +MSS_SYS_unlock_debug_passcode( + uint8_t* cmd_data, uint16_t mb_offset, uint16_t resp_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_one_way_passcode() function is used to provide a + mechanism for overriding the software debug lock SWL_DEBUG without requiring + any interaction with an external intelligence. + The following conditions must be met for the OWP to proceed and write the + payload HWM to the device: + • HWM stored in the device must be valid + • OWP passcode matches + • Payload HWM is greater than the HWM stored in the device + After HWM is written the OWP is successful and SWL_DEBUG is unlocked. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param msg_id + The msg_id parameter stores the value of message ID. + @param validator + The 256-bit validator parameter store the validator key. + @param keymode + The Keymode parameter specifies the permitted keymodes for + OWP service. + + KEYID Key Mode Permitted + 0 KM_INIT_FACTORY No + 1 KM_ZERO_RECOVERY No + 2 KM_DEFAULT_KEY Yes + 3 KM_USER_KEY1 Yes + 4 KM_USER_KEY2 Yes + 5 - + 6 KM_AUTH_CODE No + 7 KM_FACTORY_KEY Yes + 8 KM_FACTORY_EC No + 9 KM_FACTORY_EC_E No + 10 - + 11 - + 12 KM_USER_EC No + 13 KM_USER_EC_E No + 14 - + 15 - + + @param dsn + The dsn parameter stores the value of device serial number. + @param hash + The hash parameter stores 256-bit hash value. + + @param plaintext_passcode + The plaintext_passcode parameter stores the passcode value. + @param hwm + The hwm parameter stores the high water mark value. + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @param ret_offset + The ret_offset parameter specifies the offset from the + start of Mailbox response where the data received from + the service will be available. + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + | STATUS | Description| | + |---------|------------|-------------------------------------| + | 0 | Success | | | 1 | OWPERR | If the + unlock operation fail for any| | | | reason, then the + tamper event | | | | PASSCODE_FAIL is generated. | + + If any part of the service fails, then all unlocked passcodes are re-locked + and the tamper event PASSCODE_FAIL is generated. + */ uint16_t -MSS_SYS_one_way_passcode -( - uint8_t* msg_id, - uint8_t* validator, - uint8_t keymode, - uint8_t* dsn, - uint8_t* hash, - uint8_t* plaintext_passcode, - uint8_t* hwm, - uint16_t mb_offset, - uint16_t resp_offset -); - -/*-------------------------------------------------------------------------*//** - The MSS_SYS_debug_terminate() function will terminate the debug - session. Its purpose is to re-lock all the software based debug locks - (SWL_DEBUG) if needed and to release any memories previously locked using - the MEM Select Debug Service. - This function is non-blocking in the interrupt mode , in that, it will exit - immediately after requesting the service. In polling mode, it becomes a - blocking function. It will block until the the service is completed and a - response is received from the system controller. - - @param mb_offset - The mb_offset parameter specifies the offset from the start - of mailbox where the data related to this service is - available. All accesses to the mailbox are of word length - (4 bytes). A value 10 (decimal) of this parameter would - mean that the data access area for this service, in the - mailbox starts from 11th word (offset 10). - @param resp_offset - The resp_offset parameter specifies the offset from the - start of Mailbox, where the data received from - the service will be available. - @return - This function returns a value to indicate whether the - service was executed successfully or not. A zero value - indicates that the service was executed successfully. A - non-zero value can indicate that either the driver was not - able to kick-start the service or that the driver was able - to kick-start the service and receive a status response code - from the system controller. - See theory of operations section for detailed information - about the return status. - The following table lists the service status code from - system controller. - - |STATUS | Description | - |-------|--------------| - | 0 | Success | -*/ +MSS_SYS_one_way_passcode( + uint8_t* msg_id, uint8_t* validator, uint8_t keymode, uint8_t* dsn, + uint8_t* hash, uint8_t* plaintext_passcode, uint8_t* hwm, + uint16_t mb_offset, uint16_t resp_offset); + +/*-------------------------------------------------------------------------*/ /** + The MSS_SYS_debug_terminate() function will terminate the debug + session. Its purpose is to re-lock all the software based debug locks + (SWL_DEBUG) if needed and to release any memories previously locked using + the MEM Select Debug Service. + This function is non-blocking in the interrupt mode , in that, it will exit + immediately after requesting the service. In polling mode, it becomes a + blocking function. It will block until the the service is completed and a + response is received from the system controller. + + @param mb_offset + The mb_offset parameter specifies the offset from the start + of mailbox where the data related to this service is + available. All accesses to the mailbox are of word length + (4 bytes). A value 10 (decimal) of this parameter would + mean that the data access area for this service, in the + mailbox starts from 11th word (offset 10). + @param resp_offset + The resp_offset parameter specifies the offset from the + start of Mailbox, where the data received from + the service will be available. + @return + This function returns a value to indicate whether the + service was executed successfully or not. A zero value + indicates that the service was executed successfully. A + non-zero value can indicate that either the driver was not + able to kick-start the service or that the driver was able + to kick-start the service and receive a status response + code from the system controller. See theory of operations section for + detailed information about the return status. The following table lists the + service status code from system controller. + + |STATUS | Description | + |-------|--------------| + | 0 | Success | + */ uint16_t -MSS_SYS_debug_terminate -( - uint16_t mb_offset, - uint16_t resp_offset -); - -typedef struct -{ - volatile uint32_t SOFT_RESET; - volatile uint32_t VDETECTOR; - volatile uint32_t TVS_CONTROL; - volatile uint32_t TVS_TEMP_A; - volatile uint32_t TVS_TEMP_B; - volatile uint32_t TVS_TEMP_C; - volatile uint32_t TVS_VOLT_A; - volatile uint32_t TVS_VOLT_B; - volatile uint32_t TVS_VOLT_C; - volatile uint32_t TVS_OUTPUT0; - volatile uint32_t TVS_OUTPUT1; - volatile uint32_t TVS_TRIGGER; - volatile uint32_t TRIM_VDET1P05; - volatile uint32_t TRIM_VDET1P8; - volatile uint32_t TRIM_VDET2P5; - volatile uint32_t TRIM_TVS; - volatile uint32_t TRIM_GDET1P05; - volatile uint32_t RESERVED0; - volatile uint32_t RESERVED1; - volatile uint32_t RESERVED2; - volatile uint32_t SERVICES_CR; - volatile uint32_t SERVICES_SR; - volatile uint32_t USER_DETECTOR_SR; - volatile uint32_t USER_DETECTOR_CR; - volatile uint32_t MSS_SPI_CR; +MSS_SYS_debug_terminate(uint16_t mb_offset, uint16_t resp_offset); + +typedef struct { + volatile uint32_t SOFT_RESET; + volatile uint32_t VDETECTOR; + volatile uint32_t TVS_CONTROL; + volatile uint32_t TVS_TEMP_A; + volatile uint32_t TVS_TEMP_B; + volatile uint32_t TVS_TEMP_C; + volatile uint32_t TVS_VOLT_A; + volatile uint32_t TVS_VOLT_B; + volatile uint32_t TVS_VOLT_C; + volatile uint32_t TVS_OUTPUT0; + volatile uint32_t TVS_OUTPUT1; + volatile uint32_t TVS_TRIGGER; + volatile uint32_t TRIM_VDET1P05; + volatile uint32_t TRIM_VDET1P8; + volatile uint32_t TRIM_VDET2P5; + volatile uint32_t TRIM_TVS; + volatile uint32_t TRIM_GDET1P05; + volatile uint32_t RESERVED0; + volatile uint32_t RESERVED1; + volatile uint32_t RESERVED2; + volatile uint32_t SERVICES_CR; + volatile uint32_t SERVICES_SR; + volatile uint32_t USER_DETECTOR_SR; + volatile uint32_t USER_DETECTOR_CR; + volatile uint32_t MSS_SPI_CR; } SCBCTRL_TypeDef; -#define MSS_SCBCTRL ((SCBCTRL_TypeDef*) (0x37020000UL)) +#define MSS_SCBCTRL ((SCBCTRL_TypeDef*)(0x37020000UL)) /*2kB bytes long mailbox.*/ -#define MSS_SCBMAILBOX ((uint32_t*) (0x37020800UL)) +#define MSS_SCBMAILBOX ((uint32_t*)(0x37020800UL)) /*SCB message register*/ -#define MSS_SCBMESSAGE ((uint32_t*) (0x20003190UL)) +#define MSS_SCBMESSAGE ((uint32_t*)(0x20003190UL)) /*SCB message interrupt register*/ -#define MSS_SCBMESSAGE_INT ((uint32_t*) (0x2000318CUL)) +#define MSS_SCBMESSAGE_INT ((uint32_t*)(0x2000318CUL)) #ifdef __cplusplus } diff --git a/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services_regs.h b/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services_regs.h index 3611202fb..3852e3438 100644 --- a/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services_regs.h +++ b/sm/plat/mpfs/drivers/mss_sys_services/mss_sys_services_regs.h @@ -1,4 +1,4 @@ - /******************************************************************************* +/******************************************************************************* * Copyright 2019 Microchip Corporation. * * SPDX-License-Identifier: MIT @@ -17,37 +17,36 @@ extern "C" { #endif /***************SCBCTRL SERVICES_CR register*************************/ -#define SCBCTRL_SERVICESCR_REQ (0u) -#define SCBCTRL_SERVICESCR_REQ_MASK (1u << SCBCTRL_SERVICESCR_REQ) +#define SCBCTRL_SERVICESCR_REQ (0u) +#define SCBCTRL_SERVICESCR_REQ_MASK (1u << SCBCTRL_SERVICESCR_REQ) -#define SCBCTRL_SERVICESCR_BUSY (1u) -#define SCBCTRL_SERVICESCR_BUSY_MASK (1u << SCBCTRL_SERVICESCR_BUSY) +#define SCBCTRL_SERVICESCR_BUSY (1u) +#define SCBCTRL_SERVICESCR_BUSY_MASK (1u << SCBCTRL_SERVICESCR_BUSY) -#define SCBCTRL_SERVICESCR_ABORT (2u) -#define SCBCTRL_SERVICESCR_ABORT_MASK (1u << SCBCTRL_SERVICESCR_ABORT) +#define SCBCTRL_SERVICESCR_ABORT (2u) +#define SCBCTRL_SERVICESCR_ABORT_MASK (1u << SCBCTRL_SERVICESCR_ABORT) -#define SCBCTRL_SERVICESCR_NOTIFY (3u) -#define SCBCTRL_SERVICESCR_NOTIFY_MASK (1u << SCBCTRL_SERVICESCR_NOTIFY) - -#define SCBCTRL_SERVICESCR_COMMAND (16u) -#define SCBCTRL_SERVICESCR_COMMAND_MASK (0xFFFFu << SCBCTRL_SERVICESCR_COMMAND) +#define SCBCTRL_SERVICESCR_NOTIFY (3u) +#define SCBCTRL_SERVICESCR_NOTIFY_MASK (1u << SCBCTRL_SERVICESCR_NOTIFY) +#define SCBCTRL_SERVICESCR_COMMAND (16u) +#define SCBCTRL_SERVICESCR_COMMAND_MASK (0xFFFFu << SCBCTRL_SERVICESCR_COMMAND) /***************SCBCTRL SERVICES_SR registers*************************/ -#define SCBCTRL_SERVICESSR_REQ (0u) -#define SCBCTRL_SERVICESSR_REQ_MASK (1u << SCBCTRL_SERVICESSR_REQ) +#define SCBCTRL_SERVICESSR_REQ (0u) +#define SCBCTRL_SERVICESSR_REQ_MASK (1u << SCBCTRL_SERVICESSR_REQ) -#define SCBCTRL_SERVICESSR_BUSY (1u) -#define SCBCTRL_SERVICESSR_BUSY_MASK (1u << SCBCTRL_SERVICESSR_BUSY) +#define SCBCTRL_SERVICESSR_BUSY (1u) +#define SCBCTRL_SERVICESSR_BUSY_MASK (1u << SCBCTRL_SERVICESSR_BUSY) -#define SCBCTRL_SERVICESSR_ABORT (2u) -#define SCBCTRL_SERVICESSR_ABORT_MASK (1u << SCBCTRL_SERVICESSR_ABORT) +#define SCBCTRL_SERVICESSR_ABORT (2u) +#define SCBCTRL_SERVICESSR_ABORT_MASK (1u << SCBCTRL_SERVICESSR_ABORT) -#define SCBCTRL_SERVICESSR_NOTIFY (3u) -#define SCBCTRL_SERVICESSR_NOTIFY_MASK (1u << SCBCTRL_SERVICESSR_NOTIFY) +#define SCBCTRL_SERVICESSR_NOTIFY (3u) +#define SCBCTRL_SERVICESSR_NOTIFY_MASK (1u << SCBCTRL_SERVICESSR_NOTIFY) -#define SCBCTRL_SERVICESSR_STATUS (16u) -#define SCBCTRL_SERVICESSR_STATUS_MASK (0xFFFFu << SCBCTRL_SERVICESSR_STATUS) +#define SCBCTRL_SERVICESSR_STATUS (16u) +#define SCBCTRL_SERVICESSR_STATUS_MASK (0xFFFFu << SCBCTRL_SERVICESSR_STATUS) #ifdef __cplusplus } diff --git a/sm/plat/mpfs/drivers/mss_uart/mss_uart.c b/sm/plat/mpfs/drivers/mss_uart/mss_uart.c index 24e184323..db5a7bed7 100644 --- a/sm/plat/mpfs/drivers/mss_uart/mss_uart.c +++ b/sm/plat/mpfs/drivers/mss_uart/mss_uart.c @@ -9,27 +9,28 @@ */ #include "mss_uart.h" -#include "mss_uart_regs.h" -#include "../../clocks/hw_mss_clks.h" + #include + +#include "../../clocks/hw_mss_clks.h" +#include "mss_uart_regs.h" #define ASSERT sm_assert #ifdef __cplusplus extern "C" { #endif -#define MSS_UART0_LO_BASE (MSS_UART_TypeDef*)0x20000000UL -#define MSS_UART1_LO_BASE (MSS_UART_TypeDef*)0x20100000UL -#define MSS_UART2_LO_BASE (MSS_UART_TypeDef*)0x20102000UL -#define MSS_UART3_LO_BASE (MSS_UART_TypeDef*)0x20104000UL -#define MSS_UART4_LO_BASE (MSS_UART_TypeDef*)0x20106000UL - -#define MSS_UART0_HI_BASE (MSS_UART_TypeDef*)0x28000000UL -#define MSS_UART1_HI_BASE (MSS_UART_TypeDef*)0x28100000UL -#define MSS_UART2_HI_BASE (MSS_UART_TypeDef*)0x28102000UL -#define MSS_UART3_HI_BASE (MSS_UART_TypeDef*)0x28104000UL -#define MSS_UART4_HI_BASE (MSS_UART_TypeDef*)0x28106000UL +#define MSS_UART0_LO_BASE (MSS_UART_TypeDef*)0x20000000UL +#define MSS_UART1_LO_BASE (MSS_UART_TypeDef*)0x20100000UL +#define MSS_UART2_LO_BASE (MSS_UART_TypeDef*)0x20102000UL +#define MSS_UART3_LO_BASE (MSS_UART_TypeDef*)0x20104000UL +#define MSS_UART4_LO_BASE (MSS_UART_TypeDef*)0x20106000UL +#define MSS_UART0_HI_BASE (MSS_UART_TypeDef*)0x28000000UL +#define MSS_UART1_HI_BASE (MSS_UART_TypeDef*)0x28100000UL +#define MSS_UART2_HI_BASE (MSS_UART_TypeDef*)0x28102000UL +#define MSS_UART3_HI_BASE (MSS_UART_TypeDef*)0x28104000UL +#define MSS_UART4_HI_BASE (MSS_UART_TypeDef*)0x28106000UL mss_uart_instance_t g_mss_uart0_lo; mss_uart_instance_t g_mss_uart1_lo; @@ -59,790 +60,631 @@ static uint8_t g_uart_axi_pos = 0x0u; /******************************************************************************* * Defines */ -#define TX_COMPLETE 0u -#define TX_FIFO_SIZE 16u +#define TX_COMPLETE 0u +#define TX_FIFO_SIZE 16u -#define FCR_TRIG_LEVEL_MASK 0xC0u +#define FCR_TRIG_LEVEL_MASK 0xC0u -#define IIRF_MASK 0x0Fu +#define IIRF_MASK 0x0Fu -#define INVALID_INTERRUPT 0u +#define INVALID_INTERRUPT 0u -#define MSS_UART_DATA_READY ((uint8_t) 0x01) +#define MSS_UART_DATA_READY ((uint8_t)0x01) -#define SYNC_ASYNC_MODE_MASK (0x7u) +#define SYNC_ASYNC_MODE_MASK (0x7u) /******************************************************************************* * Possible values for Interrupt Identification Register Field. */ -#define IIRF_MODEM_STATUS 0x00u -#define IIRF_THRE 0x02u -#define IIRF_MMI 0x03u -#define IIRF_RX_DATA 0x04u -#define IIRF_RX_LINE_STATUS 0x06u -#define IIRF_DATA_TIMEOUT 0x0Cu +#define IIRF_MODEM_STATUS 0x00u +#define IIRF_THRE 0x02u +#define IIRF_MMI 0x03u +#define IIRF_RX_DATA 0x04u +#define IIRF_RX_LINE_STATUS 0x06u +#define IIRF_DATA_TIMEOUT 0x0Cu /******************************************************************************* * Receiver error status mask. */ -#define STATUS_ERROR_MASK ( MSS_UART_OVERUN_ERROR | MSS_UART_PARITY_ERROR | \ - MSS_UART_FRAMING_ERROR | MSS_UART_BREAK_ERROR | \ - MSS_UART_FIFO_ERROR) +#define STATUS_ERROR_MASK \ + (MSS_UART_OVERUN_ERROR | MSS_UART_PARITY_ERROR | MSS_UART_FRAMING_ERROR | \ + MSS_UART_BREAK_ERROR | MSS_UART_FIFO_ERROR) /******************************************************************************* * Local functions. */ -static void global_init(mss_uart_instance_t * this_uart, uint32_t baud_rate, - uint8_t line_config); -static void config_baud_divisors -( - mss_uart_instance_t * this_uart, - uint32_t baudrate -); +static void +global_init( + mss_uart_instance_t* this_uart, uint32_t baud_rate, uint8_t line_config); +static void +config_baud_divisors(mss_uart_instance_t* this_uart, uint32_t baudrate); /******************************************************************************* * Public Functions *******************************************************************************/ -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_init -( - mss_uart_instance_t* this_uart, - uint32_t baud_rate, - uint8_t line_config -) -{ - /* Perform generic initialization */ - global_init(this_uart, baud_rate, line_config); - - /* Disable LIN mode */ - this_uart->hw_reg->MM0 &= ~ELIN_MASK; - - /* Disable IrDA mode */ - this_uart->hw_reg->MM1 &= ~EIRD_MASK; - - /* Disable SmartCard Mode */ - this_uart->hw_reg->MM2 &= ~EERR_MASK; -} +MSS_UART_init( + mss_uart_instance_t* this_uart, uint32_t baud_rate, uint8_t line_config) { + /* Perform generic initialization */ + global_init(this_uart, baud_rate, line_config); -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ -void MSS_UART_lin_init -( - mss_uart_instance_t* this_uart, - uint32_t baud_rate, - uint8_t line_config -) -{ - /* Perform generic initialization */ - global_init(this_uart, baud_rate, line_config); - - /* Enable LIN mode */ - this_uart->hw_reg->MM0 |= ELIN_MASK; - - /* Disable IrDA mode */ - this_uart->hw_reg->MM1 &= ~EIRD_MASK; - - /* Disable SmartCard Mode */ - this_uart->hw_reg->MM2 &= ~EERR_MASK; + /* Disable LIN mode */ + this_uart->hw_reg->MM0 &= ~ELIN_MASK; + + /* Disable IrDA mode */ + this_uart->hw_reg->MM1 &= ~EIRD_MASK; + + /* Disable SmartCard Mode */ + this_uart->hw_reg->MM2 &= ~EERR_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_irda_init -( - mss_uart_instance_t* this_uart, - uint32_t baud_rate, - uint8_t line_config, - mss_uart_rzi_polarity_t rxpol, - mss_uart_rzi_polarity_t txpol, - mss_uart_rzi_pulsewidth_t pw -) -{ - /* Perform generic initialization */ - global_init(this_uart, baud_rate, line_config); - - /* Enable LIN mode */ - this_uart->hw_reg->MM0 &= ~ELIN_MASK; - - /* Disable IrDA mode */ - this_uart->hw_reg->MM1 |= EIRD_MASK; - - ((rxpol == MSS_UART_ACTIVE_LOW) ? (this_uart->hw_reg->MM1 &= ~EIRX_MASK) : - (this_uart->hw_reg->MM1 |= EIRX_MASK)); - - ((txpol == MSS_UART_ACTIVE_LOW) ? (this_uart->hw_reg->MM1 &= ~EITX_MASK) : - (this_uart->hw_reg->MM1 |= EITX_MASK)); - - ((pw == MSS_UART_3_BY_16) ? (this_uart->hw_reg->MM1 &= ~EITP_MASK) : - (this_uart->hw_reg->MM1 |= EITP_MASK)); - /* Disable SmartCard Mode */ - this_uart->hw_reg->MM2 &= ~EERR_MASK; +MSS_UART_lin_init( + mss_uart_instance_t* this_uart, uint32_t baud_rate, uint8_t line_config) { + /* Perform generic initialization */ + global_init(this_uart, baud_rate, line_config); + + /* Enable LIN mode */ + this_uart->hw_reg->MM0 |= ELIN_MASK; + + /* Disable IrDA mode */ + this_uart->hw_reg->MM1 &= ~EIRD_MASK; + + /* Disable SmartCard Mode */ + this_uart->hw_reg->MM2 &= ~EERR_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_smartcard_init -( - mss_uart_instance_t* this_uart, - uint32_t baud_rate, - uint8_t line_config -) -{ - /* Perform generic initialization */ - global_init(this_uart, baud_rate, line_config); - - /* Disable LIN mode */ - this_uart->hw_reg->MM0 &= ~ELIN_MASK; - - /* Disable IrDA mode */ - this_uart->hw_reg->MM1 &= ~EIRD_MASK; - - /* Enable SmartCard Mode : Only when data is 8-bit and 2 stop bits*/ - if ((MSS_UART_DATA_8_BITS | MSS_UART_TWO_STOP_BITS) == - (line_config & (MSS_UART_DATA_8_BITS | MSS_UART_TWO_STOP_BITS))) - { - this_uart->hw_reg->MM2 |= EERR_MASK; - - /* Enable single wire half-duplex mode */ - this_uart->hw_reg->MM2 |= ESWM_MASK; - } +MSS_UART_irda_init( + mss_uart_instance_t* this_uart, uint32_t baud_rate, uint8_t line_config, + mss_uart_rzi_polarity_t rxpol, mss_uart_rzi_polarity_t txpol, + mss_uart_rzi_pulsewidth_t pw) { + /* Perform generic initialization */ + global_init(this_uart, baud_rate, line_config); + + /* Enable LIN mode */ + this_uart->hw_reg->MM0 &= ~ELIN_MASK; + + /* Disable IrDA mode */ + this_uart->hw_reg->MM1 |= EIRD_MASK; + + ((rxpol == MSS_UART_ACTIVE_LOW) ? (this_uart->hw_reg->MM1 &= ~EIRX_MASK) + : (this_uart->hw_reg->MM1 |= EIRX_MASK)); + + ((txpol == MSS_UART_ACTIVE_LOW) ? (this_uart->hw_reg->MM1 &= ~EITX_MASK) + : (this_uart->hw_reg->MM1 |= EITX_MASK)); + + ((pw == MSS_UART_3_BY_16) ? (this_uart->hw_reg->MM1 &= ~EITP_MASK) + : (this_uart->hw_reg->MM1 |= EITP_MASK)); + /* Disable SmartCard Mode */ + this_uart->hw_reg->MM2 &= ~EERR_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_polled_tx -( - mss_uart_instance_t * this_uart, - const uint8_t * pbuff, - uint32_t tx_size -) -{ - uint32_t char_idx = 0u; - uint32_t size_sent; - uint8_t status; - uint32_t temp_tx_size = tx_size; - - ASSERT(pbuff != ( (uint8_t*)0)); - ASSERT(tx_size > 0u); - - if ((pbuff != ((uint8_t*)0)) && (temp_tx_size > 0u)) - { - /* Remain in this loop until the entire input buffer - * has been transferred to the UART. - */ - do - { - /* Read the Line Status Register and update the sticky record */ - status = this_uart->hw_reg->LSR; - this_uart->status |= status; - - /* Check if TX FIFO is empty. */ - if (status & MSS_UART_THRE) - { - uint32_t fill_size = TX_FIFO_SIZE; - - /* Calculate the number of bytes to transmit. */ - if (temp_tx_size < TX_FIFO_SIZE) - { - fill_size = temp_tx_size; - } - - /* Fill the TX FIFO with the calculated the number of bytes. */ - for (size_sent = 0u; size_sent < fill_size; ++size_sent) - { - /* Send next character in the buffer. */ - this_uart->hw_reg->THR = pbuff[char_idx]; - char_idx++; - } - - /* Calculate the number of bytes remaining(not transmitted yet)*/ - temp_tx_size -= size_sent; - } - }while (temp_tx_size); - } +MSS_UART_smartcard_init( + mss_uart_instance_t* this_uart, uint32_t baud_rate, uint8_t line_config) { + /* Perform generic initialization */ + global_init(this_uart, baud_rate, line_config); + + /* Disable LIN mode */ + this_uart->hw_reg->MM0 &= ~ELIN_MASK; + + /* Disable IrDA mode */ + this_uart->hw_reg->MM1 &= ~EIRD_MASK; + + /* Enable SmartCard Mode : Only when data is 8-bit and 2 stop bits*/ + if ((MSS_UART_DATA_8_BITS | MSS_UART_TWO_STOP_BITS) == + (line_config & (MSS_UART_DATA_8_BITS | MSS_UART_TWO_STOP_BITS))) { + this_uart->hw_reg->MM2 |= EERR_MASK; + + /* Enable single wire half-duplex mode */ + this_uart->hw_reg->MM2 |= ESWM_MASK; + } } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_polled_tx_string -( - mss_uart_instance_t * this_uart, - const uint8_t * p_sz_string -) -{ - uint32_t char_idx = 0u; - uint32_t fill_size; - uint8_t data_byte; - uint8_t status; - - ASSERT(p_sz_string != ((uint8_t*)0)); - - if (p_sz_string != ((uint8_t*)0)) - { - /* Get the first data byte from the input buffer */ - data_byte = p_sz_string[char_idx]; +MSS_UART_polled_tx( + mss_uart_instance_t* this_uart, const uint8_t* pbuff, uint32_t tx_size) { + uint32_t char_idx = 0u; + uint32_t size_sent; + uint8_t status; + uint32_t temp_tx_size = tx_size; + + ASSERT(pbuff != ((uint8_t*)0)); + ASSERT(tx_size > 0u); + + if ((pbuff != ((uint8_t*)0)) && (temp_tx_size > 0u)) { + /* Remain in this loop until the entire input buffer + * has been transferred to the UART. + */ + do { + /* Read the Line Status Register and update the sticky record */ + status = this_uart->hw_reg->LSR; + this_uart->status |= status; + + /* Check if TX FIFO is empty. */ + if (status & MSS_UART_THRE) { + uint32_t fill_size = TX_FIFO_SIZE; + + /* Calculate the number of bytes to transmit. */ + if (temp_tx_size < TX_FIFO_SIZE) { + fill_size = temp_tx_size; + } - /* First check for the NULL terminator byte. - * Then remain in this loop until the entire string in the input buffer - * has been transferred to the UART. - */ - while (0u != data_byte) - { - /* Wait until TX FIFO is empty. */ - do - { - status = this_uart->hw_reg->LSR; - this_uart->status |= status; - }while (0u == (status & MSS_UART_THRE)); - - /* Send bytes from the input buffer until the TX FIFO is full - * or we reach the NULL terminator byte. - */ - fill_size = 0u; - - while ((0u != data_byte) && (fill_size < TX_FIFO_SIZE)) - { - /* Send the data byte */ - this_uart->hw_reg->THR = data_byte; - ++fill_size; - char_idx++; - /* Get the next data byte from the input buffer */ - data_byte = p_sz_string[char_idx]; - } + /* Fill the TX FIFO with the calculated the number of bytes. */ + for (size_sent = 0u; size_sent < fill_size; ++size_sent) { + /* Send next character in the buffer. */ + this_uart->hw_reg->THR = pbuff[char_idx]; + char_idx++; } - } + + /* Calculate the number of bytes remaining(not transmitted yet)*/ + temp_tx_size -= size_sent; + } + } while (temp_tx_size); + } } +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ +void +MSS_UART_polled_tx_string( + mss_uart_instance_t* this_uart, const uint8_t* p_sz_string) { + uint32_t char_idx = 0u; + uint32_t fill_size; + uint8_t data_byte; + uint8_t status; + + ASSERT(p_sz_string != ((uint8_t*)0)); + + if (p_sz_string != ((uint8_t*)0)) { + /* Get the first data byte from the input buffer */ + data_byte = p_sz_string[char_idx]; + + /* First check for the NULL terminator byte. + * Then remain in this loop until the entire string in the input buffer + * has been transferred to the UART. + */ + while (0u != data_byte) { + /* Wait until TX FIFO is empty. */ + do { + status = this_uart->hw_reg->LSR; + this_uart->status |= status; + } while (0u == (status & MSS_UART_THRE)); + + /* Send bytes from the input buffer until the TX FIFO is full + * or we reach the NULL terminator byte. + */ + fill_size = 0u; + + while ((0u != data_byte) && (fill_size < TX_FIFO_SIZE)) { + /* Send the data byte */ + this_uart->hw_reg->THR = data_byte; + ++fill_size; + char_idx++; + /* Get the next data byte from the input buffer */ + data_byte = p_sz_string[char_idx]; + } + } + } +} -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ int8_t -MSS_UART_tx_complete -( - mss_uart_instance_t * this_uart -) -{ - int8_t ret_value = 0; - uint8_t status = 0u; - - /* Read the Line Status Register and update the sticky record. */ - status = this_uart->hw_reg->LSR; - this_uart->status |= status; +MSS_UART_tx_complete(mss_uart_instance_t* this_uart) { + int8_t ret_value = 0; + uint8_t status = 0u; - if ((TX_COMPLETE == this_uart->tx_buff_size) && - ((status & MSS_UART_TEMT) != 0u)) - { - ret_value = (int8_t)1; - } + /* Read the Line Status Register and update the sticky record. */ + status = this_uart->hw_reg->LSR; + this_uart->status |= status; + + if ((TX_COMPLETE == this_uart->tx_buff_size) && + ((status & MSS_UART_TEMT) != 0u)) { + ret_value = (int8_t)1; + } - return ret_value; + return ret_value; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ size_t -MSS_UART_get_rx -( - mss_uart_instance_t * this_uart, - uint8_t * rx_buff, - size_t buff_size -) -{ - size_t rx_size = 0u; - uint8_t status = 0u; - - ASSERT(rx_buff != ((uint8_t*)0)); - ASSERT(buff_size > 0u); - - if ((rx_buff != (uint8_t*)0) && (buff_size > 0u)) - { - status = this_uart->hw_reg->LSR; - this_uart->status |= status; +MSS_UART_get_rx( + mss_uart_instance_t* this_uart, uint8_t* rx_buff, size_t buff_size) { + size_t rx_size = 0u; + uint8_t status = 0u; - while (((status & MSS_UART_DATA_READY) != 0u) && (rx_size < buff_size)) - { - rx_buff[rx_size] = this_uart->hw_reg->RBR; - ++rx_size; - status = this_uart->hw_reg->LSR; - this_uart->status |= status; - } + ASSERT(rx_buff != ((uint8_t*)0)); + ASSERT(buff_size > 0u); + + if ((rx_buff != (uint8_t*)0) && (buff_size > 0u)) { + status = this_uart->hw_reg->LSR; + this_uart->status |= status; + + while (((status & MSS_UART_DATA_READY) != 0u) && (rx_size < buff_size)) { + rx_buff[rx_size] = this_uart->hw_reg->RBR; + ++rx_size; + status = this_uart->hw_reg->LSR; + this_uart->status |= status; } + } - return rx_size; + return rx_size; } - -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_set_loopback -( - mss_uart_instance_t * this_uart, - mss_uart_loopback_t loopback -) -{ - ASSERT(MSS_UART_INVALID_LOOPBACK > loopback); - - if (MSS_UART_INVALID_LOOPBACK > loopback) - { - switch (loopback) - { - case MSS_UART_LOCAL_LOOPBACK_OFF: - /* Disable local loopback */ - this_uart->hw_reg->MCR &= ~LOOP_MASK; - break; - - case MSS_UART_LOCAL_LOOPBACK_ON: - /* Enable local loopback */ - this_uart->hw_reg->MCR |= LOOP_MASK; - break; - - case MSS_UART_REMOTE_LOOPBACK_OFF: - case MSS_UART_AUTO_ECHO_OFF: - /* Disable remote loopback & automatic echo*/ - this_uart->hw_reg->MCR &= ~(RLOOP_MASK|ECHO_MASK); - break; - - case MSS_UART_REMOTE_LOOPBACK_ON: - /* Enable remote loopback */ - this_uart->hw_reg->MCR |= (1u << RLOOP); - break; - - case MSS_UART_AUTO_ECHO_ON: - /* Enable automatic echo */ - this_uart->hw_reg->MCR |= (1u << ECHO); - break; - - case MSS_UART_INVALID_LOOPBACK: - /* Fall through to default. */ - default: - ASSERT(0); - break; - } +MSS_UART_set_loopback( + mss_uart_instance_t* this_uart, mss_uart_loopback_t loopback) { + ASSERT(MSS_UART_INVALID_LOOPBACK > loopback); + + if (MSS_UART_INVALID_LOOPBACK > loopback) { + switch (loopback) { + case MSS_UART_LOCAL_LOOPBACK_OFF: + /* Disable local loopback */ + this_uart->hw_reg->MCR &= ~LOOP_MASK; + break; + + case MSS_UART_LOCAL_LOOPBACK_ON: + /* Enable local loopback */ + this_uart->hw_reg->MCR |= LOOP_MASK; + break; + + case MSS_UART_REMOTE_LOOPBACK_OFF: + case MSS_UART_AUTO_ECHO_OFF: + /* Disable remote loopback & automatic echo*/ + this_uart->hw_reg->MCR &= ~(RLOOP_MASK | ECHO_MASK); + break; + + case MSS_UART_REMOTE_LOOPBACK_ON: + /* Enable remote loopback */ + this_uart->hw_reg->MCR |= (1u << RLOOP); + break; + + case MSS_UART_AUTO_ECHO_ON: + /* Enable automatic echo */ + this_uart->hw_reg->MCR |= (1u << ECHO); + break; + + case MSS_UART_INVALID_LOOPBACK: + /* Fall through to default. */ + default: + ASSERT(0); + break; } + } } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ size_t -MSS_UART_fill_tx_fifo -( - mss_uart_instance_t * this_uart, - const uint8_t * tx_buffer, - size_t tx_size -) -{ - uint8_t status = 0u; - uint32_t size_sent = 0u; - - ASSERT(tx_buffer != ( (uint8_t*)0)); - ASSERT(tx_size > 0); - - /* Fill the UART's Tx FIFO until the FIFO is full or the complete input - * buffer has been written. */ - if ((tx_buffer != ((uint8_t*)0)) && (tx_size > 0u)) - { - status = this_uart->hw_reg->LSR; - this_uart->status |= status; +MSS_UART_fill_tx_fifo( + mss_uart_instance_t* this_uart, const uint8_t* tx_buffer, size_t tx_size) { + uint8_t status = 0u; + uint32_t size_sent = 0u; - if (status & MSS_UART_THRE) - { - uint32_t fill_size = TX_FIFO_SIZE; - - if (tx_size < TX_FIFO_SIZE) - { - fill_size = tx_size; - } - - /* Fill up FIFO */ - for (size_sent = 0u; size_sent < fill_size; size_sent++) - { - /* Send next character in the buffer. */ - this_uart->hw_reg->THR = tx_buffer[size_sent]; - } - } - } + ASSERT(tx_buffer != ((uint8_t*)0)); + ASSERT(tx_size > 0); - return size_sent; -} + /* Fill the UART's Tx FIFO until the FIFO is full or the complete input + * buffer has been written. */ + if ((tx_buffer != ((uint8_t*)0)) && (tx_size > 0u)) { + status = this_uart->hw_reg->LSR; + this_uart->status |= status; -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ -uint8_t -MSS_UART_get_rx_status -( - mss_uart_instance_t * this_uart -) -{ - uint8_t status = MSS_UART_INVALID_PARAM; - - /* - * Extract UART receive error status. - * Bit 1 - Overflow error status - * Bit 2 - Parity error status - * Bit 3 - Frame error status - * Bit 4 - Break interrupt indicator - * Bit 7 - FIFO data error status - */ - this_uart->status |= (this_uart->hw_reg->LSR); - status = (this_uart->status & STATUS_ERROR_MASK); - /* Clear the sticky status after reading */ - this_uart->status = 0u; + if (status & MSS_UART_THRE) { + uint32_t fill_size = TX_FIFO_SIZE; - return status; -} + if (tx_size < TX_FIFO_SIZE) { + fill_size = tx_size; + } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ -uint8_t -MSS_UART_get_modem_status -( - const mss_uart_instance_t * this_uart -) -{ - uint8_t status = MSS_UART_INVALID_PARAM; - - /* - * Extract UART modem status and place in lower bits of "status". - * Bit 0 - Delta Clear to Send Indicator - * Bit 1 - Delta Clear to Receive Indicator - * Bit 2 - Trailing edge of Ring Indicator detector - * Bit 3 - Delta Data Carrier Detect indicator - * Bit 4 - Clear To Send - * Bit 5 - Data Set Ready - * Bit 6 - Ring Indicator - * Bit 7 - Data Carrier Detect - */ - status = this_uart->hw_reg->MSR; + /* Fill up FIFO */ + for (size_sent = 0u; size_sent < fill_size; size_sent++) { + /* Send next character in the buffer. */ + this_uart->hw_reg->THR = tx_buffer[size_sent]; + } + } + } - return status; + return size_sent; } -/***************************************************************************//** - * MSS_UART_get_tx_status. - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ uint8_t -MSS_UART_get_tx_status -( - mss_uart_instance_t * this_uart -) -{ - uint8_t status = MSS_UART_TX_BUSY; - - /* Read the Line Status Register and update the sticky record. */ - status = this_uart->hw_reg->LSR; - this_uart->status |= status; +MSS_UART_get_rx_status(mss_uart_instance_t* this_uart) { + uint8_t status = MSS_UART_INVALID_PARAM; + + /* + * Extract UART receive error status. + * Bit 1 - Overflow error status + * Bit 2 - Parity error status + * Bit 3 - Frame error status + * Bit 4 - Break interrupt indicator + * Bit 7 - FIFO data error status + */ + this_uart->status |= (this_uart->hw_reg->LSR); + status = (this_uart->status & STATUS_ERROR_MASK); + /* Clear the sticky status after reading */ + this_uart->status = 0u; + + return status; +} + +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ +uint8_t +MSS_UART_get_modem_status(const mss_uart_instance_t* this_uart) { + uint8_t status = MSS_UART_INVALID_PARAM; + + /* + * Extract UART modem status and place in lower bits of "status". + * Bit 0 - Delta Clear to Send Indicator + * Bit 1 - Delta Clear to Receive Indicator + * Bit 2 - Trailing edge of Ring Indicator detector + * Bit 3 - Delta Data Carrier Detect indicator + * Bit 4 - Clear To Send + * Bit 5 - Data Set Ready + * Bit 6 - Ring Indicator + * Bit 7 - Data Carrier Detect + */ + status = this_uart->hw_reg->MSR; + + return status; +} + +/***************************************************************************/ /** + * MSS_UART_get_tx_status. + * See mss_uart.h for details of how to use this function. + */ +uint8_t +MSS_UART_get_tx_status(mss_uart_instance_t* this_uart) { + uint8_t status = MSS_UART_TX_BUSY; - /* - * Extract the transmit status bits from the UART's Line Status Register. - * Bit 5 - Transmitter Holding Register/FIFO Empty (THRE) status. - (If = 1, TX FIFO is empty) - * Bit 6 - Transmitter Empty (TEMT) status. - (If = 1, both TX FIFO and shift register are empty) - */ - status &= (MSS_UART_THRE | MSS_UART_TEMT); + /* Read the Line Status Register and update the sticky record. */ + status = this_uart->hw_reg->LSR; + this_uart->status |= status; + + /* + * Extract the transmit status bits from the UART's Line Status Register. + * Bit 5 - Transmitter Holding Register/FIFO Empty (THRE) status. + (If = 1, TX FIFO is empty) + * Bit 6 - Transmitter Empty (TEMT) status. + (If = 1, both TX FIFO and shift register are empty) + */ + status &= (MSS_UART_THRE | MSS_UART_TEMT); - return status; + return status; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_set_break -( - mss_uart_instance_t * this_uart -) -{ - /* set break character on Tx line */ - this_uart->hw_reg->LCR |= SB_MASK; +MSS_UART_set_break(mss_uart_instance_t* this_uart) { + /* set break character on Tx line */ + this_uart->hw_reg->LCR |= SB_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_clear_break -( - mss_uart_instance_t * this_uart -) -{ - /* remove break character from Tx line */ - this_uart->hw_reg->LCR &= ~SB_MASK; +MSS_UART_clear_break(mss_uart_instance_t* this_uart) { + /* remove break character from Tx line */ + this_uart->hw_reg->LCR &= ~SB_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_enable_half_duplex -( - mss_uart_instance_t * this_uart -) -{ - /* enable single wire half-duplex mode */ - this_uart->hw_reg->MM2 |= ESWM_MASK; +MSS_UART_enable_half_duplex(mss_uart_instance_t* this_uart) { + /* enable single wire half-duplex mode */ + this_uart->hw_reg->MM2 |= ESWM_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_disable_half_duplex -( - mss_uart_instance_t * this_uart -) -{ - /* enable single wire half-duplex mode */ - this_uart->hw_reg->MM2 &= ~ESWM_MASK; +MSS_UART_disable_half_duplex(mss_uart_instance_t* this_uart) { + /* enable single wire half-duplex mode */ + this_uart->hw_reg->MM2 &= ~ESWM_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_set_rx_endian -( - mss_uart_instance_t * this_uart, - mss_uart_endian_t endian -) -{ - ASSERT(MSS_UART_INVALID_ENDIAN > endian); - - if (MSS_UART_INVALID_ENDIAN > endian) - { - /* Configure MSB first / LSB first for receiver */ - ((MSS_UART_LITTLEEND == endian) ? (this_uart->hw_reg->MM1 &= ~E_MSB_RX_MASK) : - (this_uart->hw_reg->MM1 |= E_MSB_RX_MASK)); - } +MSS_UART_set_rx_endian( + mss_uart_instance_t* this_uart, mss_uart_endian_t endian) { + ASSERT(MSS_UART_INVALID_ENDIAN > endian); + + if (MSS_UART_INVALID_ENDIAN > endian) { + /* Configure MSB first / LSB first for receiver */ + ((MSS_UART_LITTLEEND == endian) + ? (this_uart->hw_reg->MM1 &= ~E_MSB_RX_MASK) + : (this_uart->hw_reg->MM1 |= E_MSB_RX_MASK)); + } } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_set_tx_endian -( - mss_uart_instance_t * this_uart, - mss_uart_endian_t endian -) -{ - ASSERT(MSS_UART_INVALID_ENDIAN > endian); - - if (MSS_UART_INVALID_ENDIAN > endian) - { - /* Configure MSB first / LSB first for transmitter */ - ((MSS_UART_LITTLEEND == endian) ? (this_uart->hw_reg->MM1 &= ~E_MSB_TX_MASK) : - (this_uart->hw_reg->MM1 |= E_MSB_TX_MASK)) ; - } +MSS_UART_set_tx_endian( + mss_uart_instance_t* this_uart, mss_uart_endian_t endian) { + ASSERT(MSS_UART_INVALID_ENDIAN > endian); + + if (MSS_UART_INVALID_ENDIAN > endian) { + /* Configure MSB first / LSB first for transmitter */ + ((MSS_UART_LITTLEEND == endian) + ? (this_uart->hw_reg->MM1 &= ~E_MSB_TX_MASK) + : (this_uart->hw_reg->MM1 |= E_MSB_TX_MASK)); + } } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_set_filter_length -( - mss_uart_instance_t * this_uart, - mss_uart_filter_length_t length -) -{ - ASSERT(MSS_UART_INVALID_FILTER_LENGTH > length); - - if (MSS_UART_INVALID_FILTER_LENGTH > length) - { - /* Configure glitch filter length */ - this_uart->hw_reg->GFR = (uint8_t)length; - } +MSS_UART_set_filter_length( + mss_uart_instance_t* this_uart, mss_uart_filter_length_t length) { + ASSERT(MSS_UART_INVALID_FILTER_LENGTH > length); + + if (MSS_UART_INVALID_FILTER_LENGTH > length) { + /* Configure glitch filter length */ + this_uart->hw_reg->GFR = (uint8_t)length; + } } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_enable_afm -( - mss_uart_instance_t * this_uart -) -{ - /* Disable RX FIFO till address flag with correct address is received */ - this_uart->hw_reg->MM2 |= EAFM_MASK; +MSS_UART_enable_afm(mss_uart_instance_t* this_uart) { + /* Disable RX FIFO till address flag with correct address is received */ + this_uart->hw_reg->MM2 |= EAFM_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_disable_afm -( - mss_uart_instance_t * this_uart -) -{ - /* Enable RX FIFO irrespective of address flag and - correct address is received */ - this_uart->hw_reg->MM2 &= ~EAFM_MASK; +MSS_UART_disable_afm(mss_uart_instance_t* this_uart) { + /* Enable RX FIFO irrespective of address flag and + correct address is received */ + this_uart->hw_reg->MM2 &= ~EAFM_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_enable_afclear -( - mss_uart_instance_t * this_uart -) -{ - /* Enable address flag clearing */ - /* Disable RX FIFO till another address flag with - correct address is received */ - this_uart->hw_reg->MM2 |= EAFC_MASK; +MSS_UART_enable_afclear(mss_uart_instance_t* this_uart) { + /* Enable address flag clearing */ + /* Disable RX FIFO till another address flag with + correct address is received */ + this_uart->hw_reg->MM2 |= EAFC_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_disable_afclear -( - mss_uart_instance_t * this_uart -) -{ - /* Disable address flag clearing */ - this_uart->hw_reg->MM2 &= ~EAFC_MASK; +MSS_UART_disable_afclear(mss_uart_instance_t* this_uart) { + /* Disable address flag clearing */ + this_uart->hw_reg->MM2 &= ~EAFC_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_enable_rx_timeout -( - mss_uart_instance_t * this_uart, - uint8_t timeout -) -{ - /* Load the receive timeout value */ - this_uart->hw_reg->RTO = timeout; - - /*Enable receiver time-out */ - this_uart->hw_reg->MM0 |= ERTO_MASK; +MSS_UART_enable_rx_timeout(mss_uart_instance_t* this_uart, uint8_t timeout) { + /* Load the receive timeout value */ + this_uart->hw_reg->RTO = timeout; + + /*Enable receiver time-out */ + this_uart->hw_reg->MM0 |= ERTO_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_disable_rx_timeout -( - mss_uart_instance_t * this_uart -) -{ - /*Disable receiver time-out */ - this_uart->hw_reg->MM0 &= ~ERTO_MASK; +MSS_UART_disable_rx_timeout(mss_uart_instance_t* this_uart) { + /*Disable receiver time-out */ + this_uart->hw_reg->MM0 &= ~ERTO_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_enable_tx_time_guard -( - mss_uart_instance_t * this_uart, - uint8_t timeguard -) -{ - /* Load the transmitter time guard value */ - this_uart->hw_reg->TTG = timeguard; - - /*Enable transmitter time guard */ - this_uart->hw_reg->MM0 |= ETTG_MASK; +MSS_UART_enable_tx_time_guard( + mss_uart_instance_t* this_uart, uint8_t timeguard) { + /* Load the transmitter time guard value */ + this_uart->hw_reg->TTG = timeguard; + + /*Enable transmitter time guard */ + this_uart->hw_reg->MM0 |= ETTG_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_disable_tx_time_guard -( - mss_uart_instance_t * this_uart -) -{ - /*Disable transmitter time guard */ - this_uart->hw_reg->MM0 &= ~ETTG_MASK; +MSS_UART_disable_tx_time_guard(mss_uart_instance_t* this_uart) { + /*Disable transmitter time guard */ + this_uart->hw_reg->MM0 &= ~ETTG_MASK; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_set_address -( - mss_uart_instance_t * this_uart, - uint8_t address -) -{ - this_uart->hw_reg->ADR = address; +MSS_UART_set_address(mss_uart_instance_t* this_uart, uint8_t address) { + this_uart->hw_reg->ADR = address; } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_set_ready_mode -( - mss_uart_instance_t * this_uart, - mss_uart_ready_mode_t mode -) -{ - ASSERT(MSS_UART_INVALID_READY_MODE > mode); - - if (MSS_UART_INVALID_READY_MODE > mode ) - { - /* Configure mode 0 or mode 1 for TXRDY and RXRDY */ - ((MSS_UART_READY_MODE0 == mode) ? (this_uart->hw_reg->FCR &= ~RDYMODE_MASK) : - (this_uart->hw_reg->FCR |= RDYMODE_MASK) ); - } +MSS_UART_set_ready_mode( + mss_uart_instance_t* this_uart, mss_uart_ready_mode_t mode) { + ASSERT(MSS_UART_INVALID_READY_MODE > mode); + + if (MSS_UART_INVALID_READY_MODE > mode) { + /* Configure mode 0 or mode 1 for TXRDY and RXRDY */ + ((MSS_UART_READY_MODE0 == mode) ? (this_uart->hw_reg->FCR &= ~RDYMODE_MASK) + : (this_uart->hw_reg->FCR |= RDYMODE_MASK)); + } } -/***************************************************************************//** - * See mss_uart.h for details of how to use this function. - */ +/***************************************************************************/ /** + * See mss_uart.h for details of how to use this function. + */ void -MSS_UART_set_usart_mode -( - mss_uart_instance_t * this_uart, - mss_uart_usart_mode_t mode -) -{ - ASSERT(MSS_UART_INVALID_SYNC_MODE > mode); - - if (MSS_UART_INVALID_SYNC_MODE > mode) - { - /* Nothing to do for the baudrate: - operates at PCLK / 2 + glitch filter length */ - /* Clear the ESYN bits 2:0 */ - this_uart->hw_reg->MM0 &= ~SYNC_ASYNC_MODE_MASK; - this_uart->hw_reg->MM0 |= (uint8_t)mode; - } +MSS_UART_set_usart_mode( + mss_uart_instance_t* this_uart, mss_uart_usart_mode_t mode) { + ASSERT(MSS_UART_INVALID_SYNC_MODE > mode); + + if (MSS_UART_INVALID_SYNC_MODE > mode) { + /* Nothing to do for the baudrate: + operates at PCLK / 2 + glitch filter length */ + /* Clear the ESYN bits 2:0 */ + this_uart->hw_reg->MM0 &= ~SYNC_ASYNC_MODE_MASK; + this_uart->hw_reg->MM0 |= (uint8_t)mode; + } } /******************************************************************************* @@ -851,232 +693,206 @@ MSS_UART_set_usart_mode /******************************************************************************* * Global initialization for all modes */ -static void global_init -( - mss_uart_instance_t * this_uart, - uint32_t baud_rate, - uint8_t line_config -) -{ - if ((&g_mss_uart0_lo == this_uart)) - { - this_uart->hw_reg = MSS_UART0_LO_BASE; - g_uart_axi_pos &= ~0x01u; - } - - else if (&g_mss_uart1_lo == this_uart) - { +static void +global_init( + mss_uart_instance_t* this_uart, uint32_t baud_rate, uint8_t line_config) { + if ((&g_mss_uart0_lo == this_uart)) { + this_uart->hw_reg = MSS_UART0_LO_BASE; + g_uart_axi_pos &= ~0x01u; + } - this_uart->hw_reg = MSS_UART1_LO_BASE; - g_uart_axi_pos &= ~0x02u; - } + else if (&g_mss_uart1_lo == this_uart) { + this_uart->hw_reg = MSS_UART1_LO_BASE; + g_uart_axi_pos &= ~0x02u; + } - else if (&g_mss_uart2_lo == this_uart) - { - this_uart->hw_reg = MSS_UART2_LO_BASE; - g_uart_axi_pos &= ~0x04u; - } + else if (&g_mss_uart2_lo == this_uart) { + this_uart->hw_reg = MSS_UART2_LO_BASE; + g_uart_axi_pos &= ~0x04u; + } - else if (&g_mss_uart3_lo == this_uart) - { - this_uart->hw_reg = MSS_UART3_LO_BASE; - g_uart_axi_pos &= ~0x08u; - } + else if (&g_mss_uart3_lo == this_uart) { + this_uart->hw_reg = MSS_UART3_LO_BASE; + g_uart_axi_pos &= ~0x08u; + } - else if (&g_mss_uart4_lo == this_uart) - { - this_uart->hw_reg = MSS_UART4_LO_BASE; - g_uart_axi_pos &= ~0x10u; - } + else if (&g_mss_uart4_lo == this_uart) { + this_uart->hw_reg = MSS_UART4_LO_BASE; + g_uart_axi_pos &= ~0x10u; + } - else if ((&g_mss_uart0_hi == this_uart)) - { - this_uart->hw_reg = MSS_UART0_HI_BASE; - g_uart_axi_pos |= 0x01u; - } + else if ((&g_mss_uart0_hi == this_uart)) { + this_uart->hw_reg = MSS_UART0_HI_BASE; + g_uart_axi_pos |= 0x01u; + } - else if (&g_mss_uart1_hi == this_uart) - { - this_uart->hw_reg = MSS_UART1_HI_BASE; - g_uart_axi_pos |= 0x02u; - } + else if (&g_mss_uart1_hi == this_uart) { + this_uart->hw_reg = MSS_UART1_HI_BASE; + g_uart_axi_pos |= 0x02u; + } - else if (&g_mss_uart2_hi == this_uart) - { - this_uart->hw_reg = MSS_UART2_HI_BASE; - g_uart_axi_pos |= 0x04u; - } + else if (&g_mss_uart2_hi == this_uart) { + this_uart->hw_reg = MSS_UART2_HI_BASE; + g_uart_axi_pos |= 0x04u; + } - else if (&g_mss_uart3_hi == this_uart) - { - this_uart->hw_reg = MSS_UART3_HI_BASE; - g_uart_axi_pos |= 0x08u; - } + else if (&g_mss_uart3_hi == this_uart) { + this_uart->hw_reg = MSS_UART3_HI_BASE; + g_uart_axi_pos |= 0x08u; + } - else if (&g_mss_uart4_hi == this_uart) - { - this_uart->hw_reg = MSS_UART4_HI_BASE; - g_uart_axi_pos |= 0x10u; - } - else - { - ASSERT(0); /*Comment to avoid LDRA warning*/ - } + else if (&g_mss_uart4_hi == this_uart) { + this_uart->hw_reg = MSS_UART4_HI_BASE; + g_uart_axi_pos |= 0x10u; + } else { + ASSERT(0); /*Comment to avoid LDRA warning*/ + } - /* disable interrupts */ - this_uart->hw_reg->IER = 0u; + /* disable interrupts */ + this_uart->hw_reg->IER = 0u; - /* FIFO configuration */ - this_uart->hw_reg->FCR = 0u; + /* FIFO configuration */ + this_uart->hw_reg->FCR = 0u; - /* clear receiver FIFO */ - this_uart->hw_reg->FCR |= CLEAR_RX_FIFO_MASK; + /* clear receiver FIFO */ + this_uart->hw_reg->FCR |= CLEAR_RX_FIFO_MASK; - /* clear transmitter FIFO */ - this_uart->hw_reg->FCR |= CLEAR_TX_FIFO_MASK; + /* clear transmitter FIFO */ + this_uart->hw_reg->FCR |= CLEAR_TX_FIFO_MASK; - /* set default READY mode : Mode 0*/ - /* enable RXRDYN and TXRDYN pins. The earlier FCR write to set the TX FIFO - * trigger level inadvertently disabled the FCR_RXRDY_TXRDYN_EN bit. */ - this_uart->hw_reg->FCR |= RXRDY_TXRDYN_EN_MASK; + /* set default READY mode : Mode 0*/ + /* enable RXRDYN and TXRDYN pins. The earlier FCR write to set the TX FIFO + * trigger level inadvertently disabled the FCR_RXRDY_TXRDYN_EN bit. */ + this_uart->hw_reg->FCR |= RXRDY_TXRDYN_EN_MASK; - /* disable loopback : local * remote */ - this_uart->hw_reg->MCR &= ~LOOP_MASK; + /* disable loopback : local * remote */ + this_uart->hw_reg->MCR &= ~LOOP_MASK; - this_uart->hw_reg->MCR &= ~RLOOP_MASK; + this_uart->hw_reg->MCR &= ~RLOOP_MASK; - /* set default TX endian */ - this_uart->hw_reg->MM1 &= ~E_MSB_TX_MASK; + /* set default TX endian */ + this_uart->hw_reg->MM1 &= ~E_MSB_TX_MASK; - /* set default RX endian */ - this_uart->hw_reg->MM1 &= ~E_MSB_RX_MASK; + /* set default RX endian */ + this_uart->hw_reg->MM1 &= ~E_MSB_RX_MASK; - /* default AFM : disabled */ - this_uart->hw_reg->MM2 &= ~EAFM_MASK; + /* default AFM : disabled */ + this_uart->hw_reg->MM2 &= ~EAFM_MASK; - /* disable TX time guard */ - this_uart->hw_reg->MM0 &= ~ETTG_MASK; + /* disable TX time guard */ + this_uart->hw_reg->MM0 &= ~ETTG_MASK; - /* set default RX timeout */ - this_uart->hw_reg->MM0 &= ~ERTO_MASK; + /* set default RX timeout */ + this_uart->hw_reg->MM0 &= ~ERTO_MASK; - /* disable fractional baud-rate */ - this_uart->hw_reg->MM0 &= ~EFBR_MASK; + /* disable fractional baud-rate */ + this_uart->hw_reg->MM0 &= ~EFBR_MASK; - /* disable single wire mode */ - this_uart->hw_reg->MM2 &= ~ESWM_MASK; + /* disable single wire mode */ + this_uart->hw_reg->MM2 &= ~ESWM_MASK; - /* set filter to minimum value */ - this_uart->hw_reg->GFR = 0u; + /* set filter to minimum value */ + this_uart->hw_reg->GFR = 0u; - /* set default TX time guard */ - this_uart->hw_reg->TTG = 0u; + /* set default TX time guard */ + this_uart->hw_reg->TTG = 0u; - /* set default RX timeout */ - this_uart->hw_reg->RTO = 0u; + /* set default RX timeout */ + this_uart->hw_reg->RTO = 0u; - /* - * Configure baud rate divisors. This uses the fractional baud rate divisor - * where possible to provide the most accurate baud rat possible. - */ - config_baud_divisors(this_uart, baud_rate); + /* + * Configure baud rate divisors. This uses the fractional baud rate divisor + * where possible to provide the most accurate baud rat possible. + */ + config_baud_divisors(this_uart, baud_rate); - /* set the line control register (bit length, stop bits, parity) */ - this_uart->hw_reg->LCR = line_config; + /* set the line control register (bit length, stop bits, parity) */ + this_uart->hw_reg->LCR = line_config; - /* Instance setup */ - this_uart->baudrate = baud_rate; - this_uart->lineconfig = line_config; - this_uart->tx_buff_size = TX_COMPLETE; - this_uart->tx_buffer = (const uint8_t*)0; - this_uart->tx_idx = 0u; + /* Instance setup */ + this_uart->baudrate = baud_rate; + this_uart->lineconfig = line_config; + this_uart->tx_buff_size = TX_COMPLETE; + this_uart->tx_buffer = (const uint8_t*)0; + this_uart->tx_idx = 0u; - /* Initialize the sticky status */ - this_uart->status = 0u; + /* Initialize the sticky status */ + this_uart->status = 0u; } -/***************************************************************************//** - * Configure baud divisors using fractional baud rate if possible. - */ +/***************************************************************************/ /** + * Configure baud divisors using fractional baud rate if possible. + */ static void -config_baud_divisors -( - mss_uart_instance_t * this_uart, - uint32_t baudrate -) -{ - uint32_t baud_value; - uint32_t baud_value_by_64; - uint32_t baud_value_by_128; - uint32_t fractional_baud_value; - uint64_t pclk_freq; - - this_uart->baudrate = baudrate; - - /* Use the system clock value from hw_platform.h */ - pclk_freq = LIBERO_SETTING_MSS_APB_AHB_CLK; - - /* - * Compute baud value based on requested baud rate and PCLK frequency. - * The baud value is computed using the following equation: - * baud_value = PCLK_Frequency / (baud_rate * 16) - */ - baud_value_by_128 = (uint32_t)((8UL * pclk_freq) / baudrate); - baud_value_by_64 = baud_value_by_128 / 2u; - baud_value = baud_value_by_64 / 64u; - fractional_baud_value = baud_value_by_64 - (baud_value * 64u); - fractional_baud_value += (baud_value_by_128 - (baud_value * 128u)) - - (fractional_baud_value * 2u); - - /* Assert if integer baud value fits in 16-bit. */ - ASSERT(baud_value <= UINT16_MAX); - - if (baud_value <= (uint32_t)UINT16_MAX) - { - if (baud_value > 1u) - { - /* - * Use Fractional baud rate divisors - */ - /* set divisor latch */ - this_uart->hw_reg->LCR |= DLAB_MASK; - - /* msb of baud value */ - this_uart->hw_reg->DMR = (uint8_t)(baud_value >> 8); - /* lsb of baud value */ - this_uart->hw_reg->DLR = (uint8_t)baud_value; - - /* reset divisor latch */ - this_uart->hw_reg->LCR &= ~DLAB_MASK; - - /* Enable Fractional baud rate */ - this_uart->hw_reg->MM0 |= EFBR_MASK; - - /* Load the fractional baud rate register */ - ASSERT(fractional_baud_value <= (uint32_t)UINT8_MAX); - this_uart->hw_reg->DFR = (uint8_t)fractional_baud_value; - } - else - { - /* - * Do NOT use Fractional baud rate divisors. - */ - /* set divisor latch */ - this_uart->hw_reg->LCR |= DLAB_MASK; - - /* msb of baud value */ - this_uart->hw_reg->DMR = (uint8_t)(baud_value >> 8u); - - /* lsb of baud value */ - this_uart->hw_reg->DLR = (uint8_t)baud_value; - - /* reset divisor latch */ - this_uart->hw_reg->LCR &= ~DLAB_MASK; - - /* Disable Fractional baud rate */ - this_uart->hw_reg->MM0 &= ~EFBR_MASK; - } +config_baud_divisors(mss_uart_instance_t* this_uart, uint32_t baudrate) { + uint32_t baud_value; + uint32_t baud_value_by_64; + uint32_t baud_value_by_128; + uint32_t fractional_baud_value; + uint64_t pclk_freq; + + this_uart->baudrate = baudrate; + + /* Use the system clock value from hw_platform.h */ + pclk_freq = LIBERO_SETTING_MSS_APB_AHB_CLK; + + /* + * Compute baud value based on requested baud rate and PCLK frequency. + * The baud value is computed using the following equation: + * baud_value = PCLK_Frequency / (baud_rate * 16) + */ + baud_value_by_128 = (uint32_t)((8UL * pclk_freq) / baudrate); + baud_value_by_64 = baud_value_by_128 / 2u; + baud_value = baud_value_by_64 / 64u; + fractional_baud_value = baud_value_by_64 - (baud_value * 64u); + fractional_baud_value += + (baud_value_by_128 - (baud_value * 128u)) - (fractional_baud_value * 2u); + + /* Assert if integer baud value fits in 16-bit. */ + ASSERT(baud_value <= UINT16_MAX); + + if (baud_value <= (uint32_t)UINT16_MAX) { + if (baud_value > 1u) { + /* + * Use Fractional baud rate divisors + */ + /* set divisor latch */ + this_uart->hw_reg->LCR |= DLAB_MASK; + + /* msb of baud value */ + this_uart->hw_reg->DMR = (uint8_t)(baud_value >> 8); + /* lsb of baud value */ + this_uart->hw_reg->DLR = (uint8_t)baud_value; + + /* reset divisor latch */ + this_uart->hw_reg->LCR &= ~DLAB_MASK; + + /* Enable Fractional baud rate */ + this_uart->hw_reg->MM0 |= EFBR_MASK; + + /* Load the fractional baud rate register */ + ASSERT(fractional_baud_value <= (uint32_t)UINT8_MAX); + this_uart->hw_reg->DFR = (uint8_t)fractional_baud_value; + } else { + /* + * Do NOT use Fractional baud rate divisors. + */ + /* set divisor latch */ + this_uart->hw_reg->LCR |= DLAB_MASK; + + /* msb of baud value */ + this_uart->hw_reg->DMR = (uint8_t)(baud_value >> 8u); + + /* lsb of baud value */ + this_uart->hw_reg->DLR = (uint8_t)baud_value; + + /* reset divisor latch */ + this_uart->hw_reg->LCR &= ~DLAB_MASK; + + /* Disable Fractional baud rate */ + this_uart->hw_reg->MM0 &= ~EFBR_MASK; } + } } #ifdef __cplusplus diff --git a/sm/plat/mpfs/drivers/mss_uart/mss_uart.h b/sm/plat/mpfs/drivers/mss_uart/mss_uart.h index 8334e1013..829446085 100644 --- a/sm/plat/mpfs/drivers/mss_uart/mss_uart.h +++ b/sm/plat/mpfs/drivers/mss_uart/mss_uart.h @@ -323,425 +323,418 @@ extern "C" { #endif - -/***************************************************************************//** - Baud rates - ========== - The following definitions are used to specify standard baud rates as a - parameter to the MSS_UART_init() function. - - | Constant | Description | - |----------------------|------------------| - | MSS_UART_110_BAUD | 110 baud rate | - | MSS_UART_300_BAUD | 300 baud rate | - | MSS_UART_600_BAUD | 600 baud rate | - | MSS_UART_1200_BAUD | 1200 baud rate | - | MSS_UART_2400_BAUD | 2400 baud rate | - | MSS_UART_4800_BAUD | 4800 baud rate | - | MSS_UART_9600_BAUD | 9600 baud rate | - | MSS_UART_19200_BAUD | 19200 baud rate | - | MSS_UART_38400_BAUD | 38400 baud rate | - | MSS_UART_57600_BAUD | 57600 baud rate | - | MSS_UART_115200_BAUD | 115200 baud rate | - | MSS_UART_230400_BAUD | 230400 baud rate | - | MSS_UART_460800_BAUD | 460800 baud rate | - | MSS_UART_921600_BAUD | 921600 baud rate | - - */ -#define MSS_UART_110_BAUD 110U -#define MSS_UART_300_BAUD 300U -#define MSS_UART_600_BAUD 600U -#define MSS_UART_1200_BAUD 1200U -#define MSS_UART_2400_BAUD 2400U -#define MSS_UART_4800_BAUD 4800U -#define MSS_UART_9600_BAUD 9600U -#define MSS_UART_19200_BAUD 19200U -#define MSS_UART_38400_BAUD 38400U -#define MSS_UART_57600_BAUD 57600U -#define MSS_UART_115200_BAUD 115200U -#define MSS_UART_230400_BAUD 230400U -#define MSS_UART_460800_BAUD 460800U -#define MSS_UART_921600_BAUD 921600U - -/***************************************************************************//** - Data Bits Length - ================ - The following defines are used to build the value of the MSS_UART_init() - function line_config parameter. - - | Constant | Description | - |----------------------|----------------------------| - | MSS_UART_DATA_5_BITS | 5 bits of data transmitted | - | MSS_UART_DATA_6_BITS | 6 bits of data transmitted | - | MSS_UART_DATA_7_BITS | 7 bits of data transmitted | - | MSS_UART_DATA_8_BITS | 8 bits of data transmitted | - - */ -#define MSS_UART_DATA_5_BITS ((uint8_t) 0x00) -#define MSS_UART_DATA_6_BITS ((uint8_t) 0x01) -#define MSS_UART_DATA_7_BITS ((uint8_t) 0x02) -#define MSS_UART_DATA_8_BITS ((uint8_t) 0x03) - -/***************************************************************************//** - Parity - ====== - The following defines are used to build the value of the MSS_UART_init() - function line_config parameter. - - | Constant | Description | - |-------------------------|--------------------------| - | MSS_UART_NO_PARITY | No parity | - | MSS_UART_ODD_PARITY | Odd Parity | - | MSS_UART_EVEN_PARITY | Even parity | - | MSS_UART_STICK_PARITY_0 | Stick parity bit to zero | - | MSS_UART_STICK_PARITY_1 | Stick parity bit to one | - - */ -#define MSS_UART_NO_PARITY ((uint8_t) 0x00) -#define MSS_UART_ODD_PARITY ((uint8_t) 0x08) -#define MSS_UART_EVEN_PARITY ((uint8_t) 0x18) -#define MSS_UART_STICK_PARITY_0 ((uint8_t) 0x38) -#define MSS_UART_STICK_PARITY_1 ((uint8_t) 0x28) - -/***************************************************************************//** - Number of Stop Bits - =================== - The following defines are used to build the value of the MSS_UART_init() - function line_config parameter. - - | Constant | Description | - |---------------------------|--------------------------| - | MSS_UART_ONE_STOP_BIT | One stop bit | - | MSS_UART_ONEHALF_STOP_BIT | One and a half stop bits | - | MSS_UART_TWO_STOP_BITS | Two stop bits | - - */ -#define MSS_UART_ONE_STOP_BIT ((uint8_t) 0x00) -#define MSS_UART_ONEHALF_STOP_BIT ((uint8_t) 0x04) -#define MSS_UART_TWO_STOP_BITS ((uint8_t) 0x04) - -/***************************************************************************//** - Receiver Error Status - ===================== - The following defines are used to determine the UART receiver error type. - These bit mask constants are used with the return value of the - MSS_UART_get_rx_status() function to find out if any errors occurred while - receiving data. - - - | Constant | Description | - |------------------------|--------------------------------------------| - | MSS_UART_NO_ERROR | No error bit mask (0x00) | - | MSS_UART_OVERUN_ERROR | Overrun error bit mask (0x02) | - | MSS_UART_PARITY_ERROR | Parity error bit mask (0x04) | - | MSS_UART_FRAMING_ERROR | Framing error bit mask (0x08) | - | MSS_UART_BREAK_ERROR | Break error bit mask (0x10) | - | MSS_UART_FIFO_ERROR | FIFO error bit mask (0x80) | - | MSS_UART_INVALID_PARAM | Invalid function parameter bit mask (0xFF) | - - */ -#define MSS_UART_INVALID_PARAM ((uint8_t)0xFF) -#define MSS_UART_NO_ERROR ((uint8_t)0x00 ) -#define MSS_UART_OVERUN_ERROR ((uint8_t)0x02) -#define MSS_UART_PARITY_ERROR ((uint8_t)0x04) -#define MSS_UART_FRAMING_ERROR ((uint8_t)0x08) -#define MSS_UART_BREAK_ERROR ((uint8_t)0x10) -#define MSS_UART_FIFO_ERROR ((uint8_t)0x80) - -/***************************************************************************//** - Transmitter Status - ================== - The following definitions are used to determine the UART transmitter status. - These bit mask constants are used with the return value of the - MSS_UART_get_tx_status() function to find out the status of the transmitter. - - | Constant | Description | - |------------------|----------------------------------------------------| - | MSS_UART_TX_BUSY | Transmitter busy (0x00) | - | MSS_UART_THRE | Transmitter holding register empty bit mask (0x20) | - | MSS_UART_TEMT | Transmitter empty bit mask (0x40) | - - */ -#define MSS_UART_TX_BUSY ((uint8_t) 0x00) -#define MSS_UART_THRE ((uint8_t) 0x20) -#define MSS_UART_TEMT ((uint8_t) 0x40) - -/***************************************************************************//** - Modem Status - ============ - The following defines are used to determine the modem status. These bit - mask constants are used with the return value of the - MSS_UART_get_modem_status() function to find out the modem status of - the UART. - - | Constant | Description | - |---------------|-------------------------------------------------| - | MSS_UART_DCTS | Delta clear to send bit mask (0x01) | - | MSS_UART_DDSR | Delta data set ready bit mask (0x02) | - | MSS_UART_TERI | Trailing edge of ring indicator bit mask (0x04) | - | MSS_UART_DDCD | Delta data carrier detect bit mask (0x08) | - | MSS_UART_CTS | Clear to send bit mask (0x10) | - | MSS_UART_DSR | Data set ready bit mask (0x20) | - | MSS_UART_RI | Ring indicator bit mask (0x40) | - | MSS_UART_DCD | Data carrier detect bit mask (0x80) | - - */ -#define MSS_UART_DCTS ((uint8_t) 0x01) -#define MSS_UART_DDSR ((uint8_t) 0x02) -#define MSS_UART_TERI ((uint8_t) 0x04) -#define MSS_UART_DDCD ((uint8_t) 0x08) -#define MSS_UART_CTS ((uint8_t) 0x10) -#define MSS_UART_DSR ((uint8_t) 0x20) -#define MSS_UART_RI ((uint8_t) 0x40) -#define MSS_UART_DCD ((uint8_t) 0x80) - - -/***************************************************************************//** - This enumeration specifies the receiver FIFO trigger level. This is the number - of bytes that must be received before the UART generates a receive data - available interrupt. It provides the allowed values for the - MSS_UART_set_rx_handler() function trigger_level parameter. - */ +/***************************************************************************/ /** + Baud rates + ========== + The following definitions are used to specify standard baud rates as a + parameter to the MSS_UART_init() function. + + | Constant | Description | + |----------------------|------------------| + | MSS_UART_110_BAUD | 110 baud rate | + | MSS_UART_300_BAUD | 300 baud rate | + | MSS_UART_600_BAUD | 600 baud rate | + | MSS_UART_1200_BAUD | 1200 baud rate | + | MSS_UART_2400_BAUD | 2400 baud rate | + | MSS_UART_4800_BAUD | 4800 baud rate | + | MSS_UART_9600_BAUD | 9600 baud rate | + | MSS_UART_19200_BAUD | 19200 baud rate | + | MSS_UART_38400_BAUD | 38400 baud rate | + | MSS_UART_57600_BAUD | 57600 baud rate | + | MSS_UART_115200_BAUD | 115200 baud rate | + | MSS_UART_230400_BAUD | 230400 baud rate | + | MSS_UART_460800_BAUD | 460800 baud rate | + | MSS_UART_921600_BAUD | 921600 baud rate | + + */ +#define MSS_UART_110_BAUD 110U +#define MSS_UART_300_BAUD 300U +#define MSS_UART_600_BAUD 600U +#define MSS_UART_1200_BAUD 1200U +#define MSS_UART_2400_BAUD 2400U +#define MSS_UART_4800_BAUD 4800U +#define MSS_UART_9600_BAUD 9600U +#define MSS_UART_19200_BAUD 19200U +#define MSS_UART_38400_BAUD 38400U +#define MSS_UART_57600_BAUD 57600U +#define MSS_UART_115200_BAUD 115200U +#define MSS_UART_230400_BAUD 230400U +#define MSS_UART_460800_BAUD 460800U +#define MSS_UART_921600_BAUD 921600U + +/***************************************************************************/ /** + Data Bits Length + ================ + The following defines are used to build the value of the MSS_UART_init() + function line_config parameter. + + | Constant | Description | + |----------------------|----------------------------| + | MSS_UART_DATA_5_BITS | 5 bits of data transmitted | + | MSS_UART_DATA_6_BITS | 6 bits of data transmitted | + | MSS_UART_DATA_7_BITS | 7 bits of data transmitted | + | MSS_UART_DATA_8_BITS | 8 bits of data transmitted | + + */ +#define MSS_UART_DATA_5_BITS ((uint8_t)0x00) +#define MSS_UART_DATA_6_BITS ((uint8_t)0x01) +#define MSS_UART_DATA_7_BITS ((uint8_t)0x02) +#define MSS_UART_DATA_8_BITS ((uint8_t)0x03) + +/***************************************************************************/ /** + Parity + ====== + The following defines are used to build the value of the MSS_UART_init() + function line_config parameter. + + | Constant | Description | + |-------------------------|--------------------------| + | MSS_UART_NO_PARITY | No parity | + | MSS_UART_ODD_PARITY | Odd Parity | + | MSS_UART_EVEN_PARITY | Even parity | + | MSS_UART_STICK_PARITY_0 | Stick parity bit to zero | + | MSS_UART_STICK_PARITY_1 | Stick parity bit to one | + + */ +#define MSS_UART_NO_PARITY ((uint8_t)0x00) +#define MSS_UART_ODD_PARITY ((uint8_t)0x08) +#define MSS_UART_EVEN_PARITY ((uint8_t)0x18) +#define MSS_UART_STICK_PARITY_0 ((uint8_t)0x38) +#define MSS_UART_STICK_PARITY_1 ((uint8_t)0x28) + +/***************************************************************************/ /** + Number of Stop Bits + =================== + The following defines are used to build the value of the MSS_UART_init() + function line_config parameter. + + | Constant | Description | + |---------------------------|--------------------------| + | MSS_UART_ONE_STOP_BIT | One stop bit | + | MSS_UART_ONEHALF_STOP_BIT | One and a half stop bits | + | MSS_UART_TWO_STOP_BITS | Two stop bits | + + */ +#define MSS_UART_ONE_STOP_BIT ((uint8_t)0x00) +#define MSS_UART_ONEHALF_STOP_BIT ((uint8_t)0x04) +#define MSS_UART_TWO_STOP_BITS ((uint8_t)0x04) + +/***************************************************************************/ /** + Receiver Error Status + ===================== + The following defines are used to determine the UART receiver error type. + These bit mask constants are used with the return value of the + MSS_UART_get_rx_status() function to find out if any errors occurred while + receiving data. + + + | Constant | Description | + |------------------------|--------------------------------------------| + | MSS_UART_NO_ERROR | No error bit mask (0x00) | + | MSS_UART_OVERUN_ERROR | Overrun error bit mask (0x02) | + | MSS_UART_PARITY_ERROR | Parity error bit mask (0x04) | + | MSS_UART_FRAMING_ERROR | Framing error bit mask (0x08) | + | MSS_UART_BREAK_ERROR | Break error bit mask (0x10) | + | MSS_UART_FIFO_ERROR | FIFO error bit mask (0x80) | + | MSS_UART_INVALID_PARAM | Invalid function parameter bit mask (0xFF) | + + */ +#define MSS_UART_INVALID_PARAM ((uint8_t)0xFF) +#define MSS_UART_NO_ERROR ((uint8_t)0x00) +#define MSS_UART_OVERUN_ERROR ((uint8_t)0x02) +#define MSS_UART_PARITY_ERROR ((uint8_t)0x04) +#define MSS_UART_FRAMING_ERROR ((uint8_t)0x08) +#define MSS_UART_BREAK_ERROR ((uint8_t)0x10) +#define MSS_UART_FIFO_ERROR ((uint8_t)0x80) + +/***************************************************************************/ /** + Transmitter Status + ================== + The following definitions are used to determine the UART transmitter status. + These bit mask constants are used with the return value of the + MSS_UART_get_tx_status() function to find out the status of the transmitter. + + | Constant | Description | + |------------------|----------------------------------------------------| + | MSS_UART_TX_BUSY | Transmitter busy (0x00) | + | MSS_UART_THRE | Transmitter holding register empty bit mask (0x20) | + | MSS_UART_TEMT | Transmitter empty bit mask (0x40) | + + */ +#define MSS_UART_TX_BUSY ((uint8_t)0x00) +#define MSS_UART_THRE ((uint8_t)0x20) +#define MSS_UART_TEMT ((uint8_t)0x40) + +/***************************************************************************/ /** + Modem Status + ============ + The following defines are used to determine the modem status. These bit + mask constants are used with the return value of the + MSS_UART_get_modem_status() function to find out the modem status of + the UART. + + | Constant | Description | + |---------------|-------------------------------------------------| + | MSS_UART_DCTS | Delta clear to send bit mask (0x01) | + | MSS_UART_DDSR | Delta data set ready bit mask (0x02) | + | MSS_UART_TERI | Trailing edge of ring indicator bit mask (0x04) | + | MSS_UART_DDCD | Delta data carrier detect bit mask (0x08) | + | MSS_UART_CTS | Clear to send bit mask (0x10) | + | MSS_UART_DSR | Data set ready bit mask (0x20) | + | MSS_UART_RI | Ring indicator bit mask (0x40) | + | MSS_UART_DCD | Data carrier detect bit mask (0x80) | + + */ +#define MSS_UART_DCTS ((uint8_t)0x01) +#define MSS_UART_DDSR ((uint8_t)0x02) +#define MSS_UART_TERI ((uint8_t)0x04) +#define MSS_UART_DDCD ((uint8_t)0x08) +#define MSS_UART_CTS ((uint8_t)0x10) +#define MSS_UART_DSR ((uint8_t)0x20) +#define MSS_UART_RI ((uint8_t)0x40) +#define MSS_UART_DCD ((uint8_t)0x80) + +/***************************************************************************/ /** + This enumeration specifies the receiver FIFO trigger level. This is the + number of bytes that must be received before the UART generates a receive + data available interrupt. It provides the allowed values for the + MSS_UART_set_rx_handler() function trigger_level parameter. + */ typedef enum { - MSS_UART_FIFO_SINGLE_BYTE = 0x00, - MSS_UART_FIFO_FOUR_BYTES = 0x40, - MSS_UART_FIFO_EIGHT_BYTES = 0x80, - MSS_UART_FIFO_FOURTEEN_BYTES = 0xC0, - MSS_UART_FIFO_INVALID_TRIG_LEVEL + MSS_UART_FIFO_SINGLE_BYTE = 0x00, + MSS_UART_FIFO_FOUR_BYTES = 0x40, + MSS_UART_FIFO_EIGHT_BYTES = 0x80, + MSS_UART_FIFO_FOURTEEN_BYTES = 0xC0, + MSS_UART_FIFO_INVALID_TRIG_LEVEL } mss_uart_rx_trig_level_t; -/***************************************************************************//** - This enumeration specifies the loopback configuration of the UART. It provides - the allowed values for the MSS_UART_set_loopback() function's loopback - parameter. Use MSS_UART_LOCAL_LOOPBACK_ON to set up the UART to locally - loopback its Tx and Rx lines. Use MSS_UART_REMOTE_LOOPBACK_ON to set up the - UART in remote loopback mode. - */ +/***************************************************************************/ /** + This enumeration specifies the loopback configuration of the UART. It + provides the allowed values for the MSS_UART_set_loopback() function's + loopback parameter. Use MSS_UART_LOCAL_LOOPBACK_ON to set up the UART to + locally loopback its Tx and Rx lines. Use MSS_UART_REMOTE_LOOPBACK_ON to set + up the UART in remote loopback mode. + */ typedef enum { - MSS_UART_LOCAL_LOOPBACK_OFF, - MSS_UART_LOCAL_LOOPBACK_ON, - MSS_UART_REMOTE_LOOPBACK_OFF, - MSS_UART_REMOTE_LOOPBACK_ON, - MSS_UART_AUTO_ECHO_OFF, - MSS_UART_AUTO_ECHO_ON, - MSS_UART_INVALID_LOOPBACK + MSS_UART_LOCAL_LOOPBACK_OFF, + MSS_UART_LOCAL_LOOPBACK_ON, + MSS_UART_REMOTE_LOOPBACK_OFF, + MSS_UART_REMOTE_LOOPBACK_ON, + MSS_UART_AUTO_ECHO_OFF, + MSS_UART_AUTO_ECHO_ON, + MSS_UART_INVALID_LOOPBACK } mss_uart_loopback_t; -/***************************************************************************//** - IrDA input / output polarity. - This enumeration specifies the RZI modem polarity for input and output signals. - This is passed as parameters in MSS_UART_irda_init() function. - */ +/***************************************************************************/ /** + IrDA input / output polarity. + This enumeration specifies the RZI modem polarity for input and output + signals. This is passed as parameters in MSS_UART_irda_init() function. + */ typedef enum { - MSS_UART_ACTIVE_LOW = 0u, - MSS_UART_ACTIVE_HIGH = 1u, - MSS_UART_INVALID_POLARITY + MSS_UART_ACTIVE_LOW = 0u, + MSS_UART_ACTIVE_HIGH = 1u, + MSS_UART_INVALID_POLARITY } mss_uart_rzi_polarity_t; -/***************************************************************************//** - IrDA input / output pulse width. - This enumeration specifies the RZI modem pulse width for input and output - signals. This is passed as parameters in MSS_UART_irda_init() function. - */ +/***************************************************************************/ /** + IrDA input / output pulse width. + This enumeration specifies the RZI modem pulse width for input and output + signals. This is passed as parameters in MSS_UART_irda_init() function. + */ typedef enum { - MSS_UART_3_BY_16 = 0u, - MSS_UART_1_BY_4 = 1u, - MSS_UART_INVALID_PW + MSS_UART_3_BY_16 = 0u, + MSS_UART_1_BY_4 = 1u, + MSS_UART_INVALID_PW } mss_uart_rzi_pulsewidth_t; -/***************************************************************************//** - Tx / Rx endianess. - This enumeration specifies the MSB first or LSB first for MSS UART transmitter - and receiver. The parameter of this type shall be passed in - MSS_UART_set_rx_endian()and MSS_UART_set_tx_endian() functions. - */ +/***************************************************************************/ /** + Tx / Rx endianess. + This enumeration specifies the MSB first or LSB first for MSS UART + transmitter and receiver. The parameter of this type shall be passed in + MSS_UART_set_rx_endian()and MSS_UART_set_tx_endian() functions. + */ typedef enum { - MSS_UART_LITTLEEND, - MSS_UART_BIGEND, - MSS_UART_INVALID_ENDIAN + MSS_UART_LITTLEEND, + MSS_UART_BIGEND, + MSS_UART_INVALID_ENDIAN } mss_uart_endian_t; -/***************************************************************************//** - Glitch filter length. - This enumeration specifies the glitch filter length. The function - MSS_UART_set_filter_length() accepts the parameter of this type. - */ +/***************************************************************************/ /** + Glitch filter length. + This enumeration specifies the glitch filter length. The function + MSS_UART_set_filter_length() accepts the parameter of this type. + */ typedef enum { - MSS_UART_LEN0 = 0, - MSS_UART_LEN1 = 1, - MSS_UART_LEN2 = 2, - MSS_UART_LEN3 = 3, - MSS_UART_LEN4 = 4, - MSS_UART_LEN5 = 5, - MSS_UART_LEN6 = 6, - MSS_UART_LEN7 = 7, - MSS_UART_INVALID_FILTER_LENGTH = 8 + MSS_UART_LEN0 = 0, + MSS_UART_LEN1 = 1, + MSS_UART_LEN2 = 2, + MSS_UART_LEN3 = 3, + MSS_UART_LEN4 = 4, + MSS_UART_LEN5 = 5, + MSS_UART_LEN6 = 6, + MSS_UART_LEN7 = 7, + MSS_UART_INVALID_FILTER_LENGTH = 8 } mss_uart_filter_length_t; -/***************************************************************************//** - TXRDY and RXRDY mode. - This enumeration specifies the TXRDY and RXRDY signal modes. The function - MSS_UART_set_ready_mode() accepts the parameter of this type. - */ +/***************************************************************************/ /** + TXRDY and RXRDY mode. + This enumeration specifies the TXRDY and RXRDY signal modes. The function + MSS_UART_set_ready_mode() accepts the parameter of this type. + */ typedef enum { - MSS_UART_READY_MODE0, - MSS_UART_READY_MODE1, - MSS_UART_INVALID_READY_MODE + MSS_UART_READY_MODE0, + MSS_UART_READY_MODE1, + MSS_UART_INVALID_READY_MODE } mss_uart_ready_mode_t; -/***************************************************************************//** - USART mode of operation. - This enumeration specifies the mode of operation of MSS UART when operating - as USART. The function MSS_UART_set_usart_mode() accepts the parameter of this - type. - */ +/***************************************************************************/ /** + USART mode of operation. + This enumeration specifies the mode of operation of MSS UART when operating + as USART. The function MSS_UART_set_usart_mode() accepts the parameter of + this type. + */ typedef enum { - MSS_UART_ASYNC_MODE = 0, - MSS_UART_SYNC_SLAVE_POS_EDGE_CLK = 1, - MSS_UART_SYNC_SLAVE_NEG_EDGE_CLK = 2, - MSS_UART_SYNC_MASTER_POS_EDGE_CLK = 3, - MSS_UART_SYNC_MASTER_NEG_EDGE_CLK = 4, - MSS_UART_INVALID_SYNC_MODE = 5 + MSS_UART_ASYNC_MODE = 0, + MSS_UART_SYNC_SLAVE_POS_EDGE_CLK = 1, + MSS_UART_SYNC_SLAVE_NEG_EDGE_CLK = 2, + MSS_UART_SYNC_MASTER_POS_EDGE_CLK = 3, + MSS_UART_SYNC_MASTER_NEG_EDGE_CLK = 4, + MSS_UART_INVALID_SYNC_MODE = 5 } mss_uart_usart_mode_t; - typedef enum { - MSS_UART0_LO = 0, - MSS_UART1_LO = 1, - MSS_UART2_LO = 2, - MSS_UART3_LO = 3, - MSS_UART4_LO = 4, - MSS_UART0_HI = 5, - MSS_UART1_HI = 6, - MSS_UART2_HI = 7, - MSS_UART3_HI = 8, - MSS_UAR4_HI = 9, + MSS_UART0_LO = 0, + MSS_UART1_LO = 1, + MSS_UART2_LO = 2, + MSS_UART3_LO = 3, + MSS_UART4_LO = 4, + MSS_UART0_HI = 5, + MSS_UART1_HI = 6, + MSS_UART2_HI = 7, + MSS_UART3_HI = 8, + MSS_UAR4_HI = 9, } mss_uart_num_t; -/***************************************************************************//** - MSS UART instance type. - This is type definition for MSS UART instance. You need to create and - maintain a record of this type. This holds all data regarding the MSS UART - instance - */ -typedef struct mss_uart_instance mss_uart_instance_t; +/***************************************************************************/ /** + MSS UART instance type. + This is type definition for MSS UART instance. You need to create and + maintain a record of this type. This holds all data regarding the MSS UART + instance + */ +typedef struct mss_uart_instance mss_uart_instance_t; /*----------------------------------------------------------------------------*/ /*----------------------------------- UART -----------------------------------*/ /*----------------------------------------------------------------------------*/ -typedef struct -{ - union - { - volatile const uint8_t RBR; - volatile uint8_t THR; - volatile uint8_t DLR; - uint32_t RESERVED0; - }; +typedef struct { + union { + volatile const uint8_t RBR; + volatile uint8_t THR; + volatile uint8_t DLR; + uint32_t RESERVED0; + }; - union - { - volatile uint8_t DMR; - volatile uint8_t IER; - uint32_t RESERVED1; - }; + union { + volatile uint8_t DMR; + volatile uint8_t IER; + uint32_t RESERVED1; + }; - union - { - volatile uint8_t IIR; - volatile uint8_t FCR; - uint32_t RESERVED2; - }; + union { + volatile uint8_t IIR; + volatile uint8_t FCR; + uint32_t RESERVED2; + }; - volatile uint8_t LCR; - uint8_t RESERVED3[3]; + volatile uint8_t LCR; + uint8_t RESERVED3[3]; - volatile uint8_t MCR; - uint8_t RESERVED4[3]; + volatile uint8_t MCR; + uint8_t RESERVED4[3]; - volatile const uint8_t LSR; - uint8_t RESERVED5[3]; + volatile const uint8_t LSR; + uint8_t RESERVED5[3]; - volatile const uint8_t MSR; - uint8_t RESERVED6[3]; + volatile const uint8_t MSR; + uint8_t RESERVED6[3]; - volatile uint8_t SR; - uint8_t RESERVED7[7]; + volatile uint8_t SR; + uint8_t RESERVED7[7]; - volatile uint8_t IEM; - uint8_t RESERVED8[3]; + volatile uint8_t IEM; + uint8_t RESERVED8[3]; - volatile uint8_t IIM; - uint8_t RESERVED9[7]; + volatile uint8_t IIM; + uint8_t RESERVED9[7]; - volatile uint8_t MM0; - uint8_t RESERVED10[3]; + volatile uint8_t MM0; + uint8_t RESERVED10[3]; - volatile uint8_t MM1; - uint8_t RESERVED11[3]; + volatile uint8_t MM1; + uint8_t RESERVED11[3]; - volatile uint8_t MM2; - uint8_t RESERVED12[3]; + volatile uint8_t MM2; + uint8_t RESERVED12[3]; - volatile uint8_t DFR; - uint8_t RESERVED13[7]; + volatile uint8_t DFR; + uint8_t RESERVED13[7]; - volatile uint8_t GFR; - uint8_t RESERVED14[3]; + volatile uint8_t GFR; + uint8_t RESERVED14[3]; - volatile uint8_t TTG; - uint8_t RESERVED15[3]; + volatile uint8_t TTG; + uint8_t RESERVED15[3]; - volatile uint8_t RTO; - uint8_t RESERVED16[3]; + volatile uint8_t RTO; + uint8_t RESERVED16[3]; - volatile uint8_t ADR; - uint8_t RESERVED17[3]; + volatile uint8_t ADR; + uint8_t RESERVED17[3]; } MSS_UART_TypeDef; - -/***************************************************************************//** - mss_uart_instance. - There is one instance of this structure for each instance of the - microprocessor subsystem's UARTs. Instances of this structure are used to - identify a specific UART. A pointer to an initialized instance of the - mss_uart_instance_t structure is passed as the first parameter to - MSS UART driver functions to identify which UART should perform the - requested operation. - */ -struct mss_uart_instance{ - /* CMSIS related defines identifying the UART hardware. */ - MSS_UART_TypeDef * hw_reg; /*!< Pointer to UART registers. */ - uint32_t baudrate; /*!< Operating baud rate. */ - uint8_t lineconfig; /*!< Line configuration parameters. */ - uint8_t status; /*!< Sticky line status. */ - - /* transmit related info (used with interrupt driven transmit): */ - const uint8_t * tx_buffer; /*!< Pointer to transmit buffer. */ - uint32_t tx_buff_size; /*!< Transmit buffer size. */ - uint32_t tx_idx; /*!< Index within transmit buffer of next byte to transmit.*/ - - void* user_data; /*!< Pointer to user provided pointer for user specific use. */ - +/***************************************************************************/ /** + mss_uart_instance. + There is one instance of this structure for each instance of the + microprocessor subsystem's UARTs. Instances of this structure are used to + identify a specific UART. A pointer to an initialized instance of the + mss_uart_instance_t structure is passed as the first parameter to + MSS UART driver functions to identify which UART should perform the + requested operation. + */ +struct mss_uart_instance { + /* CMSIS related defines identifying the UART hardware. */ + MSS_UART_TypeDef* hw_reg; /*!< Pointer to UART registers. */ + uint32_t baudrate; /*!< Operating baud rate. */ + uint8_t lineconfig; /*!< Line configuration parameters. */ + uint8_t status; /*!< Sticky line status. */ + + /* transmit related info (used with interrupt driven transmit): */ + const uint8_t* tx_buffer; /*!< Pointer to transmit buffer. */ + uint32_t tx_buff_size; /*!< Transmit buffer size. */ + uint32_t tx_idx; /*!< Index within transmit buffer of next byte to transmit.*/ + + void* + user_data; /*!< Pointer to user provided pointer for user specific use. */ }; -/***************************************************************************//** - This instance of mss_uart_instance_t holds all data related to the operations - performed by the MMUART. The function MSS_UART_init() initializes this structure. - A pointer to g_mss_uart0_lo is passed as the first parameter to MSS UART driver - functions to indicate that MMUART0 should perform the requested operation. - */ +/***************************************************************************/ /** + This instance of mss_uart_instance_t holds all data related to the operations + performed by the MMUART. The function MSS_UART_init() initializes this + structure. A pointer to g_mss_uart0_lo is passed as the first parameter to + MSS UART driver functions to indicate that MMUART0 should perform the + requested operation. + */ extern mss_uart_instance_t g_mss_uart0_lo; extern mss_uart_instance_t g_mss_uart1_lo; @@ -755,1584 +748,1510 @@ extern mss_uart_instance_t g_mss_uart2_hi; extern mss_uart_instance_t g_mss_uart3_hi; extern mss_uart_instance_t g_mss_uart4_hi; +/***************************************************************************/ /** + The MSS_UART_init() function initializes and configures one of the PolarFire + SoC MSS UARTs with the configuration passed as a parameter. The configuration + parameters are the baud_rate which is used to generate the baud value and the + line_config which is used to specify the line configuration (bit length, + stop bits and parity). + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + Note that if you are using the UART on the AMP APB bus, the hardware + configuration to connect UART on AMP APB bus must already be done by the + application using SYSREG registers before initializing the UART instance + structure. + + @param baud_rate + The baud_rate parameter specifies the baud rate. It can be specified for + common baud rates using the following defines: + - MSS_UART_110_BAUD + - MSS_UART_300_BAUD + - MSS_UART_600_BAUD + - MSS_UART_1200_BAUD + - MSS_UART_2400_BAUD + - MSS_UART_4800_BAUD + - MSS_UART_9600_BAUD + - MSS_UART_19200_BAUD + - MSS_UART_38400_BAUD + - MSS_UART_57600_BAUD + - MSS_UART_115200_BAUD + - MSS_UART_230400_BAUD + - MSS_UART_460800_BAUD + - MSS_UART_921600_BAUD + + Alternatively, any nonstandard baud rate can be specified by simply passing + the actual required baud rate as the value for this parameter. + + @param line_config + The line_config parameter is the line configuration specifying the bit + length, number of stop bits and parity settings. + + This is a bitwise OR of one value from each of the following groups of + allowed values: + + One of the following to specify the transmit/receive data bit length: + - MSS_UART_DATA_5_BITS + - MSS_UART_DATA_6_BITS, + - MSS_UART_DATA_7_BITS + - MSS_UART_DATA_8_BITS + + One of the following to specify the parity setting: + - MSS_UART_NO_PARITY + - MSS_UART_EVEN_PARITY + - MSS_UART_ODD_PARITY + - MSS_UART_STICK_PARITY_0 + - MSS_UART_STICK_PARITY_1 + + One of the following to specify the number of stop bits: + - MSS_UART_ONE_STOP_BIT + - MSS_UART_ONEHALF_STOP_BIT + - MSS_UART_TWO_STOP_BITS + + @return + This function does not return a value. + + Example: + @code + #include "mss_uart.h" + + int main(void) + { + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); -/***************************************************************************//** - The MSS_UART_init() function initializes and configures one of the PolarFire SoC - MSS UARTs with the configuration passed as a parameter. The configuration - parameters are the baud_rate which is used to generate the baud value and the - line_config which is used to specify the line configuration (bit length, - stop bits and parity). - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - Note that if you are using the UART on the AMP APB bus, the hardware - configuration to connect UART on AMP APB bus must already be done by the - application using SYSREG registers before initializing the UART instance - structure. - - @param baud_rate - The baud_rate parameter specifies the baud rate. It can be specified for - common baud rates using the following defines: - - MSS_UART_110_BAUD - - MSS_UART_300_BAUD - - MSS_UART_600_BAUD - - MSS_UART_1200_BAUD - - MSS_UART_2400_BAUD - - MSS_UART_4800_BAUD - - MSS_UART_9600_BAUD - - MSS_UART_19200_BAUD - - MSS_UART_38400_BAUD - - MSS_UART_57600_BAUD - - MSS_UART_115200_BAUD - - MSS_UART_230400_BAUD - - MSS_UART_460800_BAUD - - MSS_UART_921600_BAUD - - Alternatively, any nonstandard baud rate can be specified by simply passing - the actual required baud rate as the value for this parameter. - - @param line_config - The line_config parameter is the line configuration specifying the bit length, - number of stop bits and parity settings. - - This is a bitwise OR of one value from each of the following groups of - allowed values: - - One of the following to specify the transmit/receive data bit length: - - MSS_UART_DATA_5_BITS - - MSS_UART_DATA_6_BITS, - - MSS_UART_DATA_7_BITS - - MSS_UART_DATA_8_BITS - - One of the following to specify the parity setting: - - MSS_UART_NO_PARITY - - MSS_UART_EVEN_PARITY - - MSS_UART_ODD_PARITY - - MSS_UART_STICK_PARITY_0 - - MSS_UART_STICK_PARITY_1 - - One of the following to specify the number of stop bits: - - MSS_UART_ONE_STOP_BIT - - MSS_UART_ONEHALF_STOP_BIT - - MSS_UART_TWO_STOP_BITS - - @return - This function does not return a value. - - Example: - @code - #include "mss_uart.h" - - int main(void) - { - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - return(0); - } - @endcode - */ + return(0); + } + @endcode + */ void -MSS_UART_init -( - mss_uart_instance_t* this_uart, - uint32_t baud_rate, - uint8_t line_config -); - -/***************************************************************************//** - The MSS_UART_lin_init() function is used to initialize the MSS UART for - LIN mode of operation. The configuration parameters are the baud_rate which is - used to generate the baud value and the line_config which is used to specify - the line configuration (bit length, stop bits and parity). - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - Note that if you are using the UART on the AMP APB bus, the hardware - configuration to connect UART on AMP APB bus must already be done by the - application using SYSREG registers before initializing the UART instance - structure. - - @param baud_rate - The baud_rate parameter specifies the baud rate. It can be specified for - common baud rates using the following defines: - - MSS_UART_110_BAUD - - MSS_UART_300_BAUD - - MSS_UART_600_BAUD - - MSS_UART_1200_BAUD - - MSS_UART_2400_BAUD - - MSS_UART_4800_BAUD - - MSS_UART_9600_BAUD - - MSS_UART_19200_BAUD - - MSS_UART_38400_BAUD - - MSS_UART_57600_BAUD - - MSS_UART_115200_BAUD - - MSS_UART_230400_BAUD - - MSS_UART_460800_BAUD - - MSS_UART_921600_BAUD - - Alternatively, any nonstandard baud rate can be specified by simply passing - the actual required baud rate as the value for this parameter. - - @param line_config - The line_config parameter is the line configuration specifying the bit length, - number of stop bits and parity settings. - - This is a bitwise OR of one value from each of the following groups of - allowed values: - - One of the following to specify the transmit/receive data bit length: - - MSS_UART_DATA_5_BITS - - MSS_UART_DATA_6_BITS, - - MSS_UART_DATA_7_BITS - - MSS_UART_DATA_8_BITS - - One of the following to specify the parity setting: - - MSS_UART_NO_PARITY - - MSS_UART_EVEN_PARITY - - MSS_UART_ODD_PARITY - - MSS_UART_STICK_PARITY_0 - - MSS_UART_STICK_PARITY_1 - - One of the following to specify the number of stop bits: - - MSS_UART_ONE_STOP_BIT - - MSS_UART_ONEHALF_STOP_BIT - - MSS_UART_TWO_STOP_BITS - - @return - This function does not return a value. - - Example: - @code - #include "mss_uart.h" - - int main(void) - { - MSS_UART_lin_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); +MSS_UART_init( + mss_uart_instance_t* this_uart, uint32_t baud_rate, uint8_t line_config); + +/***************************************************************************/ /** + The MSS_UART_lin_init() function is used to initialize the MSS UART for + LIN mode of operation. The configuration parameters are the baud_rate which is + used to generate the baud value and the line_config which is used to specify + the line configuration (bit length, stop bits and parity). + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + Note that if you are using the UART on the AMP APB bus, the hardware + configuration to connect UART on AMP APB bus must already be done by the + application using SYSREG registers before initializing the UART instance + structure. + + @param baud_rate + The baud_rate parameter specifies the baud rate. It can be specified for + common baud rates using the following defines: + - MSS_UART_110_BAUD + - MSS_UART_300_BAUD + - MSS_UART_600_BAUD + - MSS_UART_1200_BAUD + - MSS_UART_2400_BAUD + - MSS_UART_4800_BAUD + - MSS_UART_9600_BAUD + - MSS_UART_19200_BAUD + - MSS_UART_38400_BAUD + - MSS_UART_57600_BAUD + - MSS_UART_115200_BAUD + - MSS_UART_230400_BAUD + - MSS_UART_460800_BAUD + - MSS_UART_921600_BAUD + + Alternatively, any nonstandard baud rate can be specified by simply passing + the actual required baud rate as the value for this parameter. + + @param line_config + The line_config parameter is the line configuration specifying the bit + length, number of stop bits and parity settings. + + This is a bitwise OR of one value from each of the following groups of + allowed values: + + One of the following to specify the transmit/receive data bit length: + - MSS_UART_DATA_5_BITS + - MSS_UART_DATA_6_BITS, + - MSS_UART_DATA_7_BITS + - MSS_UART_DATA_8_BITS + + One of the following to specify the parity setting: + - MSS_UART_NO_PARITY + - MSS_UART_EVEN_PARITY + - MSS_UART_ODD_PARITY + - MSS_UART_STICK_PARITY_0 + - MSS_UART_STICK_PARITY_1 + + One of the following to specify the number of stop bits: + - MSS_UART_ONE_STOP_BIT + - MSS_UART_ONEHALF_STOP_BIT + - MSS_UART_TWO_STOP_BITS + + @return + This function does not return a value. + + Example: + @code + #include "mss_uart.h" + + int main(void) + { + MSS_UART_lin_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); - return(0); - } - @endcode - */ + return(0); + } + @endcode + */ void -MSS_UART_lin_init -( - mss_uart_instance_t* this_uart, - uint32_t baud_rate, - uint8_t line_config -); - -/***************************************************************************//** - The MSS_UART_irda_init() function is used to initialize the MSS UART instance - referenced by the parameter this_uart for IrDA mode of operation. This - function must be called before calling any other IrDA functionality specific - functions. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - Note that if you are using the UART on the AMP APB bus, the hardware - configuration to connect UART on AMP APB bus must already be done by the - application using SYSREG registers before initializing the UART instance - structure. - - @param baud_rate - The baud_rate parameter specifies the baud rate. It can be specified for - common baud rates using the following defines: - - MSS_UART_110_BAUD - - MSS_UART_300_BAUD - - MSS_UART_600_BAUD - - MSS_UART_1200_BAUD - - MSS_UART_2400_BAUD - - MSS_UART_4800_BAUD - - MSS_UART_9600_BAUD - - MSS_UART_19200_BAUD - - MSS_UART_38400_BAUD - - MSS_UART_57600_BAUD - - MSS_UART_115200_BAUD - - MSS_UART_230400_BAUD - - MSS_UART_460800_BAUD - - MSS_UART_921600_BAUD - - Alternatively, any nonstandard baud rate can be specified by simply passing - the actual required baud rate as the value for this parameter. - - @param line_config - The line_config parameter is the line configuration specifying the bit - length, number of stop bits and parity settings. - - This is a bitwise OR of one value from each of the following groups of - allowed values: - - One of the following to specify the transmit/receive data bit length: - - MSS_UART_DATA_5_BITS - - MSS_UART_DATA_6_BITS, - - MSS_UART_DATA_7_BITS - - MSS_UART_DATA_8_BITS - - One of the following to specify the parity setting: - - MSS_UART_NO_PARITY - - MSS_UART_EVEN_PARITY - - MSS_UART_ODD_PARITY - - MSS_UART_STICK_PARITY_0 - - MSS_UART_STICK_PARITY_1 - - One of the following to specify the number of stop bits: - - MSS_UART_ONE_STOP_BIT - - MSS_UART_ONEHALF_STOP_BIT - - MSS_UART_TWO_STOP_BITS - - @return - This function does not return a value. - - Example: - @code - MSS_UART_irda_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT, - MSS_UART_ACTIVE_LOW, - MSS_UART_ACTIVE_LOW, - MSS_UART_3_BY_16); - @endcode - */ +MSS_UART_lin_init( + mss_uart_instance_t* this_uart, uint32_t baud_rate, uint8_t line_config); + +/***************************************************************************/ /** + The MSS_UART_irda_init() function is used to initialize the MSS UART instance + referenced by the parameter this_uart for IrDA mode of operation. This + function must be called before calling any other IrDA functionality specific + functions. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + Note that if you are using the UART on the AMP APB bus, the hardware + configuration to connect UART on AMP APB bus must already be done by the + application using SYSREG registers before initializing the UART instance + structure. + + @param baud_rate + The baud_rate parameter specifies the baud rate. It can be specified for + common baud rates using the following defines: + - MSS_UART_110_BAUD + - MSS_UART_300_BAUD + - MSS_UART_600_BAUD + - MSS_UART_1200_BAUD + - MSS_UART_2400_BAUD + - MSS_UART_4800_BAUD + - MSS_UART_9600_BAUD + - MSS_UART_19200_BAUD + - MSS_UART_38400_BAUD + - MSS_UART_57600_BAUD + - MSS_UART_115200_BAUD + - MSS_UART_230400_BAUD + - MSS_UART_460800_BAUD + - MSS_UART_921600_BAUD + + Alternatively, any nonstandard baud rate can be specified by simply passing + the actual required baud rate as the value for this parameter. + + @param line_config + The line_config parameter is the line configuration specifying the bit + length, number of stop bits and parity settings. + + This is a bitwise OR of one value from each of the following groups of + allowed values: + + One of the following to specify the transmit/receive data bit length: + - MSS_UART_DATA_5_BITS + - MSS_UART_DATA_6_BITS, + - MSS_UART_DATA_7_BITS + - MSS_UART_DATA_8_BITS + + One of the following to specify the parity setting: + - MSS_UART_NO_PARITY + - MSS_UART_EVEN_PARITY + - MSS_UART_ODD_PARITY + - MSS_UART_STICK_PARITY_0 + - MSS_UART_STICK_PARITY_1 + + One of the following to specify the number of stop bits: + - MSS_UART_ONE_STOP_BIT + - MSS_UART_ONEHALF_STOP_BIT + - MSS_UART_TWO_STOP_BITS + + @return + This function does not return a value. + + Example: + @code + MSS_UART_irda_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT, MSS_UART_ACTIVE_LOW, MSS_UART_ACTIVE_LOW, + MSS_UART_3_BY_16); + @endcode + */ void -MSS_UART_irda_init -( - mss_uart_instance_t* this_uart, - uint32_t baud_rate, - uint8_t line_config, - mss_uart_rzi_polarity_t rxpol, - mss_uart_rzi_polarity_t txpol, - mss_uart_rzi_pulsewidth_t pw -); - -/***************************************************************************//** - The MSS_UART_smartcard_init() function is used to initialize the MSS UART - for ISO 7816 (smartcard) mode of operation. The configuration parameters are - the baud_rate which is used to generate the baud value and the line_config - which is used to specify the line configuration (bit length, stop bits and - parity). This function disables all other modes of the MSS UART instance - pointed by the parameter this_uart. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - Note that if you are using the UART on the AMP APB bus, the hardware - configuration to connect UART on AMP APB bus must already be done by the - application using SYSREG registers before initializing the UART instance - structure. - - @param baud_rate - The baud_rate parameter specifies the baud rate. It can be specified for - common baud rates using the following defines: - - MSS_UART_110_BAUD - - MSS_UART_300_BAUD - - MSS_UART_600_BAUD - - MSS_UART_1200_BAUD - - MSS_UART_2400_BAUD - - MSS_UART_4800_BAUD - - MSS_UART_9600_BAUD - - MSS_UART_19200_BAUD - - MSS_UART_38400_BAUD - - MSS_UART_57600_BAUD - - MSS_UART_115200_BAUD - - MSS_UART_230400_BAUD - - MSS_UART_460800_BAUD - - MSS_UART_921600_BAUD - - Alternatively, any nonstandard baud rate can be specified by simply passing - the actual required baud rate as the value for this parameter. - - @param line_config - The line_config parameter is the line configuration specifying the bit - length, number of stop bits and parity settings. - - This is a bitwise OR of one value from each of the following groups of - allowed values: - - One of the following to specify the transmit/receive data bit length: - - MSS_UART_DATA_5_BITS - - MSS_UART_DATA_6_BITS, - - MSS_UART_DATA_7_BITS - - MSS_UART_DATA_8_BITS - - One of the following to specify the parity setting: - - MSS_UART_NO_PARITY - - MSS_UART_EVEN_PARITY - - MSS_UART_ODD_PARITY - - MSS_UART_STICK_PARITY_0 - - MSS_UART_STICK_PARITY_1 - - One of the following to specify the number of stop bits: - - MSS_UART_ONE_STOP_BIT - - MSS_UART_ONEHALF_STOP_BIT - - MSS_UART_TWO_STOP_BITS - - @return - This function does not return a value. - - Example: - @code - #include "mss_uart.h" - - int main(void) - { - MSS_UART_smartcard_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - return(0); - } - @endcode - */ +MSS_UART_irda_init( + mss_uart_instance_t* this_uart, uint32_t baud_rate, uint8_t line_config, + mss_uart_rzi_polarity_t rxpol, mss_uart_rzi_polarity_t txpol, + mss_uart_rzi_pulsewidth_t pw); + +/***************************************************************************/ /** + The MSS_UART_smartcard_init() function is used to initialize the MSS UART + for ISO 7816 (smartcard) mode of operation. The configuration parameters are + the baud_rate which is used to generate the baud value and the line_config + which is used to specify the line configuration (bit length, stop bits and + parity). This function disables all other modes of the MSS UART instance + pointed by the parameter this_uart. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + Note that if you are using the UART on the AMP APB bus, the hardware + configuration to connect UART on AMP APB bus must already be done by the + application using SYSREG registers before initializing the UART instance + structure. + + @param baud_rate + The baud_rate parameter specifies the baud rate. It can be specified for + common baud rates using the following defines: + - MSS_UART_110_BAUD + - MSS_UART_300_BAUD + - MSS_UART_600_BAUD + - MSS_UART_1200_BAUD + - MSS_UART_2400_BAUD + - MSS_UART_4800_BAUD + - MSS_UART_9600_BAUD + - MSS_UART_19200_BAUD + - MSS_UART_38400_BAUD + - MSS_UART_57600_BAUD + - MSS_UART_115200_BAUD + - MSS_UART_230400_BAUD + - MSS_UART_460800_BAUD + - MSS_UART_921600_BAUD + + Alternatively, any nonstandard baud rate can be specified by simply passing + the actual required baud rate as the value for this parameter. + + @param line_config + The line_config parameter is the line configuration specifying the bit + length, number of stop bits and parity settings. + + This is a bitwise OR of one value from each of the following groups of + allowed values: + + One of the following to specify the transmit/receive data bit length: + - MSS_UART_DATA_5_BITS + - MSS_UART_DATA_6_BITS, + - MSS_UART_DATA_7_BITS + - MSS_UART_DATA_8_BITS + + One of the following to specify the parity setting: + - MSS_UART_NO_PARITY + - MSS_UART_EVEN_PARITY + - MSS_UART_ODD_PARITY + - MSS_UART_STICK_PARITY_0 + - MSS_UART_STICK_PARITY_1 + + One of the following to specify the number of stop bits: + - MSS_UART_ONE_STOP_BIT + - MSS_UART_ONEHALF_STOP_BIT + - MSS_UART_TWO_STOP_BITS + + @return + This function does not return a value. + + Example: + @code + #include "mss_uart.h" + + int main(void) + { + MSS_UART_smartcard_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + return(0); + } + @endcode + */ void -MSS_UART_smartcard_init -( - mss_uart_instance_t* this_uart, - uint32_t baud_rate, - uint8_t line_config -); - -/***************************************************************************//** - The function MSS_UART_polled_tx() is used to transmit data. It transfers the - contents of the transmitter data buffer, passed as a function parameter, into - the UART's hardware transmitter FIFO. It returns when the full content of the - transmit data buffer has been transferred to the UART's transmit FIFO. It is - safe to release or reuse the memory used as the transmitter data buffer once - this function returns. - - Note: This function reads the UART's line status register (LSR) to poll - for the active state of the transmitter holding register empty (THRE) bit - before transferring data from the data buffer to the transmitter FIFO. It - transfers data to the transmitter FIFO in blocks of 16 bytes or less and - allows the FIFO to empty before transferring the next block of data. - - Note: The actual transmission over the serial connection will still be - in progress when this function returns. Use the MSS_UART_get_tx_status() - function if you need to know when the transmitter is empty. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param pbuff - The pbuff parameter is a pointer to a buffer containing the data to - be transmitted. - - @param tx_size - The tx_size parameter specifies the size, in bytes, of the data to - be transmitted. - - @return - This function does not return a value. - - Example: - @code - #include "mss_uart.h" - - int main(void) - { - uint8_t message[12] = "Hello World"; +MSS_UART_smartcard_init( + mss_uart_instance_t* this_uart, uint32_t baud_rate, uint8_t line_config); + +/***************************************************************************/ /** + The function MSS_UART_polled_tx() is used to transmit data. It transfers the + contents of the transmitter data buffer, passed as a function parameter, into + the UART's hardware transmitter FIFO. It returns when the full content of the + transmit data buffer has been transferred to the UART's transmit FIFO. It is + safe to release or reuse the memory used as the transmitter data buffer once + this function returns. + + Note: This function reads the UART's line status register (LSR) to poll + for the active state of the transmitter holding register empty (THRE) bit + before transferring data from the data buffer to the transmitter FIFO. It + transfers data to the transmitter FIFO in blocks of 16 bytes or less and + allows the FIFO to empty before transferring the next block of data. + + Note: The actual transmission over the serial connection will still be + in progress when this function returns. Use the MSS_UART_get_tx_status() + function if you need to know when the transmitter is empty. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param pbuff + The pbuff parameter is a pointer to a buffer containing the data to + be transmitted. + + @param tx_size + The tx_size parameter specifies the size, in bytes, of the data to + be transmitted. + + @return + This function does not return a value. + + Example: + @code + #include "mss_uart.h" + + int main(void) + { + uint8_t message[12] = "Hello World"; - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - SS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + SS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); - MSS_UART_polled_tx(&g_mss_uart0_lo, message, sizeof(message)); + MSS_UART_polled_tx(&g_mss_uart0_lo, message, sizeof(message)); - return(0); - } - @endcode - */ + return(0); + } + @endcode + */ void -MSS_UART_polled_tx -( - mss_uart_instance_t * this_uart, - const uint8_t * pbuff, - uint32_t tx_size -); - -/***************************************************************************//** - The function MSS_UART_polled_tx_string() is used to transmit a NULL ('\0') - terminated string. It transfers the text string, from the buffer starting at - the address pointed to by p_sz_string into the UART's hardware transmitter - FIFO. It returns when the complete string has been transferred to the UART's - transmit FIFO. It is safe to release or reuse the memory used as the string - buffer once this function returns. - - Note: This function reads the UART's line status register (LSR) to poll - for the active state of the transmitter holding register empty (THRE) bit - before transferring data from the data buffer to the transmitter FIFO. It - transfers data to the transmitter FIFO in blocks of 16 bytes or less and - allows the FIFO to empty before transferring the next block of data. - - Note: The actual transmission over the serial connection will still be - in progress when this function returns. Use the MSS_UART_get_tx_status() - function if you need to know when the transmitter is empty. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param p_sz_string - The p_sz_string parameter is a pointer to a buffer containing the NULL - ('\0') terminated string to be transmitted. - - @return - This function does not return a value. - - Example: - @code - #include "mss_uart.h" - - int main(void) - { - uint8_t message[12] = "Hello World"; +MSS_UART_polled_tx( + mss_uart_instance_t* this_uart, const uint8_t* pbuff, uint32_t tx_size); + +/***************************************************************************/ /** + The function MSS_UART_polled_tx_string() is used to transmit a NULL ('\0') + terminated string. It transfers the text string, from the buffer starting at + the address pointed to by p_sz_string into the UART's hardware transmitter + FIFO. It returns when the complete string has been transferred to the UART's + transmit FIFO. It is safe to release or reuse the memory used as the string + buffer once this function returns. + + Note: This function reads the UART's line status register (LSR) to poll + for the active state of the transmitter holding register empty (THRE) bit + before transferring data from the data buffer to the transmitter FIFO. It + transfers data to the transmitter FIFO in blocks of 16 bytes or less and + allows the FIFO to empty before transferring the next block of data. + + Note: The actual transmission over the serial connection will still be + in progress when this function returns. Use the MSS_UART_get_tx_status() + function if you need to know when the transmitter is empty. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param p_sz_string + The p_sz_string parameter is a pointer to a buffer containing the NULL + ('\0') terminated string to be transmitted. + + @return + This function does not return a value. + + Example: + @code + #include "mss_uart.h" + + int main(void) + { + uint8_t message[12] = "Hello World"; - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); - MSS_UART_polled_tx_string(&g_mss_uart0_lo, message); + MSS_UART_polled_tx_string(&g_mss_uart0_lo, message); - return(0); - } - @endcode + return(0); + } + @endcode - */ + */ void -MSS_UART_polled_tx_string -( - mss_uart_instance_t * this_uart, - const uint8_t * p_sz_string -); - -/***************************************************************************//** - The MSS_UART_get_rx() function reads the content of the UART receiver's FIFO - and stores it in the receive buffer that is passed via the rx_buff function - parameter. It copies either the full contents of the FIFO into the receive - buffer, or just enough data from the FIFO to fill the receive buffer, - dependent upon the size of the receive buffer passed by the buff_size - parameter. The MSS_UART_get_rx() function returns the number of bytes copied - into the receive buffer .This function is non-blocking and will return 0 - immediately if no data has been received. - - Note: The MSS_UART_get_rx() function reads and accumulates the receiver - status of the MSS UART instance before reading each byte from the receiver's - data register/FIFO. This allows the driver to maintain a sticky record of any - receiver errors that occur as the UART receives each data byte; receiver - errors would otherwise be lost after each read from the receiver's data - register. A call to the MSS_UART_get_rx_status() function returns any receiver - errors accumulated during the execution of the MSS_UART_get_rx() function. - - Note: If you need to read the error status for each byte received, set - the buff_size to 1 and read the receive line error status for each byte - using the MSS_UART_get_rx_status() function. - - The MSS_UART_get_rx() function can be used in polled mode, where it is called - at regular intervals to find out if any data has been received, or in - interrupt driven-mode, where it is called as part of a receive handler that is - called by the driver as a result of data being received. - - Note: In interrupt driven mode you should call the MSS_UART_get_rx() - function as part of the receive handler function that you register with - the MSS UART driver through a call to MSS_UART_set_rx_handler(). - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param rx_buff - The rx_buff parameter is a pointer to a buffer where the received - data is copied. - - @param buff_size - The buff_size parameter specifies the size of the receive buffer in bytes. - - @return - This function returns the number of bytes that were copied into the - rx_buff buffer. It returns 0 if no data has been received. - - Polled mode example: - @code - int main( void ) - { - uint8_t rx_buff[RX_BUFF_SIZE]; - uint32_t rx_idx = 0; +MSS_UART_polled_tx_string( + mss_uart_instance_t* this_uart, const uint8_t* p_sz_string); + +/***************************************************************************/ /** + The MSS_UART_get_rx() function reads the content of the UART receiver's FIFO + and stores it in the receive buffer that is passed via the rx_buff function + parameter. It copies either the full contents of the FIFO into the receive + buffer, or just enough data from the FIFO to fill the receive buffer, + dependent upon the size of the receive buffer passed by the buff_size + parameter. The MSS_UART_get_rx() function returns the number of bytes copied + into the receive buffer .This function is non-blocking and will return 0 + immediately if no data has been received. + + Note: The MSS_UART_get_rx() function reads and accumulates the receiver + status of the MSS UART instance before reading each byte from the receiver's + data register/FIFO. This allows the driver to maintain a sticky record of any + receiver errors that occur as the UART receives each data byte; receiver + errors would otherwise be lost after each read from the receiver's data + register. A call to the MSS_UART_get_rx_status() function returns any + receiver errors accumulated during the execution of the MSS_UART_get_rx() + function. + + Note: If you need to read the error status for each byte received, set + the buff_size to 1 and read the receive line error status for each byte + using the MSS_UART_get_rx_status() function. + + The MSS_UART_get_rx() function can be used in polled mode, where it is called + at regular intervals to find out if any data has been received, or in + interrupt driven-mode, where it is called as part of a receive handler that + is called by the driver as a result of data being received. + + Note: In interrupt driven mode you should call the MSS_UART_get_rx() + function as part of the receive handler function that you register with + the MSS UART driver through a call to MSS_UART_set_rx_handler(). + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param rx_buff + The rx_buff parameter is a pointer to a buffer where the received + data is copied. + + @param buff_size + The buff_size parameter specifies the size of the receive buffer in bytes. + + @return + This function returns the number of bytes that were copied into the + rx_buff buffer. It returns 0 if no data has been received. + + Polled mode example: + @code + int main( void ) + { + uint8_t rx_buff[RX_BUFF_SIZE]; + uint32_t rx_idx = 0; - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + while(1) + { + rx_size = MSS_UART_get_rx(&g_mss_uart0_lo, rx_buff, sizeof(rx_buff)); + if(rx_size > 0) + { + process_rx_data(rx_buff, rx_size); + } + task_a(); + task_b(); + } + return 0; + } + @endcode - while(1) - { - rx_size = MSS_UART_get_rx(&g_mss_uart0_lo, rx_buff, sizeof(rx_buff)); - if(rx_size > 0) - { - process_rx_data(rx_buff, rx_size); - } - task_a(); - task_b(); - } - return 0; - } - @endcode + Interrupt driven example: + @code + int main( void ) + { + MSS_UART_init(&g_mss_uart1, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_set_rx_handler(&g_mss_uart1, + uart1_rx_handler, + MSS_UART_FIFO_SINGLE_BYTE); + + while(1) + { + task_a(); + task_b(); + } + return 0; + } - Interrupt driven example: - @code - int main( void ) - { - MSS_UART_init(&g_mss_uart1, + void uart1_rx_handler(mss_uart_instance_t * this_uart) + { + uint8_t rx_buff[RX_BUFF_SIZE]; + uint32_t rx_idx = 0; + rx_size = MSS_UART_get_rx(this_uart, rx_buff, sizeof(rx_buff)); + process_rx_data(rx_buff, rx_size); + } + @endcode + */ +size_t +MSS_UART_get_rx( + mss_uart_instance_t* this_uart, uint8_t* rx_buff, size_t buff_size); + +/***************************************************************************/ /** + The MSS_UART_set_loopback() function is used to locally loop-back the Tx and + Rx lines of a UART. This is not to be confused with the loop-back of UART0 + to UART1, which can be achieved through the microprocessor subsystem's + system registers. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param loopback + The loopback parameter indicates whether or not the UART's transmit and + receive lines should be looped back. Allowed values are as follows: + - MSS_UART_LOCAL_LOOPBACK_ON + - MSS_UART_LOCAL_LOOPBACK_OFF + - MSS_UART_REMOTE_LOOPBACK_ON + - MSS_UART_REMOTE_LOOPBACK_OFF + - MSS_UART_AUTO_ECHO_ON + - MSS_UART_AUTO_ECHO_OFF + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_set_rx_handler(&g_mss_uart1, - uart1_rx_handler, - MSS_UART_FIFO_SINGLE_BYTE); + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); - while(1) + MSS_UART_set_loopback(&g_mss_uart0_lo, MSS_UART_LOCAL_LOOPBACK_OFF); + @endcode + */ +void +MSS_UART_set_loopback( + mss_uart_instance_t* this_uart, mss_uart_loopback_t loopback); + +/***************************************************************************/ /** + The MSS_UART_fill_tx_fifo() function fills the UART's hardware transmitter + FIFO with the data found in the transmitter buffer that is passed via the + tx_buffer function parameter. If the transmitter FIFO is not empty when + the function is called, the function returns immediately without transferring + any data to the FIFO; otherwise, the function transfers data from the + transmitter buffer to the FIFO until it is full or until the complete + contents of the transmitter buffer have been copied into the FIFO. The + function returns the number of bytes copied into the UART's transmitter FIFO. + + Note: This function reads the UART's line status register (LSR) to check + for the active state of the transmitter holding register empty (THRE) bit + before transferring data from the data buffer to the transmitter FIFO. If + THRE is 0, the function returns immediately, without transferring any data + to the FIFO. If THRE is 1, the function transfers up to 16 bytes of data + to the FIFO and then returns. + + Note: The actual transmission over the serial connection will still be + in progress when this function returns. Use the MSS_UART_get_tx_status() + function if you need to know when the transmitter is empty. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param tx_buffer + The tx_buffer parameter is a pointer to a buffer containing the data + to be transmitted. + + @param tx_size + The tx_size parameter is the size in bytes, of the data to be transmitted. + + @return + This function returns the number of bytes copied into the UART's + transmitter FIFO. + + Example: + @code + void send_using_interrupt(uint8_t * pbuff, size_t tx_size) { - task_a(); - task_b(); + size_t size_in_fifo; + size_in_fifo = MSS_UART_fill_tx_fifo(&g_mss_uart0_lo, pbuff, tx_size); } - return 0; - } - - void uart1_rx_handler(mss_uart_instance_t * this_uart) - { - uint8_t rx_buff[RX_BUFF_SIZE]; - uint32_t rx_idx = 0; - rx_size = MSS_UART_get_rx(this_uart, rx_buff, sizeof(rx_buff)); - process_rx_data(rx_buff, rx_size); - } - @endcode - */ + @endcode + */ size_t -MSS_UART_get_rx -( - mss_uart_instance_t * this_uart, - uint8_t * rx_buff, - size_t buff_size -); - - -/***************************************************************************//** - The MSS_UART_set_loopback() function is used to locally loop-back the Tx and - Rx lines of a UART. This is not to be confused with the loop-back of UART0 - to UART1, which can be achieved through the microprocessor subsystem's - system registers. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param loopback - The loopback parameter indicates whether or not the UART's transmit and - receive lines should be looped back. Allowed values are as follows: - - MSS_UART_LOCAL_LOOPBACK_ON - - MSS_UART_LOCAL_LOOPBACK_OFF - - MSS_UART_REMOTE_LOOPBACK_ON - - MSS_UART_REMOTE_LOOPBACK_OFF - - MSS_UART_AUTO_ECHO_ON - - MSS_UART_AUTO_ECHO_OFF - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_set_loopback(&g_mss_uart0_lo, MSS_UART_LOCAL_LOOPBACK_OFF); - @endcode - */ -void -MSS_UART_set_loopback -( - mss_uart_instance_t * this_uart, - mss_uart_loopback_t loopback -); - -/***************************************************************************//** - The MSS_UART_fill_tx_fifo() function fills the UART's hardware transmitter - FIFO with the data found in the transmitter buffer that is passed via the - tx_buffer function parameter. If the transmitter FIFO is not empty when - the function is called, the function returns immediately without transferring - any data to the FIFO; otherwise, the function transfers data from the - transmitter buffer to the FIFO until it is full or until the complete - contents of the transmitter buffer have been copied into the FIFO. The - function returns the number of bytes copied into the UART's transmitter FIFO. - - Note: This function reads the UART's line status register (LSR) to check - for the active state of the transmitter holding register empty (THRE) bit - before transferring data from the data buffer to the transmitter FIFO. If - THRE is 0, the function returns immediately, without transferring any data - to the FIFO. If THRE is 1, the function transfers up to 16 bytes of data - to the FIFO and then returns. - - Note: The actual transmission over the serial connection will still be - in progress when this function returns. Use the MSS_UART_get_tx_status() - function if you need to know when the transmitter is empty. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param tx_buffer - The tx_buffer parameter is a pointer to a buffer containing the data - to be transmitted. - - @param tx_size - The tx_size parameter is the size in bytes, of the data to be transmitted. - - @return - This function returns the number of bytes copied into the UART's - transmitter FIFO. - - Example: - @code - void send_using_interrupt(uint8_t * pbuff, size_t tx_size) +MSS_UART_fill_tx_fifo( + mss_uart_instance_t* this_uart, const uint8_t* tx_buffer, size_t tx_size); + +/***************************************************************************/ /** + The MSS_UART_get_rx_status() function returns the receiver error status of + the MSS UART instance. It reads both the current error status of the receiver + from the UART's line status register (LSR) and the accumulated error status + from preceding calls to the MSS_UART_get_rx() function, and it combines them + using a bitwise OR. It returns the cumulative overrun, parity, framing, break + and FIFO error status of the receiver, since the previous call to + MSS_UART_get_rx_status(), as an 8-bit encoded value. + + Note: The MSS_UART_get_rx() function reads and accumulates the receiver + status of the MSS UART instance before reading each byte from the receiver's + data register/FIFO. The driver maintains a sticky record of the cumulative + receiver error status, which persists after the MSS_UART_get_rx() function + returns. The MSS_UART_get_rx_status() function clears the driver's sticky + receiver error record before returning. + + Note: The driver's transmit functions also read the line status + register (LSR) as part of their implementation. When the driver reads the + LSR, the UART clears any active receiver error bits in the LSR. This could + result in the driver losing receiver errors. To avoid any loss of receiver + errors, the transmit functions also update the driver's sticky record of the + cumulative receiver error status whenever they read the LSR. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @return + This function returns the UART's receiver error status as an 8-bit unsigned + integer. The returned value is 0 if no receiver errors occurred. The driver + provides a set of bit mask constants that should be compared with and/or + used to mask the returned value to determine the receiver error status. + When the return value is compared to the following bit masks, a non-zero + result indicates that the corresponding error occurred: + - MSS_UART_OVERRUN_ERROR (bit mask = 0x02) + - MSS_UART_PARITY_ERROR (bit mask = 0x04) + - MSS_UART_FRAMING_ERROR (bit mask = 0x08) + - MSS_UART_BREAK_ERROR (bit mask = 0x10) + - MSS_UART_FIFO_ERROR (bit mask = 0x80) + + When the return value is compared to the following bit mask, a non-zero + result indicates that no error occurred: + - MSS_UART_NO_ERROR (bit mask = 0x00) + + Upon unsuccessful execution, this function returns: + - MSS_UART_INVALID_PARAM (bit mask = 0xFF) + + Example: + @code + uint8_t rx_data[MAX_RX_DATA_SIZE]; + uint8_t err_status; + err_status = MSS_UART_get_rx_status(&g_mss_uart0); + + if(MSS_UART_NO_ERROR == err_status) { - size_t size_in_fifo; - size_in_fifo = MSS_UART_fill_tx_fifo(&g_mss_uart0_lo, pbuff, tx_size); + rx_size = MSS_UART_get_rx(&g_mss_uart0_lo, rx_data, MAX_RX_DATA_SIZE); } - @endcode - */ -size_t -MSS_UART_fill_tx_fifo -( - mss_uart_instance_t * this_uart, - const uint8_t * tx_buffer, - size_t tx_size -); - -/***************************************************************************//** - The MSS_UART_get_rx_status() function returns the receiver error status of the - MSS UART instance. It reads both the current error status of the receiver from - the UART's line status register (LSR) and the accumulated error status from - preceding calls to the MSS_UART_get_rx() function, and it combines them using - a bitwise OR. It returns the cumulative overrun, parity, framing, break and - FIFO error status of the receiver, since the previous call to - MSS_UART_get_rx_status(), as an 8-bit encoded value. - - Note: The MSS_UART_get_rx() function reads and accumulates the receiver - status of the MSS UART instance before reading each byte from the receiver's - data register/FIFO. The driver maintains a sticky record of the cumulative - receiver error status, which persists after the MSS_UART_get_rx() function - returns. The MSS_UART_get_rx_status() function clears the driver's sticky - receiver error record before returning. - - Note: The driver's transmit functions also read the line status - register (LSR) as part of their implementation. When the driver reads the - LSR, the UART clears any active receiver error bits in the LSR. This could - result in the driver losing receiver errors. To avoid any loss of receiver - errors, the transmit functions also update the driver's sticky record of the - cumulative receiver error status whenever they read the LSR. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @return - This function returns the UART's receiver error status as an 8-bit unsigned - integer. The returned value is 0 if no receiver errors occurred. The driver - provides a set of bit mask constants that should be compared with and/or - used to mask the returned value to determine the receiver error status. - When the return value is compared to the following bit masks, a non-zero - result indicates that the corresponding error occurred: - - MSS_UART_OVERRUN_ERROR (bit mask = 0x02) - - MSS_UART_PARITY_ERROR (bit mask = 0x04) - - MSS_UART_FRAMING_ERROR (bit mask = 0x08) - - MSS_UART_BREAK_ERROR (bit mask = 0x10) - - MSS_UART_FIFO_ERROR (bit mask = 0x80) - - When the return value is compared to the following bit mask, a non-zero - result indicates that no error occurred: - - MSS_UART_NO_ERROR (bit mask = 0x00) - - Upon unsuccessful execution, this function returns: - - MSS_UART_INVALID_PARAM (bit mask = 0xFF) - - Example: - @code - uint8_t rx_data[MAX_RX_DATA_SIZE]; - uint8_t err_status; - err_status = MSS_UART_get_rx_status(&g_mss_uart0); - - if(MSS_UART_NO_ERROR == err_status) - { - rx_size = MSS_UART_get_rx(&g_mss_uart0_lo, rx_data, MAX_RX_DATA_SIZE); - } - @endcode - */ + @endcode + */ uint8_t -MSS_UART_get_rx_status -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_get_modem_status() function returns the modem status of the - MSS UART instance. It reads the modem status register (MSR) and returns - the 8 bit value. The bit encoding of the returned value is exactly the - same as the definition of the bits in the MSR. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @return - This function returns current state of the UART's MSR as an 8 bit - unsigned integer. The driver provides the following set of bit mask - constants that should be compared with and/or used to mask the - returned value to determine the modem status: - - MSS_UART_DCTS (bit mask = 0x01) - - MSS_UART_DDSR (bit mask = 0x02) - - MSS_UART_TERI (bit mask = 0x04) - - MSS_UART_DDCD (bit mask = 0x08) - - MSS_UART_CTS (bit mask = 0x10) - - MSS_UART_DSR (bit mask = 0x20) - - MSS_UART_RI (bit mask = 0x40) - - MSS_UART_DCD (bit mask = 0x80) - - Example: - @code - void uart_modem_status_isr(mss_uart_instance_t * this_uart) - { - uint8_t status; - status = MSS_UART_get_modem_status(this_uart); - if( status & MSS_UART_DCTS ) - { - uart_dcts_handler(); - } - if( status & MSS_UART_CTS ) - { - uart_cts_handler(); - } - } - @endcode - */ +MSS_UART_get_rx_status(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_get_modem_status() function returns the modem status of the + MSS UART instance. It reads the modem status register (MSR) and returns + the 8 bit value. The bit encoding of the returned value is exactly the + same as the definition of the bits in the MSR. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @return + This function returns current state of the UART's MSR as an 8 bit + unsigned integer. The driver provides the following set of bit mask + constants that should be compared with and/or used to mask the + returned value to determine the modem status: + - MSS_UART_DCTS (bit mask = 0x01) + - MSS_UART_DDSR (bit mask = 0x02) + - MSS_UART_TERI (bit mask = 0x04) + - MSS_UART_DDCD (bit mask = 0x08) + - MSS_UART_CTS (bit mask = 0x10) + - MSS_UART_DSR (bit mask = 0x20) + - MSS_UART_RI (bit mask = 0x40) + - MSS_UART_DCD (bit mask = 0x80) + + Example: + @code + void uart_modem_status_isr(mss_uart_instance_t * this_uart) + { + uint8_t status; + status = MSS_UART_get_modem_status(this_uart); + if( status & MSS_UART_DCTS ) + { + uart_dcts_handler(); + } + if( status & MSS_UART_CTS ) + { + uart_cts_handler(); + } + } + @endcode + */ uint8_t -MSS_UART_get_modem_status -( - const mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_get_tx_status() function returns the transmitter status of the - MSS UART instance. It reads both the UART's line status register (LSR) and - returns the status of the transmit holding register empty (THRE) and - transmitter empty (TEMT) bits. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @return - This function returns the UART's transmitter status as an 8-bit unsigned - integer. The returned value is 0 if the transmitter status bits are not - set or the function execution failed. The driver provides a set of bit - mask constants that should be compared with and/or used to mask the - returned value to determine the transmitter status. - When the return value is compared to the following bit mask, a non-zero - result indicates that the corresponding transmitter status bit is set: - - MSS_UART_THRE (bit mask = 0x20) - - MSS_UART_TEMT (bit mask = 0x40) - - When the return value is compared to the following bit mask, a non-zero - result indicates that the transmitter is busy or the function execution - failed. - - MSS_UART_TX_BUSY (bit mask = 0x00) - - Example: - @code - uint8_t tx_buff[10] = "abcdefghi"; - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_polled_tx(&g_mss_uart0_lo, tx_buff, sizeof(tx_buff)); - - while(!(MSS_UART_TEMT & MSS_UART_get_tx_status(&g_mss_uart0))) - { - ; - } - @endcode - */ +MSS_UART_get_modem_status(const mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_get_tx_status() function returns the transmitter status of the + MSS UART instance. It reads both the UART's line status register (LSR) and + returns the status of the transmit holding register empty (THRE) and + transmitter empty (TEMT) bits. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @return + This function returns the UART's transmitter status as an 8-bit unsigned + integer. The returned value is 0 if the transmitter status bits are not + set or the function execution failed. The driver provides a set of bit + mask constants that should be compared with and/or used to mask the + returned value to determine the transmitter status. + When the return value is compared to the following bit mask, a non-zero + result indicates that the corresponding transmitter status bit is set: + - MSS_UART_THRE (bit mask = 0x20) + - MSS_UART_TEMT (bit mask = 0x40) + + When the return value is compared to the following bit mask, a non-zero + result indicates that the transmitter is busy or the function execution + failed. + - MSS_UART_TX_BUSY (bit mask = 0x00) + + Example: + @code + uint8_t tx_buff[10] = "abcdefghi"; + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_polled_tx(&g_mss_uart0_lo, tx_buff, sizeof(tx_buff)); + + while(!(MSS_UART_TEMT & MSS_UART_get_tx_status(&g_mss_uart0))) + { + ; + } + @endcode + */ uint8_t -MSS_UART_get_tx_status -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_set_break() function is used to send the break - (9 zeros after stop bit) signal on the TX line. This function can be used - only when the MSS UART is initialized in LIN mode by using MSS_UART_lin_init(). - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_lin_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_set_break(&g_mss_uart0); - @endcode - */ -void -MSS_UART_set_break -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_clear_break() function is used to remove the break signal on the - TX line. This function can be used only when the MSS UART is initialized in - LIN mode by using MSS_UART_lin_init(). - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_lin_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_clear_break(&g_mss_uart0_lo); - @endcode - */ +MSS_UART_get_tx_status(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_set_break() function is used to send the break + (9 zeros after stop bit) signal on the TX line. This function can be used + only when the MSS UART is initialized in LIN mode by using + MSS_UART_lin_init(). + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_lin_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_set_break(&g_mss_uart0); + @endcode + */ void -MSS_UART_clear_break -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_enable_half_duplex() function is used to enable the half-duplex - (single wire) mode for the MSS UART. Though it finds application in Smartcard - mode, half-duplex mode can be used in other modes as well. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_enable_half_duplex(&g_mss_uart0_lo); - @endcode - */ +MSS_UART_set_break(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_clear_break() function is used to remove the break signal on the + TX line. This function can be used only when the MSS UART is initialized in + LIN mode by using MSS_UART_lin_init(). + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_lin_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_clear_break(&g_mss_uart0_lo); + @endcode + */ void -MSS_UART_enable_half_duplex -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_disable_half_duplex() function is used to disable the half-duplex - (single wire) mode for the MSS UART. Though it finds application in Smartcard - mode, half-duplex mode can be used in other modes as well. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_disable_half_duplex(&g_mss_uart0_lo); - @endcode - */ +MSS_UART_clear_break(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_enable_half_duplex() function is used to enable the half-duplex + (single wire) mode for the MSS UART. Though it finds application in Smartcard + mode, half-duplex mode can be used in other modes as well. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_enable_half_duplex(&g_mss_uart0_lo); + @endcode + */ void -MSS_UART_disable_half_duplex -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_set_rx_endian() function is used to configure the LSB first or - MSB first setting for MSS UART receiver - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param endian - The endian parameter tells the LSB first or MSB first configuration. - This parameter is of type mss_uart_endian_t. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_set_rx_endian(&g_mss_uart0_lo, MSS_UART_LITTLEEND); - @endcode - */ +MSS_UART_enable_half_duplex(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_disable_half_duplex() function is used to disable the + half-duplex (single wire) mode for the MSS UART. Though it finds application + in Smartcard mode, half-duplex mode can be used in other modes as well. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_disable_half_duplex(&g_mss_uart0_lo); + @endcode + */ void -MSS_UART_set_rx_endian -( - mss_uart_instance_t * this_uart, - mss_uart_endian_t endian -); - -/***************************************************************************//** - The MSS_UART_set_tx_endian() function is used to configure the LSB first or - MSB first setting for MSS UART transmitter. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param endian - The endian parameter tells the LSB first or MSB first configuration. - This parameter is of type mss_uart_endian_t. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_set_tx_endian(&g_mss_uart0_lo, MSS_UART_LITTLEEND); - @endcode - */ +MSS_UART_disable_half_duplex(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_set_rx_endian() function is used to configure the LSB first or + MSB first setting for MSS UART receiver + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param endian + The endian parameter tells the LSB first or MSB first configuration. + This parameter is of type mss_uart_endian_t. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_set_rx_endian(&g_mss_uart0_lo, MSS_UART_LITTLEEND); + @endcode + */ void -MSS_UART_set_tx_endian -( - mss_uart_instance_t * this_uart, - mss_uart_endian_t endian -); - -/***************************************************************************//** - The MSS_UART_set_filter_length () function is used to configure the glitch - filter length of the MSS UART. This should be configured in accordance with - the chosen baud rate. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param length - The length parameter is of mss_uart_filter_length_t type that determines - the length of the glitch filter. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_set_filter_length(&g_mss_uart0_lo, MSS_UART_LEN2); - @endcode - */ +MSS_UART_set_rx_endian( + mss_uart_instance_t* this_uart, mss_uart_endian_t endian); + +/***************************************************************************/ /** + The MSS_UART_set_tx_endian() function is used to configure the LSB first or + MSB first setting for MSS UART transmitter. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param endian + The endian parameter tells the LSB first or MSB first configuration. + This parameter is of type mss_uart_endian_t. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_set_tx_endian(&g_mss_uart0_lo, MSS_UART_LITTLEEND); + @endcode + */ void -MSS_UART_set_filter_length -( - mss_uart_instance_t * this_uart, - mss_uart_filter_length_t length -); - -/***************************************************************************//** - The MSS_UART_enable_afm() function is used to enable address flag detection - mode of the MSS UART - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_enable_afm(&g_mss_uart0_lo); - @endcode - */ +MSS_UART_set_tx_endian( + mss_uart_instance_t* this_uart, mss_uart_endian_t endian); + +/***************************************************************************/ /** + The MSS_UART_set_filter_length () function is used to configure the glitch + filter length of the MSS UART. This should be configured in accordance with + the chosen baud rate. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param length + The length parameter is of mss_uart_filter_length_t type that determines + the length of the glitch filter. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_set_filter_length(&g_mss_uart0_lo, MSS_UART_LEN2); + @endcode + */ void -MSS_UART_enable_afm -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_disable_afm() function is used to disable address flag detection - mode of the MSS UART. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - Note that if you are using the UART on the AMP APB bus, the hardware - configuration to connect UART on AMP APB bus must already be done by the - application using SYSREG registers before initializing the UART instance - structure. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_disable_afm(&g_mss_uart0_lo); - @endcode - */ +MSS_UART_set_filter_length( + mss_uart_instance_t* this_uart, mss_uart_filter_length_t length); + +/***************************************************************************/ /** + The MSS_UART_enable_afm() function is used to enable address flag detection + mode of the MSS UART + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_enable_afm(&g_mss_uart0_lo); + @endcode + */ void -MSS_UART_disable_afm -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_enable_afclear () function is used to enable address flag clear - of the MSS UART. This should be used in conjunction with address flag - detection mode (AFM). - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_enable_afclear(&g_mss_uart0_lo); - @endcode - */ +MSS_UART_enable_afm(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_disable_afm() function is used to disable address flag detection + mode of the MSS UART. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + Note that if you are using the UART on the AMP APB bus, the hardware + configuration to connect UART on AMP APB bus must already be done by the + application using SYSREG registers before initializing the UART instance + structure. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_disable_afm(&g_mss_uart0_lo); + @endcode + */ void -MSS_UART_enable_afclear -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_disable_afclear () function is used to disable address flag - clear of the MSS UART. This should be used in conjunction with address flag - detection mode (AFM). - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - Note that if you are using the UART on the AMP APB bus, the hardware - configuration to connect UART on AMP APB bus must already be done by the - application using SYSREG registers before initializing the UART instance - structure. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_disable_afclear(&g_mss_uart0_lo); - @endcode - */ +MSS_UART_disable_afm(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_enable_afclear () function is used to enable address flag clear + of the MSS UART. This should be used in conjunction with address flag + detection mode (AFM). + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_enable_afclear(&g_mss_uart0_lo); + @endcode + */ void -MSS_UART_disable_afclear -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_enable_rx_timeout() function is used to enable and configure - the receiver timeout functionality of MSS UART. This function accepts the - timeout parameter and applies the timeout based up on the baud rate as per - the formula 4 x timeout x bit time. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param timeout - The timeout parameter specifies the receiver timeout multiple. - It should be configured according to the baud rate in use. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_enable_rx_timeout(&g_mss_uart0_lo, 24); - @endcode - */ +MSS_UART_enable_afclear(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_disable_afclear () function is used to disable address flag + clear of the MSS UART. This should be used in conjunction with address flag + detection mode (AFM). + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + Note that if you are using the UART on the AMP APB bus, the hardware + configuration to connect UART on AMP APB bus must already be done by the + application using SYSREG registers before initializing the UART instance + structure. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_disable_afclear(&g_mss_uart0_lo); + @endcode + */ void -MSS_UART_enable_rx_timeout -( - mss_uart_instance_t * this_uart, - uint8_t timeout -); - -/***************************************************************************//** - The MSS_UART_disable_rx_timeout() function is used to disable the receiver - timeout functionality of MSS UART. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - Note that if you are using the UART on the AMP APB bus, the hardware - configuration to connect UART on AMP APB bus must already be done by the - application using SYSREG registers before initializing the UART instance - structure. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_disable_rx_timeout(&g_mss_uart0_lo); - @endcode - */ +MSS_UART_disable_afclear(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_enable_rx_timeout() function is used to enable and configure + the receiver timeout functionality of MSS UART. This function accepts the + timeout parameter and applies the timeout based up on the baud rate as per + the formula 4 x timeout x bit time. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param timeout + The timeout parameter specifies the receiver timeout multiple. + It should be configured according to the baud rate in use. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_enable_rx_timeout(&g_mss_uart0_lo, 24); + @endcode + */ void -MSS_UART_disable_rx_timeout -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_enable_tx_time_guard() function is used to enable and configure - the transmitter time guard functionality of MSS UART. This function accepts - the timeguard parameter and applies the timeguard based up on the baud rate - as per the formula timeguard x bit time. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - Note that if you are using the UART on the AMP APB bus, the hardware - configuration to connect UART on AMP APB bus must already be done by the - application using SYSREG registers before initializing the UART instance - structure. - - @param timeguard - The timeguard parameter specifies the transmitter time guard multiple. - It should be configured according to the baud rate in use. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_enable_tx_time_guard(&g_mss_uart0_lo, 24); - @endcode - */ +MSS_UART_enable_rx_timeout(mss_uart_instance_t* this_uart, uint8_t timeout); + +/***************************************************************************/ /** + The MSS_UART_disable_rx_timeout() function is used to disable the receiver + timeout functionality of MSS UART. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + Note that if you are using the UART on the AMP APB bus, the hardware + configuration to connect UART on AMP APB bus must already be done by the + application using SYSREG registers before initializing the UART instance + structure. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_disable_rx_timeout(&g_mss_uart0_lo); + @endcode + */ void -MSS_UART_enable_tx_time_guard -( - mss_uart_instance_t * this_uart, - uint8_t timeguard -); - -/***************************************************************************//** - The MSS_UART_disable_tx_time_guard() function is used to disable the - transmitter time guard functionality of MSS UART. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - Note that if you are using the UART on the AMP APB bus, the hardware - configuration to connect UART on AMP APB bus must already be done by the - application using SYSREG registers before initializing the UART instance - structure. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_disable_tx_time_guard(&g_mss_uart0_lo); - @endcode - */ +MSS_UART_disable_rx_timeout(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_enable_tx_time_guard() function is used to enable and configure + the transmitter time guard functionality of MSS UART. This function accepts + the timeguard parameter and applies the timeguard based up on the baud rate + as per the formula timeguard x bit time. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + Note that if you are using the UART on the AMP APB bus, the hardware + configuration to connect UART on AMP APB bus must already be done by the + application using SYSREG registers before initializing the UART instance + structure. + + @param timeguard + The timeguard parameter specifies the transmitter time guard multiple. + It should be configured according to the baud rate in use. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_enable_tx_time_guard(&g_mss_uart0_lo, 24); + @endcode + */ void -MSS_UART_disable_tx_time_guard -( - mss_uart_instance_t * this_uart -); - -/***************************************************************************//** - The MSS_UART_set_address() function is used to set the 8-bit address for - the MSS UART referenced by this_uart parameter. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param address - The address parameter is the 8-bit address which is to be configured - to the MSS UART referenced by this_uart parameter. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_set_address(&g_mss_uart0_lo, 0xAA); - @endcode - */ +MSS_UART_enable_tx_time_guard( + mss_uart_instance_t* this_uart, uint8_t timeguard); + +/***************************************************************************/ /** + The MSS_UART_disable_tx_time_guard() function is used to disable the + transmitter time guard functionality of MSS UART. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + Note that if you are using the UART on the AMP APB bus, the hardware + configuration to connect UART on AMP APB bus must already be done by the + application using SYSREG registers before initializing the UART instance + structure. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_disable_tx_time_guard(&g_mss_uart0_lo); + @endcode + */ void -MSS_UART_set_address -( - mss_uart_instance_t * this_uart, - uint8_t address -); - -/***************************************************************************//** - The MSS_UART_set_ready_mode() function is used to configure the MODE0 or MODE1 - to the TXRDY and RXRDY signals of the MSS UART referenced by this_uart - parameter. The mode parameter is used to provide the mode to be configured. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param mode - The mode parameter is the mss_uart_ready_mode_t type which is used to - configure the TXRDY and RXRDY signal modes. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_set_ready_mode(&g_mss_uart0_lo, MSS_UART_READY_MODE0); - @endcode - */ +MSS_UART_disable_tx_time_guard(mss_uart_instance_t* this_uart); + +/***************************************************************************/ /** + The MSS_UART_set_address() function is used to set the 8-bit address for + the MSS UART referenced by this_uart parameter. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param address + The address parameter is the 8-bit address which is to be configured + to the MSS UART referenced by this_uart parameter. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_set_address(&g_mss_uart0_lo, 0xAA); + @endcode + */ void -MSS_UART_set_ready_mode -( - mss_uart_instance_t * this_uart, - mss_uart_ready_mode_t mode -); - -/***************************************************************************//** - The MSS_UART_set_usart_mode() function is used to configure the MSS UART - referenced by the parameter this_uart in USART mode. Various USART modes - are supported which can be configured by the parameter mode of type - mss_uart_usart_mode_t. - - @param this_uart - The this_uart parameter is a pointer to an mss_uart_instance_t - structure identifying the MSS UART hardware block that will perform - the requested function. There are ten such data structures, - g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 5 (main APB bus) and - g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 - when they are connected on the AXI switch slave 6 (AMP APB bus). - This parameter must point to one of these ten global data structure defined - within the UART driver. - - @param mode - The mode parameter is the USART mode to be configured. - This parameter is of type mss_uart_usart_mode_t. - - @return - This function does not return a value. - - Example: - @code - MSS_UART_init(&g_mss_uart0_lo, - MSS_UART_57600_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_set_usart_mode(&g_mss_uart0_lo, MSS_UART_SYNC_MASTER_POS_EDGE_CLK); - @endcode - */ +MSS_UART_set_address(mss_uart_instance_t* this_uart, uint8_t address); + +/***************************************************************************/ /** + The MSS_UART_set_ready_mode() function is used to configure the MODE0 or + MODE1 to the TXRDY and RXRDY signals of the MSS UART referenced by this_uart + parameter. The mode parameter is used to provide the mode to be configured. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param mode + The mode parameter is the mss_uart_ready_mode_t type which is used to + configure the TXRDY and RXRDY signal modes. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + + MSS_UART_set_ready_mode(&g_mss_uart0_lo, MSS_UART_READY_MODE0); + @endcode + */ void -MSS_UART_set_usart_mode -( - mss_uart_instance_t * this_uart, - mss_uart_usart_mode_t mode -); +MSS_UART_set_ready_mode( + mss_uart_instance_t* this_uart, mss_uart_ready_mode_t mode); + +/***************************************************************************/ /** + The MSS_UART_set_usart_mode() function is used to configure the MSS UART + referenced by the parameter this_uart in USART mode. Various USART modes + are supported which can be configured by the parameter mode of type + mss_uart_usart_mode_t. + + @param this_uart + The this_uart parameter is a pointer to an mss_uart_instance_t + structure identifying the MSS UART hardware block that will perform + the requested function. There are ten such data structures, + g_mss_uart0_lo to g_mss_uart4_lo, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 5 (main APB bus) and + g_mss_uart0_hi to g_mss_uart4_hi, associated with MSS UART0 to MSS UART4 + when they are connected on the AXI switch slave 6 (AMP APB bus). + This parameter must point to one of these ten global data structure defined + within the UART driver. + + @param mode + The mode parameter is the USART mode to be configured. + This parameter is of type mss_uart_usart_mode_t. + + @return + This function does not return a value. + + Example: + @code + MSS_UART_init(&g_mss_uart0_lo, + MSS_UART_57600_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | + MSS_UART_ONE_STOP_BIT); + MSS_UART_set_usart_mode(&g_mss_uart0_lo, + MSS_UART_SYNC_MASTER_POS_EDGE_CLK); + @endcode + */ +void +MSS_UART_set_usart_mode( + mss_uart_instance_t* this_uart, mss_uart_usart_mode_t mode); #ifdef __cplusplus } diff --git a/sm/plat/mpfs/drivers/mss_uart/mss_uart_regs.h b/sm/plat/mpfs/drivers/mss_uart/mss_uart_regs.h index 4ff56a525..bfec46f3e 100644 --- a/sm/plat/mpfs/drivers/mss_uart/mss_uart_regs.h +++ b/sm/plat/mpfs/drivers/mss_uart/mss_uart_regs.h @@ -1,4 +1,4 @@ - /******************************************************************************* +/******************************************************************************* * Copyright 2019-2020 Microchip FPGA Embedded Systems Solutions. * * SPDX-License-Identifier: MIT @@ -19,112 +19,114 @@ extern "C" { */ /* Line Control register bit definitions */ -#define SB 6u /* Set break */ -#define DLAB 7u /* Divisor latch access bit */ +#define SB 6u /* Set break */ +#define DLAB 7u /* Divisor latch access bit */ /* Line Control register bit masks */ -#define SB_MASK (0x01u << SB) /* Set break */ -#define DLAB_MASK (0x01u << DLAB) /* Divisor latch access bit */ +#define SB_MASK (0x01u << SB) /* Set break */ +#define DLAB_MASK (0x01u << DLAB) /* Divisor latch access bit */ /* FIFO Control register bit definitions */ -#define RXRDY_TXRDYN_EN 0u /* Enable TXRDY and RXRDY signals */ -#define CLEAR_RX_FIFO 1u /* Clear receiver FIFO */ -#define CLEAR_TX_FIFO 2u /* Clear transmitter FIFO */ -#define RDYMODE 3u /* Mode 0 or Mode 1 for TXRDY and RXRDY */ +#define RXRDY_TXRDYN_EN 0u /* Enable TXRDY and RXRDY signals */ +#define CLEAR_RX_FIFO 1u /* Clear receiver FIFO */ +#define CLEAR_TX_FIFO 2u /* Clear transmitter FIFO */ +#define RDYMODE 3u /* Mode 0 or Mode 1 for TXRDY and RXRDY */ /* FIFO Control register bit MASKS */ -#define RXRDY_TXRDYN_EN_MASK (0x01u << 0u) /* Enable TXRDY and RXRDY signals */ -#define CLEAR_RX_FIFO_MASK (0x01u << 1u) /* Clear receiver FIFO */ -#define CLEAR_TX_FIFO_MASK (0x01u << 2u) /* Clear transmitter FIFO */ -#define RDYMODE_MASK (0x01u << 3u) /* Mode 0 or Mode 1 for TXRDY and RXRDY */ +#define RXRDY_TXRDYN_EN_MASK (0x01u << 0u) /* Enable TXRDY and RXRDY signals \ + */ +#define CLEAR_RX_FIFO_MASK (0x01u << 1u) /* Clear receiver FIFO */ +#define CLEAR_TX_FIFO_MASK (0x01u << 2u) /* Clear transmitter FIFO */ +#define RDYMODE_MASK (0x01u << 3u) /* Mode 0 or Mode 1 for TXRDY and RXRDY */ /* Modem Control register bit definitions */ -#define LOOP 4u /* Local loopback */ -#define RLOOP 5u /* Remote loopback */ -#define ECHO 6u /* Automatic echo */ +#define LOOP 4u /* Local loopback */ +#define RLOOP 5u /* Remote loopback */ +#define ECHO 6u /* Automatic echo */ /* Modem Control register bit MASKS */ -#define LOOP_MASK (0x01u << 4u) /* Local loopback */ -#define RLOOP_MASK (0x01u << 5u) /* Remote loopback & Automatic echo*/ -#define ECHO_MASK (0x01u << 6u) /* Automatic echo */ +#define LOOP_MASK (0x01u << 4u) /* Local loopback */ +#define RLOOP_MASK (0x01u << 5u) /* Remote loopback & Automatic echo*/ +#define ECHO_MASK (0x01u << 6u) /* Automatic echo */ /* Line Status register bit definitions */ -#define DR 0u /* Data ready */ -#define THRE 5u /* Transmitter holding register empty */ -#define TEMT 6u /* Transmitter empty */ +#define DR 0u /* Data ready */ +#define THRE 5u /* Transmitter holding register empty */ +#define TEMT 6u /* Transmitter empty */ /* Line Status register bit MASKS */ -#define DR_MASK (0x01u << 0u) /* Data ready */ -#define THRE_MASK (0x01u << 5u) /* Transmitter holding register empty */ -#define TEMT_MASK (0x01u << 6u) /* Transmitter empty */ +#define DR_MASK (0x01u << 0u) /* Data ready */ +#define THRE_MASK (0x01u << 5u) /* Transmitter holding register empty */ +#define TEMT_MASK (0x01u << 6u) /* Transmitter empty */ /* Interrupt Enable register bit definitions */ -#define ERBFI 0u /* Enable receiver buffer full interrupt */ -#define ETBEI 1u /* Enable transmitter buffer empty interrupt */ -#define ELSI 2u /* Enable line status interrupt */ -#define EDSSI 3u /* Enable modem status interrupt */ +#define ERBFI 0u /* Enable receiver buffer full interrupt */ +#define ETBEI 1u /* Enable transmitter buffer empty interrupt */ +#define ELSI 2u /* Enable line status interrupt */ +#define EDSSI 3u /* Enable modem status interrupt */ /* Interrupt Enable register bit MASKS */ -#define ERBFI_MASK (0x01u << 0u) /* Enable receiver buffer full interrupt */ -#define ETBEI_MASK (0x01u << 1u) /* Enable transmitter buffer empty interrupt */ -#define ELSI_MASK (0x01u << 2u) /* Enable line status interrupt */ -#define EDSSI_MASK (0x01u << 3u) /* Enable modem status interrupt */ +#define ERBFI_MASK (0x01u << 0u) /* Enable receiver buffer full interrupt */ +#define ETBEI_MASK (0x01u << 1u) /* Enable transmitter buffer empty interrupt \ + */ +#define ELSI_MASK (0x01u << 2u) /* Enable line status interrupt */ +#define EDSSI_MASK (0x01u << 3u) /* Enable modem status interrupt */ /* Multimode register 0 bit definitions */ -#define ELIN 3u /* Enable LIN header detection */ -#define ETTG 5u /* Enable transmitter time guard */ -#define ERTO 6u /* Enable receiver time-out */ -#define EFBR 7u /* Enable fractional baud rate mode */ +#define ELIN 3u /* Enable LIN header detection */ +#define ETTG 5u /* Enable transmitter time guard */ +#define ERTO 6u /* Enable receiver time-out */ +#define EFBR 7u /* Enable fractional baud rate mode */ /* Multimode register 0 bit MASKS */ -#define ELIN_MASK (0x01u << 3u) /* Enable LIN header detection */ -#define ETTG_MASK (0x01u << 5u) /* Enable transmitter time guard */ -#define ERTO_MASK (0x01u << 6u) /* Enable receiver time-out */ -#define EFBR_MASK (0x01u << 7u) /* Enable fractional baud rate mode */ +#define ELIN_MASK (0x01u << 3u) /* Enable LIN header detection */ +#define ETTG_MASK (0x01u << 5u) /* Enable transmitter time guard */ +#define ERTO_MASK (0x01u << 6u) /* Enable receiver time-out */ +#define EFBR_MASK (0x01u << 7u) /* Enable fractional baud rate mode */ /* Multimode register 1 bit definitions */ -#define E_MSB_RX 0u /* MSB / LSB first for receiver */ -#define E_MSB_TX 1u /* MSB / LSB first for transmitter */ -#define EIRD 2u /* Enable IrDA modem */ -#define EIRX 3u /* Input polarity for IrDA modem */ -#define EITX 4u /* Output polarity for IrDA modem */ -#define EITP 5u /* Output pulse width for IrDA modem */ +#define E_MSB_RX 0u /* MSB / LSB first for receiver */ +#define E_MSB_TX 1u /* MSB / LSB first for transmitter */ +#define EIRD 2u /* Enable IrDA modem */ +#define EIRX 3u /* Input polarity for IrDA modem */ +#define EITX 4u /* Output polarity for IrDA modem */ +#define EITP 5u /* Output pulse width for IrDA modem */ /* Multimode register 1 bit MASKS */ -#define E_MSB_RX_MASK (0x01u << 0u) /* MSB / LSB first for receiver */ -#define E_MSB_TX_MASK (0x01u << 1u) /* MSB / LSB first for transmitter */ -#define EIRD_MASK (0x01u << 2u) /* Enable IrDA modem */ -#define EIRX_MASK (0x01u << 3u) /* Input polarity for IrDA modem */ -#define EITX_MASK (0x01u << 4u) /* Output polarity for IrDA modem */ -#define EITP_MASK (0x01u << 5u) /* Output pulse width for IrDA modem */ +#define E_MSB_RX_MASK (0x01u << 0u) /* MSB / LSB first for receiver */ +#define E_MSB_TX_MASK (0x01u << 1u) /* MSB / LSB first for transmitter */ +#define EIRD_MASK (0x01u << 2u) /* Enable IrDA modem */ +#define EIRX_MASK (0x01u << 3u) /* Input polarity for IrDA modem */ +#define EITX_MASK (0x01u << 4u) /* Output polarity for IrDA modem */ +#define EITP_MASK (0x01u << 5u) /* Output pulse width for IrDA modem */ /* Multimode register 2 bit definitions */ -#define EERR 0u /* Enable ERR / NACK during stop time */ -#define EAFM 1u /* Enable 9-bit address flag mode */ -#define EAFC 2u /* Enable address flag clear */ -#define ESWM 3u /* Enable single wire half-duplex mode */ +#define EERR 0u /* Enable ERR / NACK during stop time */ +#define EAFM 1u /* Enable 9-bit address flag mode */ +#define EAFC 2u /* Enable address flag clear */ +#define ESWM 3u /* Enable single wire half-duplex mode */ /* Multimode register 2 bit MASKS */ -#define EERR_MASK (0x01u << 0u) /* Enable ERR / NACK during stop time */ -#define EAFM_MASK (0x01u << 1u) /* Enable 9-bit address flag mode */ -#define EAFC_MASK (0x01u << 2u) /* Enable address flag clear */ -#define ESWM_MASK (0x01u << 3u) /* Enable single wire half-duplex mode */ +#define EERR_MASK (0x01u << 0u) /* Enable ERR / NACK during stop time */ +#define EAFM_MASK (0x01u << 1u) /* Enable 9-bit address flag mode */ +#define EAFC_MASK (0x01u << 2u) /* Enable address flag clear */ +#define ESWM_MASK (0x01u << 3u) /* Enable single wire half-duplex mode */ /* Multimode Interrupt Enable register and Multimode Interrupt Identification register definitions */ -#define ERTOI 0u /* Enable receiver timeout interrupt */ -#define ENACKI 1u /* Enable NACK / ERR interrupt */ -#define EPID_PEI 2u /* Enable PID parity error interrupt */ -#define ELINBI 3u /* Enable LIN break interrupt */ -#define ELINSI 4u /* Enable LIN sync detection interrupt */ +#define ERTOI 0u /* Enable receiver timeout interrupt */ +#define ENACKI 1u /* Enable NACK / ERR interrupt */ +#define EPID_PEI 2u /* Enable PID parity error interrupt */ +#define ELINBI 3u /* Enable LIN break interrupt */ +#define ELINSI 4u /* Enable LIN sync detection interrupt */ /* Multimode Interrupt Enable register and Multimode Interrupt Identification register MASKS */ -#define ERTOI_MASK (0x01u << 0u) /* Enable receiver timeout interrupt */ -#define ENACKI_MASK (0x01u << 1u) /* Enable NACK / ERR interrupt */ -#define EPID_PEI_MASK (0x01u << 2u) /* Enable PID parity error interrupt */ -#define ELINBI_MASK (0x01u << 3u) /* Enable LIN break interrupt */ -#define ELINSI_MASK (0x01u << 4u) /* Enable LIN sync detection interrupt */ +#define ERTOI_MASK (0x01u << 0u) /* Enable receiver timeout interrupt */ +#define ENACKI_MASK (0x01u << 1u) /* Enable NACK / ERR interrupt */ +#define EPID_PEI_MASK (0x01u << 2u) /* Enable PID parity error interrupt */ +#define ELINBI_MASK (0x01u << 3u) /* Enable LIN break interrupt */ +#define ELINSI_MASK (0x01u << 4u) /* Enable LIN sync detection interrupt */ #ifdef __cplusplus } diff --git a/sm/plat/mpfs/encoding.h b/sm/plat/mpfs/encoding.h index 0c5c25695..33248a637 100644 --- a/sm/plat/mpfs/encoding.h +++ b/sm/plat/mpfs/encoding.h @@ -14,12 +14,12 @@ derived from this software without specific prior written permission. IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, - SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING - OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS - BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, + ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF + REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. @@ -29,113 +29,112 @@ * Record of Microchip changes */ - #ifndef RISCV_CSR_ENCODING_H #define RISCV_CSR_ENCODING_H -#define MSTATUS_UIE 0x00000001 -#define MSTATUS_SIE 0x00000002 -#define MSTATUS_HIE 0x00000004 -#define MSTATUS_MIE 0x00000008 -#define MSTATUS_UPIE 0x00000010 -#define MSTATUS_SPIE 0x00000020 -#define MSTATUS_HPIE 0x00000040 -#define MSTATUS_MPIE 0x00000080 -#define MSTATUS_SPP 0x00000100 -#define MSTATUS_HPP 0x00000600 -#define MSTATUS_MPP 0x00001800 -#define MSTATUS_FS 0x00006000 -#define MSTATUS_XS 0x00018000 -#define MSTATUS_MPRV 0x00020000 -#define MSTATUS_SUM 0x00040000 -#define MSTATUS_MXR 0x00080000 -#define MSTATUS_TVM 0x00100000 -#define MSTATUS_TW 0x00200000 -#define MSTATUS_TSR 0x00400000 -#define MSTATUS32_SD 0x80000000 -#define MSTATUS64_SD 0x8000000000000000 +#define MSTATUS_UIE 0x00000001 +#define MSTATUS_SIE 0x00000002 +#define MSTATUS_HIE 0x00000004 +#define MSTATUS_MIE 0x00000008 +#define MSTATUS_UPIE 0x00000010 +#define MSTATUS_SPIE 0x00000020 +#define MSTATUS_HPIE 0x00000040 +#define MSTATUS_MPIE 0x00000080 +#define MSTATUS_SPP 0x00000100 +#define MSTATUS_HPP 0x00000600 +#define MSTATUS_MPP 0x00001800 +#define MSTATUS_FS 0x00006000 +#define MSTATUS_XS 0x00018000 +#define MSTATUS_MPRV 0x00020000 +#define MSTATUS_SUM 0x00040000 +#define MSTATUS_MXR 0x00080000 +#define MSTATUS_TVM 0x00100000 +#define MSTATUS_TW 0x00200000 +#define MSTATUS_TSR 0x00400000 +#define MSTATUS32_SD 0x80000000 +#define MSTATUS64_SD 0x8000000000000000 -#define MCAUSE32_CAUSE 0x7FFFFFFF -#define MCAUSE64_CAUSE 0x7FFFFFFFFFFFFFFF -#define MCAUSE32_INT 0x80000000 -#define MCAUSE64_INT 0x8000000000000000 +#define MCAUSE32_CAUSE 0x7FFFFFFF +#define MCAUSE64_CAUSE 0x7FFFFFFFFFFFFFFF +#define MCAUSE32_INT 0x80000000 +#define MCAUSE64_INT 0x8000000000000000 -#define SSTATUS_UIE 0x00000001 -#define SSTATUS_SIE 0x00000002 -#define SSTATUS_UPIE 0x00000010 -#define SSTATUS_SPIE 0x00000020 -#define SSTATUS_SPP 0x00000100 -#define SSTATUS_FS 0x00006000 -#define SSTATUS_XS 0x00018000 -#define SSTATUS_SUM 0x00040000 -#define SSTATUS_MXR 0x00080000 -#define SSTATUS32_SD 0x80000000 -#define SSTATUS64_SD 0x8000000000000000 +#define SSTATUS_UIE 0x00000001 +#define SSTATUS_SIE 0x00000002 +#define SSTATUS_UPIE 0x00000010 +#define SSTATUS_SPIE 0x00000020 +#define SSTATUS_SPP 0x00000100 +#define SSTATUS_FS 0x00006000 +#define SSTATUS_XS 0x00018000 +#define SSTATUS_SUM 0x00040000 +#define SSTATUS_MXR 0x00080000 +#define SSTATUS32_SD 0x80000000 +#define SSTATUS64_SD 0x8000000000000000 -#define DCSR_XDEBUGVER (3U<<30) -#define DCSR_NDRESET (1<<29) -#define DCSR_FULLRESET (1<<28) -#define DCSR_EBREAKM (1<<15) -#define DCSR_EBREAKH (1<<14) -#define DCSR_EBREAKS (1<<13) -#define DCSR_EBREAKU (1<<12) -#define DCSR_STOPCYCLE (1<<10) -#define DCSR_STOPTIME (1<<9) -#define DCSR_CAUSE (7<<6) -#define DCSR_DEBUGINT (1<<5) -#define DCSR_HALT (1<<3) -#define DCSR_STEP (1<<2) -#define DCSR_PRV (3<<0) +#define DCSR_XDEBUGVER (3U << 30) +#define DCSR_NDRESET (1 << 29) +#define DCSR_FULLRESET (1 << 28) +#define DCSR_EBREAKM (1 << 15) +#define DCSR_EBREAKH (1 << 14) +#define DCSR_EBREAKS (1 << 13) +#define DCSR_EBREAKU (1 << 12) +#define DCSR_STOPCYCLE (1 << 10) +#define DCSR_STOPTIME (1 << 9) +#define DCSR_CAUSE (7 << 6) +#define DCSR_DEBUGINT (1 << 5) +#define DCSR_HALT (1 << 3) +#define DCSR_STEP (1 << 2) +#define DCSR_PRV (3 << 0) -#define DCSR_CAUSE_NONE 0 -#define DCSR_CAUSE_SWBP 1 -#define DCSR_CAUSE_HWBP 2 +#define DCSR_CAUSE_NONE 0 +#define DCSR_CAUSE_SWBP 1 +#define DCSR_CAUSE_HWBP 2 #define DCSR_CAUSE_DEBUGINT 3 -#define DCSR_CAUSE_STEP 4 -#define DCSR_CAUSE_HALT 5 +#define DCSR_CAUSE_STEP 4 +#define DCSR_CAUSE_HALT 5 -#define MCONTROL_TYPE(xlen) (0xfULL<<((xlen)-4)) -#define MCONTROL_DMODE(xlen) (1ULL<<((xlen)-5)) -#define MCONTROL_MASKMAX(xlen) (0x3fULL<<((xlen)-11)) +#define MCONTROL_TYPE(xlen) (0xfULL << ((xlen)-4)) +#define MCONTROL_DMODE(xlen) (1ULL << ((xlen)-5)) +#define MCONTROL_MASKMAX(xlen) (0x3fULL << ((xlen)-11)) -#define MCONTROL_SELECT (1U<<19) -#define MCONTROL_TIMING (1U<<18) -#define MCONTROL_ACTION (0x3fU<<12) -#define MCONTROL_CHAIN (1U<<11) -#define MCONTROL_MATCH (0xfU<<7) -#define MCONTROL_M (1U<<6) -#define MCONTROL_H (1U<<5) -#define MCONTROL_S (1U<<4) -#define MCONTROL_U (1U<<3) -#define MCONTROL_EXECUTE (1U<<2) -#define MCONTROL_STORE (1U<<1) -#define MCONTROL_LOAD (1U<<0) +#define MCONTROL_SELECT (1U << 19) +#define MCONTROL_TIMING (1U << 18) +#define MCONTROL_ACTION (0x3fU << 12) +#define MCONTROL_CHAIN (1U << 11) +#define MCONTROL_MATCH (0xfU << 7) +#define MCONTROL_M (1U << 6) +#define MCONTROL_H (1U << 5) +#define MCONTROL_S (1U << 4) +#define MCONTROL_U (1U << 3) +#define MCONTROL_EXECUTE (1U << 2) +#define MCONTROL_STORE (1U << 1) +#define MCONTROL_LOAD (1U << 0) -#define MCONTROL_TYPE_NONE 0 -#define MCONTROL_TYPE_MATCH 2 +#define MCONTROL_TYPE_NONE 0 +#define MCONTROL_TYPE_MATCH 2 -#define MCONTROL_ACTION_DEBUG_EXCEPTION 0 -#define MCONTROL_ACTION_DEBUG_MODE 1 -#define MCONTROL_ACTION_TRACE_START 2 -#define MCONTROL_ACTION_TRACE_STOP 3 -#define MCONTROL_ACTION_TRACE_EMIT 4 +#define MCONTROL_ACTION_DEBUG_EXCEPTION 0 +#define MCONTROL_ACTION_DEBUG_MODE 1 +#define MCONTROL_ACTION_TRACE_START 2 +#define MCONTROL_ACTION_TRACE_STOP 3 +#define MCONTROL_ACTION_TRACE_EMIT 4 -#define MCONTROL_MATCH_EQUAL 0 -#define MCONTROL_MATCH_NAPOT 1 -#define MCONTROL_MATCH_GE 2 -#define MCONTROL_MATCH_LT 3 -#define MCONTROL_MATCH_MASK_LOW 4 +#define MCONTROL_MATCH_EQUAL 0 +#define MCONTROL_MATCH_NAPOT 1 +#define MCONTROL_MATCH_GE 2 +#define MCONTROL_MATCH_LT 3 +#define MCONTROL_MATCH_MASK_LOW 4 #define MCONTROL_MATCH_MASK_HIGH 5 -#define MIP_SSIP (1U << IRQ_S_SOFT) -#define MIP_HSIP (1U << IRQ_H_SOFT) -#define MIP_MSIP (1U << IRQ_M_SOFT) -#define MIP_STIP (1U << IRQ_S_TIMER) -#define MIP_HTIP (1U << IRQ_H_TIMER) -#define MIP_MTIP (1U << IRQ_M_TIMER) -#define MIP_SEIP (1U << IRQ_S_EXT) -#define MIP_HEIP (1U << IRQ_H_EXT) -#define MIP_MEIP (1U << IRQ_M_EXT) +#define MIP_SSIP (1U << IRQ_S_SOFT) +#define MIP_HSIP (1U << IRQ_H_SOFT) +#define MIP_MSIP (1U << IRQ_M_SOFT) +#define MIP_STIP (1U << IRQ_S_TIMER) +#define MIP_HTIP (1U << IRQ_H_TIMER) +#define MIP_MTIP (1U << IRQ_M_TIMER) +#define MIP_SEIP (1U << IRQ_S_EXT) +#define MIP_HEIP (1U << IRQ_H_EXT) +#define MIP_MEIP (1U << IRQ_M_EXT) #define SIP_SSIP MIP_SSIP #define SIP_STIP MIP_STIP @@ -147,57 +146,57 @@ #define SPTBR32_MODE 0x80000000 #define SPTBR32_ASID 0x7FC00000 -#define SPTBR32_PPN 0x003FFFFF +#define SPTBR32_PPN 0x003FFFFF #define SPTBR64_MODE 0xF000000000000000 #define SPTBR64_ASID 0x0FFFF00000000000 -#define SPTBR64_PPN 0x00000FFFFFFFFFFF +#define SPTBR64_PPN 0x00000FFFFFFFFFFF -#define SPTBR_MODE_OFF 0 +#define SPTBR_MODE_OFF 0 #define SPTBR_MODE_SV32 1 #define SPTBR_MODE_SV39 8 #define SPTBR_MODE_SV48 9 #define SPTBR_MODE_SV57 10 #define SPTBR_MODE_SV64 11 -#define PMP_R 0x01 -#define PMP_W 0x02 -#define PMP_X 0x04 -#define PMP_A 0x18 -#define PMP_L 0x80 +#define PMP_R 0x01 +#define PMP_W 0x02 +#define PMP_X 0x04 +#define PMP_A 0x18 +#define PMP_L 0x80 #define PMP_SHIFT 2 -#define PMP_TOR 0x08 -#define PMP_NA4 0x10 +#define PMP_TOR 0x08 +#define PMP_NA4 0x10 #define PMP_NAPOT 0x18 -#define IRQ_S_SOFT 1 -#define IRQ_H_SOFT 2 -#define IRQ_M_SOFT 3 -#define IRQ_S_TIMER 5 -#define IRQ_H_TIMER 6 -#define IRQ_M_TIMER 7 -#define IRQ_S_EXT 9 -#define IRQ_H_EXT 10 -#define IRQ_M_EXT 11 -#define IRQ_COP 12 -#define IRQ_HOST 13 +#define IRQ_S_SOFT 1 +#define IRQ_H_SOFT 2 +#define IRQ_M_SOFT 3 +#define IRQ_S_TIMER 5 +#define IRQ_H_TIMER 6 +#define IRQ_M_TIMER 7 +#define IRQ_S_EXT 9 +#define IRQ_H_EXT 10 +#define IRQ_M_EXT 11 +#define IRQ_COP 12 +#define IRQ_HOST 13 -#define DEFAULT_RSTVEC 0x00001000 -#define CLINT_BASE 0x02000000 -#define CLINT_SIZE 0x000c0000 -#define EXT_IO_BASE 0x40000000 -#define DRAM_BASE 0x80000000 +#define DEFAULT_RSTVEC 0x00001000 +#define CLINT_BASE 0x02000000 +#define CLINT_SIZE 0x000c0000 +#define EXT_IO_BASE 0x40000000 +#define DRAM_BASE 0x80000000 // page table entry (PTE) fields -#define PTE_V 0x001 // Valid -#define PTE_R 0x002 // Read -#define PTE_W 0x004 // Write -#define PTE_X 0x008 // Execute -#define PTE_U 0x010 // User -#define PTE_G 0x020 // Global -#define PTE_A 0x040 // Accessed -#define PTE_D 0x080 // Dirty -#define PTE_SOFT 0x300 // Reserved for Software +#define PTE_V 0x001 // Valid +#define PTE_R 0x002 // Read +#define PTE_W 0x004 // Write +#define PTE_X 0x008 // Execute +#define PTE_U 0x010 // User +#define PTE_G 0x020 // Global +#define PTE_A 0x040 // Accessed +#define PTE_D 0x080 // Dirty +#define PTE_SOFT 0x300 // Reserved for Software #define PTE_PPN_SHIFT 10 @@ -206,19 +205,23 @@ #ifdef __riscv #if __riscv_xlen == 64 -# define MSTATUS_SD MSTATUS64_SD -# define SSTATUS_SD SSTATUS64_SD -# define RISCV_PGLEVEL_BITS 9 -# define SPTBR_MODE SPTBR64_MODE -# define MCAUSE_INT MCAUSE64_INT //ML added- should we be using later encoding.h? -# define MCAUSE_CAUSE MCAUSE64_CAUSE //ML added- should we be using later encoding.h? +#define MSTATUS_SD MSTATUS64_SD +#define SSTATUS_SD SSTATUS64_SD +#define RISCV_PGLEVEL_BITS 9 +#define SPTBR_MODE SPTBR64_MODE +#define MCAUSE_INT \ + MCAUSE64_INT // ML added- should we be using later encoding.h? +#define MCAUSE_CAUSE \ + MCAUSE64_CAUSE // ML added- should we be using later encoding.h? #else -# define MSTATUS_SD MSTATUS32_SD -# define SSTATUS_SD SSTATUS32_SD -# define RISCV_PGLEVEL_BITS 10 -# define SPTBR_MODE SPTBR32_MODE -# define MCAUSE_INT MCAUSE32_INT //ML added- should we be using later encoding.h? -# define MCAUSE_CAUSE MCAUSE32_CAUSE //ML added- should we be using later encoding.h? +#define MSTATUS_SD MSTATUS32_SD +#define SSTATUS_SD SSTATUS32_SD +#define RISCV_PGLEVEL_BITS 10 +#define SPTBR_MODE SPTBR32_MODE +#define MCAUSE_INT \ + MCAUSE32_INT // ML added- should we be using later encoding.h? +#define MCAUSE_CAUSE \ + MCAUSE32_CAUSE // ML added- should we be using later encoding.h? #endif #define RISCV_PGSHIFT 12 #define RISCV_PGSIZE (1 << RISCV_PGSHIFT) @@ -227,45 +230,58 @@ #ifdef __GNUC__ -#define read_reg(reg) ({ unsigned long __tmp; \ - asm volatile ("mv %0, " #reg : "=r"(__tmp)); \ - __tmp; }) +#define read_reg(reg) \ + ({ \ + unsigned long __tmp; \ + asm volatile("mv %0, " #reg : "=r"(__tmp)); \ + __tmp; \ + }) -#define read_csr(reg) ({ unsigned long __tmp; \ - asm volatile ("csrr %0, " #reg : "=r"(__tmp)); \ - __tmp; }) +#define read_csr(reg) \ + ({ \ + unsigned long __tmp; \ + asm volatile("csrr %0, " #reg : "=r"(__tmp)); \ + __tmp; \ + }) -#define write_csr(reg, val) ({ \ - asm volatile ("csrw " #reg ", %0" :: "rK"(val)); }) +#define write_csr(reg, val) ({ asm volatile("csrw " #reg ", %0" ::"rK"(val)); }) -#define swap_csr(reg, val) ({ unsigned long __tmp; \ - asm volatile ("csrrw %0, " #reg ", %1" : "=r"(__tmp) : "rK"(val)); \ - __tmp; }) +#define swap_csr(reg, val) \ + ({ \ + unsigned long __tmp; \ + asm volatile("csrrw %0, " #reg ", %1" : "=r"(__tmp) : "rK"(val)); \ + __tmp; \ + }) -#define set_csr(reg, bit) ({ unsigned long __tmp; \ - asm volatile ("csrrs %0, " #reg ", %1" : "=r"(__tmp) : "rK"(bit)); \ - __tmp; }) +#define set_csr(reg, bit) \ + ({ \ + unsigned long __tmp; \ + asm volatile("csrrs %0, " #reg ", %1" : "=r"(__tmp) : "rK"(bit)); \ + __tmp; \ + }) -#define clear_csr(reg, bit) ({ unsigned long __tmp; \ - asm volatile ("csrrc %0, " #reg ", %1" : "=r"(__tmp) : "rK"(bit)); \ - __tmp; }) +#define clear_csr(reg, bit) \ + ({ \ + unsigned long __tmp; \ + asm volatile("csrrc %0, " #reg ", %1" : "=r"(__tmp) : "rK"(bit)); \ + __tmp; \ + }) #if 0 -#define csr_write(csr, val) \ -({ \ - unsigned long __v = (unsigned long)(val); \ - asm volatile ("csrw " __ASM_STR(csr) ", %0" \ - : : "rK" (__v) \ - : "memory"); \ -}) +#define csr_write(csr, val) \ + ({ \ + unsigned long __v = (unsigned long)(val); \ + asm volatile("csrw " __ASM_STR(csr) ", %0" : : "rK"(__v) : "memory"); \ + }) -#define csr_write(csr, val) \ -({ \ - unsigned long __v = (unsigned long)(val); \ - __asm__ __volatile__ ("csrw " __ASM_STR(csr) ", %0" \ - : : "rK" (__v) \ - : "memory"); \ -}) +#define csr_write(csr, val) \ + ({ \ + unsigned long __v = (unsigned long)(val); \ + __asm__ __volatile__("csrw " __ASM_STR(csr) ", %0" \ + : \ + : "rK"(__v) \ + : "memory"); \ + }) #endif #define rdtime() read_csr(time) @@ -283,531 +299,531 @@ #ifndef RISCV_ENCODING_H #define RISCV_ENCODING_H #define MATCH_BEQ 0x63 -#define MASK_BEQ 0x707f +#define MASK_BEQ 0x707f #define MATCH_BNE 0x1063 -#define MASK_BNE 0x707f +#define MASK_BNE 0x707f #define MATCH_BLT 0x4063 -#define MASK_BLT 0x707f +#define MASK_BLT 0x707f #define MATCH_BGE 0x5063 -#define MASK_BGE 0x707f +#define MASK_BGE 0x707f #define MATCH_BLTU 0x6063 -#define MASK_BLTU 0x707f +#define MASK_BLTU 0x707f #define MATCH_BGEU 0x7063 -#define MASK_BGEU 0x707f +#define MASK_BGEU 0x707f #define MATCH_JALR 0x67 -#define MASK_JALR 0x707f +#define MASK_JALR 0x707f #define MATCH_JAL 0x6f -#define MASK_JAL 0x7f +#define MASK_JAL 0x7f #define MATCH_LUI 0x37 -#define MASK_LUI 0x7f +#define MASK_LUI 0x7f #define MATCH_AUIPC 0x17 -#define MASK_AUIPC 0x7f +#define MASK_AUIPC 0x7f #define MATCH_ADDI 0x13 -#define MASK_ADDI 0x707f +#define MASK_ADDI 0x707f #define MATCH_SLLI 0x1013 -#define MASK_SLLI 0xfc00707f +#define MASK_SLLI 0xfc00707f #define MATCH_SLTI 0x2013 -#define MASK_SLTI 0x707f +#define MASK_SLTI 0x707f #define MATCH_SLTIU 0x3013 -#define MASK_SLTIU 0x707f +#define MASK_SLTIU 0x707f #define MATCH_XORI 0x4013 -#define MASK_XORI 0x707f +#define MASK_XORI 0x707f #define MATCH_SRLI 0x5013 -#define MASK_SRLI 0xfc00707f +#define MASK_SRLI 0xfc00707f #define MATCH_SRAI 0x40005013 -#define MASK_SRAI 0xfc00707f +#define MASK_SRAI 0xfc00707f #define MATCH_ORI 0x6013 -#define MASK_ORI 0x707f +#define MASK_ORI 0x707f #define MATCH_ANDI 0x7013 -#define MASK_ANDI 0x707f +#define MASK_ANDI 0x707f #define MATCH_ADD 0x33 -#define MASK_ADD 0xfe00707f +#define MASK_ADD 0xfe00707f #define MATCH_SUB 0x40000033 -#define MASK_SUB 0xfe00707f +#define MASK_SUB 0xfe00707f #define MATCH_SLL 0x1033 -#define MASK_SLL 0xfe00707f +#define MASK_SLL 0xfe00707f #define MATCH_SLT 0x2033 -#define MASK_SLT 0xfe00707f +#define MASK_SLT 0xfe00707f #define MATCH_SLTU 0x3033 -#define MASK_SLTU 0xfe00707f +#define MASK_SLTU 0xfe00707f #define MATCH_XOR 0x4033 -#define MASK_XOR 0xfe00707f +#define MASK_XOR 0xfe00707f #define MATCH_SRL 0x5033 -#define MASK_SRL 0xfe00707f +#define MASK_SRL 0xfe00707f #define MATCH_SRA 0x40005033 -#define MASK_SRA 0xfe00707f +#define MASK_SRA 0xfe00707f #define MATCH_OR 0x6033 -#define MASK_OR 0xfe00707f +#define MASK_OR 0xfe00707f #define MATCH_AND 0x7033 -#define MASK_AND 0xfe00707f +#define MASK_AND 0xfe00707f #define MATCH_ADDIW 0x1b -#define MASK_ADDIW 0x707f +#define MASK_ADDIW 0x707f #define MATCH_SLLIW 0x101b -#define MASK_SLLIW 0xfe00707f +#define MASK_SLLIW 0xfe00707f #define MATCH_SRLIW 0x501b -#define MASK_SRLIW 0xfe00707f +#define MASK_SRLIW 0xfe00707f #define MATCH_SRAIW 0x4000501b -#define MASK_SRAIW 0xfe00707f +#define MASK_SRAIW 0xfe00707f #define MATCH_ADDW 0x3b -#define MASK_ADDW 0xfe00707f +#define MASK_ADDW 0xfe00707f #define MATCH_SUBW 0x4000003b -#define MASK_SUBW 0xfe00707f +#define MASK_SUBW 0xfe00707f #define MATCH_SLLW 0x103b -#define MASK_SLLW 0xfe00707f +#define MASK_SLLW 0xfe00707f #define MATCH_SRLW 0x503b -#define MASK_SRLW 0xfe00707f +#define MASK_SRLW 0xfe00707f #define MATCH_SRAW 0x4000503b -#define MASK_SRAW 0xfe00707f +#define MASK_SRAW 0xfe00707f #define MATCH_LB 0x3 -#define MASK_LB 0x707f +#define MASK_LB 0x707f #define MATCH_LH 0x1003 -#define MASK_LH 0x707f +#define MASK_LH 0x707f #define MATCH_LW 0x2003 -#define MASK_LW 0x707f +#define MASK_LW 0x707f #define MATCH_LD 0x3003 -#define MASK_LD 0x707f +#define MASK_LD 0x707f #define MATCH_LBU 0x4003 -#define MASK_LBU 0x707f +#define MASK_LBU 0x707f #define MATCH_LHU 0x5003 -#define MASK_LHU 0x707f +#define MASK_LHU 0x707f #define MATCH_LWU 0x6003 -#define MASK_LWU 0x707f +#define MASK_LWU 0x707f #define MATCH_SB 0x23 -#define MASK_SB 0x707f +#define MASK_SB 0x707f #define MATCH_SH 0x1023 -#define MASK_SH 0x707f +#define MASK_SH 0x707f #define MATCH_SW 0x2023 -#define MASK_SW 0x707f +#define MASK_SW 0x707f #define MATCH_SD 0x3023 -#define MASK_SD 0x707f +#define MASK_SD 0x707f #define MATCH_FENCE 0xf -#define MASK_FENCE 0x707f +#define MASK_FENCE 0x707f #define MATCH_FENCE_I 0x100f -#define MASK_FENCE_I 0x707f +#define MASK_FENCE_I 0x707f #define MATCH_MUL 0x2000033 -#define MASK_MUL 0xfe00707f +#define MASK_MUL 0xfe00707f #define MATCH_MULH 0x2001033 -#define MASK_MULH 0xfe00707f +#define MASK_MULH 0xfe00707f #define MATCH_MULHSU 0x2002033 -#define MASK_MULHSU 0xfe00707f +#define MASK_MULHSU 0xfe00707f #define MATCH_MULHU 0x2003033 -#define MASK_MULHU 0xfe00707f +#define MASK_MULHU 0xfe00707f #define MATCH_DIV 0x2004033 -#define MASK_DIV 0xfe00707f +#define MASK_DIV 0xfe00707f #define MATCH_DIVU 0x2005033 -#define MASK_DIVU 0xfe00707f +#define MASK_DIVU 0xfe00707f #define MATCH_REM 0x2006033 -#define MASK_REM 0xfe00707f +#define MASK_REM 0xfe00707f #define MATCH_REMU 0x2007033 -#define MASK_REMU 0xfe00707f +#define MASK_REMU 0xfe00707f #define MATCH_MULW 0x200003b -#define MASK_MULW 0xfe00707f +#define MASK_MULW 0xfe00707f #define MATCH_DIVW 0x200403b -#define MASK_DIVW 0xfe00707f +#define MASK_DIVW 0xfe00707f #define MATCH_DIVUW 0x200503b -#define MASK_DIVUW 0xfe00707f +#define MASK_DIVUW 0xfe00707f #define MATCH_REMW 0x200603b -#define MASK_REMW 0xfe00707f +#define MASK_REMW 0xfe00707f #define MATCH_REMUW 0x200703b -#define MASK_REMUW 0xfe00707f +#define MASK_REMUW 0xfe00707f #define MATCH_AMOADD_W 0x202f -#define MASK_AMOADD_W 0xf800707f +#define MASK_AMOADD_W 0xf800707f #define MATCH_AMOXOR_W 0x2000202f -#define MASK_AMOXOR_W 0xf800707f +#define MASK_AMOXOR_W 0xf800707f #define MATCH_AMOOR_W 0x4000202f -#define MASK_AMOOR_W 0xf800707f +#define MASK_AMOOR_W 0xf800707f #define MATCH_AMOAND_W 0x6000202f -#define MASK_AMOAND_W 0xf800707f +#define MASK_AMOAND_W 0xf800707f #define MATCH_AMOMIN_W 0x8000202f -#define MASK_AMOMIN_W 0xf800707f +#define MASK_AMOMIN_W 0xf800707f #define MATCH_AMOMAX_W 0xa000202f -#define MASK_AMOMAX_W 0xf800707f +#define MASK_AMOMAX_W 0xf800707f #define MATCH_AMOMINU_W 0xc000202f -#define MASK_AMOMINU_W 0xf800707f +#define MASK_AMOMINU_W 0xf800707f #define MATCH_AMOMAXU_W 0xe000202f -#define MASK_AMOMAXU_W 0xf800707f +#define MASK_AMOMAXU_W 0xf800707f #define MATCH_AMOSWAP_W 0x800202f -#define MASK_AMOSWAP_W 0xf800707f +#define MASK_AMOSWAP_W 0xf800707f #define MATCH_LR_W 0x1000202f -#define MASK_LR_W 0xf9f0707f +#define MASK_LR_W 0xf9f0707f #define MATCH_SC_W 0x1800202f -#define MASK_SC_W 0xf800707f +#define MASK_SC_W 0xf800707f #define MATCH_AMOADD_D 0x302f -#define MASK_AMOADD_D 0xf800707f +#define MASK_AMOADD_D 0xf800707f #define MATCH_AMOXOR_D 0x2000302f -#define MASK_AMOXOR_D 0xf800707f +#define MASK_AMOXOR_D 0xf800707f #define MATCH_AMOOR_D 0x4000302f -#define MASK_AMOOR_D 0xf800707f +#define MASK_AMOOR_D 0xf800707f #define MATCH_AMOAND_D 0x6000302f -#define MASK_AMOAND_D 0xf800707f +#define MASK_AMOAND_D 0xf800707f #define MATCH_AMOMIN_D 0x8000302f -#define MASK_AMOMIN_D 0xf800707f +#define MASK_AMOMIN_D 0xf800707f #define MATCH_AMOMAX_D 0xa000302f -#define MASK_AMOMAX_D 0xf800707f +#define MASK_AMOMAX_D 0xf800707f #define MATCH_AMOMINU_D 0xc000302f -#define MASK_AMOMINU_D 0xf800707f +#define MASK_AMOMINU_D 0xf800707f #define MATCH_AMOMAXU_D 0xe000302f -#define MASK_AMOMAXU_D 0xf800707f +#define MASK_AMOMAXU_D 0xf800707f #define MATCH_AMOSWAP_D 0x800302f -#define MASK_AMOSWAP_D 0xf800707f +#define MASK_AMOSWAP_D 0xf800707f #define MATCH_LR_D 0x1000302f -#define MASK_LR_D 0xf9f0707f +#define MASK_LR_D 0xf9f0707f #define MATCH_SC_D 0x1800302f -#define MASK_SC_D 0xf800707f +#define MASK_SC_D 0xf800707f #define MATCH_ECALL 0x73 -#define MASK_ECALL 0xffffffff +#define MASK_ECALL 0xffffffff #define MATCH_EBREAK 0x100073 -#define MASK_EBREAK 0xffffffff +#define MASK_EBREAK 0xffffffff #define MATCH_URET 0x200073 -#define MASK_URET 0xffffffff +#define MASK_URET 0xffffffff #define MATCH_SRET 0x10200073 -#define MASK_SRET 0xffffffff +#define MASK_SRET 0xffffffff #define MATCH_HRET 0x20200073 -#define MASK_HRET 0xffffffff +#define MASK_HRET 0xffffffff #define MATCH_MRET 0x30200073 -#define MASK_MRET 0xffffffff +#define MASK_MRET 0xffffffff #define MATCH_DRET 0x7b200073 -#define MASK_DRET 0xffffffff +#define MASK_DRET 0xffffffff #define MATCH_SFENCE_VMA 0x12000073 -#define MASK_SFENCE_VMA 0xfe007fff +#define MASK_SFENCE_VMA 0xfe007fff #define MATCH_WFI 0x10500073 -#define MASK_WFI 0xffffffff +#define MASK_WFI 0xffffffff #define MATCH_CSRRW 0x1073 -#define MASK_CSRRW 0x707f +#define MASK_CSRRW 0x707f #define MATCH_CSRRS 0x2073 -#define MASK_CSRRS 0x707f +#define MASK_CSRRS 0x707f #define MATCH_CSRRC 0x3073 -#define MASK_CSRRC 0x707f +#define MASK_CSRRC 0x707f #define MATCH_CSRRWI 0x5073 -#define MASK_CSRRWI 0x707f +#define MASK_CSRRWI 0x707f #define MATCH_CSRRSI 0x6073 -#define MASK_CSRRSI 0x707f +#define MASK_CSRRSI 0x707f #define MATCH_CSRRCI 0x7073 -#define MASK_CSRRCI 0x707f +#define MASK_CSRRCI 0x707f #define MATCH_FADD_S 0x53 -#define MASK_FADD_S 0xfe00007f +#define MASK_FADD_S 0xfe00007f #define MATCH_FSUB_S 0x8000053 -#define MASK_FSUB_S 0xfe00007f +#define MASK_FSUB_S 0xfe00007f #define MATCH_FMUL_S 0x10000053 -#define MASK_FMUL_S 0xfe00007f +#define MASK_FMUL_S 0xfe00007f #define MATCH_FDIV_S 0x18000053 -#define MASK_FDIV_S 0xfe00007f +#define MASK_FDIV_S 0xfe00007f #define MATCH_FSGNJ_S 0x20000053 -#define MASK_FSGNJ_S 0xfe00707f +#define MASK_FSGNJ_S 0xfe00707f #define MATCH_FSGNJN_S 0x20001053 -#define MASK_FSGNJN_S 0xfe00707f +#define MASK_FSGNJN_S 0xfe00707f #define MATCH_FSGNJX_S 0x20002053 -#define MASK_FSGNJX_S 0xfe00707f +#define MASK_FSGNJX_S 0xfe00707f #define MATCH_FMIN_S 0x28000053 -#define MASK_FMIN_S 0xfe00707f +#define MASK_FMIN_S 0xfe00707f #define MATCH_FMAX_S 0x28001053 -#define MASK_FMAX_S 0xfe00707f +#define MASK_FMAX_S 0xfe00707f #define MATCH_FSQRT_S 0x58000053 -#define MASK_FSQRT_S 0xfff0007f +#define MASK_FSQRT_S 0xfff0007f #define MATCH_FADD_D 0x2000053 -#define MASK_FADD_D 0xfe00007f +#define MASK_FADD_D 0xfe00007f #define MATCH_FSUB_D 0xa000053 -#define MASK_FSUB_D 0xfe00007f +#define MASK_FSUB_D 0xfe00007f #define MATCH_FMUL_D 0x12000053 -#define MASK_FMUL_D 0xfe00007f +#define MASK_FMUL_D 0xfe00007f #define MATCH_FDIV_D 0x1a000053 -#define MASK_FDIV_D 0xfe00007f +#define MASK_FDIV_D 0xfe00007f #define MATCH_FSGNJ_D 0x22000053 -#define MASK_FSGNJ_D 0xfe00707f +#define MASK_FSGNJ_D 0xfe00707f #define MATCH_FSGNJN_D 0x22001053 -#define MASK_FSGNJN_D 0xfe00707f +#define MASK_FSGNJN_D 0xfe00707f #define MATCH_FSGNJX_D 0x22002053 -#define MASK_FSGNJX_D 0xfe00707f +#define MASK_FSGNJX_D 0xfe00707f #define MATCH_FMIN_D 0x2a000053 -#define MASK_FMIN_D 0xfe00707f +#define MASK_FMIN_D 0xfe00707f #define MATCH_FMAX_D 0x2a001053 -#define MASK_FMAX_D 0xfe00707f +#define MASK_FMAX_D 0xfe00707f #define MATCH_FCVT_S_D 0x40100053 -#define MASK_FCVT_S_D 0xfff0007f +#define MASK_FCVT_S_D 0xfff0007f #define MATCH_FCVT_D_S 0x42000053 -#define MASK_FCVT_D_S 0xfff0007f +#define MASK_FCVT_D_S 0xfff0007f #define MATCH_FSQRT_D 0x5a000053 -#define MASK_FSQRT_D 0xfff0007f +#define MASK_FSQRT_D 0xfff0007f #define MATCH_FADD_Q 0x6000053 -#define MASK_FADD_Q 0xfe00007f +#define MASK_FADD_Q 0xfe00007f #define MATCH_FSUB_Q 0xe000053 -#define MASK_FSUB_Q 0xfe00007f +#define MASK_FSUB_Q 0xfe00007f #define MATCH_FMUL_Q 0x16000053 -#define MASK_FMUL_Q 0xfe00007f +#define MASK_FMUL_Q 0xfe00007f #define MATCH_FDIV_Q 0x1e000053 -#define MASK_FDIV_Q 0xfe00007f +#define MASK_FDIV_Q 0xfe00007f #define MATCH_FSGNJ_Q 0x26000053 -#define MASK_FSGNJ_Q 0xfe00707f +#define MASK_FSGNJ_Q 0xfe00707f #define MATCH_FSGNJN_Q 0x26001053 -#define MASK_FSGNJN_Q 0xfe00707f +#define MASK_FSGNJN_Q 0xfe00707f #define MATCH_FSGNJX_Q 0x26002053 -#define MASK_FSGNJX_Q 0xfe00707f +#define MASK_FSGNJX_Q 0xfe00707f #define MATCH_FMIN_Q 0x2e000053 -#define MASK_FMIN_Q 0xfe00707f +#define MASK_FMIN_Q 0xfe00707f #define MATCH_FMAX_Q 0x2e001053 -#define MASK_FMAX_Q 0xfe00707f +#define MASK_FMAX_Q 0xfe00707f #define MATCH_FCVT_S_Q 0x40300053 -#define MASK_FCVT_S_Q 0xfff0007f +#define MASK_FCVT_S_Q 0xfff0007f #define MATCH_FCVT_Q_S 0x46000053 -#define MASK_FCVT_Q_S 0xfff0007f +#define MASK_FCVT_Q_S 0xfff0007f #define MATCH_FCVT_D_Q 0x42300053 -#define MASK_FCVT_D_Q 0xfff0007f +#define MASK_FCVT_D_Q 0xfff0007f #define MATCH_FCVT_Q_D 0x46100053 -#define MASK_FCVT_Q_D 0xfff0007f +#define MASK_FCVT_Q_D 0xfff0007f #define MATCH_FSQRT_Q 0x5e000053 -#define MASK_FSQRT_Q 0xfff0007f +#define MASK_FSQRT_Q 0xfff0007f #define MATCH_FLE_S 0xa0000053 -#define MASK_FLE_S 0xfe00707f +#define MASK_FLE_S 0xfe00707f #define MATCH_FLT_S 0xa0001053 -#define MASK_FLT_S 0xfe00707f +#define MASK_FLT_S 0xfe00707f #define MATCH_FEQ_S 0xa0002053 -#define MASK_FEQ_S 0xfe00707f +#define MASK_FEQ_S 0xfe00707f #define MATCH_FLE_D 0xa2000053 -#define MASK_FLE_D 0xfe00707f +#define MASK_FLE_D 0xfe00707f #define MATCH_FLT_D 0xa2001053 -#define MASK_FLT_D 0xfe00707f +#define MASK_FLT_D 0xfe00707f #define MATCH_FEQ_D 0xa2002053 -#define MASK_FEQ_D 0xfe00707f +#define MASK_FEQ_D 0xfe00707f #define MATCH_FLE_Q 0xa6000053 -#define MASK_FLE_Q 0xfe00707f +#define MASK_FLE_Q 0xfe00707f #define MATCH_FLT_Q 0xa6001053 -#define MASK_FLT_Q 0xfe00707f +#define MASK_FLT_Q 0xfe00707f #define MATCH_FEQ_Q 0xa6002053 -#define MASK_FEQ_Q 0xfe00707f +#define MASK_FEQ_Q 0xfe00707f #define MATCH_FCVT_W_S 0xc0000053 -#define MASK_FCVT_W_S 0xfff0007f +#define MASK_FCVT_W_S 0xfff0007f #define MATCH_FCVT_WU_S 0xc0100053 -#define MASK_FCVT_WU_S 0xfff0007f +#define MASK_FCVT_WU_S 0xfff0007f #define MATCH_FCVT_L_S 0xc0200053 -#define MASK_FCVT_L_S 0xfff0007f +#define MASK_FCVT_L_S 0xfff0007f #define MATCH_FCVT_LU_S 0xc0300053 -#define MASK_FCVT_LU_S 0xfff0007f +#define MASK_FCVT_LU_S 0xfff0007f #define MATCH_FMV_X_S 0xe0000053 -#define MASK_FMV_X_S 0xfff0707f +#define MASK_FMV_X_S 0xfff0707f #define MATCH_FCLASS_S 0xe0001053 -#define MASK_FCLASS_S 0xfff0707f +#define MASK_FCLASS_S 0xfff0707f #define MATCH_FCVT_W_D 0xc2000053 -#define MASK_FCVT_W_D 0xfff0007f +#define MASK_FCVT_W_D 0xfff0007f #define MATCH_FCVT_WU_D 0xc2100053 -#define MASK_FCVT_WU_D 0xfff0007f +#define MASK_FCVT_WU_D 0xfff0007f #define MATCH_FCVT_L_D 0xc2200053 -#define MASK_FCVT_L_D 0xfff0007f +#define MASK_FCVT_L_D 0xfff0007f #define MATCH_FCVT_LU_D 0xc2300053 -#define MASK_FCVT_LU_D 0xfff0007f +#define MASK_FCVT_LU_D 0xfff0007f #define MATCH_FMV_X_D 0xe2000053 -#define MASK_FMV_X_D 0xfff0707f +#define MASK_FMV_X_D 0xfff0707f #define MATCH_FCLASS_D 0xe2001053 -#define MASK_FCLASS_D 0xfff0707f +#define MASK_FCLASS_D 0xfff0707f #define MATCH_FCVT_W_Q 0xc6000053 -#define MASK_FCVT_W_Q 0xfff0007f +#define MASK_FCVT_W_Q 0xfff0007f #define MATCH_FCVT_WU_Q 0xc6100053 -#define MASK_FCVT_WU_Q 0xfff0007f +#define MASK_FCVT_WU_Q 0xfff0007f #define MATCH_FCVT_L_Q 0xc6200053 -#define MASK_FCVT_L_Q 0xfff0007f +#define MASK_FCVT_L_Q 0xfff0007f #define MATCH_FCVT_LU_Q 0xc6300053 -#define MASK_FCVT_LU_Q 0xfff0007f +#define MASK_FCVT_LU_Q 0xfff0007f #define MATCH_FMV_X_Q 0xe6000053 -#define MASK_FMV_X_Q 0xfff0707f +#define MASK_FMV_X_Q 0xfff0707f #define MATCH_FCLASS_Q 0xe6001053 -#define MASK_FCLASS_Q 0xfff0707f +#define MASK_FCLASS_Q 0xfff0707f #define MATCH_FCVT_S_W 0xd0000053 -#define MASK_FCVT_S_W 0xfff0007f +#define MASK_FCVT_S_W 0xfff0007f #define MATCH_FCVT_S_WU 0xd0100053 -#define MASK_FCVT_S_WU 0xfff0007f +#define MASK_FCVT_S_WU 0xfff0007f #define MATCH_FCVT_S_L 0xd0200053 -#define MASK_FCVT_S_L 0xfff0007f +#define MASK_FCVT_S_L 0xfff0007f #define MATCH_FCVT_S_LU 0xd0300053 -#define MASK_FCVT_S_LU 0xfff0007f +#define MASK_FCVT_S_LU 0xfff0007f #define MATCH_FMV_S_X 0xf0000053 -#define MASK_FMV_S_X 0xfff0707f +#define MASK_FMV_S_X 0xfff0707f #define MATCH_FCVT_D_W 0xd2000053 -#define MASK_FCVT_D_W 0xfff0007f +#define MASK_FCVT_D_W 0xfff0007f #define MATCH_FCVT_D_WU 0xd2100053 -#define MASK_FCVT_D_WU 0xfff0007f +#define MASK_FCVT_D_WU 0xfff0007f #define MATCH_FCVT_D_L 0xd2200053 -#define MASK_FCVT_D_L 0xfff0007f +#define MASK_FCVT_D_L 0xfff0007f #define MATCH_FCVT_D_LU 0xd2300053 -#define MASK_FCVT_D_LU 0xfff0007f +#define MASK_FCVT_D_LU 0xfff0007f #define MATCH_FMV_D_X 0xf2000053 -#define MASK_FMV_D_X 0xfff0707f +#define MASK_FMV_D_X 0xfff0707f #define MATCH_FCVT_Q_W 0xd6000053 -#define MASK_FCVT_Q_W 0xfff0007f +#define MASK_FCVT_Q_W 0xfff0007f #define MATCH_FCVT_Q_WU 0xd6100053 -#define MASK_FCVT_Q_WU 0xfff0007f +#define MASK_FCVT_Q_WU 0xfff0007f #define MATCH_FCVT_Q_L 0xd6200053 -#define MASK_FCVT_Q_L 0xfff0007f +#define MASK_FCVT_Q_L 0xfff0007f #define MATCH_FCVT_Q_LU 0xd6300053 -#define MASK_FCVT_Q_LU 0xfff0007f +#define MASK_FCVT_Q_LU 0xfff0007f #define MATCH_FMV_Q_X 0xf6000053 -#define MASK_FMV_Q_X 0xfff0707f +#define MASK_FMV_Q_X 0xfff0707f #define MATCH_FLW 0x2007 -#define MASK_FLW 0x707f +#define MASK_FLW 0x707f #define MATCH_FLD 0x3007 -#define MASK_FLD 0x707f +#define MASK_FLD 0x707f #define MATCH_FLQ 0x4007 -#define MASK_FLQ 0x707f +#define MASK_FLQ 0x707f #define MATCH_FSW 0x2027 -#define MASK_FSW 0x707f +#define MASK_FSW 0x707f #define MATCH_FSD 0x3027 -#define MASK_FSD 0x707f +#define MASK_FSD 0x707f #define MATCH_FSQ 0x4027 -#define MASK_FSQ 0x707f +#define MASK_FSQ 0x707f #define MATCH_FMADD_S 0x43 -#define MASK_FMADD_S 0x600007f +#define MASK_FMADD_S 0x600007f #define MATCH_FMSUB_S 0x47 -#define MASK_FMSUB_S 0x600007f +#define MASK_FMSUB_S 0x600007f #define MATCH_FNMSUB_S 0x4b -#define MASK_FNMSUB_S 0x600007f +#define MASK_FNMSUB_S 0x600007f #define MATCH_FNMADD_S 0x4f -#define MASK_FNMADD_S 0x600007f +#define MASK_FNMADD_S 0x600007f #define MATCH_FMADD_D 0x2000043 -#define MASK_FMADD_D 0x600007f +#define MASK_FMADD_D 0x600007f #define MATCH_FMSUB_D 0x2000047 -#define MASK_FMSUB_D 0x600007f +#define MASK_FMSUB_D 0x600007f #define MATCH_FNMSUB_D 0x200004b -#define MASK_FNMSUB_D 0x600007f +#define MASK_FNMSUB_D 0x600007f #define MATCH_FNMADD_D 0x200004f -#define MASK_FNMADD_D 0x600007f +#define MASK_FNMADD_D 0x600007f #define MATCH_FMADD_Q 0x6000043 -#define MASK_FMADD_Q 0x600007f +#define MASK_FMADD_Q 0x600007f #define MATCH_FMSUB_Q 0x6000047 -#define MASK_FMSUB_Q 0x600007f +#define MASK_FMSUB_Q 0x600007f #define MATCH_FNMSUB_Q 0x600004b -#define MASK_FNMSUB_Q 0x600007f +#define MASK_FNMSUB_Q 0x600007f #define MATCH_FNMADD_Q 0x600004f -#define MASK_FNMADD_Q 0x600007f +#define MASK_FNMADD_Q 0x600007f #define MATCH_C_NOP 0x1 -#define MASK_C_NOP 0xffff +#define MASK_C_NOP 0xffff #define MATCH_C_ADDI16SP 0x6101 -#define MASK_C_ADDI16SP 0xef83 +#define MASK_C_ADDI16SP 0xef83 #define MATCH_C_JR 0x8002 -#define MASK_C_JR 0xf07f +#define MASK_C_JR 0xf07f #define MATCH_C_JALR 0x9002 -#define MASK_C_JALR 0xf07f +#define MASK_C_JALR 0xf07f #define MATCH_C_EBREAK 0x9002 -#define MASK_C_EBREAK 0xffff +#define MASK_C_EBREAK 0xffff #define MATCH_C_LD 0x6000 -#define MASK_C_LD 0xe003 +#define MASK_C_LD 0xe003 #define MATCH_C_SD 0xe000 -#define MASK_C_SD 0xe003 +#define MASK_C_SD 0xe003 #define MATCH_C_ADDIW 0x2001 -#define MASK_C_ADDIW 0xe003 +#define MASK_C_ADDIW 0xe003 #define MATCH_C_LDSP 0x6002 -#define MASK_C_LDSP 0xe003 +#define MASK_C_LDSP 0xe003 #define MATCH_C_SDSP 0xe002 -#define MASK_C_SDSP 0xe003 +#define MASK_C_SDSP 0xe003 #define MATCH_C_ADDI4SPN 0x0 -#define MASK_C_ADDI4SPN 0xe003 +#define MASK_C_ADDI4SPN 0xe003 #define MATCH_C_FLD 0x2000 -#define MASK_C_FLD 0xe003 +#define MASK_C_FLD 0xe003 #define MATCH_C_LW 0x4000 -#define MASK_C_LW 0xe003 +#define MASK_C_LW 0xe003 #define MATCH_C_FLW 0x6000 -#define MASK_C_FLW 0xe003 +#define MASK_C_FLW 0xe003 #define MATCH_C_FSD 0xa000 -#define MASK_C_FSD 0xe003 +#define MASK_C_FSD 0xe003 #define MATCH_C_SW 0xc000 -#define MASK_C_SW 0xe003 +#define MASK_C_SW 0xe003 #define MATCH_C_FSW 0xe000 -#define MASK_C_FSW 0xe003 +#define MASK_C_FSW 0xe003 #define MATCH_C_ADDI 0x1 -#define MASK_C_ADDI 0xe003 +#define MASK_C_ADDI 0xe003 #define MATCH_C_JAL 0x2001 -#define MASK_C_JAL 0xe003 +#define MASK_C_JAL 0xe003 #define MATCH_C_LI 0x4001 -#define MASK_C_LI 0xe003 +#define MASK_C_LI 0xe003 #define MATCH_C_LUI 0x6001 -#define MASK_C_LUI 0xe003 +#define MASK_C_LUI 0xe003 #define MATCH_C_SRLI 0x8001 -#define MASK_C_SRLI 0xec03 +#define MASK_C_SRLI 0xec03 #define MATCH_C_SRAI 0x8401 -#define MASK_C_SRAI 0xec03 +#define MASK_C_SRAI 0xec03 #define MATCH_C_ANDI 0x8801 -#define MASK_C_ANDI 0xec03 +#define MASK_C_ANDI 0xec03 #define MATCH_C_SUB 0x8c01 -#define MASK_C_SUB 0xfc63 +#define MASK_C_SUB 0xfc63 #define MATCH_C_XOR 0x8c21 -#define MASK_C_XOR 0xfc63 +#define MASK_C_XOR 0xfc63 #define MATCH_C_OR 0x8c41 -#define MASK_C_OR 0xfc63 +#define MASK_C_OR 0xfc63 #define MATCH_C_AND 0x8c61 -#define MASK_C_AND 0xfc63 +#define MASK_C_AND 0xfc63 #define MATCH_C_SUBW 0x9c01 -#define MASK_C_SUBW 0xfc63 +#define MASK_C_SUBW 0xfc63 #define MATCH_C_ADDW 0x9c21 -#define MASK_C_ADDW 0xfc63 +#define MASK_C_ADDW 0xfc63 #define MATCH_C_J 0xa001 -#define MASK_C_J 0xe003 +#define MASK_C_J 0xe003 #define MATCH_C_BEQZ 0xc001 -#define MASK_C_BEQZ 0xe003 +#define MASK_C_BEQZ 0xe003 #define MATCH_C_BNEZ 0xe001 -#define MASK_C_BNEZ 0xe003 +#define MASK_C_BNEZ 0xe003 #define MATCH_C_SLLI 0x2 -#define MASK_C_SLLI 0xe003 +#define MASK_C_SLLI 0xe003 #define MATCH_C_FLDSP 0x2002 -#define MASK_C_FLDSP 0xe003 +#define MASK_C_FLDSP 0xe003 #define MATCH_C_LWSP 0x4002 -#define MASK_C_LWSP 0xe003 +#define MASK_C_LWSP 0xe003 #define MATCH_C_FLWSP 0x6002 -#define MASK_C_FLWSP 0xe003 +#define MASK_C_FLWSP 0xe003 #define MATCH_C_MV 0x8002 -#define MASK_C_MV 0xf003 +#define MASK_C_MV 0xf003 #define MATCH_C_ADD 0x9002 -#define MASK_C_ADD 0xf003 +#define MASK_C_ADD 0xf003 #define MATCH_C_FSDSP 0xa002 -#define MASK_C_FSDSP 0xe003 +#define MASK_C_FSDSP 0xe003 #define MATCH_C_SWSP 0xc002 -#define MASK_C_SWSP 0xe003 +#define MASK_C_SWSP 0xe003 #define MATCH_C_FSWSP 0xe002 -#define MASK_C_FSWSP 0xe003 +#define MASK_C_FSWSP 0xe003 #define MATCH_CUSTOM0 0xb -#define MASK_CUSTOM0 0x707f +#define MASK_CUSTOM0 0x707f #define MATCH_CUSTOM0_RS1 0x200b -#define MASK_CUSTOM0_RS1 0x707f +#define MASK_CUSTOM0_RS1 0x707f #define MATCH_CUSTOM0_RS1_RS2 0x300b -#define MASK_CUSTOM0_RS1_RS2 0x707f +#define MASK_CUSTOM0_RS1_RS2 0x707f #define MATCH_CUSTOM0_RD 0x400b -#define MASK_CUSTOM0_RD 0x707f +#define MASK_CUSTOM0_RD 0x707f #define MATCH_CUSTOM0_RD_RS1 0x600b -#define MASK_CUSTOM0_RD_RS1 0x707f +#define MASK_CUSTOM0_RD_RS1 0x707f #define MATCH_CUSTOM0_RD_RS1_RS2 0x700b -#define MASK_CUSTOM0_RD_RS1_RS2 0x707f +#define MASK_CUSTOM0_RD_RS1_RS2 0x707f #define MATCH_CUSTOM1 0x2b -#define MASK_CUSTOM1 0x707f +#define MASK_CUSTOM1 0x707f #define MATCH_CUSTOM1_RS1 0x202b -#define MASK_CUSTOM1_RS1 0x707f +#define MASK_CUSTOM1_RS1 0x707f #define MATCH_CUSTOM1_RS1_RS2 0x302b -#define MASK_CUSTOM1_RS1_RS2 0x707f +#define MASK_CUSTOM1_RS1_RS2 0x707f #define MATCH_CUSTOM1_RD 0x402b -#define MASK_CUSTOM1_RD 0x707f +#define MASK_CUSTOM1_RD 0x707f #define MATCH_CUSTOM1_RD_RS1 0x602b -#define MASK_CUSTOM1_RD_RS1 0x707f +#define MASK_CUSTOM1_RD_RS1 0x707f #define MATCH_CUSTOM1_RD_RS1_RS2 0x702b -#define MASK_CUSTOM1_RD_RS1_RS2 0x707f +#define MASK_CUSTOM1_RD_RS1_RS2 0x707f #define MATCH_CUSTOM2 0x5b -#define MASK_CUSTOM2 0x707f +#define MASK_CUSTOM2 0x707f #define MATCH_CUSTOM2_RS1 0x205b -#define MASK_CUSTOM2_RS1 0x707f +#define MASK_CUSTOM2_RS1 0x707f #define MATCH_CUSTOM2_RS1_RS2 0x305b -#define MASK_CUSTOM2_RS1_RS2 0x707f +#define MASK_CUSTOM2_RS1_RS2 0x707f #define MATCH_CUSTOM2_RD 0x405b -#define MASK_CUSTOM2_RD 0x707f +#define MASK_CUSTOM2_RD 0x707f #define MATCH_CUSTOM2_RD_RS1 0x605b -#define MASK_CUSTOM2_RD_RS1 0x707f +#define MASK_CUSTOM2_RD_RS1 0x707f #define MATCH_CUSTOM2_RD_RS1_RS2 0x705b -#define MASK_CUSTOM2_RD_RS1_RS2 0x707f +#define MASK_CUSTOM2_RD_RS1_RS2 0x707f #define MATCH_CUSTOM3 0x7b -#define MASK_CUSTOM3 0x707f +#define MASK_CUSTOM3 0x707f #define MATCH_CUSTOM3_RS1 0x207b -#define MASK_CUSTOM3_RS1 0x707f +#define MASK_CUSTOM3_RS1 0x707f #define MATCH_CUSTOM3_RS1_RS2 0x307b -#define MASK_CUSTOM3_RS1_RS2 0x707f +#define MASK_CUSTOM3_RS1_RS2 0x707f #define MATCH_CUSTOM3_RD 0x407b -#define MASK_CUSTOM3_RD 0x707f +#define MASK_CUSTOM3_RD 0x707f #define MATCH_CUSTOM3_RD_RS1 0x607b -#define MASK_CUSTOM3_RD_RS1 0x707f +#define MASK_CUSTOM3_RD_RS1 0x707f #define MATCH_CUSTOM3_RD_RS1_RS2 0x707b -#define MASK_CUSTOM3_RD_RS1_RS2 0x707f +#define MASK_CUSTOM3_RD_RS1_RS2 0x707f #define CSR_FFLAGS 0x1 #define CSR_FRM 0x2 #define CSR_FCSR 0x3 @@ -1280,25 +1296,29 @@ DECLARE_INSN(custom0_rs1, MATCH_CUSTOM0_RS1, MASK_CUSTOM0_RS1) DECLARE_INSN(custom0_rs1_rs2, MATCH_CUSTOM0_RS1_RS2, MASK_CUSTOM0_RS1_RS2) DECLARE_INSN(custom0_rd, MATCH_CUSTOM0_RD, MASK_CUSTOM0_RD) DECLARE_INSN(custom0_rd_rs1, MATCH_CUSTOM0_RD_RS1, MASK_CUSTOM0_RD_RS1) -DECLARE_INSN(custom0_rd_rs1_rs2, MATCH_CUSTOM0_RD_RS1_RS2, MASK_CUSTOM0_RD_RS1_RS2) +DECLARE_INSN( + custom0_rd_rs1_rs2, MATCH_CUSTOM0_RD_RS1_RS2, MASK_CUSTOM0_RD_RS1_RS2) DECLARE_INSN(custom1, MATCH_CUSTOM1, MASK_CUSTOM1) DECLARE_INSN(custom1_rs1, MATCH_CUSTOM1_RS1, MASK_CUSTOM1_RS1) DECLARE_INSN(custom1_rs1_rs2, MATCH_CUSTOM1_RS1_RS2, MASK_CUSTOM1_RS1_RS2) DECLARE_INSN(custom1_rd, MATCH_CUSTOM1_RD, MASK_CUSTOM1_RD) DECLARE_INSN(custom1_rd_rs1, MATCH_CUSTOM1_RD_RS1, MASK_CUSTOM1_RD_RS1) -DECLARE_INSN(custom1_rd_rs1_rs2, MATCH_CUSTOM1_RD_RS1_RS2, MASK_CUSTOM1_RD_RS1_RS2) +DECLARE_INSN( + custom1_rd_rs1_rs2, MATCH_CUSTOM1_RD_RS1_RS2, MASK_CUSTOM1_RD_RS1_RS2) DECLARE_INSN(custom2, MATCH_CUSTOM2, MASK_CUSTOM2) DECLARE_INSN(custom2_rs1, MATCH_CUSTOM2_RS1, MASK_CUSTOM2_RS1) DECLARE_INSN(custom2_rs1_rs2, MATCH_CUSTOM2_RS1_RS2, MASK_CUSTOM2_RS1_RS2) DECLARE_INSN(custom2_rd, MATCH_CUSTOM2_RD, MASK_CUSTOM2_RD) DECLARE_INSN(custom2_rd_rs1, MATCH_CUSTOM2_RD_RS1, MASK_CUSTOM2_RD_RS1) -DECLARE_INSN(custom2_rd_rs1_rs2, MATCH_CUSTOM2_RD_RS1_RS2, MASK_CUSTOM2_RD_RS1_RS2) +DECLARE_INSN( + custom2_rd_rs1_rs2, MATCH_CUSTOM2_RD_RS1_RS2, MASK_CUSTOM2_RD_RS1_RS2) DECLARE_INSN(custom3, MATCH_CUSTOM3, MASK_CUSTOM3) DECLARE_INSN(custom3_rs1, MATCH_CUSTOM3_RS1, MASK_CUSTOM3_RS1) DECLARE_INSN(custom3_rs1_rs2, MATCH_CUSTOM3_RS1_RS2, MASK_CUSTOM3_RS1_RS2) DECLARE_INSN(custom3_rd, MATCH_CUSTOM3_RD, MASK_CUSTOM3_RD) DECLARE_INSN(custom3_rd_rs1, MATCH_CUSTOM3_RD_RS1, MASK_CUSTOM3_RD_RS1) -DECLARE_INSN(custom3_rd_rs1_rs2, MATCH_CUSTOM3_RD_RS1_RS2, MASK_CUSTOM3_RD_RS1_RS2) +DECLARE_INSN( + custom3_rd_rs1_rs2, MATCH_CUSTOM3_RD_RS1_RS2, MASK_CUSTOM3_RD_RS1_RS2) #endif #ifdef DECLARE_CSR DECLARE_CSR(fflags, CSR_FFLAGS) diff --git a/sm/plat/mpfs/hss_clock.c b/sm/plat/mpfs/hss_clock.c index 39af0e64f..ab1f17eb5 100644 --- a/sm/plat/mpfs/hss_clock.c +++ b/sm/plat/mpfs/hss_clock.c @@ -12,46 +12,51 @@ * \brief Get acccess to tick counts from processor */ -#include +#include "hss_clock.h" + #include +#include #include "config.h" -#include "hss_clock.h" #include "csr_helper.h" /** * \brief Get acccess to tick counts from processor */ -HSSTicks_t HSS_GetTime(void) -{ - HSSTicks_t tickCount; +HSSTicks_t +HSS_GetTime(void) { + HSSTicks_t tickCount; - tickCount = CSR_GetTime(); - return tickCount; + tickCount = CSR_GetTime(); + return tickCount; } -HSSTicks_t HSS_GetTickCount(void) -{ - HSSTicks_t volatile tickCount; +HSSTicks_t +HSS_GetTickCount(void) { + HSSTicks_t volatile tickCount; - tickCount = CSR_GetTickCount(); - return tickCount; + tickCount = CSR_GetTickCount(); + return tickCount; } -bool HSS_Timer_IsElapsed(HSSTicks_t startTick, HSSTicks_t durationInTicks) -{ - return (HSS_GetTime() > (startTick + durationInTicks)); +bool +HSS_Timer_IsElapsed(HSSTicks_t startTick, HSSTicks_t durationInTicks) { + return (HSS_GetTime() > (startTick + durationInTicks)); } -void HSS_SpinDelay_MilliSecs(uint32_t milliseconds) -{ - HSSTicks_t delayTick = HSS_GetTime(); - while (!HSS_Timer_IsElapsed(delayTick, ONE_MILLISEC * milliseconds)) { ; } +void +HSS_SpinDelay_MilliSecs(uint32_t milliseconds) { + HSSTicks_t delayTick = HSS_GetTime(); + while (!HSS_Timer_IsElapsed(delayTick, ONE_MILLISEC * milliseconds)) { + ; + } } -void HSS_SpinDelay_Secs(uint32_t seconds) -{ - HSSTicks_t delayTick = HSS_GetTime(); - while (!HSS_Timer_IsElapsed(delayTick, ONE_SEC * seconds)) { ; } +void +HSS_SpinDelay_Secs(uint32_t seconds) { + HSSTicks_t delayTick = HSS_GetTime(); + while (!HSS_Timer_IsElapsed(delayTick, ONE_SEC * seconds)) { + ; + } } diff --git a/sm/plat/mpfs/hss_clock.h b/sm/plat/mpfs/hss_clock.h index 5ca21b8f6..7f957cf3e 100644 --- a/sm/plat/mpfs/hss_clock.h +++ b/sm/plat/mpfs/hss_clock.h @@ -40,26 +40,31 @@ extern "C" { //# define TICKS_PER_MILLISEC 5llu // This is about 1 millisec on RENODE #if IS_ENABLED(CONFIG_PLATFORM_MPFS) -# include "clocks/hw_mss_clks.h" -# define TICKS_PER_SEC ((unsigned long long)LIBERO_SETTING_MSS_RTC_TOGGLE_CLK) -# define TICKS_PER_MILLISEC (TICKS_PER_SEC/1000llu) -# define ONE_SEC (1llu * TICKS_PER_SEC) -# define ONE_MILLISEC (1llu * TICKS_PER_MILLISEC) +#include "clocks/hw_mss_clks.h" +#define TICKS_PER_SEC ((unsigned long long)LIBERO_SETTING_MSS_RTC_TOGGLE_CLK) +#define TICKS_PER_MILLISEC (TICKS_PER_SEC / 1000llu) +#define ONE_SEC (1llu * TICKS_PER_SEC) +#define ONE_MILLISEC (1llu * TICKS_PER_MILLISEC) #endif #if IS_ENABLED(CONFIG_PLATFORM_FU540) -# define TICKS_PER_MILLISEC 1000llu -# define TICKS_PER_SEC (1000llu * TICKS_PER_MILLISEC) -# define ONE_SEC (1llu * TICKS_PER_SEC) -# define ONE_MILLISEC (1llu * TICKS_PER_MILLISEC) +#define TICKS_PER_MILLISEC 1000llu +#define TICKS_PER_SEC (1000llu * TICKS_PER_MILLISEC) +#define ONE_SEC (1llu * TICKS_PER_SEC) +#define ONE_MILLISEC (1llu * TICKS_PER_MILLISEC) #endif typedef uint64_t HSSTicks_t; -HSSTicks_t HSS_GetTime(void); -HSSTicks_t HSS_GetTickCount(void); -bool HSS_Timer_IsElapsed(HSSTicks_t startTick, HSSTicks_t durationInTicks); -void HSS_SpinDelay_MilliSecs(uint32_t milliseconds); -void HSS_SpinDelay_Secs(uint32_t seconds); +HSSTicks_t +HSS_GetTime(void); +HSSTicks_t +HSS_GetTickCount(void); +bool +HSS_Timer_IsElapsed(HSSTicks_t startTick, HSSTicks_t durationInTicks); +void +HSS_SpinDelay_MilliSecs(uint32_t milliseconds); +void +HSS_SpinDelay_Secs(uint32_t seconds); #ifdef __cplusplus } diff --git a/sm/plat/mpfs/mpfs_reg_map.h b/sm/plat/mpfs/mpfs_reg_map.h index 386d1b7d8..58352af14 100644 --- a/sm/plat/mpfs/mpfs_reg_map.h +++ b/sm/plat/mpfs/mpfs_reg_map.h @@ -29,197 +29,221 @@ * */ - #ifdef __cplusplus extern "C" { #endif -#define E51_DTIM_BASE_ADDR (0x01000000u) +#define E51_DTIM_BASE_ADDR (0x01000000u) -#define E51_ITIM_BASE_ADDR (0x01800000u) +#define E51_ITIM_BASE_ADDR (0x01800000u) -#define U54_1_ITIM_BASE_ADDR (0x01808000u) +#define U54_1_ITIM_BASE_ADDR (0x01808000u) -#define U54_2_ITIM_BASE_ADDR (0x01810000u) +#define U54_2_ITIM_BASE_ADDR (0x01810000u) -#define U54_3_ITIM_BASE_ADDR (0x01818000u) +#define U54_3_ITIM_BASE_ADDR (0x01818000u) -#define U54_4_ITIM_BASE_ADDR (0x01820000u) +#define U54_4_ITIM_BASE_ADDR (0x01820000u) -#define CLINT_BASE_ADDR (0x02000000u) -#define CLINT_MSIP_E51_0_OFFSET (0x0000u) -#define CLINT_MSIP_U54_1_OFFSET (0x0004u) -#define CLINT_MSIP_U54_2_OFFSET (0x0008u) -#define CLINT_MSIP_U54_3_OFFSET (0x000Cu) -#define CLINT_MSIP_U54_4_OFFSET (0x0010u) -#define CLINT_MTIME_OFFSET (0xBFF8u) +#define CLINT_BASE_ADDR (0x02000000u) +#define CLINT_MSIP_E51_0_OFFSET (0x0000u) +#define CLINT_MSIP_U54_1_OFFSET (0x0004u) +#define CLINT_MSIP_U54_2_OFFSET (0x0008u) +#define CLINT_MSIP_U54_3_OFFSET (0x000Cu) +#define CLINT_MSIP_U54_4_OFFSET (0x0010u) +#define CLINT_MTIME_OFFSET (0xBFF8u) -#define L2_CACHE_CTRL_BASE_ADDR (0x02010000u) -#define L2_CACHE_CTRL_CONFIG_OFFSET (0x000u) -#define L2_CACHE_CTRL_WAYENABLE_OFFSET (0x008u) -#define L2_CACHE_CTRL_WAYMASK0_OFFSET (0x800u) -#define L2_CACHE_CTRL_WAYMASK1_OFFSET (0x008u) -#define L2_CACHE_CTRL_WAYMASK2_OFFSET (0x810u) -#define L2_CACHE_CTRL_WAYMASK3_OFFSET (0x818u) -#define L2_CACHE_CTRL_WAYMASK4_OFFSET (0x820u) +#define L2_CACHE_CTRL_BASE_ADDR (0x02010000u) +#define L2_CACHE_CTRL_CONFIG_OFFSET (0x000u) +#define L2_CACHE_CTRL_WAYENABLE_OFFSET (0x008u) +#define L2_CACHE_CTRL_WAYMASK0_OFFSET (0x800u) +#define L2_CACHE_CTRL_WAYMASK1_OFFSET (0x008u) +#define L2_CACHE_CTRL_WAYMASK2_OFFSET (0x810u) +#define L2_CACHE_CTRL_WAYMASK3_OFFSET (0x818u) +#define L2_CACHE_CTRL_WAYMASK4_OFFSET (0x820u) -#define WCB_BASE_ADDR (0x02020000u) +#define WCB_BASE_ADDR (0x02020000u) -#define DMA_CTRL_BASE_ADDR (0x03000000u) +#define DMA_CTRL_BASE_ADDR (0x03000000u) -#define L2_LIM_BASE_ADDR (0x08000000u) +#define L2_LIM_BASE_ADDR (0x08000000u) -#define L2_ZERODEV_BASE_ADDR (0x0A000000u) +#define L2_ZERODEV_BASE_ADDR (0x0A000000u) #ifndef PLIC_BASE_ADDR -# define PLIC_BASE_ADDR (0x0C000000u) +#define PLIC_BASE_ADDR (0x0C000000u) #endif -#define SYSREGSCB_BASE_ADDR (0x20003000u) -#define SYSREGSCB_MSS_STATUS_OFFSET (0x0104u) - -#define MPU_BASE_ADDR (0x2000E000u) -#define MPU_FIC0_OFFSET (0x0000u) -#define MPU_FIC1_OFFSET (0x0100u) -#define MPU_FIC2_OFFSET (0x0200u) -#define MPU_CRYPTO_OFFSET (0x0300u) -#define MPU_ETHERNET0_OFFSET (0x0400u) -#define MPU_ETHERNET1_OFFSET (0x0500u) -#define MPU_USB_OFFSET (0x0600u) -#define MPU_MMC_OFFSET (0x0700u) -#define MPU_SCB_OFFSET (0x0800u) -#define MPU_SEG0_OFFSET (0x0D00u) -#define MPU_SEG1_OFFSET (0x0E00u) - -#define WDOG0_LO_BASE_ADDR (0x20001000u) -#define WDOG1_LO_BASE_ADDR (0x20101000u) -#define WDOG2_LO_BASE_ADDR (0x20103000u) -#define WDOG3_LO_BASE_ADDR (0x20105000u) -#define WDOG4_LO_BASE_ADDR (0x20107000u) - -#define WDOG_REFRESH_OFFSET (0x0000u) -#define WDOG_CONTROL_OFFSET (0x0004u) -#define WDOG_STATUS_OFFSET (0x0008u) -#define WDOG_TIME_OFFSET (0x000Cu) -#define WDOG_MSVP_OFFSET (0x0010u) -#define WDOG_TRIGGER_OFFSET (0x0014u) -#define WDOG_FORCE_OFFSET (0x0018u) - -#define WDOG_STATUS_DEVRST_MASK (1u << 5) -#define WDOG_STATUS_LOCKED_MASK (1u << 4) -#define WDOG_STATUS_TRIGGERED_MASK (1u << 3) -#define WDOG_STATUS_FORBIDDEN_MASK (1u << 2) -#define WDOG_STATUS_WDOG_TRIPPED_MASK (1u << 1) -#define WDOG_STATUS_MVSP_TRIPPED_MASK (1u << 0) +#define SYSREGSCB_BASE_ADDR (0x20003000u) +#define SYSREGSCB_MSS_STATUS_OFFSET (0x0104u) + +#define MPU_BASE_ADDR (0x2000E000u) +#define MPU_FIC0_OFFSET (0x0000u) +#define MPU_FIC1_OFFSET (0x0100u) +#define MPU_FIC2_OFFSET (0x0200u) +#define MPU_CRYPTO_OFFSET (0x0300u) +#define MPU_ETHERNET0_OFFSET (0x0400u) +#define MPU_ETHERNET1_OFFSET (0x0500u) +#define MPU_USB_OFFSET (0x0600u) +#define MPU_MMC_OFFSET (0x0700u) +#define MPU_SCB_OFFSET (0x0800u) +#define MPU_SEG0_OFFSET (0x0D00u) +#define MPU_SEG1_OFFSET (0x0E00u) + +#define WDOG0_LO_BASE_ADDR (0x20001000u) +#define WDOG1_LO_BASE_ADDR (0x20101000u) +#define WDOG2_LO_BASE_ADDR (0x20103000u) +#define WDOG3_LO_BASE_ADDR (0x20105000u) +#define WDOG4_LO_BASE_ADDR (0x20107000u) + +#define WDOG_REFRESH_OFFSET (0x0000u) +#define WDOG_CONTROL_OFFSET (0x0004u) +#define WDOG_STATUS_OFFSET (0x0008u) +#define WDOG_TIME_OFFSET (0x000Cu) +#define WDOG_MSVP_OFFSET (0x0010u) +#define WDOG_TRIGGER_OFFSET (0x0014u) +#define WDOG_FORCE_OFFSET (0x0018u) + +#define WDOG_STATUS_DEVRST_MASK (1u << 5) +#define WDOG_STATUS_LOCKED_MASK (1u << 4) +#define WDOG_STATUS_TRIGGERED_MASK (1u << 3) +#define WDOG_STATUS_FORBIDDEN_MASK (1u << 2) +#define WDOG_STATUS_WDOG_TRIPPED_MASK (1u << 1) +#define WDOG_STATUS_MVSP_TRIPPED_MASK (1u << 0) #define WDOG0_LO_REFRESH_OFFSET WDOG_REFRESH_OFFSET #define WDOG0_LO_CONTROL_OFFSET WDOG_CONTROL_OFFSET -#define WDOG0_LO_STATUS_OFFSET WDOG_STATUS_OFFSET -#define WDOG0_LO_TIME_OFFSET WDOG_TIME_OFFSET -#define WDOG0_LO_MSVP_OFFSET WDOG_MSVP_OFFSET +#define WDOG0_LO_STATUS_OFFSET WDOG_STATUS_OFFSET +#define WDOG0_LO_TIME_OFFSET WDOG_TIME_OFFSET +#define WDOG0_LO_MSVP_OFFSET WDOG_MSVP_OFFSET #define WDOG0_LO_TRIGGER_OFFSET WDOG_TRIGGER_OFFSET -#define WDOG0_LO_FORCE_OFFSET WDOG_FORCE_OFFSET +#define WDOG0_LO_FORCE_OFFSET WDOG_FORCE_OFFSET #define WDOG1_LO_REFRESH_OFFSET WDOG_REFRESH_OFFSET #define WDOG1_LO_CONTROL_OFFSET WDOG_CONTROL_OFFSET -#define WDOG1_LO_STATUS_OFFSET WDOG_STATUS_OFFSET -#define WDOG1_LO_TIME_OFFSET WDOG_TIME_OFFSET -#define WDOG1_LO_MSVP_OFFSET WDOG_MSVP_OFFSET +#define WDOG1_LO_STATUS_OFFSET WDOG_STATUS_OFFSET +#define WDOG1_LO_TIME_OFFSET WDOG_TIME_OFFSET +#define WDOG1_LO_MSVP_OFFSET WDOG_MSVP_OFFSET #define WDOG1_LO_TRIGGER_OFFSET WDOG_TRIGGER_OFFSET -#define WDOG1_LO_FORCE_OFFSET WDOG_FORCE_OFFSET +#define WDOG1_LO_FORCE_OFFSET WDOG_FORCE_OFFSET #define WDOG2_LO_REFRESH_OFFSET WDOG_REFRESH_OFFSET #define WDOG2_LO_CONTROL_OFFSET WDOG_CONTROL_OFFSET -#define WDOG2_LO_STATUS_OFFSET WDOG_STATUS_OFFSET -#define WDOG2_LO_TIME_OFFSET WDOG_TIME_OFFSET -#define WDOG2_LO_MSVP_OFFSET WDOG_MSVP_OFFSET +#define WDOG2_LO_STATUS_OFFSET WDOG_STATUS_OFFSET +#define WDOG2_LO_TIME_OFFSET WDOG_TIME_OFFSET +#define WDOG2_LO_MSVP_OFFSET WDOG_MSVP_OFFSET #define WDOG2_LO_TRIGGER_OFFSET WDOG_TRIGGER_OFFSET -#define WDOG2_LO_FORCE_OFFSET WDOG_FORCE_OFFSET +#define WDOG2_LO_FORCE_OFFSET WDOG_FORCE_OFFSET #define WDOG3_LO_REFRESH_OFFSET WDOG_REFRESH_OFFSET #define WDOG3_LO_CONTROL_OFFSET WDOG_CONTROL_OFFSET -#define WDOG3_LO_STATUS_OFFSET WDOG_STATUS_OFFSET -#define WDOG3_LO_TIME_OFFSET WDOG_TIME_OFFSET -#define WDOG3_LO_MSVP_OFFSET WDOG_MSVP_OFFSET +#define WDOG3_LO_STATUS_OFFSET WDOG_STATUS_OFFSET +#define WDOG3_LO_TIME_OFFSET WDOG_TIME_OFFSET +#define WDOG3_LO_MSVP_OFFSET WDOG_MSVP_OFFSET #define WDOG3_LO_TRIGGER_OFFSET WDOG_TRIGGER_OFFSET -#define WDOG3_LO_FORCE_OFFSET WDOG_FORCE_OFFSET +#define WDOG3_LO_FORCE_OFFSET WDOG_FORCE_OFFSET #define WDOG4_LO_REFRESH_OFFSET WDOG_REFRESH_OFFSET #define WDOG4_LO_CONTROL_OFFSET WDOG_CONTROL_OFFSET -#define WDOG4_LO_STATUS_OFFSET WDOG_STATUS_OFFSET -#define WDOG4_LO_TIME_OFFSET WDOG_TIME_OFFSET -#define WDOG4_LO_MSVP_OFFSET WDOG_MSVP_OFFSET +#define WDOG4_LO_STATUS_OFFSET WDOG_STATUS_OFFSET +#define WDOG4_LO_TIME_OFFSET WDOG_TIME_OFFSET +#define WDOG4_LO_MSVP_OFFSET WDOG_MSVP_OFFSET #define WDOG4_LO_TRIGGER_OFFSET WDOG_TRIGGER_OFFSET -#define WDOG4_LO_FORCE_OFFSET WDOG_FORCE_OFFSET +#define WDOG4_LO_FORCE_OFFSET WDOG_FORCE_OFFSET -#define WDOG0_HI_BASE_ADDR (0x28001000u) -#define WDOG1_HI_BASE_ADDR (0x28101000u) -#define WDOG2_HI_BASE_ADDR (0x28103000u) -#define WDOG3_HI_BASE_ADDR (0x28105000u) -#define WDOG4_HI_BASE_ADDR (0x28107000u) +#define WDOG0_HI_BASE_ADDR (0x28001000u) +#define WDOG1_HI_BASE_ADDR (0x28101000u) +#define WDOG2_HI_BASE_ADDR (0x28103000u) +#define WDOG3_HI_BASE_ADDR (0x28105000u) +#define WDOG4_HI_BASE_ADDR (0x28107000u) #define WDOG0_HI_REFRESH_OFFSET WDOG_REFRESH_OFFSET #define WDOG0_HI_CONTROL_OFFSET WDOG_CONTROL_OFFSET -#define WDOG0_HI_STATUS_OFFSET WDOG_STATUS_OFFSET -#define WDOG0_HI_TIME_OFFSET WDOG_TIME_OFFSET -#define WDOG0_HI_MSVP_OFFSET WDOG_MSVP_OFFSET +#define WDOG0_HI_STATUS_OFFSET WDOG_STATUS_OFFSET +#define WDOG0_HI_TIME_OFFSET WDOG_TIME_OFFSET +#define WDOG0_HI_MSVP_OFFSET WDOG_MSVP_OFFSET #define WDOG0_HI_TRIGGER_OFFSET WDOG_TRIGGER_OFFSET -#define WDOG0_HI_FORCE_OFFSET WDOG_FORCE_OFFSET +#define WDOG0_HI_FORCE_OFFSET WDOG_FORCE_OFFSET #define WDOG1_HI_REFRESH_OFFSET WDOG_REFRESH_OFFSET #define WDOG1_HI_CONTROL_OFFSET WDOG_CONTROL_OFFSET -#define WDOG1_HI_STATUS_OFFSET WDOG_STATUS_OFFSET -#define WDOG1_HI_TIME_OFFSET WDOG_TIME_OFFSET -#define WDOG1_HI_MSVP_OFFSET WDOG_MSVP_OFFSET +#define WDOG1_HI_STATUS_OFFSET WDOG_STATUS_OFFSET +#define WDOG1_HI_TIME_OFFSET WDOG_TIME_OFFSET +#define WDOG1_HI_MSVP_OFFSET WDOG_MSVP_OFFSET #define WDOG1_HI_TRIGGER_OFFSET WDOG_TRIGGER_OFFSET -#define WDOG1_HI_FORCE_OFFSET WDOG_FORCE_OFFSET +#define WDOG1_HI_FORCE_OFFSET WDOG_FORCE_OFFSET #define WDOG2_HI_REFRESH_OFFSET WDOG_REFRESH_OFFSET #define WDOG2_LO_CONTROL_OFFSET WDOG_CONTROL_OFFSET -#define WDOG2_HI_STATUS_OFFSET WDOG_STATUS_OFFSET -#define WDOG2_HI_TIME_OFFSET WDOG_TIME_OFFSET -#define WDOG2_LO_MSVP_OFFSET WDOG_MSVP_OFFSET +#define WDOG2_HI_STATUS_OFFSET WDOG_STATUS_OFFSET +#define WDOG2_HI_TIME_OFFSET WDOG_TIME_OFFSET +#define WDOG2_LO_MSVP_OFFSET WDOG_MSVP_OFFSET #define WDOG2_HI_TRIGGER_OFFSET WDOG_TRIGGER_OFFSET -#define WDOG2_LO_FORCE_OFFSET WDOG_FORCE_OFFSET +#define WDOG2_LO_FORCE_OFFSET WDOG_FORCE_OFFSET #define WDOG3_LO_REFRESH_OFFSET WDOG_REFRESH_OFFSET #define WDOG3_HI_CONTROL_OFFSET WDOG_CONTROL_OFFSET -#define WDOG3_HI_STATUS_OFFSET WDOG_STATUS_OFFSET -#define WDOG3_LO_TIME_OFFSET WDOG_TIME_OFFSET -#define WDOG3_HI_MSVP_OFFSET WDOG_MSVP_OFFSET +#define WDOG3_HI_STATUS_OFFSET WDOG_STATUS_OFFSET +#define WDOG3_LO_TIME_OFFSET WDOG_TIME_OFFSET +#define WDOG3_HI_MSVP_OFFSET WDOG_MSVP_OFFSET #define WDOG3_HI_TRIGGER_OFFSET WDOG_TRIGGER_OFFSET -#define WDOG3_HI_FORCE_OFFSET WDOG_FORCE_OFFSET +#define WDOG3_HI_FORCE_OFFSET WDOG_FORCE_OFFSET #define WDOG4_HI_REFRESH_OFFSET WDOG_REFRESH_OFFSET #define WDOG4_HI_CONTROL_OFFSET WDOG_CONTROL_OFFSET -#define WDOG4_HI_STATUS_OFFSET WDOG_STATUS_OFFSET -#define WDOG4_HI_TIME_OFFSET WDOG_TIME_OFFSET -#define WDOG4_HI_MSVP_OFFSET WDOG_MSVP_OFFSET +#define WDOG4_HI_STATUS_OFFSET WDOG_STATUS_OFFSET +#define WDOG4_HI_TIME_OFFSET WDOG_TIME_OFFSET +#define WDOG4_HI_MSVP_OFFSET WDOG_MSVP_OFFSET #define WDOG4_HI_TRIGGER_OFFSET WDOG_TRIGGER_OFFSET -#define WDOG4_LO_FORCE_OFFSET WDOG_FORCE_OFFSET - -#define mHSS_WriteRegEx(type, block, reg, value) { *(type*)(block##_BASE_ADDR + block##_##reg##_OFFSET) = value; } -#define mHSS_WriteRegU8(block, reg, value) mHSS_WriteRegEx(uint8_t, block, reg, value) -#define mHSS_WriteRegU16(block, reg, value) mHSS_WriteRegEx(uint16_t, block, reg, value) -#define mHSS_WriteRegU32(block, reg, value) mHSS_WriteRegEx(uint32_t, block, reg, value) - -#define mHSS_WriteRegEx(type, block, reg, value) { *(type*)(block##_BASE_ADDR + block##_##reg##_OFFSET) = value; } -#define mHSS_WriteRegU8(block, reg, value) mHSS_WriteRegEx(uint8_t, block, reg, value) -#define mHSS_WriteRegU16(block, reg, value) mHSS_WriteRegEx(uint16_t, block, reg, value) -#define mHSS_WriteRegU32(block, reg, value) mHSS_WriteRegEx(uint32_t, block, reg, value) -#define mHSS_WriteRegU64(block, reg, value) mHSS_WriteRegEx(uint64_t, block, reg, value) - -#define mHSS_ReadRegEx(type, block, reg) (*(volatile type*)(block##_BASE_ADDR + block##_##reg##_OFFSET)) -#define mHSS_ReadRegU8(block, reg) mHSS_ReadRegEx(uint8_t, block, reg) +#define WDOG4_LO_FORCE_OFFSET WDOG_FORCE_OFFSET + +#define mHSS_WriteRegEx(type, block, reg, value) \ + { *(type*)(block##_BASE_ADDR + block##_##reg##_OFFSET) = value; } +#define mHSS_WriteRegU8(block, reg, value) \ + mHSS_WriteRegEx(uint8_t, block, reg, value) +#define mHSS_WriteRegU16(block, reg, value) \ + mHSS_WriteRegEx(uint16_t, block, reg, value) +#define mHSS_WriteRegU32(block, reg, value) \ + mHSS_WriteRegEx(uint32_t, block, reg, value) + +#define mHSS_WriteRegEx(type, block, reg, value) \ + { *(type*)(block##_BASE_ADDR + block##_##reg##_OFFSET) = value; } +#define mHSS_WriteRegU8(block, reg, value) \ + mHSS_WriteRegEx(uint8_t, block, reg, value) +#define mHSS_WriteRegU16(block, reg, value) \ + mHSS_WriteRegEx(uint16_t, block, reg, value) +#define mHSS_WriteRegU32(block, reg, value) \ + mHSS_WriteRegEx(uint32_t, block, reg, value) +#define mHSS_WriteRegU64(block, reg, value) \ + mHSS_WriteRegEx(uint64_t, block, reg, value) + +#define mHSS_ReadRegEx(type, block, reg) \ + (*(volatile type*)(block##_BASE_ADDR + block##_##reg##_OFFSET)) +#define mHSS_ReadRegU8(block, reg) mHSS_ReadRegEx(uint8_t, block, reg) #define mHSS_ReadRegU16(block, reg) mHSS_ReadRegEx(uint16_t, block, reg) #define mHSS_ReadRegU32(block, reg) mHSS_ReadRegEx(uint32_t, block, reg) #define mHSS_ReadRegU64(block, reg) mHSS_ReadRegEx(uint64_t, block, reg) -#define mHSS_ReadModWriteRegEx(type, block, reg, mask, value) mHSS_WriteRegEx(type, block, reg, (mHSS_ReadRegEx(type, block, reg) & mask) | (value & mask)) -#define mHSS_ReadModWriteRegU8(block, reg, mask, value) mHSS_WriteRegEx(uint8_t, block, reg, (mHSS_ReadRegEx(uint8_t, block, reg) & mask) | (value & mask)) -#define mHSS_ReadModWriteRegU16(block, reg, mask, value) mHSS_WriteRegEx(uint16_t, block, reg, (mHSS_ReadRegEx(uint16_t, block, reg) & mask) | (value & mask)) -#define mHSS_ReadModWriteRegU32(block, reg, mask, value) mHSS_WriteRegEx(uint32_t, block, reg, (mHSS_ReadRegEx(uint32_t, block, reg) & mask) | (value & mask)) -#define mHSS_ReadModWriteRegU64(block, reg, mask, value) mHSS_WriteRegEx(uint64_t, block, reg, (mHSS_ReadRegEx(uint64_t, block, reg) & mask) | (value & mask)) +#define mHSS_ReadModWriteRegEx(type, block, reg, mask, value) \ + mHSS_WriteRegEx( \ + type, block, reg, \ + (mHSS_ReadRegEx(type, block, reg) & mask) | (value & mask)) +#define mHSS_ReadModWriteRegU8(block, reg, mask, value) \ + mHSS_WriteRegEx( \ + uint8_t, block, reg, \ + (mHSS_ReadRegEx(uint8_t, block, reg) & mask) | (value & mask)) +#define mHSS_ReadModWriteRegU16(block, reg, mask, value) \ + mHSS_WriteRegEx( \ + uint16_t, block, reg, \ + (mHSS_ReadRegEx(uint16_t, block, reg) & mask) | (value & mask)) +#define mHSS_ReadModWriteRegU32(block, reg, mask, value) \ + mHSS_WriteRegEx( \ + uint32_t, block, reg, \ + (mHSS_ReadRegEx(uint32_t, block, reg) & mask) | (value & mask)) +#define mHSS_ReadModWriteRegU64(block, reg, mask, value) \ + mHSS_WriteRegEx( \ + uint64_t, block, reg, \ + (mHSS_ReadRegEx(uint64_t, block, reg) & mask) | (value & mask)) #ifdef __cplusplus } diff --git a/sm/plat/mpfs/platform.c b/sm/plat/mpfs/platform.c index e03f63c64..c7137a4b9 100644 --- a/sm/plat/mpfs/platform.c +++ b/sm/plat/mpfs/platform.c @@ -31,188 +31,189 @@ * */ -#include - #include +#include +#include #include #include -#include #include -#include +#include #include #include #include #include +#include -#include "uart_helper.h" #include "drivers/mss_uart/mss_uart.h" +#include "uart_helper.h" -#include - -#define MPFS_HART_COUNT 5 -#define MPFS_HART_STACK_SIZE 8192 +#define MPFS_HART_COUNT 5 +#define MPFS_HART_STACK_SIZE 8192 -#define MPFS_CLINT_ADDR 0x2000000 +#define MPFS_CLINT_ADDR 0x2000000 -#define MPFS_PLIC_ADDR 0xc000000 -#define MPFS_PLIC_NUM_SOURCES 0x35 -#define MPFS_PLIC_NUM_PRIORITIES 7 +#define MPFS_PLIC_ADDR 0xc000000 +#define MPFS_PLIC_NUM_SOURCES 0x35 +#define MPFS_PLIC_NUM_PRIORITIES 7 /** * The MPFS SoC has 5 HARTs but HART ID 0 doesn't have S mode. enable only * HARTs 1 to 4. */ static u32 hart_idx2id[MPFS_HART_COUNT - 1] = { - [0] = 1, - [1] = 2, - [2] = 3, - [3] = 4, + [0] = 1, + [1] = 2, + [2] = 3, + [3] = 4, }; extern unsigned long STACK_SIZE_PER_HART; -static int mpfs_early_init(bool cold_boot) -{ - struct sbi_scratch *sbi = sbi_scratch_thishart_ptr(); - - // The SM expects that we'll be able to protect a region of size - // 0x200000. If we don't grow the fw_size, OpenSBI will only mark - // a small region of memory as reserved, and so later stage boot - // will try to access illegal memory. - if (sbi->fw_size > 0x200000) - return -1; - sbi->fw_size = 0x200000; - return 0; +static int +mpfs_early_init(bool cold_boot) { + struct sbi_scratch* sbi = sbi_scratch_thishart_ptr(); + + // The SM expects that we'll be able to protect a region of size + // 0x200000. If we don't grow the fw_size, OpenSBI will only mark + // a small region of memory as reserved, and so later stage boot + // will try to access illegal memory. + if (sbi->fw_size > 0x200000) return -1; + sbi->fw_size = 0x200000; + return 0; } -static int mpfs_final_init(bool cold_boot) -{ - sm_init(cold_boot); +static int +mpfs_final_init(bool cold_boot) { + sm_init(cold_boot); - if (!cold_boot) return 0; + if (!cold_boot) return 0; - void *fdt = sbi_scratch_thishart_arg1_ptr(); - fdt_cpu_fixup(fdt); - fdt_fixups(fdt); - fdt_reserved_memory_nomap_fixup(fdt); + void* fdt = sbi_scratch_thishart_arg1_ptr(); + fdt_cpu_fixup(fdt); + fdt_fixups(fdt); + fdt_reserved_memory_nomap_fixup(fdt); - return 0; + return 0; } static bool console_initialized = false; -static void mpfs_console_putc(char ch) -{ - if (console_initialized) { - u32 hartid = current_hartid(); - uart_putc(hartid, ch); - } +static void +mpfs_console_putc(char ch) { + if (console_initialized) { + u32 hartid = current_hartid(); + uart_putc(hartid, ch); + } } #define NO_BLOCK 0 #define GETC_EOF -1 -static int mpfs_console_getc(void) -{ - int result = GETC_EOF; +static int +mpfs_console_getc(void) { + int result = GETC_EOF; - uint8_t rcvBuf; - if (uart_getchar(&rcvBuf, NO_BLOCK, FALSE)) { - result = rcvBuf; - } + uint8_t rcvBuf; + if (uart_getchar(&rcvBuf, NO_BLOCK, FALSE)) { + result = rcvBuf; + } - return result; + return result; } -static int mpfs_console_init(void) -{ - console_initialized = true; - MSS_UART_init(&g_mss_uart0_lo, MSS_UART_115200_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - // default all UARTs to 115200 for now - // subsequent OS loads can change these if needed... - MSS_UART_init(&g_mss_uart1_lo, MSS_UART_115200_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_init(&g_mss_uart2_lo, MSS_UART_115200_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_init(&g_mss_uart3_lo, MSS_UART_115200_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - - MSS_UART_init(&g_mss_uart4_lo, MSS_UART_115200_BAUD, - MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); - return 0; +static int +mpfs_console_init(void) { + console_initialized = true; + MSS_UART_init( + &g_mss_uart0_lo, MSS_UART_115200_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); + + // default all UARTs to 115200 for now + // subsequent OS loads can change these if needed... + MSS_UART_init( + &g_mss_uart1_lo, MSS_UART_115200_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); + + MSS_UART_init( + &g_mss_uart2_lo, MSS_UART_115200_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); + + MSS_UART_init( + &g_mss_uart3_lo, MSS_UART_115200_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); + + MSS_UART_init( + &g_mss_uart4_lo, MSS_UART_115200_BAUD, + MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT); + return 0; } -static struct plic_data plic = { MPFS_PLIC_ADDR, MPFS_PLIC_NUM_SOURCES }; +static struct plic_data plic = {MPFS_PLIC_ADDR, MPFS_PLIC_NUM_SOURCES}; -static int mpfs_irqchip_init(bool cold_boot) -{ - int rc; - u32 hartid = current_hartid(); +static int +mpfs_irqchip_init(bool cold_boot) { + int rc; + u32 hartid = current_hartid(); - if (cold_boot) { - rc = plic_cold_irqchip_init(&plic); + if (cold_boot) { + rc = plic_cold_irqchip_init(&plic); - if (rc) { - return rc; - } + if (rc) { + return rc; } + } - rc = plic_warm_irqchip_init(&plic, - (hartid) ? (2 * hartid - 1) : 0, (hartid) ? (2 * hartid) : -1); + rc = plic_warm_irqchip_init( + &plic, (hartid) ? (2 * hartid - 1) : 0, (hartid) ? (2 * hartid) : -1); - return rc; + return rc; } static struct clint_data clint = { - .addr = MPFS_CLINT_ADDR, - .first_hartid = 0, - .hart_count = MPFS_HART_COUNT, + .addr = MPFS_CLINT_ADDR, + .first_hartid = 0, + .hart_count = MPFS_HART_COUNT, .has_64bit_mmio = true, }; -static int mpfs_ipi_init(bool cold_boot) -{ - int rc; - - if (cold_boot) { - rc = clint_cold_ipi_init(&clint); +static int +mpfs_ipi_init(bool cold_boot) { + int rc; - if (rc) { - return rc; - } + if (cold_boot) { + rc = clint_cold_ipi_init(&clint); + if (rc) { + return rc; } + } - return clint_warm_ipi_init(); + return clint_warm_ipi_init(); } -static int mpfs_timer_init(bool cold_boot) -{ - int rc; +static int +mpfs_timer_init(bool cold_boot) { + int rc; - if (cold_boot) { - rc = clint_cold_timer_init(&clint, NULL); + if (cold_boot) { + rc = clint_cold_timer_init(&clint, NULL); - if (rc) { - return rc; - } + if (rc) { + return rc; } + } - return clint_warm_timer_init(); + return clint_warm_timer_init(); } -static int mpfs_reset_check(u32 type, u32 reason) -{ - return 0; +static int +mpfs_reset_check(u32 type, u32 reason) { + return 0; } #define MPFS_TLB_RANGE_FLUSH_LIMIT 0u -static u64 mpfs_get_tlbr_flush_limit(void) -{ - return MPFS_TLB_RANGE_FLUSH_LIMIT; +static u64 +mpfs_get_tlbr_flush_limit(void) { + return MPFS_TLB_RANGE_FLUSH_LIMIT; } const struct sbi_platform_operations platform_ops = { @@ -227,29 +228,29 @@ const struct sbi_platform_operations platform_ops = { .irqchip_init = mpfs_irqchip_init, - .ipi_send = clint_ipi_send, + .ipi_send = clint_ipi_send, .ipi_clear = clint_ipi_clear, - .ipi_init = mpfs_ipi_init, + .ipi_init = mpfs_ipi_init, .get_tlbr_flush_limit = mpfs_get_tlbr_flush_limit, - .timer_value = clint_timer_value, + .timer_value = clint_timer_value, .timer_event_start = clint_timer_event_start, - .timer_event_stop = clint_timer_event_stop, - .timer_init = mpfs_timer_init, + .timer_event_stop = clint_timer_event_stop, + .timer_init = mpfs_timer_init, .system_reset_check = mpfs_reset_check, }; const struct sbi_platform platform = { - .opensbi_version = OPENSBI_VERSION, + .opensbi_version = OPENSBI_VERSION, .platform_version = SBI_PLATFORM_VERSION(0x0, 0x01), - .name = "Microchip PolarFire SoC", - //.features = SBI_PLATFORM_DEFAULT_FEATURES & (~SBI_PLATFORM_HAS_PMP), // already have PMPs setup - .features = SBI_PLATFORM_DEFAULT_FEATURES, // already have PMPs setup - .hart_count = (MPFS_HART_COUNT-1), - .hart_stack_size = MPFS_HART_STACK_SIZE, //TODO: revisit - .hart_index2id = hart_idx2id, + .name = "Microchip PolarFire SoC", + //.features = SBI_PLATFORM_DEFAULT_FEATURES & (~SBI_PLATFORM_HAS_PMP), // + //already have PMPs setup + .features = SBI_PLATFORM_DEFAULT_FEATURES, // already have PMPs setup + .hart_count = (MPFS_HART_COUNT - 1), + .hart_stack_size = MPFS_HART_STACK_SIZE, // TODO: revisit + .hart_index2id = hart_idx2id, .platform_ops_addr = (unsigned long)&platform_ops, - .firmware_context = 0 -}; \ No newline at end of file + .firmware_context = 0}; \ No newline at end of file diff --git a/sm/plat/mpfs/uart_helper.c b/sm/plat/mpfs/uart_helper.c index a6a50df7c..b1aa93658 100644 --- a/sm/plat/mpfs/uart_helper.c +++ b/sm/plat/mpfs/uart_helper.c @@ -7,197 +7,200 @@ * This is function is intended to be used from ee_printf(). */ -#include +#include "uart_helper.h" -#include "drivers/mss_uart/mss_uart.h" -#include -#include -#include +#include #include +#include +#include +#include #include #include "config.h" +#include "drivers/mss_uart/mss_uart.h" #include "hss_clock.h" -#include "uart_helper.h" -static inline mss_uart_instance_t *get_uart_instance(int hartid) -{ - mss_uart_instance_t *pUart; +static inline mss_uart_instance_t* +get_uart_instance(int hartid) { + mss_uart_instance_t* pUart; - switch (hartid) { + switch (hartid) { default: - pUart = &g_mss_uart0_lo; - break; + pUart = &g_mss_uart0_lo; + break; case HSS_HART_E51: - pUart = &g_mss_uart0_lo; - break; + pUart = &g_mss_uart0_lo; + break; case HSS_HART_U54_1: - pUart = &g_mss_uart1_lo; - break; + pUart = &g_mss_uart1_lo; + break; case HSS_HART_U54_2: - pUart = &g_mss_uart2_lo; - break; + pUart = &g_mss_uart2_lo; + break; case HSS_HART_U54_3: - pUart = &g_mss_uart3_lo; - break; + pUart = &g_mss_uart3_lo; + break; case HSS_HART_U54_4: - pUart = &g_mss_uart4_lo; - break; - } + pUart = &g_mss_uart4_lo; + break; + } - return pUart; + return pUart; } -int uart_putstring(int hartid, const char *p) -{ - const uint32_t len = (uint32_t)strlen(p); +int +uart_putstring(int hartid, const char* p) { + const uint32_t len = (uint32_t)strlen(p); - mss_uart_instance_t *pUart = get_uart_instance(hartid); - MSS_UART_polled_tx_string(pUart, (const uint8_t *)p); - // TODO: if hartId is zero (i.e., E51), replace this with non-blocking - // queue implementation, with HSS_UART state machine consuming from queues... - return len; + mss_uart_instance_t* pUart = get_uart_instance(hartid); + MSS_UART_polled_tx_string(pUart, (const uint8_t*)p); + // TODO: if hartId is zero (i.e., E51), replace this with non-blocking + // queue implementation, with HSS_UART state machine consuming from queues... + return len; } -void uart_putc(int hartid, const char ch) -{ - uint8_t string[2]; - string[0] = (uint8_t)ch; - string[1] = 0u; +void +uart_putc(int hartid, const char ch) { + uint8_t string[2]; + string[0] = (uint8_t)ch; + string[1] = 0u; - mss_uart_instance_t *pUart = get_uart_instance(hartid); - MSS_UART_polled_tx_string(pUart, (const uint8_t *)string); + mss_uart_instance_t* pUart = get_uart_instance(hartid); + MSS_UART_polled_tx_string(pUart, (const uint8_t*)string); } #define HSS_UART_HELPER_MAX_GETLINE 80 -ssize_t uart_getline(char **pBuffer, size_t *pBufLen) -{ - ssize_t result = 0; - bool finished = false; - static char myBuffer[HSS_UART_HELPER_MAX_GETLINE]; // static to be stack friendly - const size_t bufferLen = ARRAY_SIZE(myBuffer); - - memset(myBuffer, 0, bufferLen); - - uint8_t cBuf[1]; - while (!finished) { - while (0 == MSS_UART_get_rx(&g_mss_uart0_lo, cBuf, 1)); - - switch (cBuf[0]) { - case '\r': - MSS_UART_polled_tx(&g_mss_uart0_lo, cBuf, 1u); - finished = true; - break; - - case '\n': - MSS_UART_polled_tx(&g_mss_uart0_lo, cBuf, 1u); - finished = true; - break; - - case 0x7Fu: // delete - if (result) { - result--; - MSS_UART_polled_tx(&g_mss_uart0_lo, (uint8_t const *)"\033[D \033[D", 7u); - myBuffer[result] = 0; - } - break; - - case 0x08u: // backspace - ^H - if (result) { - result--; - MSS_UART_polled_tx(&g_mss_uart0_lo, (uint8_t const *)" \033[D", 4u); - myBuffer[result] = 0; - } - break; - - case 0x03u: // intr - ^C - result = -1; - myBuffer[0] = 0; - finished = true; - break; - - case 0x1Bu: // ESC - result = -1; - myBuffer[0] = 0; - finished = true; - break; - - case 0x04u: // ^D - if (result == 0) { - result = -1; - myBuffer[0] = 0; - finished = true; - } - break; - - default: - if (result < bufferLen) { - MSS_UART_polled_tx(&g_mss_uart0_lo, cBuf, 1u); - myBuffer[result] = cBuf[0]; - result++; - } - break; +ssize_t +uart_getline(char** pBuffer, size_t* pBufLen) { + ssize_t result = 0; + bool finished = false; + static char + myBuffer[HSS_UART_HELPER_MAX_GETLINE]; // static to be stack friendly + const size_t bufferLen = ARRAY_SIZE(myBuffer); + + memset(myBuffer, 0, bufferLen); + + uint8_t cBuf[1]; + while (!finished) { + while (0 == MSS_UART_get_rx(&g_mss_uart0_lo, cBuf, 1)) + ; + + switch (cBuf[0]) { + case '\r': + MSS_UART_polled_tx(&g_mss_uart0_lo, cBuf, 1u); + finished = true; + break; + + case '\n': + MSS_UART_polled_tx(&g_mss_uart0_lo, cBuf, 1u); + finished = true; + break; + + case 0x7Fu: // delete + if (result) { + result--; + MSS_UART_polled_tx( + &g_mss_uart0_lo, (uint8_t const*)"\033[D \033[D", 7u); + myBuffer[result] = 0; } - } + break; - const char crlf[] = CRLF; - MSS_UART_polled_tx_string(&g_mss_uart0_lo, (const uint8_t *)crlf); + case 0x08u: // backspace - ^H + if (result) { + result--; + MSS_UART_polled_tx(&g_mss_uart0_lo, (uint8_t const*)" \033[D", 4u); + myBuffer[result] = 0; + } + break; - if (result > 0) { - *pBuffer = myBuffer; - *pBufLen = (size_t)result; - } else { - *pBuffer = NULL; - *pBufLen = 0u; - } + case 0x03u: // intr - ^C + result = -1; + myBuffer[0] = 0; + finished = true; + break; - return result; -} + case 0x1Bu: // ESC + result = -1; + myBuffer[0] = 0; + finished = true; + break; -bool uart_getchar(uint8_t *pbuf, int32_t timeout_sec, bool do_sec_tick) -{ - bool result = false; - bool done = false; - uint8_t rx_buff[1]; - HSSTicks_t start_time = 0u; - HSSTicks_t last_sec_time = 0u; - - //if (timeout_sec > 0) { - start_time = last_sec_time = HSS_GetTime(); - //} - - const HSSTicks_t timeout_ticks = timeout_sec * TICKS_PER_SEC; - //(void)MSS_UART_get_rx_status(&g_mss_uart0_lo); // clear sticky status - - while (!done) { - size_t received = MSS_UART_get_rx(&g_mss_uart0_lo, rx_buff, 1u); - if (0u != received) { - done = true; - if (MSS_UART_NO_ERROR == MSS_UART_get_rx_status(&g_mss_uart0_lo)) { - *pbuf = rx_buff[0]; - result = true; - break; - } else { - mHSS_DEBUG_PRINTF(LOG_ERROR, "UART error" CRLF); - } + case 0x04u: // ^D + if (result == 0) { + result = -1; + myBuffer[0] = 0; + finished = true; } + break; - if (do_sec_tick && HSS_Timer_IsElapsed(last_sec_time, TICKS_PER_SEC)) { - const uint8_t dot='.'; - MSS_UART_polled_tx(&g_mss_uart0_lo, &dot, 1); - last_sec_time = HSS_GetTime(); + default: + if (result < bufferLen) { + MSS_UART_polled_tx(&g_mss_uart0_lo, cBuf, 1u); + myBuffer[result] = cBuf[0]; + result++; } + break; + } + } - if (timeout_sec < 0) { - ; // blocking until UART data received, so nothing extra to do here... - } else if (timeout_sec > 0) { - // time limited - done = HSS_Timer_IsElapsed(start_time, timeout_ticks); - } else /* timeout == 0 */ { - // one-shot - break; - } + const char crlf[] = CRLF; + MSS_UART_polled_tx_string(&g_mss_uart0_lo, (const uint8_t*)crlf); + + if (result > 0) { + *pBuffer = myBuffer; + *pBufLen = (size_t)result; + } else { + *pBuffer = NULL; + *pBufLen = 0u; + } + + return result; +} + +bool +uart_getchar(uint8_t* pbuf, int32_t timeout_sec, bool do_sec_tick) { + bool result = false; + bool done = false; + uint8_t rx_buff[1]; + HSSTicks_t start_time = 0u; + HSSTicks_t last_sec_time = 0u; + + // if (timeout_sec > 0) { + start_time = last_sec_time = HSS_GetTime(); + //} + + const HSSTicks_t timeout_ticks = timeout_sec * TICKS_PER_SEC; + //(void)MSS_UART_get_rx_status(&g_mss_uart0_lo); // clear sticky status + + while (!done) { + size_t received = MSS_UART_get_rx(&g_mss_uart0_lo, rx_buff, 1u); + if (0u != received) { + done = true; + if (MSS_UART_NO_ERROR == MSS_UART_get_rx_status(&g_mss_uart0_lo)) { + *pbuf = rx_buff[0]; + result = true; + break; + } else { + mHSS_DEBUG_PRINTF(LOG_ERROR, "UART error" CRLF); + } + } + + if (do_sec_tick && HSS_Timer_IsElapsed(last_sec_time, TICKS_PER_SEC)) { + const uint8_t dot = '.'; + MSS_UART_polled_tx(&g_mss_uart0_lo, &dot, 1); + last_sec_time = HSS_GetTime(); + } + + if (timeout_sec < 0) { + ; // blocking until UART data received, so nothing extra to do here... + } else if (timeout_sec > 0) { + // time limited + done = HSS_Timer_IsElapsed(start_time, timeout_ticks); + } else /* timeout == 0 */ { + // one-shot + break; } + } - return result; + return result; } diff --git a/sm/plat/mpfs/uart_helper.h b/sm/plat/mpfs/uart_helper.h index 5105977a6..039942318 100644 --- a/sm/plat/mpfs/uart_helper.h +++ b/sm/plat/mpfs/uart_helper.h @@ -32,10 +32,14 @@ extern "C" { #endif -int uart_putstring(int hartid, const char *p); -ssize_t uart_getline(char **pBuffer, size_t *pBufLen); -bool uart_getchar(uint8_t *pbuf, int32_t timeout_sec, bool do_sec_tick); -void uart_putc(int hartid, const char ch); +int +uart_putstring(int hartid, const char* p); +ssize_t +uart_getline(char** pBuffer, size_t* pBufLen); +bool +uart_getchar(uint8_t* pbuf, int32_t timeout_sec, bool do_sec_tick); +void +uart_putc(int hartid, const char ch); #ifdef __cplusplus } diff --git a/sm/plat/sifive/fu540/platform.c b/sm/plat/sifive/fu540/platform.c index a5c27ea5e..0f92af03b 100644 --- a/sm/plat/sifive/fu540/platform.c +++ b/sm/plat/sifive/fu540/platform.c @@ -9,8 +9,8 @@ #include #include -#include #include +#include #include #include #include @@ -48,138 +48,131 @@ /* clang-format on */ static struct plic_data plic = { - .addr = FU540_PLIC_ADDR, - .num_src = FU540_PLIC_NUM_SOURCES, + .addr = FU540_PLIC_ADDR, + .num_src = FU540_PLIC_NUM_SOURCES, }; static struct clint_data clint = { - .addr = FU540_CLINT_ADDR, - .first_hartid = 0, - .hart_count = FU540_HART_COUNT, - .has_64bit_mmio = TRUE, + .addr = FU540_CLINT_ADDR, + .first_hartid = 0, + .hart_count = FU540_HART_COUNT, + .has_64bit_mmio = TRUE, }; -static void fu540_modify_dt(void *fdt) -{ - fdt_cpu_fixup(fdt); +static void +fu540_modify_dt(void* fdt) { + fdt_cpu_fixup(fdt); - fdt_fixups(fdt); + fdt_fixups(fdt); - /* - * SiFive Freedom U540 has an erratum that prevents S-mode software - * to access a PMP protected region using 1GB page table mapping, so - * always add the no-map attribute on this platform. - */ - fdt_reserved_memory_nomap_fixup(fdt); + /* + * SiFive Freedom U540 has an erratum that prevents S-mode software + * to access a PMP protected region using 1GB page table mapping, so + * always add the no-map attribute on this platform. + */ + fdt_reserved_memory_nomap_fixup(fdt); } -static int fu540_final_init(bool cold_boot) -{ - void *fdt; +static int +fu540_final_init(bool cold_boot) { + void* fdt; sm_init(cold_boot); - if (!cold_boot) - return 0; + if (!cold_boot) return 0; - fdt = sbi_scratch_thishart_arg1_ptr(); - fu540_modify_dt(fdt); + fdt = sbi_scratch_thishart_arg1_ptr(); + fu540_modify_dt(fdt); - return 0; + return 0; } -static int fu540_console_init(void) -{ - unsigned long peri_in_freq; +static int +fu540_console_init(void) { + unsigned long peri_in_freq; - if (readl((volatile void *)FU540_PRCI_BASE_ADDR + - FU540_PRCI_CLKMUXSTATUSREG) & - FU540_PRCI_CLKMUX_STATUS_TLCLKSEL) { - peri_in_freq = FU540_SYS_CLK; - } else { - peri_in_freq = FU540_SYS_CLK / 2; - } + if (readl((volatile void*)FU540_PRCI_BASE_ADDR + FU540_PRCI_CLKMUXSTATUSREG) & + FU540_PRCI_CLKMUX_STATUS_TLCLKSEL) { + peri_in_freq = FU540_SYS_CLK; + } else { + peri_in_freq = FU540_SYS_CLK / 2; + } - return sifive_uart_init(FU540_UART0_ADDR, peri_in_freq, - FU540_UART_BAUDRATE); + return sifive_uart_init(FU540_UART0_ADDR, peri_in_freq, FU540_UART_BAUDRATE); } -static int fu540_irqchip_init(bool cold_boot) -{ - int rc; - u32 hartid = current_hartid(); +static int +fu540_irqchip_init(bool cold_boot) { + int rc; + u32 hartid = current_hartid(); - if (cold_boot) { - rc = plic_cold_irqchip_init(&plic); - if (rc) - return rc; - } + if (cold_boot) { + rc = plic_cold_irqchip_init(&plic); + if (rc) return rc; + } - return plic_warm_irqchip_init(&plic, (hartid) ? (2 * hartid - 1) : 0, - (hartid) ? (2 * hartid) : -1); + return plic_warm_irqchip_init( + &plic, (hartid) ? (2 * hartid - 1) : 0, (hartid) ? (2 * hartid) : -1); } -static int fu540_ipi_init(bool cold_boot) -{ - int rc; +static int +fu540_ipi_init(bool cold_boot) { + int rc; - if (cold_boot) { - rc = clint_cold_ipi_init(&clint); - if (rc) - return rc; - } + if (cold_boot) { + rc = clint_cold_ipi_init(&clint); + if (rc) return rc; + } - return clint_warm_ipi_init(); + return clint_warm_ipi_init(); } -static u64 fu540_get_tlbr_flush_limit(void) -{ - return FU540_TLB_RANGE_FLUSH_LIMIT; +static u64 +fu540_get_tlbr_flush_limit(void) { + return FU540_TLB_RANGE_FLUSH_LIMIT; } -static int fu540_timer_init(bool cold_boot) -{ - int rc; +static int +fu540_timer_init(bool cold_boot) { + int rc; - if (cold_boot) { - rc = clint_cold_timer_init(&clint, NULL); - if (rc) - return rc; - } + if (cold_boot) { + rc = clint_cold_timer_init(&clint, NULL); + if (rc) return rc; + } - return clint_warm_timer_init(); + return clint_warm_timer_init(); } static u32 fu540_hart_index2id[FU540_HART_COUNT - 1] = { - [0] = 1, - [1] = 2, - [2] = 3, - [3] = 4, + [0] = 1, + [1] = 2, + [2] = 3, + [3] = 4, }; const struct sbi_platform_operations platform_ops = { - .final_init = fu540_final_init, - .console_putc = sifive_uart_putc, - .console_getc = sifive_uart_getc, - .console_init = fu540_console_init, - .irqchip_init = fu540_irqchip_init, - .ipi_send = clint_ipi_send, - .ipi_clear = clint_ipi_clear, - .ipi_init = fu540_ipi_init, - .get_tlbr_flush_limit = fu540_get_tlbr_flush_limit, - .timer_value = clint_timer_value, - .timer_event_stop = clint_timer_event_stop, - .timer_event_start = clint_timer_event_start, - .timer_init = fu540_timer_init, + .final_init = fu540_final_init, + .console_putc = sifive_uart_putc, + .console_getc = sifive_uart_getc, + .console_init = fu540_console_init, + .irqchip_init = fu540_irqchip_init, + .ipi_send = clint_ipi_send, + .ipi_clear = clint_ipi_clear, + .ipi_init = fu540_ipi_init, + .get_tlbr_flush_limit = fu540_get_tlbr_flush_limit, + .timer_value = clint_timer_value, + .timer_event_stop = clint_timer_event_stop, + .timer_event_start = clint_timer_event_start, + .timer_init = fu540_timer_init, }; const struct sbi_platform platform = { - .opensbi_version = OPENSBI_VERSION, - .platform_version = SBI_PLATFORM_VERSION(0x0, 0x01), - .name = "SiFive Freedom U540", - .features = SBI_PLATFORM_DEFAULT_FEATURES, - .hart_count = (FU540_HART_COUNT - 1), - .hart_index2id = fu540_hart_index2id, - .hart_stack_size = SBI_PLATFORM_DEFAULT_HART_STACK_SIZE, - .platform_ops_addr = (unsigned long)&platform_ops -}; + .opensbi_version = OPENSBI_VERSION, + .platform_version = SBI_PLATFORM_VERSION(0x0, 0x01), + .name = "SiFive Freedom U540", + .features = SBI_PLATFORM_DEFAULT_FEATURES, + .hart_count = (FU540_HART_COUNT - 1), + .hart_index2id = fu540_hart_index2id, + .hart_stack_size = SBI_PLATFORM_DEFAULT_HART_STACK_SIZE, + .platform_ops_addr = (unsigned long)&platform_ops}; diff --git a/sm/src/assert.h b/sm/src/assert.h index e9e6a44a5..1eaa5639e 100644 --- a/sm/src/assert.h +++ b/sm/src/assert.h @@ -3,11 +3,12 @@ #include #include -#define sm_assert(cond) { \ - if (!(cond)) { \ - sbi_printf("[SM] assertion_failed\r\n"); \ - sbi_hart_hang(); \ - } \ -} +#define sm_assert(cond) \ + { \ + if (!(cond)) { \ + sbi_printf("[SM] assertion_failed\r\n"); \ + sbi_hart_hang(); \ + } \ + } #endif diff --git a/sm/src/attest.c b/sm/src/attest.c index 7fbca114d..875359076 100644 --- a/sm/src/attest.c +++ b/sm/src/attest.c @@ -2,38 +2,36 @@ // Copyright (c) 2018, The Regents of the University of California (Regents). // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ -#include "enclave.h" +#include + #include "crypto.h" +#include "enclave.h" #include "page.h" -#include typedef uintptr_t pte_t; /* This will walk the entire vaddr space in the enclave, validating linear at-most-once paddr mappings, and then hashing valid pages */ -int validate_and_hash_epm(hash_ctx* hash_ctx, int level, - pte_t* tb, uintptr_t vaddr, int contiguous, - struct enclave* encl, - uintptr_t* runtime_max_seen, - uintptr_t* user_max_seen) -{ +int +validate_and_hash_epm( + hash_ctx* hash_ctx, int level, pte_t* tb, uintptr_t vaddr, int contiguous, + struct enclave* encl, uintptr_t* runtime_max_seen, + uintptr_t* user_max_seen) { pte_t* walk; int i; - //TODO check for failures + // TODO check for failures uintptr_t epm_start, epm_size; uintptr_t utm_start, utm_size; - int idx = get_enclave_region_index(encl->eid, REGION_EPM); + int idx = get_enclave_region_index(encl->eid, REGION_EPM); epm_start = pmp_region_get_addr(encl->regions[idx].pmp_rid); - epm_size = pmp_region_get_size(encl->regions[idx].pmp_rid); - idx = get_enclave_region_index(encl->eid, REGION_UTM); + epm_size = pmp_region_get_size(encl->regions[idx].pmp_rid); + idx = get_enclave_region_index(encl->eid, REGION_UTM); utm_start = pmp_region_get_addr(encl->regions[idx].pmp_rid); - utm_size = pmp_region_get_size(encl->regions[idx].pmp_rid); - - + utm_size = pmp_region_get_size(encl->regions[idx].pmp_rid); /* iterate over PTEs */ - for (walk=tb, i=0; walk < tb + (RISCV_PGSIZE/sizeof(pte_t)); walk += 1,i++) - { + for (walk = tb, i = 0; walk < tb + (RISCV_PGSIZE / sizeof(pte_t)); + walk += 1, i++) { if (*walk == 0) { contiguous = 0; continue; @@ -42,19 +40,18 @@ int validate_and_hash_epm(hash_ctx* hash_ctx, int level, uintptr_t phys_addr = (*walk >> PTE_PPN_SHIFT) << RISCV_PGSHIFT; /* Check for blatently invalid mappings */ - int map_in_epm = (phys_addr >= epm_start && - phys_addr < epm_start + epm_size); - int map_in_utm = (phys_addr >= utm_start && - phys_addr < utm_start + utm_size); + int map_in_epm = + (phys_addr >= epm_start && phys_addr < epm_start + epm_size); + int map_in_utm = + (phys_addr >= utm_start && phys_addr < utm_start + utm_size); /* EPM may map anything, UTM may not map pgtables */ - if(!map_in_epm && (!map_in_utm || level != 1)){ + if (!map_in_epm && (!map_in_utm || level != 1)) { goto fatal_bail; } - /* propagate the highest bit of the VA */ - if ( level == RISCV_PGLEVEL_TOP && i & RISCV_PGTABLE_HIGHEST_BIT ) + if (level == RISCV_PGLEVEL_TOP && i & RISCV_PGTABLE_HIGHEST_BIT) vpn = ((-1UL << RISCV_PGLEVEL_BITS) | (i & RISCV_PGLEVEL_MASK)); else vpn = ((vaddr << RISCV_PGLEVEL_BITS) | (i & RISCV_PGLEVEL_MASK)); @@ -62,17 +59,13 @@ int validate_and_hash_epm(hash_ctx* hash_ctx, int level, uintptr_t va_start = vpn << RISCV_PGSHIFT; /* include the first virtual address of a contiguous range */ - if (level == 1 && !contiguous) - { - + if (level == 1 && !contiguous) { hash_extend(hash_ctx, &va_start, sizeof(uintptr_t)); - //printm("VA hashed: 0x%lx\n", va_start); + // printm("VA hashed: 0x%lx\n", va_start); contiguous = 1; } - if (level == 1) - { - + if (level == 1) { /* * This is where we enforce the at-most-one-mapping property. * To make our lives easier, we also require a 'linear' mapping @@ -86,45 +79,44 @@ int validate_and_hash_epm(hash_ctx* hash_ctx, int level, * * We also validate that all utm vaddrs -> utm paddrs */ - int in_runtime = ((phys_addr >= encl->pa_params.runtime_base) && - (phys_addr < encl->pa_params.user_base)); - int in_user = ((phys_addr >= encl->pa_params.user_base) && - (phys_addr < encl->pa_params.free_base)); + int in_runtime = + ((phys_addr >= encl->pa_params.runtime_base) && + (phys_addr < encl->pa_params.user_base)); + int in_user = + ((phys_addr >= encl->pa_params.user_base) && + (phys_addr < encl->pa_params.free_base)); /* Validate U bit */ - if(in_user && !(*walk & PTE_U)){ + if (in_user && !(*walk & PTE_U)) { goto fatal_bail; } /* If the vaddr is in UTM, the paddr must be in UTM */ - if(va_start >= encl->params.untrusted_ptr && - va_start < (encl->params.untrusted_ptr + encl->params.untrusted_size) && - !map_in_utm){ + if (va_start >= encl->params.untrusted_ptr && + va_start < + (encl->params.untrusted_ptr + encl->params.untrusted_size) && + !map_in_utm) { goto fatal_bail; } /* Do linear mapping validation */ - if(in_runtime){ - if(phys_addr <= *runtime_max_seen){ + if (in_runtime) { + if (phys_addr <= *runtime_max_seen) { goto fatal_bail; - } - else{ + } else { *runtime_max_seen = phys_addr; } - } - else if(in_user){ - if(phys_addr <= *user_max_seen){ + } else if (in_user) { + if (phys_addr <= *user_max_seen) { goto fatal_bail; - } - else{ + } else { *user_max_seen = phys_addr; } - } - else if(map_in_utm){ + } else if (map_in_utm) { // we checked this above, its OK - } - else{ - //printm("BAD GENERIC MAP %x %x %x\n", in_runtime, in_user, map_in_utm); + } else { + // printm("BAD GENERIC MAP %x %x %x\n", in_runtime, in_user, + // map_in_utm); goto fatal_bail; } @@ -133,30 +125,20 @@ int validate_and_hash_epm(hash_ctx* hash_ctx, int level, /* if PTE is leaf, extend hash for the page */ hash_extend_page(hash_ctx, (void*)phys_addr); - - - //printm("PAGE hashed: 0x%lx (pa: 0x%lx)\n", vpn << RISCV_PGSHIFT, phys_addr); - } - else - { + // printm("PAGE hashed: 0x%lx (pa: 0x%lx)\n", vpn << RISCV_PGSHIFT, + // phys_addr); + } else { /* otherwise, recurse on a lower level */ - contiguous = validate_and_hash_epm(hash_ctx, - level - 1, - (pte_t*) phys_addr, - vpn, - contiguous, - encl, - runtime_max_seen, - user_max_seen); - if(contiguous == -1){ - sbi_printf("BAD MAP: %lx->%lx epm %x %lx uer %x %lx\n", - va_start,phys_addr, - //in_runtime, - 0, - encl->pa_params.runtime_base, - 0, - //in_user, - encl->pa_params.user_base); + contiguous = validate_and_hash_epm( + hash_ctx, level - 1, (pte_t*)phys_addr, vpn, contiguous, encl, + runtime_max_seen, user_max_seen); + if (contiguous == -1) { + sbi_printf( + "BAD MAP: %lx->%lx epm %x %lx uer %x %lx\n", va_start, phys_addr, + // in_runtime, + 0, encl->pa_params.runtime_base, 0, + // in_user, + encl->pa_params.user_base); goto fatal_bail; } } @@ -164,12 +146,12 @@ int validate_and_hash_epm(hash_ctx* hash_ctx, int level, return contiguous; - fatal_bail: +fatal_bail: return -1; } -unsigned long validate_and_hash_enclave(struct enclave* enclave){ - +unsigned long +validate_and_hash_enclave(struct enclave* enclave) { hash_ctx hash_ctx; int ptlevel = RISCV_PGLEVEL_TOP; @@ -178,17 +160,16 @@ unsigned long validate_and_hash_enclave(struct enclave* enclave){ // hash the runtime parameters hash_extend(&hash_ctx, &enclave->params, sizeof(struct runtime_va_params_t)); - - uintptr_t runtime_max_seen=0; - uintptr_t user_max_seen=0;; + uintptr_t runtime_max_seen = 0; + uintptr_t user_max_seen = 0; + ; // hash the epm contents including the virtual addresses - int valid = validate_and_hash_epm(&hash_ctx, - ptlevel, - (pte_t*) (enclave->encl_satp << RISCV_PGSHIFT), - 0, 0, enclave, &runtime_max_seen, &user_max_seen); + int valid = validate_and_hash_epm( + &hash_ctx, ptlevel, (pte_t*)(enclave->encl_satp << RISCV_PGSHIFT), 0, 0, + enclave, &runtime_max_seen, &user_max_seen); - if(valid == -1){ + if (valid == -1) { return SBI_ERR_SM_ENCLAVE_ILLEGAL_PTE; } diff --git a/sm/src/cpu.c b/sm/src/cpu.c index 87bb9f3ad..0d2a19272 100644 --- a/sm/src/cpu.c +++ b/sm/src/cpu.c @@ -3,27 +3,30 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include "cpu.h" + #include -static struct cpu_state cpus[MAX_HARTS] = {0,}; +static struct cpu_state cpus[MAX_HARTS] = { + 0, +}; -int cpu_is_enclave_context() -{ +int +cpu_is_enclave_context() { return cpus[csr_read(mhartid)].is_enclave; } -int cpu_get_enclave_id() -{ +int +cpu_get_enclave_id() { return cpus[csr_read(mhartid)].eid; } -void cpu_enter_enclave_context(enclave_id eid) -{ +void +cpu_enter_enclave_context(enclave_id eid) { cpus[csr_read(mhartid)].is_enclave = 1; - cpus[csr_read(mhartid)].eid = eid; + cpus[csr_read(mhartid)].eid = eid; } -void cpu_exit_enclave_context() -{ +void +cpu_exit_enclave_context() { cpus[csr_read(mhartid)].is_enclave = 0; } diff --git a/sm/src/cpu.h b/sm/src/cpu.h index ca3f994d3..93389d4b0 100644 --- a/sm/src/cpu.h +++ b/sm/src/cpu.h @@ -5,21 +5,24 @@ #ifndef __CPU_H__ #define __CPU_H__ -#include "sm.h" #include "enclave.h" +#include "sm.h" #define MAX_HARTS 16 /* hart state for regulating SBI */ -struct cpu_state -{ +struct cpu_state { int is_enclave; enclave_id eid; }; /* external functions */ -int cpu_is_enclave_context(); -int cpu_get_enclave_id(); -void cpu_enter_enclave_context(enclave_id eid); -void cpu_exit_enclave_context(); +int +cpu_is_enclave_context(); +int +cpu_get_enclave_id(); +void +cpu_enter_enclave_context(enclave_id eid); +void +cpu_exit_enclave_context(); #endif diff --git a/sm/src/crypto.c b/sm/src/crypto.c index 00948ce09..ee4cea03b 100644 --- a/sm/src/crypto.c +++ b/sm/src/crypto.c @@ -3,37 +3,40 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include "crypto.h" + #include "page.h" -void hash_init(hash_ctx* hash_ctx) -{ +void +hash_init(hash_ctx* hash_ctx) { sha3_init(hash_ctx, MDSIZE); } -void hash_extend(hash_ctx* hash_ctx, const void* ptr, size_t len) -{ +void +hash_extend(hash_ctx* hash_ctx, const void* ptr, size_t len) { sha3_update(hash_ctx, ptr, len); } -void hash_extend_page(hash_ctx* hash_ctx, const void* ptr) -{ +void +hash_extend_page(hash_ctx* hash_ctx, const void* ptr) { sha3_update(hash_ctx, ptr, RISCV_PGSIZE); } -void hash_finalize(void* md, hash_ctx* hash_ctx) -{ +void +hash_finalize(void* md, hash_ctx* hash_ctx) { sha3_final(md, hash_ctx); } -void sign(void* sign, const void* data, size_t len, const unsigned char* public_key, const unsigned char* private_key) -{ +void +sign( + void* sign, const void* data, size_t len, const unsigned char* public_key, + const unsigned char* private_key) { ed25519_sign(sign, data, len, public_key, private_key); } -int kdf(const unsigned char* salt, size_t salt_len, - const unsigned char* ikm, size_t ikm_len, - const unsigned char* info, size_t info_len, - unsigned char* okm, size_t okm_len) -{ - return hkdf_sha3_512(salt, salt_len, ikm, ikm_len, info, info_len, okm, okm_len); +int +kdf(const unsigned char* salt, size_t salt_len, const unsigned char* ikm, + size_t ikm_len, const unsigned char* info, size_t info_len, + unsigned char* okm, size_t okm_len) { + return hkdf_sha3_512( + salt, salt_len, ikm, ikm_len, info, info_len, okm, okm_len); } diff --git a/sm/src/crypto.h b/sm/src/crypto.h index ddc3ab76b..cdc15aec5 100644 --- a/sm/src/crypto.h +++ b/sm/src/crypto.h @@ -6,15 +6,16 @@ #define __CRYPTO_H__ #include -#include "sha3/sha3.h" + #include "ed25519/ed25519.h" #include "hkdf_sha3_512/hkdf_sha3_512.h" +#include "sha3/sha3.h" typedef sha3_ctx_t hash_ctx; -#define MDSIZE 64 +#define MDSIZE 64 -#define SIGNATURE_SIZE 64 -#define PRIVATE_KEY_SIZE 64 // includes public key +#define SIGNATURE_SIZE 64 +#define PRIVATE_KEY_SIZE 64 // includes public key #define PUBLIC_KEY_SIZE 32 typedef unsigned char byte; @@ -24,14 +25,21 @@ extern byte sm_signature[SIGNATURE_SIZE]; extern byte sm_public_key[PUBLIC_KEY_SIZE]; extern byte sm_private_key[PRIVATE_KEY_SIZE]; -void hash_init(hash_ctx* hash_ctx); -void hash_extend(hash_ctx* hash_ctx, const void* ptr, size_t len); -void hash_extend_page(hash_ctx* hash_ctx, const void* ptr); -void hash_finalize(void* md, hash_ctx* hash_ctx); +void +hash_init(hash_ctx* hash_ctx); +void +hash_extend(hash_ctx* hash_ctx, const void* ptr, size_t len); +void +hash_extend_page(hash_ctx* hash_ctx, const void* ptr); +void +hash_finalize(void* md, hash_ctx* hash_ctx); -void sign(void* sign, const void* data, size_t len, const byte* public_key, const byte* private_key); -int kdf(const unsigned char* salt, size_t salt_len, - const unsigned char* ikm, size_t ikm_len, - const unsigned char* info, size_t info_len, - unsigned char* okm, size_t okm_len); +void +sign( + void* sign, const void* data, size_t len, const byte* public_key, + const byte* private_key); +int +kdf(const unsigned char* salt, size_t salt_len, const unsigned char* ikm, + size_t ikm_len, const unsigned char* info, size_t info_len, + unsigned char* okm, size_t okm_len); #endif /* crypto.h */ diff --git a/sm/src/ed25519/ed25519.h b/sm/src/ed25519/ed25519.h index 437aad033..f65771344 100644 --- a/sm/src/ed25519/ed25519.h +++ b/sm/src/ed25519/ed25519.h @@ -4,32 +4,40 @@ #include #if defined(_WIN32) - #if defined(ED25519_BUILD_DLL) - #define ED25519_DECLSPEC __declspec(dllexport) - #elif defined(ED25519_DLL) - #define ED25519_DECLSPEC __declspec(dllimport) - #else - #define ED25519_DECLSPEC - #endif +#if defined(ED25519_BUILD_DLL) +#define ED25519_DECLSPEC __declspec(dllexport) +#elif defined(ED25519_DLL) +#define ED25519_DECLSPEC __declspec(dllimport) #else - #define ED25519_DECLSPEC +#define ED25519_DECLSPEC +#endif +#else +#define ED25519_DECLSPEC #endif - #ifdef __cplusplus extern "C" { #endif #ifndef ED25519_NO_SEED -int ED25519_DECLSPEC ed25519_create_seed(unsigned char *seed); +int ED25519_DECLSPEC +ed25519_create_seed(unsigned char* seed); #endif -void ED25519_DECLSPEC ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed); -void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key); -//int ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key); -//void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar); -//void ED25519_DECLSPEC ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key); - +void ED25519_DECLSPEC +ed25519_create_keypair( + unsigned char* public_key, unsigned char* private_key, + const unsigned char* seed); +void ED25519_DECLSPEC +ed25519_sign( + unsigned char* signature, const unsigned char* message, size_t message_len, + const unsigned char* public_key, const unsigned char* private_key); +// int ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const +// unsigned char *message, size_t message_len, const unsigned char *public_key); +// void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned +// char *private_key, const unsigned char *scalar); void ED25519_DECLSPEC +// ed25519_key_exchange(unsigned char *shared_secret, const unsigned char +// *public_key, const unsigned char *private_key); #ifdef __cplusplus } diff --git a/sm/src/ed25519/fe.c b/sm/src/ed25519/fe.c index 2105eb7b2..4a61827bd 100644 --- a/sm/src/ed25519/fe.c +++ b/sm/src/ed25519/fe.c @@ -1,71 +1,69 @@ -#include "fixedint.h" #include "fe.h" +#include "fixedint.h" /* helper functions */ -static uint64_t load_3(const unsigned char *in) { - uint64_t result; +static uint64_t +load_3(const unsigned char* in) { + uint64_t result; - result = (uint64_t) in[0]; - result |= ((uint64_t) in[1]) << 8; - result |= ((uint64_t) in[2]) << 16; + result = (uint64_t)in[0]; + result |= ((uint64_t)in[1]) << 8; + result |= ((uint64_t)in[2]) << 16; - return result; + return result; } -static uint64_t load_4(const unsigned char *in) { - uint64_t result; - - result = (uint64_t) in[0]; - result |= ((uint64_t) in[1]) << 8; - result |= ((uint64_t) in[2]) << 16; - result |= ((uint64_t) in[3]) << 24; - - return result; -} +static uint64_t +load_4(const unsigned char* in) { + uint64_t result; + result = (uint64_t)in[0]; + result |= ((uint64_t)in[1]) << 8; + result |= ((uint64_t)in[2]) << 16; + result |= ((uint64_t)in[3]) << 24; + return result; +} /* h = 0 */ -void fe_0(fe h) { - h[0] = 0; - h[1] = 0; - h[2] = 0; - h[3] = 0; - h[4] = 0; - h[5] = 0; - h[6] = 0; - h[7] = 0; - h[8] = 0; - h[9] = 0; +void +fe_0(fe h) { + h[0] = 0; + h[1] = 0; + h[2] = 0; + h[3] = 0; + h[4] = 0; + h[5] = 0; + h[6] = 0; + h[7] = 0; + h[8] = 0; + h[9] = 0; } - - /* h = 1 */ -void fe_1(fe h) { - h[0] = 1; - h[1] = 0; - h[2] = 0; - h[3] = 0; - h[4] = 0; - h[5] = 0; - h[6] = 0; - h[7] = 0; - h[8] = 0; - h[9] = 0; +void +fe_1(fe h) { + h[0] = 1; + h[1] = 0; + h[2] = 0; + h[3] = 0; + h[4] = 0; + h[5] = 0; + h[6] = 0; + h[7] = 0; + h[8] = 0; + h[9] = 0; } - - /* h = f + g Can overlap h with f or g. @@ -78,52 +76,51 @@ void fe_1(fe h) { |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */ -void fe_add(fe h, const fe f, const fe g) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t g0 = g[0]; - int32_t g1 = g[1]; - int32_t g2 = g[2]; - int32_t g3 = g[3]; - int32_t g4 = g[4]; - int32_t g5 = g[5]; - int32_t g6 = g[6]; - int32_t g7 = g[7]; - int32_t g8 = g[8]; - int32_t g9 = g[9]; - int32_t h0 = f0 + g0; - int32_t h1 = f1 + g1; - int32_t h2 = f2 + g2; - int32_t h3 = f3 + g3; - int32_t h4 = f4 + g4; - int32_t h5 = f5 + g5; - int32_t h6 = f6 + g6; - int32_t h7 = f7 + g7; - int32_t h8 = f8 + g8; - int32_t h9 = f9 + g9; - - h[0] = h0; - h[1] = h1; - h[2] = h2; - h[3] = h3; - h[4] = h4; - h[5] = h5; - h[6] = h6; - h[7] = h7; - h[8] = h8; - h[9] = h9; +void +fe_add(fe h, const fe f, const fe g) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t g0 = g[0]; + int32_t g1 = g[1]; + int32_t g2 = g[2]; + int32_t g3 = g[3]; + int32_t g4 = g[4]; + int32_t g5 = g[5]; + int32_t g6 = g[6]; + int32_t g7 = g[7]; + int32_t g8 = g[8]; + int32_t g9 = g[9]; + int32_t h0 = f0 + g0; + int32_t h1 = f1 + g1; + int32_t h2 = f2 + g2; + int32_t h3 = f3 + g3; + int32_t h4 = f4 + g4; + int32_t h5 = f5 + g5; + int32_t h6 = f6 + g6; + int32_t h7 = f7 + g7; + int32_t h8 = f8 + g8; + int32_t h9 = f9 + g9; + + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; } - - /* Replace (f,g) with (g,g) if b == 1; replace (f,g) with (f,g) if b == 0. @@ -131,60 +128,61 @@ void fe_add(fe h, const fe f, const fe g) { Preconditions: b in {0,1}. */ -void fe_cmov(fe f, const fe g, unsigned int b) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t g0 = g[0]; - int32_t g1 = g[1]; - int32_t g2 = g[2]; - int32_t g3 = g[3]; - int32_t g4 = g[4]; - int32_t g5 = g[5]; - int32_t g6 = g[6]; - int32_t g7 = g[7]; - int32_t g8 = g[8]; - int32_t g9 = g[9]; - int32_t x0 = f0 ^ g0; - int32_t x1 = f1 ^ g1; - int32_t x2 = f2 ^ g2; - int32_t x3 = f3 ^ g3; - int32_t x4 = f4 ^ g4; - int32_t x5 = f5 ^ g5; - int32_t x6 = f6 ^ g6; - int32_t x7 = f7 ^ g7; - int32_t x8 = f8 ^ g8; - int32_t x9 = f9 ^ g9; - - b = (unsigned int) (- (int) b); /* silence warning */ - x0 &= b; - x1 &= b; - x2 &= b; - x3 &= b; - x4 &= b; - x5 &= b; - x6 &= b; - x7 &= b; - x8 &= b; - x9 &= b; - - f[0] = f0 ^ x0; - f[1] = f1 ^ x1; - f[2] = f2 ^ x2; - f[3] = f3 ^ x3; - f[4] = f4 ^ x4; - f[5] = f5 ^ x5; - f[6] = f6 ^ x6; - f[7] = f7 ^ x7; - f[8] = f8 ^ x8; - f[9] = f9 ^ x9; +void +fe_cmov(fe f, const fe g, unsigned int b) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t g0 = g[0]; + int32_t g1 = g[1]; + int32_t g2 = g[2]; + int32_t g3 = g[3]; + int32_t g4 = g[4]; + int32_t g5 = g[5]; + int32_t g6 = g[6]; + int32_t g7 = g[7]; + int32_t g8 = g[8]; + int32_t g9 = g[9]; + int32_t x0 = f0 ^ g0; + int32_t x1 = f1 ^ g1; + int32_t x2 = f2 ^ g2; + int32_t x3 = f3 ^ g3; + int32_t x4 = f4 ^ g4; + int32_t x5 = f5 ^ g5; + int32_t x6 = f6 ^ g6; + int32_t x7 = f7 ^ g7; + int32_t x8 = f8 ^ g8; + int32_t x9 = f9 ^ g9; + + b = (unsigned int)(-(int)b); /* silence warning */ + x0 &= b; + x1 &= b; + x2 &= b; + x3 &= b; + x4 &= b; + x5 &= b; + x6 &= b; + x7 &= b; + x8 &= b; + x9 &= b; + + f[0] = f0 ^ x0; + f[1] = f1 ^ x1; + f[2] = f2 ^ x2; + f[3] = f3 ^ x3; + f[4] = f4 ^ x4; + f[5] = f5 ^ x5; + f[6] = f6 ^ x6; + f[7] = f7 ^ x7; + f[8] = f8 ^ x8; + f[9] = f9 ^ x9; } /* @@ -194,261 +192,257 @@ void fe_cmov(fe f, const fe g, unsigned int b) { Preconditions: b in {0,1}. */ -void fe_cswap(fe f,fe g,unsigned int b) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t g0 = g[0]; - int32_t g1 = g[1]; - int32_t g2 = g[2]; - int32_t g3 = g[3]; - int32_t g4 = g[4]; - int32_t g5 = g[5]; - int32_t g6 = g[6]; - int32_t g7 = g[7]; - int32_t g8 = g[8]; - int32_t g9 = g[9]; - int32_t x0 = f0 ^ g0; - int32_t x1 = f1 ^ g1; - int32_t x2 = f2 ^ g2; - int32_t x3 = f3 ^ g3; - int32_t x4 = f4 ^ g4; - int32_t x5 = f5 ^ g5; - int32_t x6 = f6 ^ g6; - int32_t x7 = f7 ^ g7; - int32_t x8 = f8 ^ g8; - int32_t x9 = f9 ^ g9; - b = (unsigned int) (- (int) b); /* silence warning */ - x0 &= b; - x1 &= b; - x2 &= b; - x3 &= b; - x4 &= b; - x5 &= b; - x6 &= b; - x7 &= b; - x8 &= b; - x9 &= b; - f[0] = f0 ^ x0; - f[1] = f1 ^ x1; - f[2] = f2 ^ x2; - f[3] = f3 ^ x3; - f[4] = f4 ^ x4; - f[5] = f5 ^ x5; - f[6] = f6 ^ x6; - f[7] = f7 ^ x7; - f[8] = f8 ^ x8; - f[9] = f9 ^ x9; - g[0] = g0 ^ x0; - g[1] = g1 ^ x1; - g[2] = g2 ^ x2; - g[3] = g3 ^ x3; - g[4] = g4 ^ x4; - g[5] = g5 ^ x5; - g[6] = g6 ^ x6; - g[7] = g7 ^ x7; - g[8] = g8 ^ x8; - g[9] = g9 ^ x9; +void +fe_cswap(fe f, fe g, unsigned int b) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t g0 = g[0]; + int32_t g1 = g[1]; + int32_t g2 = g[2]; + int32_t g3 = g[3]; + int32_t g4 = g[4]; + int32_t g5 = g[5]; + int32_t g6 = g[6]; + int32_t g7 = g[7]; + int32_t g8 = g[8]; + int32_t g9 = g[9]; + int32_t x0 = f0 ^ g0; + int32_t x1 = f1 ^ g1; + int32_t x2 = f2 ^ g2; + int32_t x3 = f3 ^ g3; + int32_t x4 = f4 ^ g4; + int32_t x5 = f5 ^ g5; + int32_t x6 = f6 ^ g6; + int32_t x7 = f7 ^ g7; + int32_t x8 = f8 ^ g8; + int32_t x9 = f9 ^ g9; + b = (unsigned int)(-(int)b); /* silence warning */ + x0 &= b; + x1 &= b; + x2 &= b; + x3 &= b; + x4 &= b; + x5 &= b; + x6 &= b; + x7 &= b; + x8 &= b; + x9 &= b; + f[0] = f0 ^ x0; + f[1] = f1 ^ x1; + f[2] = f2 ^ x2; + f[3] = f3 ^ x3; + f[4] = f4 ^ x4; + f[5] = f5 ^ x5; + f[6] = f6 ^ x6; + f[7] = f7 ^ x7; + f[8] = f8 ^ x8; + f[9] = f9 ^ x9; + g[0] = g0 ^ x0; + g[1] = g1 ^ x1; + g[2] = g2 ^ x2; + g[3] = g3 ^ x3; + g[4] = g4 ^ x4; + g[5] = g5 ^ x5; + g[6] = g6 ^ x6; + g[7] = g7 ^ x7; + g[8] = g8 ^ x8; + g[9] = g9 ^ x9; } - - /* h = f */ -void fe_copy(fe h, const fe f) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - - h[0] = f0; - h[1] = f1; - h[2] = f2; - h[3] = f3; - h[4] = f4; - h[5] = f5; - h[6] = f6; - h[7] = f7; - h[8] = f8; - h[9] = f9; +void +fe_copy(fe h, const fe f) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + + h[0] = f0; + h[1] = f1; + h[2] = f2; + h[3] = f3; + h[4] = f4; + h[5] = f5; + h[6] = f6; + h[7] = f7; + h[8] = f8; + h[9] = f9; } - - /* Ignores top bit of h. */ -void fe_frombytes(fe h, const unsigned char *s) { - int64_t h0 = load_4(s); - int64_t h1 = load_3(s + 4) << 6; - int64_t h2 = load_3(s + 7) << 5; - int64_t h3 = load_3(s + 10) << 3; - int64_t h4 = load_3(s + 13) << 2; - int64_t h5 = load_4(s + 16); - int64_t h6 = load_3(s + 20) << 7; - int64_t h7 = load_3(s + 23) << 5; - int64_t h8 = load_3(s + 26) << 4; - int64_t h9 = (load_3(s + 29) & 8388607) << 2; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - - carry9 = (h9 + (int64_t) (1 << 24)) >> 25; - h0 += carry9 * 19; - h9 -= carry9 << 25; - carry1 = (h1 + (int64_t) (1 << 24)) >> 25; - h2 += carry1; - h1 -= carry1 << 25; - carry3 = (h3 + (int64_t) (1 << 24)) >> 25; - h4 += carry3; - h3 -= carry3 << 25; - carry5 = (h5 + (int64_t) (1 << 24)) >> 25; - h6 += carry5; - h5 -= carry5 << 25; - carry7 = (h7 + (int64_t) (1 << 24)) >> 25; - h8 += carry7; - h7 -= carry7 << 25; - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - carry2 = (h2 + (int64_t) (1 << 25)) >> 26; - h3 += carry2; - h2 -= carry2 << 26; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry6 = (h6 + (int64_t) (1 << 25)) >> 26; - h7 += carry6; - h6 -= carry6 << 26; - carry8 = (h8 + (int64_t) (1 << 25)) >> 26; - h9 += carry8; - h8 -= carry8 << 26; - - h[0] = (int32_t) h0; - h[1] = (int32_t) h1; - h[2] = (int32_t) h2; - h[3] = (int32_t) h3; - h[4] = (int32_t) h4; - h[5] = (int32_t) h5; - h[6] = (int32_t) h6; - h[7] = (int32_t) h7; - h[8] = (int32_t) h8; - h[9] = (int32_t) h9; +void +fe_frombytes(fe h, const unsigned char* s) { + int64_t h0 = load_4(s); + int64_t h1 = load_3(s + 4) << 6; + int64_t h2 = load_3(s + 7) << 5; + int64_t h3 = load_3(s + 10) << 3; + int64_t h4 = load_3(s + 13) << 2; + int64_t h5 = load_4(s + 16); + int64_t h6 = load_3(s + 20) << 7; + int64_t h7 = load_3(s + 23) << 5; + int64_t h8 = load_3(s + 26) << 4; + int64_t h9 = (load_3(s + 29) & 8388607) << 2; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + + carry9 = (h9 + (int64_t)(1 << 24)) >> 25; + h0 += carry9 * 19; + h9 -= carry9 << 25; + carry1 = (h1 + (int64_t)(1 << 24)) >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry3 = (h3 + (int64_t)(1 << 24)) >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry5 = (h5 + (int64_t)(1 << 24)) >> 25; + h6 += carry5; + h5 -= carry5 << 25; + carry7 = (h7 + (int64_t)(1 << 24)) >> 25; + h8 += carry7; + h7 -= carry7 << 25; + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry2 = (h2 + (int64_t)(1 << 25)) >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry6 = (h6 + (int64_t)(1 << 25)) >> 26; + h7 += carry6; + h6 -= carry6 << 26; + carry8 = (h8 + (int64_t)(1 << 25)) >> 26; + h9 += carry8; + h8 -= carry8 << 26; + + h[0] = (int32_t)h0; + h[1] = (int32_t)h1; + h[2] = (int32_t)h2; + h[3] = (int32_t)h3; + h[4] = (int32_t)h4; + h[5] = (int32_t)h5; + h[6] = (int32_t)h6; + h[7] = (int32_t)h7; + h[8] = (int32_t)h8; + h[9] = (int32_t)h9; } +void +fe_invert(fe out, const fe z) { + fe t0; + fe t1; + fe t2; + fe t3; + int i; + fe_sq(t0, z); -void fe_invert(fe out, const fe z) { - fe t0; - fe t1; - fe t2; - fe t3; - int i; - - fe_sq(t0, z); + for (i = 1; i < 1; ++i) { + fe_sq(t0, t0); + } - for (i = 1; i < 1; ++i) { - fe_sq(t0, t0); - } + fe_sq(t1, t0); - fe_sq(t1, t0); + for (i = 1; i < 2; ++i) { + fe_sq(t1, t1); + } - for (i = 1; i < 2; ++i) { - fe_sq(t1, t1); - } + fe_mul(t1, z, t1); + fe_mul(t0, t0, t1); + fe_sq(t2, t0); - fe_mul(t1, z, t1); - fe_mul(t0, t0, t1); - fe_sq(t2, t0); + for (i = 1; i < 1; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 1; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t1, t2); + fe_sq(t2, t1); - fe_mul(t1, t1, t2); - fe_sq(t2, t1); + for (i = 1; i < 5; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 5; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t2, t1); + fe_sq(t2, t1); - fe_mul(t1, t2, t1); - fe_sq(t2, t1); + for (i = 1; i < 10; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 10; ++i) { - fe_sq(t2, t2); - } + fe_mul(t2, t2, t1); + fe_sq(t3, t2); - fe_mul(t2, t2, t1); - fe_sq(t3, t2); + for (i = 1; i < 20; ++i) { + fe_sq(t3, t3); + } - for (i = 1; i < 20; ++i) { - fe_sq(t3, t3); - } + fe_mul(t2, t3, t2); + fe_sq(t2, t2); - fe_mul(t2, t3, t2); + for (i = 1; i < 10; ++i) { fe_sq(t2, t2); + } - for (i = 1; i < 10; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t2, t1); + fe_sq(t2, t1); - fe_mul(t1, t2, t1); - fe_sq(t2, t1); + for (i = 1; i < 50; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 50; ++i) { - fe_sq(t2, t2); - } + fe_mul(t2, t2, t1); + fe_sq(t3, t2); - fe_mul(t2, t2, t1); - fe_sq(t3, t2); + for (i = 1; i < 100; ++i) { + fe_sq(t3, t3); + } - for (i = 1; i < 100; ++i) { - fe_sq(t3, t3); - } + fe_mul(t2, t3, t2); + fe_sq(t2, t2); - fe_mul(t2, t3, t2); + for (i = 1; i < 50; ++i) { fe_sq(t2, t2); + } - for (i = 1; i < 50; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t2, t1); + fe_sq(t1, t1); - fe_mul(t1, t2, t1); + for (i = 1; i < 5; ++i) { fe_sq(t1, t1); + } - for (i = 1; i < 5; ++i) { - fe_sq(t1, t1); - } - - fe_mul(out, t1, t0); + fe_mul(out, t1, t0); } - - /* return 1 if f is in {1,3,5,...,q-2} return 0 if f is in {0,2,4,...,q-1} @@ -457,15 +451,14 @@ void fe_invert(fe out, const fe z) { |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */ -int fe_isnegative(const fe f) { - unsigned char s[32]; - - fe_tobytes(s, f); - - return s[0] & 1; -} +int +fe_isnegative(const fe f) { + unsigned char s[32]; + fe_tobytes(s, f); + return s[0] & 1; +} /* return 1 if f == 0 @@ -475,52 +468,51 @@ int fe_isnegative(const fe f) { |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */ -int fe_isnonzero(const fe f) { - unsigned char s[32]; - unsigned char r; - - fe_tobytes(s, f); - - r = s[0]; - #define F(i) r |= s[i] - F(1); - F(2); - F(3); - F(4); - F(5); - F(6); - F(7); - F(8); - F(9); - F(10); - F(11); - F(12); - F(13); - F(14); - F(15); - F(16); - F(17); - F(18); - F(19); - F(20); - F(21); - F(22); - F(23); - F(24); - F(25); - F(26); - F(27); - F(28); - F(29); - F(30); - F(31); - #undef F - - return r != 0; +int +fe_isnonzero(const fe f) { + unsigned char s[32]; + unsigned char r; + + fe_tobytes(s, f); + + r = s[0]; +#define F(i) r |= s[i] + F(1); + F(2); + F(3); + F(4); + F(5); + F(6); + F(7); + F(8); + F(9); + F(10); + F(11); + F(12); + F(13); + F(14); + F(15); + F(16); + F(17); + F(18); + F(19); + F(20); + F(21); + F(22); + F(23); + F(24); + F(25); + F(26); + F(27); + F(28); + F(29); + F(30); + F(31); +#undef F + + return r != 0; } - - /* h = f * g Can overlap h with f or g. @@ -533,238 +525,248 @@ int fe_isnonzero(const fe f) { |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc. */ - /* - Notes on implementation strategy: +/* +Notes on implementation strategy: - Using schoolbook multiplication. - Karatsuba would save a little in some cost models. +Using schoolbook multiplication. +Karatsuba would save a little in some cost models. - Most multiplications by 2 and 19 are 32-bit precomputations; - cheaper than 64-bit postcomputations. +Most multiplications by 2 and 19 are 32-bit precomputations; +cheaper than 64-bit postcomputations. - There is one remaining multiplication by 19 in the carry chain; - one *19 precomputation can be merged into this, - but the resulting data flow is considerably less clean. +There is one remaining multiplication by 19 in the carry chain; +one *19 precomputation can be merged into this, +but the resulting data flow is considerably less clean. - There are 12 carries below. - 10 of them are 2-way parallelizable and vectorizable. - Can get away with 11 carries, but then data flow is much deeper. +There are 12 carries below. +10 of them are 2-way parallelizable and vectorizable. +Can get away with 11 carries, but then data flow is much deeper. - With tighter constraints on inputs can squeeze carries into int32. +With tighter constraints on inputs can squeeze carries into int32. */ -void fe_mul(fe h, const fe f, const fe g) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t g0 = g[0]; - int32_t g1 = g[1]; - int32_t g2 = g[2]; - int32_t g3 = g[3]; - int32_t g4 = g[4]; - int32_t g5 = g[5]; - int32_t g6 = g[6]; - int32_t g7 = g[7]; - int32_t g8 = g[8]; - int32_t g9 = g[9]; - int32_t g1_19 = 19 * g1; /* 1.959375*2^29 */ - int32_t g2_19 = 19 * g2; /* 1.959375*2^30; still ok */ - int32_t g3_19 = 19 * g3; - int32_t g4_19 = 19 * g4; - int32_t g5_19 = 19 * g5; - int32_t g6_19 = 19 * g6; - int32_t g7_19 = 19 * g7; - int32_t g8_19 = 19 * g8; - int32_t g9_19 = 19 * g9; - int32_t f1_2 = 2 * f1; - int32_t f3_2 = 2 * f3; - int32_t f5_2 = 2 * f5; - int32_t f7_2 = 2 * f7; - int32_t f9_2 = 2 * f9; - int64_t f0g0 = f0 * (int64_t) g0; - int64_t f0g1 = f0 * (int64_t) g1; - int64_t f0g2 = f0 * (int64_t) g2; - int64_t f0g3 = f0 * (int64_t) g3; - int64_t f0g4 = f0 * (int64_t) g4; - int64_t f0g5 = f0 * (int64_t) g5; - int64_t f0g6 = f0 * (int64_t) g6; - int64_t f0g7 = f0 * (int64_t) g7; - int64_t f0g8 = f0 * (int64_t) g8; - int64_t f0g9 = f0 * (int64_t) g9; - int64_t f1g0 = f1 * (int64_t) g0; - int64_t f1g1_2 = f1_2 * (int64_t) g1; - int64_t f1g2 = f1 * (int64_t) g2; - int64_t f1g3_2 = f1_2 * (int64_t) g3; - int64_t f1g4 = f1 * (int64_t) g4; - int64_t f1g5_2 = f1_2 * (int64_t) g5; - int64_t f1g6 = f1 * (int64_t) g6; - int64_t f1g7_2 = f1_2 * (int64_t) g7; - int64_t f1g8 = f1 * (int64_t) g8; - int64_t f1g9_38 = f1_2 * (int64_t) g9_19; - int64_t f2g0 = f2 * (int64_t) g0; - int64_t f2g1 = f2 * (int64_t) g1; - int64_t f2g2 = f2 * (int64_t) g2; - int64_t f2g3 = f2 * (int64_t) g3; - int64_t f2g4 = f2 * (int64_t) g4; - int64_t f2g5 = f2 * (int64_t) g5; - int64_t f2g6 = f2 * (int64_t) g6; - int64_t f2g7 = f2 * (int64_t) g7; - int64_t f2g8_19 = f2 * (int64_t) g8_19; - int64_t f2g9_19 = f2 * (int64_t) g9_19; - int64_t f3g0 = f3 * (int64_t) g0; - int64_t f3g1_2 = f3_2 * (int64_t) g1; - int64_t f3g2 = f3 * (int64_t) g2; - int64_t f3g3_2 = f3_2 * (int64_t) g3; - int64_t f3g4 = f3 * (int64_t) g4; - int64_t f3g5_2 = f3_2 * (int64_t) g5; - int64_t f3g6 = f3 * (int64_t) g6; - int64_t f3g7_38 = f3_2 * (int64_t) g7_19; - int64_t f3g8_19 = f3 * (int64_t) g8_19; - int64_t f3g9_38 = f3_2 * (int64_t) g9_19; - int64_t f4g0 = f4 * (int64_t) g0; - int64_t f4g1 = f4 * (int64_t) g1; - int64_t f4g2 = f4 * (int64_t) g2; - int64_t f4g3 = f4 * (int64_t) g3; - int64_t f4g4 = f4 * (int64_t) g4; - int64_t f4g5 = f4 * (int64_t) g5; - int64_t f4g6_19 = f4 * (int64_t) g6_19; - int64_t f4g7_19 = f4 * (int64_t) g7_19; - int64_t f4g8_19 = f4 * (int64_t) g8_19; - int64_t f4g9_19 = f4 * (int64_t) g9_19; - int64_t f5g0 = f5 * (int64_t) g0; - int64_t f5g1_2 = f5_2 * (int64_t) g1; - int64_t f5g2 = f5 * (int64_t) g2; - int64_t f5g3_2 = f5_2 * (int64_t) g3; - int64_t f5g4 = f5 * (int64_t) g4; - int64_t f5g5_38 = f5_2 * (int64_t) g5_19; - int64_t f5g6_19 = f5 * (int64_t) g6_19; - int64_t f5g7_38 = f5_2 * (int64_t) g7_19; - int64_t f5g8_19 = f5 * (int64_t) g8_19; - int64_t f5g9_38 = f5_2 * (int64_t) g9_19; - int64_t f6g0 = f6 * (int64_t) g0; - int64_t f6g1 = f6 * (int64_t) g1; - int64_t f6g2 = f6 * (int64_t) g2; - int64_t f6g3 = f6 * (int64_t) g3; - int64_t f6g4_19 = f6 * (int64_t) g4_19; - int64_t f6g5_19 = f6 * (int64_t) g5_19; - int64_t f6g6_19 = f6 * (int64_t) g6_19; - int64_t f6g7_19 = f6 * (int64_t) g7_19; - int64_t f6g8_19 = f6 * (int64_t) g8_19; - int64_t f6g9_19 = f6 * (int64_t) g9_19; - int64_t f7g0 = f7 * (int64_t) g0; - int64_t f7g1_2 = f7_2 * (int64_t) g1; - int64_t f7g2 = f7 * (int64_t) g2; - int64_t f7g3_38 = f7_2 * (int64_t) g3_19; - int64_t f7g4_19 = f7 * (int64_t) g4_19; - int64_t f7g5_38 = f7_2 * (int64_t) g5_19; - int64_t f7g6_19 = f7 * (int64_t) g6_19; - int64_t f7g7_38 = f7_2 * (int64_t) g7_19; - int64_t f7g8_19 = f7 * (int64_t) g8_19; - int64_t f7g9_38 = f7_2 * (int64_t) g9_19; - int64_t f8g0 = f8 * (int64_t) g0; - int64_t f8g1 = f8 * (int64_t) g1; - int64_t f8g2_19 = f8 * (int64_t) g2_19; - int64_t f8g3_19 = f8 * (int64_t) g3_19; - int64_t f8g4_19 = f8 * (int64_t) g4_19; - int64_t f8g5_19 = f8 * (int64_t) g5_19; - int64_t f8g6_19 = f8 * (int64_t) g6_19; - int64_t f8g7_19 = f8 * (int64_t) g7_19; - int64_t f8g8_19 = f8 * (int64_t) g8_19; - int64_t f8g9_19 = f8 * (int64_t) g9_19; - int64_t f9g0 = f9 * (int64_t) g0; - int64_t f9g1_38 = f9_2 * (int64_t) g1_19; - int64_t f9g2_19 = f9 * (int64_t) g2_19; - int64_t f9g3_38 = f9_2 * (int64_t) g3_19; - int64_t f9g4_19 = f9 * (int64_t) g4_19; - int64_t f9g5_38 = f9_2 * (int64_t) g5_19; - int64_t f9g6_19 = f9 * (int64_t) g6_19; - int64_t f9g7_38 = f9_2 * (int64_t) g7_19; - int64_t f9g8_19 = f9 * (int64_t) g8_19; - int64_t f9g9_38 = f9_2 * (int64_t) g9_19; - int64_t h0 = f0g0 + f1g9_38 + f2g8_19 + f3g7_38 + f4g6_19 + f5g5_38 + f6g4_19 + f7g3_38 + f8g2_19 + f9g1_38; - int64_t h1 = f0g1 + f1g0 + f2g9_19 + f3g8_19 + f4g7_19 + f5g6_19 + f6g5_19 + f7g4_19 + f8g3_19 + f9g2_19; - int64_t h2 = f0g2 + f1g1_2 + f2g0 + f3g9_38 + f4g8_19 + f5g7_38 + f6g6_19 + f7g5_38 + f8g4_19 + f9g3_38; - int64_t h3 = f0g3 + f1g2 + f2g1 + f3g0 + f4g9_19 + f5g8_19 + f6g7_19 + f7g6_19 + f8g5_19 + f9g4_19; - int64_t h4 = f0g4 + f1g3_2 + f2g2 + f3g1_2 + f4g0 + f5g9_38 + f6g8_19 + f7g7_38 + f8g6_19 + f9g5_38; - int64_t h5 = f0g5 + f1g4 + f2g3 + f3g2 + f4g1 + f5g0 + f6g9_19 + f7g8_19 + f8g7_19 + f9g6_19; - int64_t h6 = f0g6 + f1g5_2 + f2g4 + f3g3_2 + f4g2 + f5g1_2 + f6g0 + f7g9_38 + f8g8_19 + f9g7_38; - int64_t h7 = f0g7 + f1g6 + f2g5 + f3g4 + f4g3 + f5g2 + f6g1 + f7g0 + f8g9_19 + f9g8_19; - int64_t h8 = f0g8 + f1g7_2 + f2g6 + f3g5_2 + f4g4 + f5g3_2 + f6g2 + f7g1_2 + f8g0 + f9g9_38; - int64_t h9 = f0g9 + f1g8 + f2g7 + f3g6 + f4g5 + f5g4 + f6g3 + f7g2 + f8g1 + f9g0 ; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - - carry1 = (h1 + (int64_t) (1 << 24)) >> 25; - h2 += carry1; - h1 -= carry1 << 25; - carry5 = (h5 + (int64_t) (1 << 24)) >> 25; - h6 += carry5; - h5 -= carry5 << 25; - - carry2 = (h2 + (int64_t) (1 << 25)) >> 26; - h3 += carry2; - h2 -= carry2 << 26; - carry6 = (h6 + (int64_t) (1 << 25)) >> 26; - h7 += carry6; - h6 -= carry6 << 26; - - carry3 = (h3 + (int64_t) (1 << 24)) >> 25; - h4 += carry3; - h3 -= carry3 << 25; - carry7 = (h7 + (int64_t) (1 << 24)) >> 25; - h8 += carry7; - h7 -= carry7 << 25; - - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry8 = (h8 + (int64_t) (1 << 25)) >> 26; - h9 += carry8; - h8 -= carry8 << 26; - - carry9 = (h9 + (int64_t) (1 << 24)) >> 25; - h0 += carry9 * 19; - h9 -= carry9 << 25; - - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - - h[0] = (int32_t) h0; - h[1] = (int32_t) h1; - h[2] = (int32_t) h2; - h[3] = (int32_t) h3; - h[4] = (int32_t) h4; - h[5] = (int32_t) h5; - h[6] = (int32_t) h6; - h[7] = (int32_t) h7; - h[8] = (int32_t) h8; - h[9] = (int32_t) h9; +void +fe_mul(fe h, const fe f, const fe g) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t g0 = g[0]; + int32_t g1 = g[1]; + int32_t g2 = g[2]; + int32_t g3 = g[3]; + int32_t g4 = g[4]; + int32_t g5 = g[5]; + int32_t g6 = g[6]; + int32_t g7 = g[7]; + int32_t g8 = g[8]; + int32_t g9 = g[9]; + int32_t g1_19 = 19 * g1; /* 1.959375*2^29 */ + int32_t g2_19 = 19 * g2; /* 1.959375*2^30; still ok */ + int32_t g3_19 = 19 * g3; + int32_t g4_19 = 19 * g4; + int32_t g5_19 = 19 * g5; + int32_t g6_19 = 19 * g6; + int32_t g7_19 = 19 * g7; + int32_t g8_19 = 19 * g8; + int32_t g9_19 = 19 * g9; + int32_t f1_2 = 2 * f1; + int32_t f3_2 = 2 * f3; + int32_t f5_2 = 2 * f5; + int32_t f7_2 = 2 * f7; + int32_t f9_2 = 2 * f9; + int64_t f0g0 = f0 * (int64_t)g0; + int64_t f0g1 = f0 * (int64_t)g1; + int64_t f0g2 = f0 * (int64_t)g2; + int64_t f0g3 = f0 * (int64_t)g3; + int64_t f0g4 = f0 * (int64_t)g4; + int64_t f0g5 = f0 * (int64_t)g5; + int64_t f0g6 = f0 * (int64_t)g6; + int64_t f0g7 = f0 * (int64_t)g7; + int64_t f0g8 = f0 * (int64_t)g8; + int64_t f0g9 = f0 * (int64_t)g9; + int64_t f1g0 = f1 * (int64_t)g0; + int64_t f1g1_2 = f1_2 * (int64_t)g1; + int64_t f1g2 = f1 * (int64_t)g2; + int64_t f1g3_2 = f1_2 * (int64_t)g3; + int64_t f1g4 = f1 * (int64_t)g4; + int64_t f1g5_2 = f1_2 * (int64_t)g5; + int64_t f1g6 = f1 * (int64_t)g6; + int64_t f1g7_2 = f1_2 * (int64_t)g7; + int64_t f1g8 = f1 * (int64_t)g8; + int64_t f1g9_38 = f1_2 * (int64_t)g9_19; + int64_t f2g0 = f2 * (int64_t)g0; + int64_t f2g1 = f2 * (int64_t)g1; + int64_t f2g2 = f2 * (int64_t)g2; + int64_t f2g3 = f2 * (int64_t)g3; + int64_t f2g4 = f2 * (int64_t)g4; + int64_t f2g5 = f2 * (int64_t)g5; + int64_t f2g6 = f2 * (int64_t)g6; + int64_t f2g7 = f2 * (int64_t)g7; + int64_t f2g8_19 = f2 * (int64_t)g8_19; + int64_t f2g9_19 = f2 * (int64_t)g9_19; + int64_t f3g0 = f3 * (int64_t)g0; + int64_t f3g1_2 = f3_2 * (int64_t)g1; + int64_t f3g2 = f3 * (int64_t)g2; + int64_t f3g3_2 = f3_2 * (int64_t)g3; + int64_t f3g4 = f3 * (int64_t)g4; + int64_t f3g5_2 = f3_2 * (int64_t)g5; + int64_t f3g6 = f3 * (int64_t)g6; + int64_t f3g7_38 = f3_2 * (int64_t)g7_19; + int64_t f3g8_19 = f3 * (int64_t)g8_19; + int64_t f3g9_38 = f3_2 * (int64_t)g9_19; + int64_t f4g0 = f4 * (int64_t)g0; + int64_t f4g1 = f4 * (int64_t)g1; + int64_t f4g2 = f4 * (int64_t)g2; + int64_t f4g3 = f4 * (int64_t)g3; + int64_t f4g4 = f4 * (int64_t)g4; + int64_t f4g5 = f4 * (int64_t)g5; + int64_t f4g6_19 = f4 * (int64_t)g6_19; + int64_t f4g7_19 = f4 * (int64_t)g7_19; + int64_t f4g8_19 = f4 * (int64_t)g8_19; + int64_t f4g9_19 = f4 * (int64_t)g9_19; + int64_t f5g0 = f5 * (int64_t)g0; + int64_t f5g1_2 = f5_2 * (int64_t)g1; + int64_t f5g2 = f5 * (int64_t)g2; + int64_t f5g3_2 = f5_2 * (int64_t)g3; + int64_t f5g4 = f5 * (int64_t)g4; + int64_t f5g5_38 = f5_2 * (int64_t)g5_19; + int64_t f5g6_19 = f5 * (int64_t)g6_19; + int64_t f5g7_38 = f5_2 * (int64_t)g7_19; + int64_t f5g8_19 = f5 * (int64_t)g8_19; + int64_t f5g9_38 = f5_2 * (int64_t)g9_19; + int64_t f6g0 = f6 * (int64_t)g0; + int64_t f6g1 = f6 * (int64_t)g1; + int64_t f6g2 = f6 * (int64_t)g2; + int64_t f6g3 = f6 * (int64_t)g3; + int64_t f6g4_19 = f6 * (int64_t)g4_19; + int64_t f6g5_19 = f6 * (int64_t)g5_19; + int64_t f6g6_19 = f6 * (int64_t)g6_19; + int64_t f6g7_19 = f6 * (int64_t)g7_19; + int64_t f6g8_19 = f6 * (int64_t)g8_19; + int64_t f6g9_19 = f6 * (int64_t)g9_19; + int64_t f7g0 = f7 * (int64_t)g0; + int64_t f7g1_2 = f7_2 * (int64_t)g1; + int64_t f7g2 = f7 * (int64_t)g2; + int64_t f7g3_38 = f7_2 * (int64_t)g3_19; + int64_t f7g4_19 = f7 * (int64_t)g4_19; + int64_t f7g5_38 = f7_2 * (int64_t)g5_19; + int64_t f7g6_19 = f7 * (int64_t)g6_19; + int64_t f7g7_38 = f7_2 * (int64_t)g7_19; + int64_t f7g8_19 = f7 * (int64_t)g8_19; + int64_t f7g9_38 = f7_2 * (int64_t)g9_19; + int64_t f8g0 = f8 * (int64_t)g0; + int64_t f8g1 = f8 * (int64_t)g1; + int64_t f8g2_19 = f8 * (int64_t)g2_19; + int64_t f8g3_19 = f8 * (int64_t)g3_19; + int64_t f8g4_19 = f8 * (int64_t)g4_19; + int64_t f8g5_19 = f8 * (int64_t)g5_19; + int64_t f8g6_19 = f8 * (int64_t)g6_19; + int64_t f8g7_19 = f8 * (int64_t)g7_19; + int64_t f8g8_19 = f8 * (int64_t)g8_19; + int64_t f8g9_19 = f8 * (int64_t)g9_19; + int64_t f9g0 = f9 * (int64_t)g0; + int64_t f9g1_38 = f9_2 * (int64_t)g1_19; + int64_t f9g2_19 = f9 * (int64_t)g2_19; + int64_t f9g3_38 = f9_2 * (int64_t)g3_19; + int64_t f9g4_19 = f9 * (int64_t)g4_19; + int64_t f9g5_38 = f9_2 * (int64_t)g5_19; + int64_t f9g6_19 = f9 * (int64_t)g6_19; + int64_t f9g7_38 = f9_2 * (int64_t)g7_19; + int64_t f9g8_19 = f9 * (int64_t)g8_19; + int64_t f9g9_38 = f9_2 * (int64_t)g9_19; + int64_t h0 = f0g0 + f1g9_38 + f2g8_19 + f3g7_38 + f4g6_19 + f5g5_38 + + f6g4_19 + f7g3_38 + f8g2_19 + f9g1_38; + int64_t h1 = f0g1 + f1g0 + f2g9_19 + f3g8_19 + f4g7_19 + f5g6_19 + f6g5_19 + + f7g4_19 + f8g3_19 + f9g2_19; + int64_t h2 = f0g2 + f1g1_2 + f2g0 + f3g9_38 + f4g8_19 + f5g7_38 + f6g6_19 + + f7g5_38 + f8g4_19 + f9g3_38; + int64_t h3 = f0g3 + f1g2 + f2g1 + f3g0 + f4g9_19 + f5g8_19 + f6g7_19 + + f7g6_19 + f8g5_19 + f9g4_19; + int64_t h4 = f0g4 + f1g3_2 + f2g2 + f3g1_2 + f4g0 + f5g9_38 + f6g8_19 + + f7g7_38 + f8g6_19 + f9g5_38; + int64_t h5 = f0g5 + f1g4 + f2g3 + f3g2 + f4g1 + f5g0 + f6g9_19 + f7g8_19 + + f8g7_19 + f9g6_19; + int64_t h6 = f0g6 + f1g5_2 + f2g4 + f3g3_2 + f4g2 + f5g1_2 + f6g0 + f7g9_38 + + f8g8_19 + f9g7_38; + int64_t h7 = + f0g7 + f1g6 + f2g5 + f3g4 + f4g3 + f5g2 + f6g1 + f7g0 + f8g9_19 + f9g8_19; + int64_t h8 = f0g8 + f1g7_2 + f2g6 + f3g5_2 + f4g4 + f5g3_2 + f6g2 + f7g1_2 + + f8g0 + f9g9_38; + int64_t h9 = + f0g9 + f1g8 + f2g7 + f3g6 + f4g5 + f5g4 + f6g3 + f7g2 + f8g1 + f9g0; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + + carry1 = (h1 + (int64_t)(1 << 24)) >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry5 = (h5 + (int64_t)(1 << 24)) >> 25; + h6 += carry5; + h5 -= carry5 << 25; + + carry2 = (h2 + (int64_t)(1 << 25)) >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry6 = (h6 + (int64_t)(1 << 25)) >> 26; + h7 += carry6; + h6 -= carry6 << 26; + + carry3 = (h3 + (int64_t)(1 << 24)) >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry7 = (h7 + (int64_t)(1 << 24)) >> 25; + h8 += carry7; + h7 -= carry7 << 25; + + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry8 = (h8 + (int64_t)(1 << 25)) >> 26; + h9 += carry8; + h8 -= carry8 << 26; + + carry9 = (h9 + (int64_t)(1 << 24)) >> 25; + h0 += carry9 * 19; + h9 -= carry9 << 25; + + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + + h[0] = (int32_t)h0; + h[1] = (int32_t)h1; + h[2] = (int32_t)h2; + h[3] = (int32_t)h3; + h[4] = (int32_t)h4; + h[5] = (int32_t)h5; + h[6] = (int32_t)h6; + h[7] = (int32_t)h7; + h[8] = (int32_t)h8; + h[9] = (int32_t)h9; } - /* h = f * 121666 Can overlap h with f. @@ -776,63 +778,83 @@ Can overlap h with f. |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. */ -void fe_mul121666(fe h, fe f) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int64_t h0 = f0 * (int64_t) 121666; - int64_t h1 = f1 * (int64_t) 121666; - int64_t h2 = f2 * (int64_t) 121666; - int64_t h3 = f3 * (int64_t) 121666; - int64_t h4 = f4 * (int64_t) 121666; - int64_t h5 = f5 * (int64_t) 121666; - int64_t h6 = f6 * (int64_t) 121666; - int64_t h7 = f7 * (int64_t) 121666; - int64_t h8 = f8 * (int64_t) 121666; - int64_t h9 = f9 * (int64_t) 121666; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - - carry9 = (h9 + (int64_t) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; - carry1 = (h1 + (int64_t) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25; - carry3 = (h3 + (int64_t) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25; - carry5 = (h5 + (int64_t) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25; - carry7 = (h7 + (int64_t) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25; - - carry0 = (h0 + (int64_t) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; - carry2 = (h2 + (int64_t) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26; - carry4 = (h4 + (int64_t) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; - carry6 = (h6 + (int64_t) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26; - carry8 = (h8 + (int64_t) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26; - - h[0] = (int32_t) h0; - h[1] = (int32_t) h1; - h[2] = (int32_t) h2; - h[3] = (int32_t) h3; - h[4] = (int32_t) h4; - h[5] = (int32_t) h5; - h[6] = (int32_t) h6; - h[7] = (int32_t) h7; - h[8] = (int32_t) h8; - h[9] = (int32_t) h9; +void +fe_mul121666(fe h, fe f) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int64_t h0 = f0 * (int64_t)121666; + int64_t h1 = f1 * (int64_t)121666; + int64_t h2 = f2 * (int64_t)121666; + int64_t h3 = f3 * (int64_t)121666; + int64_t h4 = f4 * (int64_t)121666; + int64_t h5 = f5 * (int64_t)121666; + int64_t h6 = f6 * (int64_t)121666; + int64_t h7 = f7 * (int64_t)121666; + int64_t h8 = f8 * (int64_t)121666; + int64_t h9 = f9 * (int64_t)121666; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + + carry9 = (h9 + (int64_t)(1 << 24)) >> 25; + h0 += carry9 * 19; + h9 -= carry9 << 25; + carry1 = (h1 + (int64_t)(1 << 24)) >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry3 = (h3 + (int64_t)(1 << 24)) >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry5 = (h5 + (int64_t)(1 << 24)) >> 25; + h6 += carry5; + h5 -= carry5 << 25; + carry7 = (h7 + (int64_t)(1 << 24)) >> 25; + h8 += carry7; + h7 -= carry7 << 25; + + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry2 = (h2 + (int64_t)(1 << 25)) >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry6 = (h6 + (int64_t)(1 << 25)) >> 26; + h7 += carry6; + h6 -= carry6 << 26; + carry8 = (h8 + (int64_t)(1 << 25)) >> 26; + h9 += carry8; + h8 -= carry8 << 26; + + h[0] = (int32_t)h0; + h[1] = (int32_t)h1; + h[2] = (int32_t)h2; + h[3] = (int32_t)h3; + h[4] = (int32_t)h4; + h[5] = (int32_t)h5; + h[6] = (int32_t)h6; + h[7] = (int32_t)h7; + h[8] = (int32_t)h8; + h[9] = (int32_t)h9; } - /* h = -f @@ -843,127 +865,127 @@ h = -f |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. */ -void fe_neg(fe h, const fe f) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t h0 = -f0; - int32_t h1 = -f1; - int32_t h2 = -f2; - int32_t h3 = -f3; - int32_t h4 = -f4; - int32_t h5 = -f5; - int32_t h6 = -f6; - int32_t h7 = -f7; - int32_t h8 = -f8; - int32_t h9 = -f9; - - h[0] = h0; - h[1] = h1; - h[2] = h2; - h[3] = h3; - h[4] = h4; - h[5] = h5; - h[6] = h6; - h[7] = h7; - h[8] = h8; - h[9] = h9; +void +fe_neg(fe h, const fe f) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t h0 = -f0; + int32_t h1 = -f1; + int32_t h2 = -f2; + int32_t h3 = -f3; + int32_t h4 = -f4; + int32_t h5 = -f5; + int32_t h6 = -f6; + int32_t h7 = -f7; + int32_t h8 = -f8; + int32_t h9 = -f9; + + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; } +void +fe_pow22523(fe out, const fe z) { + fe t0; + fe t1; + fe t2; + int i; + fe_sq(t0, z); -void fe_pow22523(fe out, const fe z) { - fe t0; - fe t1; - fe t2; - int i; - fe_sq(t0, z); + for (i = 1; i < 1; ++i) { + fe_sq(t0, t0); + } - for (i = 1; i < 1; ++i) { - fe_sq(t0, t0); - } + fe_sq(t1, t0); - fe_sq(t1, t0); + for (i = 1; i < 2; ++i) { + fe_sq(t1, t1); + } - for (i = 1; i < 2; ++i) { - fe_sq(t1, t1); - } + fe_mul(t1, z, t1); + fe_mul(t0, t0, t1); + fe_sq(t0, t0); - fe_mul(t1, z, t1); - fe_mul(t0, t0, t1); + for (i = 1; i < 1; ++i) { fe_sq(t0, t0); + } - for (i = 1; i < 1; ++i) { - fe_sq(t0, t0); - } + fe_mul(t0, t1, t0); + fe_sq(t1, t0); - fe_mul(t0, t1, t0); - fe_sq(t1, t0); + for (i = 1; i < 5; ++i) { + fe_sq(t1, t1); + } - for (i = 1; i < 5; ++i) { - fe_sq(t1, t1); - } + fe_mul(t0, t1, t0); + fe_sq(t1, t0); - fe_mul(t0, t1, t0); - fe_sq(t1, t0); + for (i = 1; i < 10; ++i) { + fe_sq(t1, t1); + } - for (i = 1; i < 10; ++i) { - fe_sq(t1, t1); - } + fe_mul(t1, t1, t0); + fe_sq(t2, t1); - fe_mul(t1, t1, t0); - fe_sq(t2, t1); + for (i = 1; i < 20; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 20; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t2, t1); + fe_sq(t1, t1); - fe_mul(t1, t2, t1); + for (i = 1; i < 10; ++i) { fe_sq(t1, t1); + } - for (i = 1; i < 10; ++i) { - fe_sq(t1, t1); - } + fe_mul(t0, t1, t0); + fe_sq(t1, t0); - fe_mul(t0, t1, t0); - fe_sq(t1, t0); + for (i = 1; i < 50; ++i) { + fe_sq(t1, t1); + } - for (i = 1; i < 50; ++i) { - fe_sq(t1, t1); - } + fe_mul(t1, t1, t0); + fe_sq(t2, t1); - fe_mul(t1, t1, t0); - fe_sq(t2, t1); + for (i = 1; i < 100; ++i) { + fe_sq(t2, t2); + } - for (i = 1; i < 100; ++i) { - fe_sq(t2, t2); - } + fe_mul(t1, t2, t1); + fe_sq(t1, t1); - fe_mul(t1, t2, t1); + for (i = 1; i < 50; ++i) { fe_sq(t1, t1); + } - for (i = 1; i < 50; ++i) { - fe_sq(t1, t1); - } + fe_mul(t0, t1, t0); + fe_sq(t0, t0); - fe_mul(t0, t1, t0); + for (i = 1; i < 2; ++i) { fe_sq(t0, t0); + } - for (i = 1; i < 2; ++i) { - fe_sq(t0, t0); - } - - fe_mul(out, t0, z); - return; + fe_mul(out, t0, z); + return; } - /* h = f * f Can overlap h with f. @@ -979,154 +1001,154 @@ Can overlap h with f. See fe_mul.c for discussion of implementation strategy. */ -void fe_sq(fe h, const fe f) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t f0_2 = 2 * f0; - int32_t f1_2 = 2 * f1; - int32_t f2_2 = 2 * f2; - int32_t f3_2 = 2 * f3; - int32_t f4_2 = 2 * f4; - int32_t f5_2 = 2 * f5; - int32_t f6_2 = 2 * f6; - int32_t f7_2 = 2 * f7; - int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */ - int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */ - int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */ - int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */ - int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */ - int64_t f0f0 = f0 * (int64_t) f0; - int64_t f0f1_2 = f0_2 * (int64_t) f1; - int64_t f0f2_2 = f0_2 * (int64_t) f2; - int64_t f0f3_2 = f0_2 * (int64_t) f3; - int64_t f0f4_2 = f0_2 * (int64_t) f4; - int64_t f0f5_2 = f0_2 * (int64_t) f5; - int64_t f0f6_2 = f0_2 * (int64_t) f6; - int64_t f0f7_2 = f0_2 * (int64_t) f7; - int64_t f0f8_2 = f0_2 * (int64_t) f8; - int64_t f0f9_2 = f0_2 * (int64_t) f9; - int64_t f1f1_2 = f1_2 * (int64_t) f1; - int64_t f1f2_2 = f1_2 * (int64_t) f2; - int64_t f1f3_4 = f1_2 * (int64_t) f3_2; - int64_t f1f4_2 = f1_2 * (int64_t) f4; - int64_t f1f5_4 = f1_2 * (int64_t) f5_2; - int64_t f1f6_2 = f1_2 * (int64_t) f6; - int64_t f1f7_4 = f1_2 * (int64_t) f7_2; - int64_t f1f8_2 = f1_2 * (int64_t) f8; - int64_t f1f9_76 = f1_2 * (int64_t) f9_38; - int64_t f2f2 = f2 * (int64_t) f2; - int64_t f2f3_2 = f2_2 * (int64_t) f3; - int64_t f2f4_2 = f2_2 * (int64_t) f4; - int64_t f2f5_2 = f2_2 * (int64_t) f5; - int64_t f2f6_2 = f2_2 * (int64_t) f6; - int64_t f2f7_2 = f2_2 * (int64_t) f7; - int64_t f2f8_38 = f2_2 * (int64_t) f8_19; - int64_t f2f9_38 = f2 * (int64_t) f9_38; - int64_t f3f3_2 = f3_2 * (int64_t) f3; - int64_t f3f4_2 = f3_2 * (int64_t) f4; - int64_t f3f5_4 = f3_2 * (int64_t) f5_2; - int64_t f3f6_2 = f3_2 * (int64_t) f6; - int64_t f3f7_76 = f3_2 * (int64_t) f7_38; - int64_t f3f8_38 = f3_2 * (int64_t) f8_19; - int64_t f3f9_76 = f3_2 * (int64_t) f9_38; - int64_t f4f4 = f4 * (int64_t) f4; - int64_t f4f5_2 = f4_2 * (int64_t) f5; - int64_t f4f6_38 = f4_2 * (int64_t) f6_19; - int64_t f4f7_38 = f4 * (int64_t) f7_38; - int64_t f4f8_38 = f4_2 * (int64_t) f8_19; - int64_t f4f9_38 = f4 * (int64_t) f9_38; - int64_t f5f5_38 = f5 * (int64_t) f5_38; - int64_t f5f6_38 = f5_2 * (int64_t) f6_19; - int64_t f5f7_76 = f5_2 * (int64_t) f7_38; - int64_t f5f8_38 = f5_2 * (int64_t) f8_19; - int64_t f5f9_76 = f5_2 * (int64_t) f9_38; - int64_t f6f6_19 = f6 * (int64_t) f6_19; - int64_t f6f7_38 = f6 * (int64_t) f7_38; - int64_t f6f8_38 = f6_2 * (int64_t) f8_19; - int64_t f6f9_38 = f6 * (int64_t) f9_38; - int64_t f7f7_38 = f7 * (int64_t) f7_38; - int64_t f7f8_38 = f7_2 * (int64_t) f8_19; - int64_t f7f9_76 = f7_2 * (int64_t) f9_38; - int64_t f8f8_19 = f8 * (int64_t) f8_19; - int64_t f8f9_38 = f8 * (int64_t) f9_38; - int64_t f9f9_38 = f9 * (int64_t) f9_38; - int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38; - int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38; - int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19; - int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38; - int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38; - int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38; - int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19; - int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38; - int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38; - int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry1 = (h1 + (int64_t) (1 << 24)) >> 25; - h2 += carry1; - h1 -= carry1 << 25; - carry5 = (h5 + (int64_t) (1 << 24)) >> 25; - h6 += carry5; - h5 -= carry5 << 25; - carry2 = (h2 + (int64_t) (1 << 25)) >> 26; - h3 += carry2; - h2 -= carry2 << 26; - carry6 = (h6 + (int64_t) (1 << 25)) >> 26; - h7 += carry6; - h6 -= carry6 << 26; - carry3 = (h3 + (int64_t) (1 << 24)) >> 25; - h4 += carry3; - h3 -= carry3 << 25; - carry7 = (h7 + (int64_t) (1 << 24)) >> 25; - h8 += carry7; - h7 -= carry7 << 25; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry8 = (h8 + (int64_t) (1 << 25)) >> 26; - h9 += carry8; - h8 -= carry8 << 26; - carry9 = (h9 + (int64_t) (1 << 24)) >> 25; - h0 += carry9 * 19; - h9 -= carry9 << 25; - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - h[0] = (int32_t) h0; - h[1] = (int32_t) h1; - h[2] = (int32_t) h2; - h[3] = (int32_t) h3; - h[4] = (int32_t) h4; - h[5] = (int32_t) h5; - h[6] = (int32_t) h6; - h[7] = (int32_t) h7; - h[8] = (int32_t) h8; - h[9] = (int32_t) h9; +void +fe_sq(fe h, const fe f) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t f0_2 = 2 * f0; + int32_t f1_2 = 2 * f1; + int32_t f2_2 = 2 * f2; + int32_t f3_2 = 2 * f3; + int32_t f4_2 = 2 * f4; + int32_t f5_2 = 2 * f5; + int32_t f6_2 = 2 * f6; + int32_t f7_2 = 2 * f7; + int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */ + int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */ + int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */ + int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */ + int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */ + int64_t f0f0 = f0 * (int64_t)f0; + int64_t f0f1_2 = f0_2 * (int64_t)f1; + int64_t f0f2_2 = f0_2 * (int64_t)f2; + int64_t f0f3_2 = f0_2 * (int64_t)f3; + int64_t f0f4_2 = f0_2 * (int64_t)f4; + int64_t f0f5_2 = f0_2 * (int64_t)f5; + int64_t f0f6_2 = f0_2 * (int64_t)f6; + int64_t f0f7_2 = f0_2 * (int64_t)f7; + int64_t f0f8_2 = f0_2 * (int64_t)f8; + int64_t f0f9_2 = f0_2 * (int64_t)f9; + int64_t f1f1_2 = f1_2 * (int64_t)f1; + int64_t f1f2_2 = f1_2 * (int64_t)f2; + int64_t f1f3_4 = f1_2 * (int64_t)f3_2; + int64_t f1f4_2 = f1_2 * (int64_t)f4; + int64_t f1f5_4 = f1_2 * (int64_t)f5_2; + int64_t f1f6_2 = f1_2 * (int64_t)f6; + int64_t f1f7_4 = f1_2 * (int64_t)f7_2; + int64_t f1f8_2 = f1_2 * (int64_t)f8; + int64_t f1f9_76 = f1_2 * (int64_t)f9_38; + int64_t f2f2 = f2 * (int64_t)f2; + int64_t f2f3_2 = f2_2 * (int64_t)f3; + int64_t f2f4_2 = f2_2 * (int64_t)f4; + int64_t f2f5_2 = f2_2 * (int64_t)f5; + int64_t f2f6_2 = f2_2 * (int64_t)f6; + int64_t f2f7_2 = f2_2 * (int64_t)f7; + int64_t f2f8_38 = f2_2 * (int64_t)f8_19; + int64_t f2f9_38 = f2 * (int64_t)f9_38; + int64_t f3f3_2 = f3_2 * (int64_t)f3; + int64_t f3f4_2 = f3_2 * (int64_t)f4; + int64_t f3f5_4 = f3_2 * (int64_t)f5_2; + int64_t f3f6_2 = f3_2 * (int64_t)f6; + int64_t f3f7_76 = f3_2 * (int64_t)f7_38; + int64_t f3f8_38 = f3_2 * (int64_t)f8_19; + int64_t f3f9_76 = f3_2 * (int64_t)f9_38; + int64_t f4f4 = f4 * (int64_t)f4; + int64_t f4f5_2 = f4_2 * (int64_t)f5; + int64_t f4f6_38 = f4_2 * (int64_t)f6_19; + int64_t f4f7_38 = f4 * (int64_t)f7_38; + int64_t f4f8_38 = f4_2 * (int64_t)f8_19; + int64_t f4f9_38 = f4 * (int64_t)f9_38; + int64_t f5f5_38 = f5 * (int64_t)f5_38; + int64_t f5f6_38 = f5_2 * (int64_t)f6_19; + int64_t f5f7_76 = f5_2 * (int64_t)f7_38; + int64_t f5f8_38 = f5_2 * (int64_t)f8_19; + int64_t f5f9_76 = f5_2 * (int64_t)f9_38; + int64_t f6f6_19 = f6 * (int64_t)f6_19; + int64_t f6f7_38 = f6 * (int64_t)f7_38; + int64_t f6f8_38 = f6_2 * (int64_t)f8_19; + int64_t f6f9_38 = f6 * (int64_t)f9_38; + int64_t f7f7_38 = f7 * (int64_t)f7_38; + int64_t f7f8_38 = f7_2 * (int64_t)f8_19; + int64_t f7f9_76 = f7_2 * (int64_t)f9_38; + int64_t f8f8_19 = f8 * (int64_t)f8_19; + int64_t f8f9_38 = f8 * (int64_t)f9_38; + int64_t f9f9_38 = f9 * (int64_t)f9_38; + int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38; + int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38; + int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19; + int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38; + int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38; + int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38; + int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19; + int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38; + int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38; + int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry1 = (h1 + (int64_t)(1 << 24)) >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry5 = (h5 + (int64_t)(1 << 24)) >> 25; + h6 += carry5; + h5 -= carry5 << 25; + carry2 = (h2 + (int64_t)(1 << 25)) >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry6 = (h6 + (int64_t)(1 << 25)) >> 26; + h7 += carry6; + h6 -= carry6 << 26; + carry3 = (h3 + (int64_t)(1 << 24)) >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry7 = (h7 + (int64_t)(1 << 24)) >> 25; + h8 += carry7; + h7 -= carry7 << 25; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry8 = (h8 + (int64_t)(1 << 25)) >> 26; + h9 += carry8; + h8 -= carry8 << 26; + carry9 = (h9 + (int64_t)(1 << 24)) >> 25; + h0 += carry9 * 19; + h9 -= carry9 << 25; + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + h[0] = (int32_t)h0; + h[1] = (int32_t)h1; + h[2] = (int32_t)h2; + h[3] = (int32_t)h3; + h[4] = (int32_t)h4; + h[5] = (int32_t)h5; + h[6] = (int32_t)h6; + h[7] = (int32_t)h7; + h[8] = (int32_t)h8; + h[9] = (int32_t)h9; } - /* h = 2 * f * f Can overlap h with f. @@ -1142,164 +1164,164 @@ Can overlap h with f. See fe_mul.c for discussion of implementation strategy. */ -void fe_sq2(fe h, const fe f) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t f0_2 = 2 * f0; - int32_t f1_2 = 2 * f1; - int32_t f2_2 = 2 * f2; - int32_t f3_2 = 2 * f3; - int32_t f4_2 = 2 * f4; - int32_t f5_2 = 2 * f5; - int32_t f6_2 = 2 * f6; - int32_t f7_2 = 2 * f7; - int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */ - int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */ - int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */ - int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */ - int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */ - int64_t f0f0 = f0 * (int64_t) f0; - int64_t f0f1_2 = f0_2 * (int64_t) f1; - int64_t f0f2_2 = f0_2 * (int64_t) f2; - int64_t f0f3_2 = f0_2 * (int64_t) f3; - int64_t f0f4_2 = f0_2 * (int64_t) f4; - int64_t f0f5_2 = f0_2 * (int64_t) f5; - int64_t f0f6_2 = f0_2 * (int64_t) f6; - int64_t f0f7_2 = f0_2 * (int64_t) f7; - int64_t f0f8_2 = f0_2 * (int64_t) f8; - int64_t f0f9_2 = f0_2 * (int64_t) f9; - int64_t f1f1_2 = f1_2 * (int64_t) f1; - int64_t f1f2_2 = f1_2 * (int64_t) f2; - int64_t f1f3_4 = f1_2 * (int64_t) f3_2; - int64_t f1f4_2 = f1_2 * (int64_t) f4; - int64_t f1f5_4 = f1_2 * (int64_t) f5_2; - int64_t f1f6_2 = f1_2 * (int64_t) f6; - int64_t f1f7_4 = f1_2 * (int64_t) f7_2; - int64_t f1f8_2 = f1_2 * (int64_t) f8; - int64_t f1f9_76 = f1_2 * (int64_t) f9_38; - int64_t f2f2 = f2 * (int64_t) f2; - int64_t f2f3_2 = f2_2 * (int64_t) f3; - int64_t f2f4_2 = f2_2 * (int64_t) f4; - int64_t f2f5_2 = f2_2 * (int64_t) f5; - int64_t f2f6_2 = f2_2 * (int64_t) f6; - int64_t f2f7_2 = f2_2 * (int64_t) f7; - int64_t f2f8_38 = f2_2 * (int64_t) f8_19; - int64_t f2f9_38 = f2 * (int64_t) f9_38; - int64_t f3f3_2 = f3_2 * (int64_t) f3; - int64_t f3f4_2 = f3_2 * (int64_t) f4; - int64_t f3f5_4 = f3_2 * (int64_t) f5_2; - int64_t f3f6_2 = f3_2 * (int64_t) f6; - int64_t f3f7_76 = f3_2 * (int64_t) f7_38; - int64_t f3f8_38 = f3_2 * (int64_t) f8_19; - int64_t f3f9_76 = f3_2 * (int64_t) f9_38; - int64_t f4f4 = f4 * (int64_t) f4; - int64_t f4f5_2 = f4_2 * (int64_t) f5; - int64_t f4f6_38 = f4_2 * (int64_t) f6_19; - int64_t f4f7_38 = f4 * (int64_t) f7_38; - int64_t f4f8_38 = f4_2 * (int64_t) f8_19; - int64_t f4f9_38 = f4 * (int64_t) f9_38; - int64_t f5f5_38 = f5 * (int64_t) f5_38; - int64_t f5f6_38 = f5_2 * (int64_t) f6_19; - int64_t f5f7_76 = f5_2 * (int64_t) f7_38; - int64_t f5f8_38 = f5_2 * (int64_t) f8_19; - int64_t f5f9_76 = f5_2 * (int64_t) f9_38; - int64_t f6f6_19 = f6 * (int64_t) f6_19; - int64_t f6f7_38 = f6 * (int64_t) f7_38; - int64_t f6f8_38 = f6_2 * (int64_t) f8_19; - int64_t f6f9_38 = f6 * (int64_t) f9_38; - int64_t f7f7_38 = f7 * (int64_t) f7_38; - int64_t f7f8_38 = f7_2 * (int64_t) f8_19; - int64_t f7f9_76 = f7_2 * (int64_t) f9_38; - int64_t f8f8_19 = f8 * (int64_t) f8_19; - int64_t f8f9_38 = f8 * (int64_t) f9_38; - int64_t f9f9_38 = f9 * (int64_t) f9_38; - int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38; - int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38; - int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19; - int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38; - int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38; - int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38; - int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19; - int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38; - int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38; - int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - h0 += h0; - h1 += h1; - h2 += h2; - h3 += h3; - h4 += h4; - h5 += h5; - h6 += h6; - h7 += h7; - h8 += h8; - h9 += h9; - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry1 = (h1 + (int64_t) (1 << 24)) >> 25; - h2 += carry1; - h1 -= carry1 << 25; - carry5 = (h5 + (int64_t) (1 << 24)) >> 25; - h6 += carry5; - h5 -= carry5 << 25; - carry2 = (h2 + (int64_t) (1 << 25)) >> 26; - h3 += carry2; - h2 -= carry2 << 26; - carry6 = (h6 + (int64_t) (1 << 25)) >> 26; - h7 += carry6; - h6 -= carry6 << 26; - carry3 = (h3 + (int64_t) (1 << 24)) >> 25; - h4 += carry3; - h3 -= carry3 << 25; - carry7 = (h7 + (int64_t) (1 << 24)) >> 25; - h8 += carry7; - h7 -= carry7 << 25; - carry4 = (h4 + (int64_t) (1 << 25)) >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry8 = (h8 + (int64_t) (1 << 25)) >> 26; - h9 += carry8; - h8 -= carry8 << 26; - carry9 = (h9 + (int64_t) (1 << 24)) >> 25; - h0 += carry9 * 19; - h9 -= carry9 << 25; - carry0 = (h0 + (int64_t) (1 << 25)) >> 26; - h1 += carry0; - h0 -= carry0 << 26; - h[0] = (int32_t) h0; - h[1] = (int32_t) h1; - h[2] = (int32_t) h2; - h[3] = (int32_t) h3; - h[4] = (int32_t) h4; - h[5] = (int32_t) h5; - h[6] = (int32_t) h6; - h[7] = (int32_t) h7; - h[8] = (int32_t) h8; - h[9] = (int32_t) h9; +void +fe_sq2(fe h, const fe f) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t f0_2 = 2 * f0; + int32_t f1_2 = 2 * f1; + int32_t f2_2 = 2 * f2; + int32_t f3_2 = 2 * f3; + int32_t f4_2 = 2 * f4; + int32_t f5_2 = 2 * f5; + int32_t f6_2 = 2 * f6; + int32_t f7_2 = 2 * f7; + int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */ + int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */ + int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */ + int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */ + int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */ + int64_t f0f0 = f0 * (int64_t)f0; + int64_t f0f1_2 = f0_2 * (int64_t)f1; + int64_t f0f2_2 = f0_2 * (int64_t)f2; + int64_t f0f3_2 = f0_2 * (int64_t)f3; + int64_t f0f4_2 = f0_2 * (int64_t)f4; + int64_t f0f5_2 = f0_2 * (int64_t)f5; + int64_t f0f6_2 = f0_2 * (int64_t)f6; + int64_t f0f7_2 = f0_2 * (int64_t)f7; + int64_t f0f8_2 = f0_2 * (int64_t)f8; + int64_t f0f9_2 = f0_2 * (int64_t)f9; + int64_t f1f1_2 = f1_2 * (int64_t)f1; + int64_t f1f2_2 = f1_2 * (int64_t)f2; + int64_t f1f3_4 = f1_2 * (int64_t)f3_2; + int64_t f1f4_2 = f1_2 * (int64_t)f4; + int64_t f1f5_4 = f1_2 * (int64_t)f5_2; + int64_t f1f6_2 = f1_2 * (int64_t)f6; + int64_t f1f7_4 = f1_2 * (int64_t)f7_2; + int64_t f1f8_2 = f1_2 * (int64_t)f8; + int64_t f1f9_76 = f1_2 * (int64_t)f9_38; + int64_t f2f2 = f2 * (int64_t)f2; + int64_t f2f3_2 = f2_2 * (int64_t)f3; + int64_t f2f4_2 = f2_2 * (int64_t)f4; + int64_t f2f5_2 = f2_2 * (int64_t)f5; + int64_t f2f6_2 = f2_2 * (int64_t)f6; + int64_t f2f7_2 = f2_2 * (int64_t)f7; + int64_t f2f8_38 = f2_2 * (int64_t)f8_19; + int64_t f2f9_38 = f2 * (int64_t)f9_38; + int64_t f3f3_2 = f3_2 * (int64_t)f3; + int64_t f3f4_2 = f3_2 * (int64_t)f4; + int64_t f3f5_4 = f3_2 * (int64_t)f5_2; + int64_t f3f6_2 = f3_2 * (int64_t)f6; + int64_t f3f7_76 = f3_2 * (int64_t)f7_38; + int64_t f3f8_38 = f3_2 * (int64_t)f8_19; + int64_t f3f9_76 = f3_2 * (int64_t)f9_38; + int64_t f4f4 = f4 * (int64_t)f4; + int64_t f4f5_2 = f4_2 * (int64_t)f5; + int64_t f4f6_38 = f4_2 * (int64_t)f6_19; + int64_t f4f7_38 = f4 * (int64_t)f7_38; + int64_t f4f8_38 = f4_2 * (int64_t)f8_19; + int64_t f4f9_38 = f4 * (int64_t)f9_38; + int64_t f5f5_38 = f5 * (int64_t)f5_38; + int64_t f5f6_38 = f5_2 * (int64_t)f6_19; + int64_t f5f7_76 = f5_2 * (int64_t)f7_38; + int64_t f5f8_38 = f5_2 * (int64_t)f8_19; + int64_t f5f9_76 = f5_2 * (int64_t)f9_38; + int64_t f6f6_19 = f6 * (int64_t)f6_19; + int64_t f6f7_38 = f6 * (int64_t)f7_38; + int64_t f6f8_38 = f6_2 * (int64_t)f8_19; + int64_t f6f9_38 = f6 * (int64_t)f9_38; + int64_t f7f7_38 = f7 * (int64_t)f7_38; + int64_t f7f8_38 = f7_2 * (int64_t)f8_19; + int64_t f7f9_76 = f7_2 * (int64_t)f9_38; + int64_t f8f8_19 = f8 * (int64_t)f8_19; + int64_t f8f9_38 = f8 * (int64_t)f9_38; + int64_t f9f9_38 = f9 * (int64_t)f9_38; + int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38; + int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38; + int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19; + int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38; + int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38; + int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38; + int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19; + int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38; + int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38; + int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + h0 += h0; + h1 += h1; + h2 += h2; + h3 += h3; + h4 += h4; + h5 += h5; + h6 += h6; + h7 += h7; + h8 += h8; + h9 += h9; + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry1 = (h1 + (int64_t)(1 << 24)) >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry5 = (h5 + (int64_t)(1 << 24)) >> 25; + h6 += carry5; + h5 -= carry5 << 25; + carry2 = (h2 + (int64_t)(1 << 25)) >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry6 = (h6 + (int64_t)(1 << 25)) >> 26; + h7 += carry6; + h6 -= carry6 << 26; + carry3 = (h3 + (int64_t)(1 << 24)) >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry7 = (h7 + (int64_t)(1 << 24)) >> 25; + h8 += carry7; + h7 -= carry7 << 25; + carry4 = (h4 + (int64_t)(1 << 25)) >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry8 = (h8 + (int64_t)(1 << 25)) >> 26; + h9 += carry8; + h8 -= carry8 << 26; + carry9 = (h9 + (int64_t)(1 << 24)) >> 25; + h0 += carry9 * 19; + h9 -= carry9 << 25; + carry0 = (h0 + (int64_t)(1 << 25)) >> 26; + h1 += carry0; + h0 -= carry0 << 26; + h[0] = (int32_t)h0; + h[1] = (int32_t)h1; + h[2] = (int32_t)h2; + h[3] = (int32_t)h3; + h[4] = (int32_t)h4; + h[5] = (int32_t)h5; + h[6] = (int32_t)h6; + h[7] = (int32_t)h7; + h[8] = (int32_t)h8; + h[9] = (int32_t)h9; } - /* h = f - g Can overlap h with f or g. @@ -1312,52 +1334,51 @@ Can overlap h with f or g. |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */ -void fe_sub(fe h, const fe f, const fe g) { - int32_t f0 = f[0]; - int32_t f1 = f[1]; - int32_t f2 = f[2]; - int32_t f3 = f[3]; - int32_t f4 = f[4]; - int32_t f5 = f[5]; - int32_t f6 = f[6]; - int32_t f7 = f[7]; - int32_t f8 = f[8]; - int32_t f9 = f[9]; - int32_t g0 = g[0]; - int32_t g1 = g[1]; - int32_t g2 = g[2]; - int32_t g3 = g[3]; - int32_t g4 = g[4]; - int32_t g5 = g[5]; - int32_t g6 = g[6]; - int32_t g7 = g[7]; - int32_t g8 = g[8]; - int32_t g9 = g[9]; - int32_t h0 = f0 - g0; - int32_t h1 = f1 - g1; - int32_t h2 = f2 - g2; - int32_t h3 = f3 - g3; - int32_t h4 = f4 - g4; - int32_t h5 = f5 - g5; - int32_t h6 = f6 - g6; - int32_t h7 = f7 - g7; - int32_t h8 = f8 - g8; - int32_t h9 = f9 - g9; - - h[0] = h0; - h[1] = h1; - h[2] = h2; - h[3] = h3; - h[4] = h4; - h[5] = h5; - h[6] = h6; - h[7] = h7; - h[8] = h8; - h[9] = h9; +void +fe_sub(fe h, const fe f, const fe g) { + int32_t f0 = f[0]; + int32_t f1 = f[1]; + int32_t f2 = f[2]; + int32_t f3 = f[3]; + int32_t f4 = f[4]; + int32_t f5 = f[5]; + int32_t f6 = f[6]; + int32_t f7 = f[7]; + int32_t f8 = f[8]; + int32_t f9 = f[9]; + int32_t g0 = g[0]; + int32_t g1 = g[1]; + int32_t g2 = g[2]; + int32_t g3 = g[3]; + int32_t g4 = g[4]; + int32_t g5 = g[5]; + int32_t g6 = g[6]; + int32_t g7 = g[7]; + int32_t g8 = g[8]; + int32_t g9 = g[9]; + int32_t h0 = f0 - g0; + int32_t h1 = f1 - g1; + int32_t h2 = f2 - g2; + int32_t h3 = f3 - g3; + int32_t h4 = f4 - g4; + int32_t h5 = f5 - g5; + int32_t h6 = f6 - g6; + int32_t h7 = f7 - g7; + int32_t h8 = f8 - g8; + int32_t h9 = f9 - g9; + + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; } - - /* Preconditions: |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. @@ -1383,109 +1404,110 @@ Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))). so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q. */ -void fe_tobytes(unsigned char *s, const fe h) { - int32_t h0 = h[0]; - int32_t h1 = h[1]; - int32_t h2 = h[2]; - int32_t h3 = h[3]; - int32_t h4 = h[4]; - int32_t h5 = h[5]; - int32_t h6 = h[6]; - int32_t h7 = h[7]; - int32_t h8 = h[8]; - int32_t h9 = h[9]; - int32_t q; - int32_t carry0; - int32_t carry1; - int32_t carry2; - int32_t carry3; - int32_t carry4; - int32_t carry5; - int32_t carry6; - int32_t carry7; - int32_t carry8; - int32_t carry9; - q = (19 * h9 + (((int32_t) 1) << 24)) >> 25; - q = (h0 + q) >> 26; - q = (h1 + q) >> 25; - q = (h2 + q) >> 26; - q = (h3 + q) >> 25; - q = (h4 + q) >> 26; - q = (h5 + q) >> 25; - q = (h6 + q) >> 26; - q = (h7 + q) >> 25; - q = (h8 + q) >> 26; - q = (h9 + q) >> 25; - /* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */ - h0 += 19 * q; - /* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */ - carry0 = h0 >> 26; - h1 += carry0; - h0 -= carry0 << 26; - carry1 = h1 >> 25; - h2 += carry1; - h1 -= carry1 << 25; - carry2 = h2 >> 26; - h3 += carry2; - h2 -= carry2 << 26; - carry3 = h3 >> 25; - h4 += carry3; - h3 -= carry3 << 25; - carry4 = h4 >> 26; - h5 += carry4; - h4 -= carry4 << 26; - carry5 = h5 >> 25; - h6 += carry5; - h5 -= carry5 << 25; - carry6 = h6 >> 26; - h7 += carry6; - h6 -= carry6 << 26; - carry7 = h7 >> 25; - h8 += carry7; - h7 -= carry7 << 25; - carry8 = h8 >> 26; - h9 += carry8; - h8 -= carry8 << 26; - carry9 = h9 >> 25; - h9 -= carry9 << 25; - - /* h10 = carry9 */ - /* - Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20. - Have h0+...+2^230 h9 between 0 and 2^255-1; - evidently 2^255 h10-2^255 q = 0. - Goal: Output h0+...+2^230 h9. - */ - s[0] = (unsigned char) (h0 >> 0); - s[1] = (unsigned char) (h0 >> 8); - s[2] = (unsigned char) (h0 >> 16); - s[3] = (unsigned char) ((h0 >> 24) | (h1 << 2)); - s[4] = (unsigned char) (h1 >> 6); - s[5] = (unsigned char) (h1 >> 14); - s[6] = (unsigned char) ((h1 >> 22) | (h2 << 3)); - s[7] = (unsigned char) (h2 >> 5); - s[8] = (unsigned char) (h2 >> 13); - s[9] = (unsigned char) ((h2 >> 21) | (h3 << 5)); - s[10] = (unsigned char) (h3 >> 3); - s[11] = (unsigned char) (h3 >> 11); - s[12] = (unsigned char) ((h3 >> 19) | (h4 << 6)); - s[13] = (unsigned char) (h4 >> 2); - s[14] = (unsigned char) (h4 >> 10); - s[15] = (unsigned char) (h4 >> 18); - s[16] = (unsigned char) (h5 >> 0); - s[17] = (unsigned char) (h5 >> 8); - s[18] = (unsigned char) (h5 >> 16); - s[19] = (unsigned char) ((h5 >> 24) | (h6 << 1)); - s[20] = (unsigned char) (h6 >> 7); - s[21] = (unsigned char) (h6 >> 15); - s[22] = (unsigned char) ((h6 >> 23) | (h7 << 3)); - s[23] = (unsigned char) (h7 >> 5); - s[24] = (unsigned char) (h7 >> 13); - s[25] = (unsigned char) ((h7 >> 21) | (h8 << 4)); - s[26] = (unsigned char) (h8 >> 4); - s[27] = (unsigned char) (h8 >> 12); - s[28] = (unsigned char) ((h8 >> 20) | (h9 << 6)); - s[29] = (unsigned char) (h9 >> 2); - s[30] = (unsigned char) (h9 >> 10); - s[31] = (unsigned char) (h9 >> 18); +void +fe_tobytes(unsigned char* s, const fe h) { + int32_t h0 = h[0]; + int32_t h1 = h[1]; + int32_t h2 = h[2]; + int32_t h3 = h[3]; + int32_t h4 = h[4]; + int32_t h5 = h[5]; + int32_t h6 = h[6]; + int32_t h7 = h[7]; + int32_t h8 = h[8]; + int32_t h9 = h[9]; + int32_t q; + int32_t carry0; + int32_t carry1; + int32_t carry2; + int32_t carry3; + int32_t carry4; + int32_t carry5; + int32_t carry6; + int32_t carry7; + int32_t carry8; + int32_t carry9; + q = (19 * h9 + (((int32_t)1) << 24)) >> 25; + q = (h0 + q) >> 26; + q = (h1 + q) >> 25; + q = (h2 + q) >> 26; + q = (h3 + q) >> 25; + q = (h4 + q) >> 26; + q = (h5 + q) >> 25; + q = (h6 + q) >> 26; + q = (h7 + q) >> 25; + q = (h8 + q) >> 26; + q = (h9 + q) >> 25; + /* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */ + h0 += 19 * q; + /* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */ + carry0 = h0 >> 26; + h1 += carry0; + h0 -= carry0 << 26; + carry1 = h1 >> 25; + h2 += carry1; + h1 -= carry1 << 25; + carry2 = h2 >> 26; + h3 += carry2; + h2 -= carry2 << 26; + carry3 = h3 >> 25; + h4 += carry3; + h3 -= carry3 << 25; + carry4 = h4 >> 26; + h5 += carry4; + h4 -= carry4 << 26; + carry5 = h5 >> 25; + h6 += carry5; + h5 -= carry5 << 25; + carry6 = h6 >> 26; + h7 += carry6; + h6 -= carry6 << 26; + carry7 = h7 >> 25; + h8 += carry7; + h7 -= carry7 << 25; + carry8 = h8 >> 26; + h9 += carry8; + h8 -= carry8 << 26; + carry9 = h9 >> 25; + h9 -= carry9 << 25; + + /* h10 = carry9 */ + /* + Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20. + Have h0+...+2^230 h9 between 0 and 2^255-1; + evidently 2^255 h10-2^255 q = 0. + Goal: Output h0+...+2^230 h9. + */ + s[0] = (unsigned char)(h0 >> 0); + s[1] = (unsigned char)(h0 >> 8); + s[2] = (unsigned char)(h0 >> 16); + s[3] = (unsigned char)((h0 >> 24) | (h1 << 2)); + s[4] = (unsigned char)(h1 >> 6); + s[5] = (unsigned char)(h1 >> 14); + s[6] = (unsigned char)((h1 >> 22) | (h2 << 3)); + s[7] = (unsigned char)(h2 >> 5); + s[8] = (unsigned char)(h2 >> 13); + s[9] = (unsigned char)((h2 >> 21) | (h3 << 5)); + s[10] = (unsigned char)(h3 >> 3); + s[11] = (unsigned char)(h3 >> 11); + s[12] = (unsigned char)((h3 >> 19) | (h4 << 6)); + s[13] = (unsigned char)(h4 >> 2); + s[14] = (unsigned char)(h4 >> 10); + s[15] = (unsigned char)(h4 >> 18); + s[16] = (unsigned char)(h5 >> 0); + s[17] = (unsigned char)(h5 >> 8); + s[18] = (unsigned char)(h5 >> 16); + s[19] = (unsigned char)((h5 >> 24) | (h6 << 1)); + s[20] = (unsigned char)(h6 >> 7); + s[21] = (unsigned char)(h6 >> 15); + s[22] = (unsigned char)((h6 >> 23) | (h7 << 3)); + s[23] = (unsigned char)(h7 >> 5); + s[24] = (unsigned char)(h7 >> 13); + s[25] = (unsigned char)((h7 >> 21) | (h8 << 4)); + s[26] = (unsigned char)(h8 >> 4); + s[27] = (unsigned char)(h8 >> 12); + s[28] = (unsigned char)((h8 >> 20) | (h9 << 6)); + s[29] = (unsigned char)(h9 >> 2); + s[30] = (unsigned char)(h9 >> 10); + s[31] = (unsigned char)(h9 >> 18); } diff --git a/sm/src/ed25519/fe.h b/sm/src/ed25519/fe.h index b4b62d282..367f5042c 100644 --- a/sm/src/ed25519/fe.h +++ b/sm/src/ed25519/fe.h @@ -3,7 +3,6 @@ #include "fixedint.h" - /* fe means field element. Here the field is \Z/(2^255-19). @@ -12,30 +11,46 @@ Bounds on each t[i] vary depending on context. */ - typedef int32_t fe[10]; - -void fe_0(fe h); -void fe_1(fe h); - -void fe_frombytes(fe h, const unsigned char *s); -void fe_tobytes(unsigned char *s, const fe h); - -void fe_copy(fe h, const fe f); -int fe_isnegative(const fe f); -int fe_isnonzero(const fe f); -void fe_cmov(fe f, const fe g, unsigned int b); -void fe_cswap(fe f, fe g, unsigned int b); - -void fe_neg(fe h, const fe f); -void fe_add(fe h, const fe f, const fe g); -void fe_invert(fe out, const fe z); -void fe_sq(fe h, const fe f); -void fe_sq2(fe h, const fe f); -void fe_mul(fe h, const fe f, const fe g); -void fe_mul121666(fe h, fe f); -void fe_pow22523(fe out, const fe z); -void fe_sub(fe h, const fe f, const fe g); +void +fe_0(fe h); +void +fe_1(fe h); + +void +fe_frombytes(fe h, const unsigned char* s); +void +fe_tobytes(unsigned char* s, const fe h); + +void +fe_copy(fe h, const fe f); +int +fe_isnegative(const fe f); +int +fe_isnonzero(const fe f); +void +fe_cmov(fe f, const fe g, unsigned int b); +void +fe_cswap(fe f, fe g, unsigned int b); + +void +fe_neg(fe h, const fe f); +void +fe_add(fe h, const fe f, const fe g); +void +fe_invert(fe out, const fe z); +void +fe_sq(fe h, const fe f); +void +fe_sq2(fe h, const fe f); +void +fe_mul(fe h, const fe f, const fe g); +void +fe_mul121666(fe h, fe f); +void +fe_pow22523(fe out, const fe z); +void +fe_sub(fe h, const fe f, const fe g); #endif diff --git a/sm/src/ed25519/fixedint.h b/sm/src/ed25519/fixedint.h index 2a5178ef6..5637cb9a4 100644 --- a/sm/src/ed25519/fixedint.h +++ b/sm/src/ed25519/fixedint.h @@ -5,69 +5,78 @@ */ #include -#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__WATCOMC__) && (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined(__UINT_FAST64_TYPE__)) )) && !defined(FIXEDINT_H_INCLUDED) - //#include - #define FIXEDINT_H_INCLUDED +#if ( \ + (defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || \ + (defined(__WATCOMC__) && \ + (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || \ + (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || \ + defined(__UINT_FAST64_TYPE__)))) && \ + !defined(FIXEDINT_H_INCLUDED) +//#include +#define FIXEDINT_H_INCLUDED - #if defined(__WATCOMC__) && __WATCOMC__ >= 1250 && !defined(UINT64_C) - #include - #define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX)) - #endif +#if defined(__WATCOMC__) && __WATCOMC__ >= 1250 && !defined(UINT64_C) +#include +#define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX)) +#endif #endif - #ifndef FIXEDINT_H_INCLUDED - #define FIXEDINT_H_INCLUDED - - #include +#define FIXEDINT_H_INCLUDED - /* (u)int32_t */ - #ifndef uint32_t - #if (ULONG_MAX == 0xffffffffUL) - typedef unsigned long uint32_t; - #elif (UINT_MAX == 0xffffffffUL) - typedef unsigned int uint32_t; - #elif (USHRT_MAX == 0xffffffffUL) - typedef unsigned short uint32_t; - #endif - #endif +#include +/* (u)int32_t */ +#ifndef uint32_t +#if (ULONG_MAX == 0xffffffffUL) +typedef unsigned long uint32_t; +#elif (UINT_MAX == 0xffffffffUL) +typedef unsigned int uint32_t; +#elif (USHRT_MAX == 0xffffffffUL) +typedef unsigned short uint32_t; +#endif +#endif - #ifndef int32_t - #if (LONG_MAX == 0x7fffffffL) - typedef signed long int32_t; - #elif (INT_MAX == 0x7fffffffL) - typedef signed int int32_t; - #elif (SHRT_MAX == 0x7fffffffL) - typedef signed short int32_t; - #endif - #endif - +#ifndef int32_t +#if (LONG_MAX == 0x7fffffffL) +typedef signed long int32_t; +#elif (INT_MAX == 0x7fffffffL) +typedef signed int int32_t; +#elif (SHRT_MAX == 0x7fffffffL) +typedef signed short int32_t; +#endif +#endif - /* (u)int64_t */ - #if (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC__ && __STDC_VERSION__ >= 199901L) - typedef long long int64_t; - typedef unsigned long long uint64_t; +/* (u)int64_t */ +#if ( \ + defined(__STDC__) && defined(__STDC_VERSION__) && __STDC__ && \ + __STDC_VERSION__ >= 199901L) +typedef long long int64_t; +typedef unsigned long long uint64_t; - #define UINT64_C(v) v ##ULL - #define INT64_C(v) v ##LL - #elif defined(__GNUC__) - __extension__ typedef long long int64_t; - __extension__ typedef unsigned long long uint64_t; +#define UINT64_C(v) v##ULL +#define INT64_C(v) v##LL +#elif defined(__GNUC__) +__extension__ typedef long long int64_t; +__extension__ typedef unsigned long long uint64_t; - #define UINT64_C(v) v ##ULL - #define INT64_C(v) v ##LL - #elif defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__APPLE_CC__) || defined(_LONG_LONG) || defined(_CRAYC) - typedef long long int64_t; - typedef unsigned long long uint64_t; +#define UINT64_C(v) v##ULL +#define INT64_C(v) v##LL +#elif defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || \ + defined(__APPLE_CC__) || defined(_LONG_LONG) || defined(_CRAYC) +typedef long long int64_t; +typedef unsigned long long uint64_t; - #define UINT64_C(v) v ##ULL - #define INT64_C(v) v ##LL - #elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || defined(__alpha) || defined(__DECC) - typedef __int64 int64_t; - typedef unsigned __int64 uint64_t; +#define UINT64_C(v) v##ULL +#define INT64_C(v) v##LL +#elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || \ + (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || \ + (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || defined(__alpha) || \ + defined(__DECC) +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; - #define UINT64_C(v) v ##UI64 - #define INT64_C(v) v ##I64 - #endif +#define UINT64_C(v) v##UI64 +#define INT64_C(v) v##I64 +#endif #endif diff --git a/sm/src/ed25519/ge.c b/sm/src/ed25519/ge.c index 87c691bff..1a8d70e1b 100644 --- a/sm/src/ed25519/ge.c +++ b/sm/src/ed25519/ge.c @@ -1,60 +1,61 @@ #include "ge.h" -#include "precomp_data.h" +#include "precomp_data.h" /* r = p + q */ -void ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) { - fe t0; - fe_add(r->X, p->Y, p->X); - fe_sub(r->Y, p->Y, p->X); - fe_mul(r->Z, r->X, q->YplusX); - fe_mul(r->Y, r->Y, q->YminusX); - fe_mul(r->T, q->T2d, p->T); - fe_mul(r->X, p->Z, q->Z); - fe_add(t0, r->X, r->X); - fe_sub(r->X, r->Z, r->Y); - fe_add(r->Y, r->Z, r->Y); - fe_add(r->Z, t0, r->T); - fe_sub(r->T, t0, r->T); +void +ge_add(ge_p1p1* r, const ge_p3* p, const ge_cached* q) { + fe t0; + fe_add(r->X, p->Y, p->X); + fe_sub(r->Y, p->Y, p->X); + fe_mul(r->Z, r->X, q->YplusX); + fe_mul(r->Y, r->Y, q->YminusX); + fe_mul(r->T, q->T2d, p->T); + fe_mul(r->X, p->Z, q->Z); + fe_add(t0, r->X, r->X); + fe_sub(r->X, r->Z, r->Y); + fe_add(r->Y, r->Z, r->Y); + fe_add(r->Z, t0, r->T); + fe_sub(r->T, t0, r->T); } - -static void slide(signed char *r, const unsigned char *a) { - int i; - int b; - int k; - - for (i = 0; i < 256; ++i) { - r[i] = 1 & (a[i >> 3] >> (i & 7)); - } - - for (i = 0; i < 256; ++i) - if (r[i]) { - for (b = 1; b <= 6 && i + b < 256; ++b) { - if (r[i + b]) { - if (r[i] + (r[i + b] << b) <= 15) { - r[i] += r[i + b] << b; - r[i + b] = 0; - } else if (r[i] - (r[i + b] << b) >= -15) { - r[i] -= r[i + b] << b; - - for (k = i + b; k < 256; ++k) { - if (!r[k]) { - r[k] = 1; - break; - } - - r[k] = 0; - } - } else { - break; - } - } +static void +slide(signed char* r, const unsigned char* a) { + int i; + int b; + int k; + + for (i = 0; i < 256; ++i) { + r[i] = 1 & (a[i >> 3] >> (i & 7)); + } + + for (i = 0; i < 256; ++i) + if (r[i]) { + for (b = 1; b <= 6 && i + b < 256; ++b) { + if (r[i + b]) { + if (r[i] + (r[i + b] << b) <= 15) { + r[i] += r[i + b] << b; + r[i + b] = 0; + } else if (r[i] - (r[i + b] << b) >= -15) { + r[i] -= r[i + b] << b; + + for (k = i + b; k < 256; ++k) { + if (!r[k]) { + r[k] = 1; + break; + } + + r[k] = 0; } + } else { + break; + } } + } + } } /* @@ -64,314 +65,313 @@ and b = b[0]+256*b[1]+...+256^31 b[31]. B is the Ed25519 base point (x,4/5) with x positive. */ -void ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b) { - signed char aslide[256]; - signed char bslide[256]; - ge_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */ - ge_p1p1 t; - ge_p3 u; - ge_p3 A2; - int i; - slide(aslide, a); - slide(bslide, b); - ge_p3_to_cached(&Ai[0], A); - ge_p3_dbl(&t, A); - ge_p1p1_to_p3(&A2, &t); - ge_add(&t, &A2, &Ai[0]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[1], &u); - ge_add(&t, &A2, &Ai[1]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[2], &u); - ge_add(&t, &A2, &Ai[2]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[3], &u); - ge_add(&t, &A2, &Ai[3]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[4], &u); - ge_add(&t, &A2, &Ai[4]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[5], &u); - ge_add(&t, &A2, &Ai[5]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[6], &u); - ge_add(&t, &A2, &Ai[6]); - ge_p1p1_to_p3(&u, &t); - ge_p3_to_cached(&Ai[7], &u); - ge_p2_0(r); - - for (i = 255; i >= 0; --i) { - if (aslide[i] || bslide[i]) { - break; - } +void +ge_double_scalarmult_vartime( + ge_p2* r, const unsigned char* a, const ge_p3* A, const unsigned char* b) { + signed char aslide[256]; + signed char bslide[256]; + ge_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */ + ge_p1p1 t; + ge_p3 u; + ge_p3 A2; + int i; + slide(aslide, a); + slide(bslide, b); + ge_p3_to_cached(&Ai[0], A); + ge_p3_dbl(&t, A); + ge_p1p1_to_p3(&A2, &t); + ge_add(&t, &A2, &Ai[0]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[1], &u); + ge_add(&t, &A2, &Ai[1]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[2], &u); + ge_add(&t, &A2, &Ai[2]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[3], &u); + ge_add(&t, &A2, &Ai[3]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[4], &u); + ge_add(&t, &A2, &Ai[4]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[5], &u); + ge_add(&t, &A2, &Ai[5]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[6], &u); + ge_add(&t, &A2, &Ai[6]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[7], &u); + ge_p2_0(r); + + for (i = 255; i >= 0; --i) { + if (aslide[i] || bslide[i]) { + break; } + } - for (; i >= 0; --i) { - ge_p2_dbl(&t, r); + for (; i >= 0; --i) { + ge_p2_dbl(&t, r); - if (aslide[i] > 0) { - ge_p1p1_to_p3(&u, &t); - ge_add(&t, &u, &Ai[aslide[i] / 2]); - } else if (aslide[i] < 0) { - ge_p1p1_to_p3(&u, &t); - ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]); - } - - if (bslide[i] > 0) { - ge_p1p1_to_p3(&u, &t); - ge_madd(&t, &u, &Bi[bslide[i] / 2]); - } else if (bslide[i] < 0) { - ge_p1p1_to_p3(&u, &t); - ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]); - } + if (aslide[i] > 0) { + ge_p1p1_to_p3(&u, &t); + ge_add(&t, &u, &Ai[aslide[i] / 2]); + } else if (aslide[i] < 0) { + ge_p1p1_to_p3(&u, &t); + ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]); + } - ge_p1p1_to_p2(r, &t); + if (bslide[i] > 0) { + ge_p1p1_to_p3(&u, &t); + ge_madd(&t, &u, &Bi[bslide[i] / 2]); + } else if (bslide[i] < 0) { + ge_p1p1_to_p3(&u, &t); + ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]); } -} + ge_p1p1_to_p2(r, &t); + } +} -static const fe d = { - -10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116 -}; - -static const fe sqrtm1 = { - -32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482 -}; - -int ge_frombytes_negate_vartime(ge_p3 *h, const unsigned char *s) { - fe u; - fe v; - fe v3; - fe vxx; - fe check; - fe_frombytes(h->Y, s); - fe_1(h->Z); - fe_sq(u, h->Y); - fe_mul(v, u, d); - fe_sub(u, u, h->Z); /* u = y^2-1 */ - fe_add(v, v, h->Z); /* v = dy^2+1 */ - fe_sq(v3, v); - fe_mul(v3, v3, v); /* v3 = v^3 */ - fe_sq(h->X, v3); - fe_mul(h->X, h->X, v); - fe_mul(h->X, h->X, u); /* x = uv^7 */ - fe_pow22523(h->X, h->X); /* x = (uv^7)^((q-5)/8) */ - fe_mul(h->X, h->X, v3); - fe_mul(h->X, h->X, u); /* x = uv^3(uv^7)^((q-5)/8) */ - fe_sq(vxx, h->X); - fe_mul(vxx, vxx, v); - fe_sub(check, vxx, u); /* vx^2-u */ +static const fe d = {-10913610, 13857413, -15372611, 6949391, 114729, + -8787816, -6275908, -3247719, -18696448, -12055116}; + +static const fe sqrtm1 = {-32595792, -7943725, 9377950, 3500415, 12389472, + -272473, -25146209, -2005654, 326686, 11406482}; + +int +ge_frombytes_negate_vartime(ge_p3* h, const unsigned char* s) { + fe u; + fe v; + fe v3; + fe vxx; + fe check; + fe_frombytes(h->Y, s); + fe_1(h->Z); + fe_sq(u, h->Y); + fe_mul(v, u, d); + fe_sub(u, u, h->Z); /* u = y^2-1 */ + fe_add(v, v, h->Z); /* v = dy^2+1 */ + fe_sq(v3, v); + fe_mul(v3, v3, v); /* v3 = v^3 */ + fe_sq(h->X, v3); + fe_mul(h->X, h->X, v); + fe_mul(h->X, h->X, u); /* x = uv^7 */ + fe_pow22523(h->X, h->X); /* x = (uv^7)^((q-5)/8) */ + fe_mul(h->X, h->X, v3); + fe_mul(h->X, h->X, u); /* x = uv^3(uv^7)^((q-5)/8) */ + fe_sq(vxx, h->X); + fe_mul(vxx, vxx, v); + fe_sub(check, vxx, u); /* vx^2-u */ + + if (fe_isnonzero(check)) { + fe_add(check, vxx, u); /* vx^2+u */ if (fe_isnonzero(check)) { - fe_add(check, vxx, u); /* vx^2+u */ - - if (fe_isnonzero(check)) { - return -1; - } - - fe_mul(h->X, h->X, sqrtm1); + return -1; } - if (fe_isnegative(h->X) == (s[31] >> 7)) { - fe_neg(h->X, h->X); - } + fe_mul(h->X, h->X, sqrtm1); + } - fe_mul(h->T, h->X, h->Y); - return 0; -} + if (fe_isnegative(h->X) == (s[31] >> 7)) { + fe_neg(h->X, h->X); + } + fe_mul(h->T, h->X, h->Y); + return 0; +} /* r = p + q */ -void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) { - fe t0; - fe_add(r->X, p->Y, p->X); - fe_sub(r->Y, p->Y, p->X); - fe_mul(r->Z, r->X, q->yplusx); - fe_mul(r->Y, r->Y, q->yminusx); - fe_mul(r->T, q->xy2d, p->T); - fe_add(t0, p->Z, p->Z); - fe_sub(r->X, r->Z, r->Y); - fe_add(r->Y, r->Z, r->Y); - fe_add(r->Z, t0, r->T); - fe_sub(r->T, t0, r->T); +void +ge_madd(ge_p1p1* r, const ge_p3* p, const ge_precomp* q) { + fe t0; + fe_add(r->X, p->Y, p->X); + fe_sub(r->Y, p->Y, p->X); + fe_mul(r->Z, r->X, q->yplusx); + fe_mul(r->Y, r->Y, q->yminusx); + fe_mul(r->T, q->xy2d, p->T); + fe_add(t0, p->Z, p->Z); + fe_sub(r->X, r->Z, r->Y); + fe_add(r->Y, r->Z, r->Y); + fe_add(r->Z, t0, r->T); + fe_sub(r->T, t0, r->T); } - /* r = p - q */ -void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) { - fe t0; - - fe_add(r->X, p->Y, p->X); - fe_sub(r->Y, p->Y, p->X); - fe_mul(r->Z, r->X, q->yminusx); - fe_mul(r->Y, r->Y, q->yplusx); - fe_mul(r->T, q->xy2d, p->T); - fe_add(t0, p->Z, p->Z); - fe_sub(r->X, r->Z, r->Y); - fe_add(r->Y, r->Z, r->Y); - fe_sub(r->Z, t0, r->T); - fe_add(r->T, t0, r->T); +void +ge_msub(ge_p1p1* r, const ge_p3* p, const ge_precomp* q) { + fe t0; + + fe_add(r->X, p->Y, p->X); + fe_sub(r->Y, p->Y, p->X); + fe_mul(r->Z, r->X, q->yminusx); + fe_mul(r->Y, r->Y, q->yplusx); + fe_mul(r->T, q->xy2d, p->T); + fe_add(t0, p->Z, p->Z); + fe_sub(r->X, r->Z, r->Y); + fe_add(r->Y, r->Z, r->Y); + fe_sub(r->Z, t0, r->T); + fe_add(r->T, t0, r->T); } - /* r = p */ -void ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p) { - fe_mul(r->X, p->X, p->T); - fe_mul(r->Y, p->Y, p->Z); - fe_mul(r->Z, p->Z, p->T); +void +ge_p1p1_to_p2(ge_p2* r, const ge_p1p1* p) { + fe_mul(r->X, p->X, p->T); + fe_mul(r->Y, p->Y, p->Z); + fe_mul(r->Z, p->Z, p->T); } - - /* r = p */ -void ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p) { - fe_mul(r->X, p->X, p->T); - fe_mul(r->Y, p->Y, p->Z); - fe_mul(r->Z, p->Z, p->T); - fe_mul(r->T, p->X, p->Y); +void +ge_p1p1_to_p3(ge_p3* r, const ge_p1p1* p) { + fe_mul(r->X, p->X, p->T); + fe_mul(r->Y, p->Y, p->Z); + fe_mul(r->Z, p->Z, p->T); + fe_mul(r->T, p->X, p->Y); } - -void ge_p2_0(ge_p2 *h) { - fe_0(h->X); - fe_1(h->Y); - fe_1(h->Z); +void +ge_p2_0(ge_p2* h) { + fe_0(h->X); + fe_1(h->Y); + fe_1(h->Z); } - - /* r = 2 * p */ -void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p) { - fe t0; - - fe_sq(r->X, p->X); - fe_sq(r->Z, p->Y); - fe_sq2(r->T, p->Z); - fe_add(r->Y, p->X, p->Y); - fe_sq(t0, r->Y); - fe_add(r->Y, r->Z, r->X); - fe_sub(r->Z, r->Z, r->X); - fe_sub(r->X, t0, r->Y); - fe_sub(r->T, r->T, r->Z); +void +ge_p2_dbl(ge_p1p1* r, const ge_p2* p) { + fe t0; + + fe_sq(r->X, p->X); + fe_sq(r->Z, p->Y); + fe_sq2(r->T, p->Z); + fe_add(r->Y, p->X, p->Y); + fe_sq(t0, r->Y); + fe_add(r->Y, r->Z, r->X); + fe_sub(r->Z, r->Z, r->X); + fe_sub(r->X, t0, r->Y); + fe_sub(r->T, r->T, r->Z); } - -void ge_p3_0(ge_p3 *h) { - fe_0(h->X); - fe_1(h->Y); - fe_1(h->Z); - fe_0(h->T); +void +ge_p3_0(ge_p3* h) { + fe_0(h->X); + fe_1(h->Y); + fe_1(h->Z); + fe_0(h->T); } - /* r = 2 * p */ -void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p) { - ge_p2 q; - ge_p3_to_p2(&q, p); - ge_p2_dbl(r, &q); +void +ge_p3_dbl(ge_p1p1* r, const ge_p3* p) { + ge_p2 q; + ge_p3_to_p2(&q, p); + ge_p2_dbl(r, &q); } - - /* r = p */ -static const fe d2 = { - -21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199 -}; +static const fe d2 = {-21827239, -5839606, -30745221, 13898782, 229458, + 15978800, -12551817, -6495438, 29715968, 9444199}; -void ge_p3_to_cached(ge_cached *r, const ge_p3 *p) { - fe_add(r->YplusX, p->Y, p->X); - fe_sub(r->YminusX, p->Y, p->X); - fe_copy(r->Z, p->Z); - fe_mul(r->T2d, p->T, d2); +void +ge_p3_to_cached(ge_cached* r, const ge_p3* p) { + fe_add(r->YplusX, p->Y, p->X); + fe_sub(r->YminusX, p->Y, p->X); + fe_copy(r->Z, p->Z); + fe_mul(r->T2d, p->T, d2); } - /* r = p */ -void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p) { - fe_copy(r->X, p->X); - fe_copy(r->Y, p->Y); - fe_copy(r->Z, p->Z); +void +ge_p3_to_p2(ge_p2* r, const ge_p3* p) { + fe_copy(r->X, p->X); + fe_copy(r->Y, p->Y); + fe_copy(r->Z, p->Z); } - -void ge_p3_tobytes(unsigned char *s, const ge_p3 *h) { - fe recip; - fe x; - fe y; - fe_invert(recip, h->Z); - fe_mul(x, h->X, recip); - fe_mul(y, h->Y, recip); - fe_tobytes(s, y); - s[31] ^= fe_isnegative(x) << 7; +void +ge_p3_tobytes(unsigned char* s, const ge_p3* h) { + fe recip; + fe x; + fe y; + fe_invert(recip, h->Z); + fe_mul(x, h->X, recip); + fe_mul(y, h->Y, recip); + fe_tobytes(s, y); + s[31] ^= fe_isnegative(x) << 7; } - -static unsigned char equal(signed char b, signed char c) { - unsigned char ub = b; - unsigned char uc = c; - unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */ - uint64_t y = x; /* 0: yes; 1..255: no */ - y -= 1; /* large: yes; 0..254: no */ - y >>= 63; /* 1: yes; 0: no */ - return (unsigned char) y; +static unsigned char +equal(signed char b, signed char c) { + unsigned char ub = b; + unsigned char uc = c; + unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */ + uint64_t y = x; /* 0: yes; 1..255: no */ + y -= 1; /* large: yes; 0..254: no */ + y >>= 63; /* 1: yes; 0: no */ + return (unsigned char)y; } -static unsigned char negative(signed char b) { - uint64_t x = b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */ - x >>= 63; /* 1: yes; 0: no */ - return (unsigned char) x; +static unsigned char +negative(signed char b) { + uint64_t x = + b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */ + x >>= 63; /* 1: yes; 0: no */ + return (unsigned char)x; } -static void cmov(ge_precomp *t, const ge_precomp *u, unsigned char b) { - fe_cmov(t->yplusx, u->yplusx, b); - fe_cmov(t->yminusx, u->yminusx, b); - fe_cmov(t->xy2d, u->xy2d, b); +static void +cmov(ge_precomp* t, const ge_precomp* u, unsigned char b) { + fe_cmov(t->yplusx, u->yplusx, b); + fe_cmov(t->yminusx, u->yminusx, b); + fe_cmov(t->xy2d, u->xy2d, b); } - -static void select(ge_precomp *t, int pos, signed char b) { - ge_precomp minust; - unsigned char bnegative = negative(b); - unsigned char babs = b - (((-bnegative) & b) << 1); - fe_1(t->yplusx); - fe_1(t->yminusx); - fe_0(t->xy2d); - cmov(t, &base[pos][0], equal(babs, 1)); - cmov(t, &base[pos][1], equal(babs, 2)); - cmov(t, &base[pos][2], equal(babs, 3)); - cmov(t, &base[pos][3], equal(babs, 4)); - cmov(t, &base[pos][4], equal(babs, 5)); - cmov(t, &base[pos][5], equal(babs, 6)); - cmov(t, &base[pos][6], equal(babs, 7)); - cmov(t, &base[pos][7], equal(babs, 8)); - fe_copy(minust.yplusx, t->yminusx); - fe_copy(minust.yminusx, t->yplusx); - fe_neg(minust.xy2d, t->xy2d); - cmov(t, &minust, bnegative); +static void +select(ge_precomp* t, int pos, signed char b) { + ge_precomp minust; + unsigned char bnegative = negative(b); + unsigned char babs = b - (((-bnegative) & b) << 1); + fe_1(t->yplusx); + fe_1(t->yminusx); + fe_0(t->xy2d); + cmov(t, &base[pos][0], equal(babs, 1)); + cmov(t, &base[pos][1], equal(babs, 2)); + cmov(t, &base[pos][2], equal(babs, 3)); + cmov(t, &base[pos][3], equal(babs, 4)); + cmov(t, &base[pos][4], equal(babs, 5)); + cmov(t, &base[pos][5], equal(babs, 6)); + cmov(t, &base[pos][6], equal(babs, 7)); + cmov(t, &base[pos][7], equal(babs, 8)); + fe_copy(minust.yplusx, t->yminusx); + fe_copy(minust.yminusx, t->yplusx); + fe_neg(minust.xy2d, t->xy2d); + cmov(t, &minust, bnegative); } /* @@ -383,85 +383,86 @@ B is the Ed25519 base point (x,4/5) with x positive. a[31] <= 127 */ -void ge_scalarmult_base(ge_p3 *h, const unsigned char *a) { - signed char e[64]; - signed char carry; - ge_p1p1 r; - ge_p2 s; - ge_precomp t; - int i; - - for (i = 0; i < 32; ++i) { - e[2 * i + 0] = (a[i] >> 0) & 15; - e[2 * i + 1] = (a[i] >> 4) & 15; - } - - /* each e[i] is between 0 and 15 */ - /* e[63] is between 0 and 7 */ - carry = 0; - - for (i = 0; i < 63; ++i) { - e[i] += carry; - carry = e[i] + 8; - carry >>= 4; - e[i] -= carry << 4; - } - - e[63] += carry; - /* each e[i] is between -8 and 8 */ - ge_p3_0(h); - - for (i = 1; i < 64; i += 2) { - select(&t, i / 2, e[i]); - ge_madd(&r, h, &t); - ge_p1p1_to_p3(h, &r); - } - - ge_p3_dbl(&r, h); - ge_p1p1_to_p2(&s, &r); - ge_p2_dbl(&r, &s); - ge_p1p1_to_p2(&s, &r); - ge_p2_dbl(&r, &s); - ge_p1p1_to_p2(&s, &r); - ge_p2_dbl(&r, &s); +void +ge_scalarmult_base(ge_p3* h, const unsigned char* a) { + signed char e[64]; + signed char carry; + ge_p1p1 r; + ge_p2 s; + ge_precomp t; + int i; + + for (i = 0; i < 32; ++i) { + e[2 * i + 0] = (a[i] >> 0) & 15; + e[2 * i + 1] = (a[i] >> 4) & 15; + } + + /* each e[i] is between 0 and 15 */ + /* e[63] is between 0 and 7 */ + carry = 0; + + for (i = 0; i < 63; ++i) { + e[i] += carry; + carry = e[i] + 8; + carry >>= 4; + e[i] -= carry << 4; + } + + e[63] += carry; + /* each e[i] is between -8 and 8 */ + ge_p3_0(h); + + for (i = 1; i < 64; i += 2) { + select(&t, i / 2, e[i]); + ge_madd(&r, h, &t); ge_p1p1_to_p3(h, &r); - - for (i = 0; i < 64; i += 2) { - select(&t, i / 2, e[i]); - ge_madd(&r, h, &t); - ge_p1p1_to_p3(h, &r); - } + } + + ge_p3_dbl(&r, h); + ge_p1p1_to_p2(&s, &r); + ge_p2_dbl(&r, &s); + ge_p1p1_to_p2(&s, &r); + ge_p2_dbl(&r, &s); + ge_p1p1_to_p2(&s, &r); + ge_p2_dbl(&r, &s); + ge_p1p1_to_p3(h, &r); + + for (i = 0; i < 64; i += 2) { + select(&t, i / 2, e[i]); + ge_madd(&r, h, &t); + ge_p1p1_to_p3(h, &r); + } } - /* r = p - q */ -void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) { - fe t0; - - fe_add(r->X, p->Y, p->X); - fe_sub(r->Y, p->Y, p->X); - fe_mul(r->Z, r->X, q->YminusX); - fe_mul(r->Y, r->Y, q->YplusX); - fe_mul(r->T, q->T2d, p->T); - fe_mul(r->X, p->Z, q->Z); - fe_add(t0, r->X, r->X); - fe_sub(r->X, r->Z, r->Y); - fe_add(r->Y, r->Z, r->Y); - fe_sub(r->Z, t0, r->T); - fe_add(r->T, t0, r->T); +void +ge_sub(ge_p1p1* r, const ge_p3* p, const ge_cached* q) { + fe t0; + + fe_add(r->X, p->Y, p->X); + fe_sub(r->Y, p->Y, p->X); + fe_mul(r->Z, r->X, q->YminusX); + fe_mul(r->Y, r->Y, q->YplusX); + fe_mul(r->T, q->T2d, p->T); + fe_mul(r->X, p->Z, q->Z); + fe_add(t0, r->X, r->X); + fe_sub(r->X, r->Z, r->Y); + fe_add(r->Y, r->Z, r->Y); + fe_sub(r->Z, t0, r->T); + fe_add(r->T, t0, r->T); } - -void ge_tobytes(unsigned char *s, const ge_p2 *h) { - fe recip; - fe x; - fe y; - fe_invert(recip, h->Z); - fe_mul(x, h->X, recip); - fe_mul(y, h->Y, recip); - fe_tobytes(s, y); - s[31] ^= fe_isnegative(x) << 7; +void +ge_tobytes(unsigned char* s, const ge_p2* h) { + fe recip; + fe x; + fe y; + fe_invert(recip, h->Z); + fe_mul(x, h->X, recip); + fe_mul(y, h->Y, recip); + fe_tobytes(s, y); + s[31] ^= fe_isnegative(x) << 7; } diff --git a/sm/src/ed25519/ge.h b/sm/src/ed25519/ge.h index 17fde2df1..d8a159eb5 100644 --- a/sm/src/ed25519/ge.h +++ b/sm/src/ed25519/ge.h @@ -3,7 +3,6 @@ #include "fe.h" - /* ge means group element. @@ -51,24 +50,42 @@ typedef struct { fe T2d; } ge_cached; -void ge_p3_tobytes(unsigned char *s, const ge_p3 *h); -void ge_tobytes(unsigned char *s, const ge_p2 *h); -int ge_frombytes_negate_vartime(ge_p3 *h, const unsigned char *s); +void +ge_p3_tobytes(unsigned char* s, const ge_p3* h); +void +ge_tobytes(unsigned char* s, const ge_p2* h); +int +ge_frombytes_negate_vartime(ge_p3* h, const unsigned char* s); -void ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q); -void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q); -void ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b); -void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q); -void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q); -void ge_scalarmult_base(ge_p3 *h, const unsigned char *a); +void +ge_add(ge_p1p1* r, const ge_p3* p, const ge_cached* q); +void +ge_sub(ge_p1p1* r, const ge_p3* p, const ge_cached* q); +void +ge_double_scalarmult_vartime( + ge_p2* r, const unsigned char* a, const ge_p3* A, const unsigned char* b); +void +ge_madd(ge_p1p1* r, const ge_p3* p, const ge_precomp* q); +void +ge_msub(ge_p1p1* r, const ge_p3* p, const ge_precomp* q); +void +ge_scalarmult_base(ge_p3* h, const unsigned char* a); -void ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p); -void ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p); -void ge_p2_0(ge_p2 *h); -void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p); -void ge_p3_0(ge_p3 *h); -void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p); -void ge_p3_to_cached(ge_cached *r, const ge_p3 *p); -void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p); +void +ge_p1p1_to_p2(ge_p2* r, const ge_p1p1* p); +void +ge_p1p1_to_p3(ge_p3* r, const ge_p1p1* p); +void +ge_p2_0(ge_p2* h); +void +ge_p2_dbl(ge_p1p1* r, const ge_p2* p); +void +ge_p3_0(ge_p3* h); +void +ge_p3_dbl(ge_p1p1* r, const ge_p3* p); +void +ge_p3_to_cached(ge_cached* r, const ge_p3* p); +void +ge_p3_to_p2(ge_p2* r, const ge_p3* p); #endif diff --git a/sm/src/ed25519/keypair.c b/sm/src/ed25519/keypair.c index 9f5cde631..9923c3eea 100644 --- a/sm/src/ed25519/keypair.c +++ b/sm/src/ed25519/keypair.c @@ -1,16 +1,18 @@ -#include "ed25519.h" #include "../sha3/sha3.h" +#include "ed25519.h" #include "ge.h" +void +ed25519_create_keypair( + unsigned char* public_key, unsigned char* private_key, + const unsigned char* seed) { + ge_p3 A; -void ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed) { - ge_p3 A; - - sha3(seed, 32, private_key, 64); - private_key[0] &= 248; - private_key[31] &= 63; - private_key[31] |= 64; + sha3(seed, 32, private_key, 64); + private_key[0] &= 248; + private_key[31] &= 63; + private_key[31] |= 64; - ge_scalarmult_base(&A, private_key); - ge_p3_tobytes(public_key, &A); + ge_scalarmult_base(&A, private_key); + ge_p3_tobytes(public_key, &A); } diff --git a/sm/src/ed25519/precomp_data.h b/sm/src/ed25519/precomp_data.h index ff23986c3..13be672e6 100644 --- a/sm/src/ed25519/precomp_data.h +++ b/sm/src/ed25519/precomp_data.h @@ -1,1391 +1,2182 @@ static const ge_precomp Bi[8] = { { - { 25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605 }, - { -12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378 }, - { -8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, 11864899, -24514362, -4438546 }, + {25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, + -11754271, -6079156, 2047605}, + {-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, + 5043384, 19500929, -15469378}, + {-8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, + 11864899, -24514362, -4438546}, }, { - { 15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, -14772189, 28944400, -1550024 }, - { 16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, -11775962, 7689662, 11199574 }, - { 30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, 10017326, -17749093, -9920357 }, + {15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, + -14772189, 28944400, -1550024}, + {16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, + -11775962, 7689662, 11199574}, + {30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, + 10017326, -17749093, -9920357}, }, { - { 10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, 14515107, -15438304, 10819380 }, - { 4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, 12483688, -12668491, 5581306 }, - { 19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, 13850243, -23678021, -15815942 }, + {10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, + 14515107, -15438304, 10819380}, + {4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, + 12483688, -12668491, 5581306}, + {19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, + 13850243, -23678021, -15815942}, }, { - { 5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, 5230134, -23952439, -15175766 }, - { -30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, 16520125, 30598449, 7715701 }, - { 28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, 1370708, 29794553, -1409300 }, + {5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, + 5230134, -23952439, -15175766}, + {-30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, + 16520125, 30598449, 7715701}, + {28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, + 1370708, 29794553, -1409300}, }, { - { -22518993, -6692182, 14201702, -8745502, -23510406, 8844726, 18474211, -1361450, -13062696, 13821877 }, - { -6455177, -7839871, 3374702, -4740862, -27098617, -10571707, 31655028, -7212327, 18853322, -14220951 }, - { 4566830, -12963868, -28974889, -12240689, -7602672, -2830569, -8514358, -10431137, 2207753, -3209784 }, + {-22518993, -6692182, 14201702, -8745502, -23510406, 8844726, 18474211, + -1361450, -13062696, 13821877}, + {-6455177, -7839871, 3374702, -4740862, -27098617, -10571707, 31655028, + -7212327, 18853322, -14220951}, + {4566830, -12963868, -28974889, -12240689, -7602672, -2830569, -8514358, + -10431137, 2207753, -3209784}, }, { - { -25154831, -4185821, 29681144, 7868801, -6854661, -9423865, -12437364, -663000, -31111463, -16132436 }, - { 25576264, -2703214, 7349804, -11814844, 16472782, 9300885, 3844789, 15725684, 171356, 6466918 }, - { 23103977, 13316479, 9739013, -16149481, 817875, -15038942, 8965339, -14088058, -30714912, 16193877 }, + {-25154831, -4185821, 29681144, 7868801, -6854661, -9423865, -12437364, + -663000, -31111463, -16132436}, + {25576264, -2703214, 7349804, -11814844, 16472782, 9300885, 3844789, + 15725684, 171356, 6466918}, + {23103977, 13316479, 9739013, -16149481, 817875, -15038942, 8965339, + -14088058, -30714912, 16193877}, }, { - { -33521811, 3180713, -2394130, 14003687, -16903474, -16270840, 17238398, 4729455, -18074513, 9256800 }, - { -25182317, -4174131, 32336398, 5036987, -21236817, 11360617, 22616405, 9761698, -19827198, 630305 }, - { -13720693, 2639453, -24237460, -7406481, 9494427, -5774029, -6554551, -15960994, -2449256, -14291300 }, + {-33521811, 3180713, -2394130, 14003687, -16903474, -16270840, 17238398, + 4729455, -18074513, 9256800}, + {-25182317, -4174131, 32336398, 5036987, -21236817, 11360617, 22616405, + 9761698, -19827198, 630305}, + {-13720693, 2639453, -24237460, -7406481, 9494427, -5774029, -6554551, + -15960994, -2449256, -14291300}, }, { - { -3151181, -5046075, 9282714, 6866145, -31907062, -863023, -18940575, 15033784, 25105118, -7894876 }, - { -24326370, 15950226, -31801215, -14592823, -11662737, -5090925, 1573892, -2625887, 2198790, -15804619 }, - { -3099351, 10324967, -2241613, 7453183, -5446979, -2735503, -13812022, -16236442, -32461234, -12290683 }, + {-3151181, -5046075, 9282714, 6866145, -31907062, -863023, -18940575, + 15033784, 25105118, -7894876}, + {-24326370, 15950226, -31801215, -14592823, -11662737, -5090925, + 1573892, -2625887, 2198790, -15804619}, + {-3099351, 10324967, -2241613, 7453183, -5446979, -2735503, -13812022, + -16236442, -32461234, -12290683}, }, }; - /* base[i][j] = (j+1)*256^i*B */ static const ge_precomp base[32][8] = { { { - { 25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605 }, - { -12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378 }, - { -8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, 11864899, -24514362, -4438546 }, + {25967493, -14356035, 29566456, 3660896, -12694345, 4014787, + 27544626, -11754271, -6079156, 2047605}, + {-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, + 5043384, 19500929, -15469378}, + {-8738181, 4489570, 9688441, -14785194, 10184609, -12363380, + 29287919, 11864899, -24514362, -4438546}, }, { - { -12815894, -12976347, -21581243, 11784320, -25355658, -2750717, -11717903, -3814571, -358445, -10211303 }, - { -21703237, 6903825, 27185491, 6451973, -29577724, -9554005, -15616551, 11189268, -26829678, -5319081 }, - { 26966642, 11152617, 32442495, 15396054, 14353839, -12752335, -3128826, -9541118, -15472047, -4166697 }, + {-12815894, -12976347, -21581243, 11784320, -25355658, -2750717, + -11717903, -3814571, -358445, -10211303}, + {-21703237, 6903825, 27185491, 6451973, -29577724, -9554005, + -15616551, 11189268, -26829678, -5319081}, + {26966642, 11152617, 32442495, 15396054, 14353839, -12752335, + -3128826, -9541118, -15472047, -4166697}, }, { - { 15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, -14772189, 28944400, -1550024 }, - { 16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, -11775962, 7689662, 11199574 }, - { 30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, 10017326, -17749093, -9920357 }, + {15636291, -9688557, 24204773, -7912398, 616977, -16685262, + 27787600, -14772189, 28944400, -1550024}, + {16568933, 4717097, -11556148, -1102322, 15682896, -11807043, + 16354577, -11775962, 7689662, 11199574}, + {30464156, -5976125, -11779434, -15670865, 23220365, 15915852, + 7512774, 10017326, -17749093, -9920357}, }, { - { -17036878, 13921892, 10945806, -6033431, 27105052, -16084379, -28926210, 15006023, 3284568, -6276540 }, - { 23599295, -8306047, -11193664, -7687416, 13236774, 10506355, 7464579, 9656445, 13059162, 10374397 }, - { 7798556, 16710257, 3033922, 2874086, 28997861, 2835604, 32406664, -3839045, -641708, -101325 }, + {-17036878, 13921892, 10945806, -6033431, 27105052, -16084379, + -28926210, 15006023, 3284568, -6276540}, + {23599295, -8306047, -11193664, -7687416, 13236774, 10506355, + 7464579, 9656445, 13059162, 10374397}, + {7798556, 16710257, 3033922, 2874086, 28997861, 2835604, 32406664, + -3839045, -641708, -101325}, }, { - { 10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, 14515107, -15438304, 10819380 }, - { 4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, 12483688, -12668491, 5581306 }, - { 19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, 13850243, -23678021, -15815942 }, + {10861363, 11473154, 27284546, 1981175, -30064349, 12577861, + 32867885, 14515107, -15438304, 10819380}, + {4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, + 12483688, -12668491, 5581306}, + {19563160, 16186464, -29386857, 4097519, 10237984, -4348115, + 28542350, 13850243, -23678021, -15815942}, }, { - { -15371964, -12862754, 32573250, 4720197, -26436522, 5875511, -19188627, -15224819, -9818940, -12085777 }, - { -8549212, 109983, 15149363, 2178705, 22900618, 4543417, 3044240, -15689887, 1762328, 14866737 }, - { -18199695, -15951423, -10473290, 1707278, -17185920, 3916101, -28236412, 3959421, 27914454, 4383652 }, + {-15371964, -12862754, 32573250, 4720197, -26436522, 5875511, + -19188627, -15224819, -9818940, -12085777}, + {-8549212, 109983, 15149363, 2178705, 22900618, 4543417, 3044240, + -15689887, 1762328, 14866737}, + {-18199695, -15951423, -10473290, 1707278, -17185920, 3916101, + -28236412, 3959421, 27914454, 4383652}, }, { - { 5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, 5230134, -23952439, -15175766 }, - { -30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, 16520125, 30598449, 7715701 }, - { 28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, 1370708, 29794553, -1409300 }, + {5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, + 5230134, -23952439, -15175766}, + {-30269007, -3463509, 7665486, 10083793, 28475525, 1649722, + 20654025, 16520125, 30598449, 7715701}, + {28881845, 14381568, 9657904, 3680757, -20181635, 7843316, + -31400660, 1370708, 29794553, -1409300}, }, { - { 14499471, -2729599, -33191113, -4254652, 28494862, 14271267, 30290735, 10876454, -33154098, 2381726 }, - { -7195431, -2655363, -14730155, 462251, -27724326, 3941372, -6236617, 3696005, -32300832, 15351955 }, - { 27431194, 8222322, 16448760, -3907995, -18707002, 11938355, -32961401, -2970515, 29551813, 10109425 }, + {14499471, -2729599, -33191113, -4254652, 28494862, 14271267, + 30290735, 10876454, -33154098, 2381726}, + {-7195431, -2655363, -14730155, 462251, -27724326, 3941372, + -6236617, 3696005, -32300832, 15351955}, + {27431194, 8222322, 16448760, -3907995, -18707002, 11938355, + -32961401, -2970515, 29551813, 10109425}, }, }, { { - { -13657040, -13155431, -31283750, 11777098, 21447386, 6519384, -2378284, -1627556, 10092783, -4764171 }, - { 27939166, 14210322, 4677035, 16277044, -22964462, -12398139, -32508754, 12005538, -17810127, 12803510 }, - { 17228999, -15661624, -1233527, 300140, -1224870, -11714777, 30364213, -9038194, 18016357, 4397660 }, + {-13657040, -13155431, -31283750, 11777098, 21447386, 6519384, + -2378284, -1627556, 10092783, -4764171}, + {27939166, 14210322, 4677035, 16277044, -22964462, -12398139, + -32508754, 12005538, -17810127, 12803510}, + {17228999, -15661624, -1233527, 300140, -1224870, -11714777, + 30364213, -9038194, 18016357, 4397660}, }, { - { -10958843, -7690207, 4776341, -14954238, 27850028, -15602212, -26619106, 14544525, -17477504, 982639 }, - { 29253598, 15796703, -2863982, -9908884, 10057023, 3163536, 7332899, -4120128, -21047696, 9934963 }, - { 5793303, 16271923, -24131614, -10116404, 29188560, 1206517, -14747930, 4559895, -30123922, -10897950 }, + {-10958843, -7690207, 4776341, -14954238, 27850028, -15602212, + -26619106, 14544525, -17477504, 982639}, + {29253598, 15796703, -2863982, -9908884, 10057023, 3163536, 7332899, + -4120128, -21047696, 9934963}, + {5793303, 16271923, -24131614, -10116404, 29188560, 1206517, + -14747930, 4559895, -30123922, -10897950}, }, { - { -27643952, -11493006, 16282657, -11036493, 28414021, -15012264, 24191034, 4541697, -13338309, 5500568 }, - { 12650548, -1497113, 9052871, 11355358, -17680037, -8400164, -17430592, 12264343, 10874051, 13524335 }, - { 25556948, -3045990, 714651, 2510400, 23394682, -10415330, 33119038, 5080568, -22528059, 5376628 }, + {-27643952, -11493006, 16282657, -11036493, 28414021, -15012264, + 24191034, 4541697, -13338309, 5500568}, + {12650548, -1497113, 9052871, 11355358, -17680037, -8400164, + -17430592, 12264343, 10874051, 13524335}, + {25556948, -3045990, 714651, 2510400, 23394682, -10415330, 33119038, + 5080568, -22528059, 5376628}, }, { - { -26088264, -4011052, -17013699, -3537628, -6726793, 1920897, -22321305, -9447443, 4535768, 1569007 }, - { -2255422, 14606630, -21692440, -8039818, 28430649, 8775819, -30494562, 3044290, 31848280, 12543772 }, - { -22028579, 2943893, -31857513, 6777306, 13784462, -4292203, -27377195, -2062731, 7718482, 14474653 }, + {-26088264, -4011052, -17013699, -3537628, -6726793, 1920897, + -22321305, -9447443, 4535768, 1569007}, + {-2255422, 14606630, -21692440, -8039818, 28430649, 8775819, + -30494562, 3044290, 31848280, 12543772}, + {-22028579, 2943893, -31857513, 6777306, 13784462, -4292203, + -27377195, -2062731, 7718482, 14474653}, }, { - { 2385315, 2454213, -22631320, 46603, -4437935, -15680415, 656965, -7236665, 24316168, -5253567 }, - { 13741529, 10911568, -33233417, -8603737, -20177830, -1033297, 33040651, -13424532, -20729456, 8321686 }, - { 21060490, -2212744, 15712757, -4336099, 1639040, 10656336, 23845965, -11874838, -9984458, 608372 }, + {2385315, 2454213, -22631320, 46603, -4437935, -15680415, 656965, + -7236665, 24316168, -5253567}, + {13741529, 10911568, -33233417, -8603737, -20177830, -1033297, + 33040651, -13424532, -20729456, 8321686}, + {21060490, -2212744, 15712757, -4336099, 1639040, 10656336, + 23845965, -11874838, -9984458, 608372}, }, { - { -13672732, -15087586, -10889693, -7557059, -6036909, 11305547, 1123968, -6780577, 27229399, 23887 }, - { -23244140, -294205, -11744728, 14712571, -29465699, -2029617, 12797024, -6440308, -1633405, 16678954 }, - { -29500620, 4770662, -16054387, 14001338, 7830047, 9564805, -1508144, -4795045, -17169265, 4904953 }, + {-13672732, -15087586, -10889693, -7557059, -6036909, 11305547, + 1123968, -6780577, 27229399, 23887}, + {-23244140, -294205, -11744728, 14712571, -29465699, -2029617, + 12797024, -6440308, -1633405, 16678954}, + {-29500620, 4770662, -16054387, 14001338, 7830047, 9564805, + -1508144, -4795045, -17169265, 4904953}, }, { - { 24059557, 14617003, 19037157, -15039908, 19766093, -14906429, 5169211, 16191880, 2128236, -4326833 }, - { -16981152, 4124966, -8540610, -10653797, 30336522, -14105247, -29806336, 916033, -6882542, -2986532 }, - { -22630907, 12419372, -7134229, -7473371, -16478904, 16739175, 285431, 2763829, 15736322, 4143876 }, + {24059557, 14617003, 19037157, -15039908, 19766093, -14906429, + 5169211, 16191880, 2128236, -4326833}, + {-16981152, 4124966, -8540610, -10653797, 30336522, -14105247, + -29806336, 916033, -6882542, -2986532}, + {-22630907, 12419372, -7134229, -7473371, -16478904, 16739175, + 285431, 2763829, 15736322, 4143876}, }, { - { 2379352, 11839345, -4110402, -5988665, 11274298, 794957, 212801, -14594663, 23527084, -16458268 }, - { 33431127, -11130478, -17838966, -15626900, 8909499, 8376530, -32625340, 4087881, -15188911, -14416214 }, - { 1767683, 7197987, -13205226, -2022635, -13091350, 448826, 5799055, 4357868, -4774191, -16323038 }, + {2379352, 11839345, -4110402, -5988665, 11274298, 794957, 212801, + -14594663, 23527084, -16458268}, + {33431127, -11130478, -17838966, -15626900, 8909499, 8376530, + -32625340, 4087881, -15188911, -14416214}, + {1767683, 7197987, -13205226, -2022635, -13091350, 448826, 5799055, + 4357868, -4774191, -16323038}, }, }, { { - { 6721966, 13833823, -23523388, -1551314, 26354293, -11863321, 23365147, -3949732, 7390890, 2759800 }, - { 4409041, 2052381, 23373853, 10530217, 7676779, -12885954, 21302353, -4264057, 1244380, -12919645 }, - { -4421239, 7169619, 4982368, -2957590, 30256825, -2777540, 14086413, 9208236, 15886429, 16489664 }, + {6721966, 13833823, -23523388, -1551314, 26354293, -11863321, + 23365147, -3949732, 7390890, 2759800}, + {4409041, 2052381, 23373853, 10530217, 7676779, -12885954, 21302353, + -4264057, 1244380, -12919645}, + {-4421239, 7169619, 4982368, -2957590, 30256825, -2777540, 14086413, + 9208236, 15886429, 16489664}, }, { - { 1996075, 10375649, 14346367, 13311202, -6874135, -16438411, -13693198, 398369, -30606455, -712933 }, - { -25307465, 9795880, -2777414, 14878809, -33531835, 14780363, 13348553, 12076947, -30836462, 5113182 }, - { -17770784, 11797796, 31950843, 13929123, -25888302, 12288344, -30341101, -7336386, 13847711, 5387222 }, + {1996075, 10375649, 14346367, 13311202, -6874135, -16438411, + -13693198, 398369, -30606455, -712933}, + {-25307465, 9795880, -2777414, 14878809, -33531835, 14780363, + 13348553, 12076947, -30836462, 5113182}, + {-17770784, 11797796, 31950843, 13929123, -25888302, 12288344, + -30341101, -7336386, 13847711, 5387222}, }, { - { -18582163, -3416217, 17824843, -2340966, 22744343, -10442611, 8763061, 3617786, -19600662, 10370991 }, - { 20246567, -14369378, 22358229, -543712, 18507283, -10413996, 14554437, -8746092, 32232924, 16763880 }, - { 9648505, 10094563, 26416693, 14745928, -30374318, -6472621, 11094161, 15689506, 3140038, -16510092 }, + {-18582163, -3416217, 17824843, -2340966, 22744343, -10442611, + 8763061, 3617786, -19600662, 10370991}, + {20246567, -14369378, 22358229, -543712, 18507283, -10413996, + 14554437, -8746092, 32232924, 16763880}, + {9648505, 10094563, 26416693, 14745928, -30374318, -6472621, + 11094161, 15689506, 3140038, -16510092}, }, { - { -16160072, 5472695, 31895588, 4744994, 8823515, 10365685, -27224800, 9448613, -28774454, 366295 }, - { 19153450, 11523972, -11096490, -6503142, -24647631, 5420647, 28344573, 8041113, 719605, 11671788 }, - { 8678025, 2694440, -6808014, 2517372, 4964326, 11152271, -15432916, -15266516, 27000813, -10195553 }, + {-16160072, 5472695, 31895588, 4744994, 8823515, 10365685, + -27224800, 9448613, -28774454, 366295}, + {19153450, 11523972, -11096490, -6503142, -24647631, 5420647, + 28344573, 8041113, 719605, 11671788}, + {8678025, 2694440, -6808014, 2517372, 4964326, 11152271, -15432916, + -15266516, 27000813, -10195553}, }, { - { -15157904, 7134312, 8639287, -2814877, -7235688, 10421742, 564065, 5336097, 6750977, -14521026 }, - { 11836410, -3979488, 26297894, 16080799, 23455045, 15735944, 1695823, -8819122, 8169720, 16220347 }, - { -18115838, 8653647, 17578566, -6092619, -8025777, -16012763, -11144307, -2627664, -5990708, -14166033 }, + {-15157904, 7134312, 8639287, -2814877, -7235688, 10421742, 564065, + 5336097, 6750977, -14521026}, + {11836410, -3979488, 26297894, 16080799, 23455045, 15735944, + 1695823, -8819122, 8169720, 16220347}, + {-18115838, 8653647, 17578566, -6092619, -8025777, -16012763, + -11144307, -2627664, -5990708, -14166033}, }, { - { -23308498, -10968312, 15213228, -10081214, -30853605, -11050004, 27884329, 2847284, 2655861, 1738395 }, - { -27537433, -14253021, -25336301, -8002780, -9370762, 8129821, 21651608, -3239336, -19087449, -11005278 }, - { 1533110, 3437855, 23735889, 459276, 29970501, 11335377, 26030092, 5821408, 10478196, 8544890 }, + {-23308498, -10968312, 15213228, -10081214, -30853605, -11050004, + 27884329, 2847284, 2655861, 1738395}, + {-27537433, -14253021, -25336301, -8002780, -9370762, 8129821, + 21651608, -3239336, -19087449, -11005278}, + {1533110, 3437855, 23735889, 459276, 29970501, 11335377, 26030092, + 5821408, 10478196, 8544890}, }, { - { 32173121, -16129311, 24896207, 3921497, 22579056, -3410854, 19270449, 12217473, 17789017, -3395995 }, - { -30552961, -2228401, -15578829, -10147201, 13243889, 517024, 15479401, -3853233, 30460520, 1052596 }, - { -11614875, 13323618, 32618793, 8175907, -15230173, 12596687, 27491595, -4612359, 3179268, -9478891 }, + {32173121, -16129311, 24896207, 3921497, 22579056, -3410854, + 19270449, 12217473, 17789017, -3395995}, + {-30552961, -2228401, -15578829, -10147201, 13243889, 517024, + 15479401, -3853233, 30460520, 1052596}, + {-11614875, 13323618, 32618793, 8175907, -15230173, 12596687, + 27491595, -4612359, 3179268, -9478891}, }, { - { 31947069, -14366651, -4640583, -15339921, -15125977, -6039709, -14756777, -16411740, 19072640, -9511060 }, - { 11685058, 11822410, 3158003, -13952594, 33402194, -4165066, 5977896, -5215017, 473099, 5040608 }, - { -20290863, 8198642, -27410132, 11602123, 1290375, -2799760, 28326862, 1721092, -19558642, -3131606 }, + {31947069, -14366651, -4640583, -15339921, -15125977, -6039709, + -14756777, -16411740, 19072640, -9511060}, + {11685058, 11822410, 3158003, -13952594, 33402194, -4165066, + 5977896, -5215017, 473099, 5040608}, + {-20290863, 8198642, -27410132, 11602123, 1290375, -2799760, + 28326862, 1721092, -19558642, -3131606}, }, }, { { - { 7881532, 10687937, 7578723, 7738378, -18951012, -2553952, 21820786, 8076149, -27868496, 11538389 }, - { -19935666, 3899861, 18283497, -6801568, -15728660, -11249211, 8754525, 7446702, -5676054, 5797016 }, - { -11295600, -3793569, -15782110, -7964573, 12708869, -8456199, 2014099, -9050574, -2369172, -5877341 }, + {7881532, 10687937, 7578723, 7738378, -18951012, -2553952, 21820786, + 8076149, -27868496, 11538389}, + {-19935666, 3899861, 18283497, -6801568, -15728660, -11249211, + 8754525, 7446702, -5676054, 5797016}, + {-11295600, -3793569, -15782110, -7964573, 12708869, -8456199, + 2014099, -9050574, -2369172, -5877341}, }, { - { -22472376, -11568741, -27682020, 1146375, 18956691, 16640559, 1192730, -3714199, 15123619, 10811505 }, - { 14352098, -3419715, -18942044, 10822655, 32750596, 4699007, -70363, 15776356, -28886779, -11974553 }, - { -28241164, -8072475, -4978962, -5315317, 29416931, 1847569, -20654173, -16484855, 4714547, -9600655 }, + {-22472376, -11568741, -27682020, 1146375, 18956691, 16640559, + 1192730, -3714199, 15123619, 10811505}, + {14352098, -3419715, -18942044, 10822655, 32750596, 4699007, -70363, + 15776356, -28886779, -11974553}, + {-28241164, -8072475, -4978962, -5315317, 29416931, 1847569, + -20654173, -16484855, 4714547, -9600655}, }, { - { 15200332, 8368572, 19679101, 15970074, -31872674, 1959451, 24611599, -4543832, -11745876, 12340220 }, - { 12876937, -10480056, 33134381, 6590940, -6307776, 14872440, 9613953, 8241152, 15370987, 9608631 }, - { -4143277, -12014408, 8446281, -391603, 4407738, 13629032, -7724868, 15866074, -28210621, -8814099 }, + {15200332, 8368572, 19679101, 15970074, -31872674, 1959451, + 24611599, -4543832, -11745876, 12340220}, + {12876937, -10480056, 33134381, 6590940, -6307776, 14872440, + 9613953, 8241152, 15370987, 9608631}, + {-4143277, -12014408, 8446281, -391603, 4407738, 13629032, -7724868, + 15866074, -28210621, -8814099}, }, { - { 26660628, -15677655, 8393734, 358047, -7401291, 992988, -23904233, 858697, 20571223, 8420556 }, - { 14620715, 13067227, -15447274, 8264467, 14106269, 15080814, 33531827, 12516406, -21574435, -12476749 }, - { 236881, 10476226, 57258, -14677024, 6472998, 2466984, 17258519, 7256740, 8791136, 15069930 }, + {26660628, -15677655, 8393734, 358047, -7401291, 992988, -23904233, + 858697, 20571223, 8420556}, + {14620715, 13067227, -15447274, 8264467, 14106269, 15080814, + 33531827, 12516406, -21574435, -12476749}, + {236881, 10476226, 57258, -14677024, 6472998, 2466984, 17258519, + 7256740, 8791136, 15069930}, }, { - { 1276410, -9371918, 22949635, -16322807, -23493039, -5702186, 14711875, 4874229, -30663140, -2331391 }, - { 5855666, 4990204, -13711848, 7294284, -7804282, 1924647, -1423175, -7912378, -33069337, 9234253 }, - { 20590503, -9018988, 31529744, -7352666, -2706834, 10650548, 31559055, -11609587, 18979186, 13396066 }, + {1276410, -9371918, 22949635, -16322807, -23493039, -5702186, + 14711875, 4874229, -30663140, -2331391}, + {5855666, 4990204, -13711848, 7294284, -7804282, 1924647, -1423175, + -7912378, -33069337, 9234253}, + {20590503, -9018988, 31529744, -7352666, -2706834, 10650548, + 31559055, -11609587, 18979186, 13396066}, }, { - { 24474287, 4968103, 22267082, 4407354, 24063882, -8325180, -18816887, 13594782, 33514650, 7021958 }, - { -11566906, -6565505, -21365085, 15928892, -26158305, 4315421, -25948728, -3916677, -21480480, 12868082 }, - { -28635013, 13504661, 19988037, -2132761, 21078225, 6443208, -21446107, 2244500, -12455797, -8089383 }, + {24474287, 4968103, 22267082, 4407354, 24063882, -8325180, + -18816887, 13594782, 33514650, 7021958}, + {-11566906, -6565505, -21365085, 15928892, -26158305, 4315421, + -25948728, -3916677, -21480480, 12868082}, + {-28635013, 13504661, 19988037, -2132761, 21078225, 6443208, + -21446107, 2244500, -12455797, -8089383}, }, { - { -30595528, 13793479, -5852820, 319136, -25723172, -6263899, 33086546, 8957937, -15233648, 5540521 }, - { -11630176, -11503902, -8119500, -7643073, 2620056, 1022908, -23710744, -1568984, -16128528, -14962807 }, - { 23152971, 775386, 27395463, 14006635, -9701118, 4649512, 1689819, 892185, -11513277, -15205948 }, + {-30595528, 13793479, -5852820, 319136, -25723172, -6263899, + 33086546, 8957937, -15233648, 5540521}, + {-11630176, -11503902, -8119500, -7643073, 2620056, 1022908, + -23710744, -1568984, -16128528, -14962807}, + {23152971, 775386, 27395463, 14006635, -9701118, 4649512, 1689819, + 892185, -11513277, -15205948}, }, { - { 9770129, 9586738, 26496094, 4324120, 1556511, -3550024, 27453819, 4763127, -19179614, 5867134 }, - { -32765025, 1927590, 31726409, -4753295, 23962434, -16019500, 27846559, 5931263, -29749703, -16108455 }, - { 27461885, -2977536, 22380810, 1815854, -23033753, -3031938, 7283490, -15148073, -19526700, 7734629 }, + {9770129, 9586738, 26496094, 4324120, 1556511, -3550024, 27453819, + 4763127, -19179614, 5867134}, + {-32765025, 1927590, 31726409, -4753295, 23962434, -16019500, + 27846559, 5931263, -29749703, -16108455}, + {27461885, -2977536, 22380810, 1815854, -23033753, -3031938, + 7283490, -15148073, -19526700, 7734629}, }, }, { { - { -8010264, -9590817, -11120403, 6196038, 29344158, -13430885, 7585295, -3176626, 18549497, 15302069 }, - { -32658337, -6171222, -7672793, -11051681, 6258878, 13504381, 10458790, -6418461, -8872242, 8424746 }, - { 24687205, 8613276, -30667046, -3233545, 1863892, -1830544, 19206234, 7134917, -11284482, -828919 }, + {-8010264, -9590817, -11120403, 6196038, 29344158, -13430885, + 7585295, -3176626, 18549497, 15302069}, + {-32658337, -6171222, -7672793, -11051681, 6258878, 13504381, + 10458790, -6418461, -8872242, 8424746}, + {24687205, 8613276, -30667046, -3233545, 1863892, -1830544, + 19206234, 7134917, -11284482, -828919}, }, { - { 11334899, -9218022, 8025293, 12707519, 17523892, -10476071, 10243738, -14685461, -5066034, 16498837 }, - { 8911542, 6887158, -9584260, -6958590, 11145641, -9543680, 17303925, -14124238, 6536641, 10543906 }, - { -28946384, 15479763, -17466835, 568876, -1497683, 11223454, -2669190, -16625574, -27235709, 8876771 }, + {11334899, -9218022, 8025293, 12707519, 17523892, -10476071, + 10243738, -14685461, -5066034, 16498837}, + {8911542, 6887158, -9584260, -6958590, 11145641, -9543680, 17303925, + -14124238, 6536641, 10543906}, + {-28946384, 15479763, -17466835, 568876, -1497683, 11223454, + -2669190, -16625574, -27235709, 8876771}, }, { - { -25742899, -12566864, -15649966, -846607, -33026686, -796288, -33481822, 15824474, -604426, -9039817 }, - { 10330056, 70051, 7957388, -9002667, 9764902, 15609756, 27698697, -4890037, 1657394, 3084098 }, - { 10477963, -7470260, 12119566, -13250805, 29016247, -5365589, 31280319, 14396151, -30233575, 15272409 }, + {-25742899, -12566864, -15649966, -846607, -33026686, -796288, + -33481822, 15824474, -604426, -9039817}, + {10330056, 70051, 7957388, -9002667, 9764902, 15609756, 27698697, + -4890037, 1657394, 3084098}, + {10477963, -7470260, 12119566, -13250805, 29016247, -5365589, + 31280319, 14396151, -30233575, 15272409}, }, { - { -12288309, 3169463, 28813183, 16658753, 25116432, -5630466, -25173957, -12636138, -25014757, 1950504 }, - { -26180358, 9489187, 11053416, -14746161, -31053720, 5825630, -8384306, -8767532, 15341279, 8373727 }, - { 28685821, 7759505, -14378516, -12002860, -31971820, 4079242, 298136, -10232602, -2878207, 15190420 }, + {-12288309, 3169463, 28813183, 16658753, 25116432, -5630466, + -25173957, -12636138, -25014757, 1950504}, + {-26180358, 9489187, 11053416, -14746161, -31053720, 5825630, + -8384306, -8767532, 15341279, 8373727}, + {28685821, 7759505, -14378516, -12002860, -31971820, 4079242, + 298136, -10232602, -2878207, 15190420}, }, { - { -32932876, 13806336, -14337485, -15794431, -24004620, 10940928, 8669718, 2742393, -26033313, -6875003 }, - { -1580388, -11729417, -25979658, -11445023, -17411874, -10912854, 9291594, -16247779, -12154742, 6048605 }, - { -30305315, 14843444, 1539301, 11864366, 20201677, 1900163, 13934231, 5128323, 11213262, 9168384 }, + {-32932876, 13806336, -14337485, -15794431, -24004620, 10940928, + 8669718, 2742393, -26033313, -6875003}, + {-1580388, -11729417, -25979658, -11445023, -17411874, -10912854, + 9291594, -16247779, -12154742, 6048605}, + {-30305315, 14843444, 1539301, 11864366, 20201677, 1900163, + 13934231, 5128323, 11213262, 9168384}, }, { - { -26280513, 11007847, 19408960, -940758, -18592965, -4328580, -5088060, -11105150, 20470157, -16398701 }, - { -23136053, 9282192, 14855179, -15390078, -7362815, -14408560, -22783952, 14461608, 14042978, 5230683 }, - { 29969567, -2741594, -16711867, -8552442, 9175486, -2468974, 21556951, 3506042, -5933891, -12449708 }, + {-26280513, 11007847, 19408960, -940758, -18592965, -4328580, + -5088060, -11105150, 20470157, -16398701}, + {-23136053, 9282192, 14855179, -15390078, -7362815, -14408560, + -22783952, 14461608, 14042978, 5230683}, + {29969567, -2741594, -16711867, -8552442, 9175486, -2468974, + 21556951, 3506042, -5933891, -12449708}, }, { - { -3144746, 8744661, 19704003, 4581278, -20430686, 6830683, -21284170, 8971513, -28539189, 15326563 }, - { -19464629, 10110288, -17262528, -3503892, -23500387, 1355669, -15523050, 15300988, -20514118, 9168260 }, - { -5353335, 4488613, -23803248, 16314347, 7780487, -15638939, -28948358, 9601605, 33087103, -9011387 }, + {-3144746, 8744661, 19704003, 4581278, -20430686, 6830683, + -21284170, 8971513, -28539189, 15326563}, + {-19464629, 10110288, -17262528, -3503892, -23500387, 1355669, + -15523050, 15300988, -20514118, 9168260}, + {-5353335, 4488613, -23803248, 16314347, 7780487, -15638939, + -28948358, 9601605, 33087103, -9011387}, }, { - { -19443170, -15512900, -20797467, -12445323, -29824447, 10229461, -27444329, -15000531, -5996870, 15664672 }, - { 23294591, -16632613, -22650781, -8470978, 27844204, 11461195, 13099750, -2460356, 18151676, 13417686 }, - { -24722913, -4176517, -31150679, 5988919, -26858785, 6685065, 1661597, -12551441, 15271676, -15452665 }, + {-19443170, -15512900, -20797467, -12445323, -29824447, 10229461, + -27444329, -15000531, -5996870, 15664672}, + {23294591, -16632613, -22650781, -8470978, 27844204, 11461195, + 13099750, -2460356, 18151676, 13417686}, + {-24722913, -4176517, -31150679, 5988919, -26858785, 6685065, + 1661597, -12551441, 15271676, -15452665}, }, }, { { - { 11433042, -13228665, 8239631, -5279517, -1985436, -725718, -18698764, 2167544, -6921301, -13440182 }, - { -31436171, 15575146, 30436815, 12192228, -22463353, 9395379, -9917708, -8638997, 12215110, 12028277 }, - { 14098400, 6555944, 23007258, 5757252, -15427832, -12950502, 30123440, 4617780, -16900089, -655628 }, + {11433042, -13228665, 8239631, -5279517, -1985436, -725718, + -18698764, 2167544, -6921301, -13440182}, + {-31436171, 15575146, 30436815, 12192228, -22463353, 9395379, + -9917708, -8638997, 12215110, 12028277}, + {14098400, 6555944, 23007258, 5757252, -15427832, -12950502, + 30123440, 4617780, -16900089, -655628}, }, { - { -4026201, -15240835, 11893168, 13718664, -14809462, 1847385, -15819999, 10154009, 23973261, -12684474 }, - { -26531820, -3695990, -1908898, 2534301, -31870557, -16550355, 18341390, -11419951, 32013174, -10103539 }, - { -25479301, 10876443, -11771086, -14625140, -12369567, 1838104, 21911214, 6354752, 4425632, -837822 }, + {-4026201, -15240835, 11893168, 13718664, -14809462, 1847385, + -15819999, 10154009, 23973261, -12684474}, + {-26531820, -3695990, -1908898, 2534301, -31870557, -16550355, + 18341390, -11419951, 32013174, -10103539}, + {-25479301, 10876443, -11771086, -14625140, -12369567, 1838104, + 21911214, 6354752, 4425632, -837822}, }, { - { -10433389, -14612966, 22229858, -3091047, -13191166, 776729, -17415375, -12020462, 4725005, 14044970 }, - { 19268650, -7304421, 1555349, 8692754, -21474059, -9910664, 6347390, -1411784, -19522291, -16109756 }, - { -24864089, 12986008, -10898878, -5558584, -11312371, -148526, 19541418, 8180106, 9282262, 10282508 }, + {-10433389, -14612966, 22229858, -3091047, -13191166, 776729, + -17415375, -12020462, 4725005, 14044970}, + {19268650, -7304421, 1555349, 8692754, -21474059, -9910664, 6347390, + -1411784, -19522291, -16109756}, + {-24864089, 12986008, -10898878, -5558584, -11312371, -148526, + 19541418, 8180106, 9282262, 10282508}, }, { - { -26205082, 4428547, -8661196, -13194263, 4098402, -14165257, 15522535, 8372215, 5542595, -10702683 }, - { -10562541, 14895633, 26814552, -16673850, -17480754, -2489360, -2781891, 6993761, -18093885, 10114655 }, - { -20107055, -929418, 31422704, 10427861, -7110749, 6150669, -29091755, -11529146, 25953725, -106158 }, + {-26205082, 4428547, -8661196, -13194263, 4098402, -14165257, + 15522535, 8372215, 5542595, -10702683}, + {-10562541, 14895633, 26814552, -16673850, -17480754, -2489360, + -2781891, 6993761, -18093885, 10114655}, + {-20107055, -929418, 31422704, 10427861, -7110749, 6150669, + -29091755, -11529146, 25953725, -106158}, }, { - { -4234397, -8039292, -9119125, 3046000, 2101609, -12607294, 19390020, 6094296, -3315279, 12831125 }, - { -15998678, 7578152, 5310217, 14408357, -33548620, -224739, 31575954, 6326196, 7381791, -2421839 }, - { -20902779, 3296811, 24736065, -16328389, 18374254, 7318640, 6295303, 8082724, -15362489, 12339664 }, + {-4234397, -8039292, -9119125, 3046000, 2101609, -12607294, + 19390020, 6094296, -3315279, 12831125}, + {-15998678, 7578152, 5310217, 14408357, -33548620, -224739, + 31575954, 6326196, 7381791, -2421839}, + {-20902779, 3296811, 24736065, -16328389, 18374254, 7318640, + 6295303, 8082724, -15362489, 12339664}, }, { - { 27724736, 2291157, 6088201, -14184798, 1792727, 5857634, 13848414, 15768922, 25091167, 14856294 }, - { -18866652, 8331043, 24373479, 8541013, -701998, -9269457, 12927300, -12695493, -22182473, -9012899 }, - { -11423429, -5421590, 11632845, 3405020, 30536730, -11674039, -27260765, 13866390, 30146206, 9142070 }, + {27724736, 2291157, 6088201, -14184798, 1792727, 5857634, 13848414, + 15768922, 25091167, 14856294}, + {-18866652, 8331043, 24373479, 8541013, -701998, -9269457, 12927300, + -12695493, -22182473, -9012899}, + {-11423429, -5421590, 11632845, 3405020, 30536730, -11674039, + -27260765, 13866390, 30146206, 9142070}, }, { - { 3924129, -15307516, -13817122, -10054960, 12291820, -668366, -27702774, 9326384, -8237858, 4171294 }, - { -15921940, 16037937, 6713787, 16606682, -21612135, 2790944, 26396185, 3731949, 345228, -5462949 }, - { -21327538, 13448259, 25284571, 1143661, 20614966, -8849387, 2031539, -12391231, -16253183, -13582083 }, + {3924129, -15307516, -13817122, -10054960, 12291820, -668366, + -27702774, 9326384, -8237858, 4171294}, + {-15921940, 16037937, 6713787, 16606682, -21612135, 2790944, + 26396185, 3731949, 345228, -5462949}, + {-21327538, 13448259, 25284571, 1143661, 20614966, -8849387, + 2031539, -12391231, -16253183, -13582083}, }, { - { 31016211, -16722429, 26371392, -14451233, -5027349, 14854137, 17477601, 3842657, 28012650, -16405420 }, - { -5075835, 9368966, -8562079, -4600902, -15249953, 6970560, -9189873, 16292057, -8867157, 3507940 }, - { 29439664, 3537914, 23333589, 6997794, -17555561, -11018068, -15209202, -15051267, -9164929, 6580396 }, + {31016211, -16722429, 26371392, -14451233, -5027349, 14854137, + 17477601, 3842657, 28012650, -16405420}, + {-5075835, 9368966, -8562079, -4600902, -15249953, 6970560, + -9189873, 16292057, -8867157, 3507940}, + {29439664, 3537914, 23333589, 6997794, -17555561, -11018068, + -15209202, -15051267, -9164929, 6580396}, }, }, { { - { -12185861, -7679788, 16438269, 10826160, -8696817, -6235611, 17860444, -9273846, -2095802, 9304567 }, - { 20714564, -4336911, 29088195, 7406487, 11426967, -5095705, 14792667, -14608617, 5289421, -477127 }, - { -16665533, -10650790, -6160345, -13305760, 9192020, -1802462, 17271490, 12349094, 26939669, -3752294 }, + {-12185861, -7679788, 16438269, 10826160, -8696817, -6235611, + 17860444, -9273846, -2095802, 9304567}, + {20714564, -4336911, 29088195, 7406487, 11426967, -5095705, + 14792667, -14608617, 5289421, -477127}, + {-16665533, -10650790, -6160345, -13305760, 9192020, -1802462, + 17271490, 12349094, 26939669, -3752294}, }, { - { -12889898, 9373458, 31595848, 16374215, 21471720, 13221525, -27283495, -12348559, -3698806, 117887 }, - { 22263325, -6560050, 3984570, -11174646, -15114008, -566785, 28311253, 5358056, -23319780, 541964 }, - { 16259219, 3261970, 2309254, -15534474, -16885711, -4581916, 24134070, -16705829, -13337066, -13552195 }, + {-12889898, 9373458, 31595848, 16374215, 21471720, 13221525, + -27283495, -12348559, -3698806, 117887}, + {22263325, -6560050, 3984570, -11174646, -15114008, -566785, + 28311253, 5358056, -23319780, 541964}, + {16259219, 3261970, 2309254, -15534474, -16885711, -4581916, + 24134070, -16705829, -13337066, -13552195}, }, { - { 9378160, -13140186, -22845982, -12745264, 28198281, -7244098, -2399684, -717351, 690426, 14876244 }, - { 24977353, -314384, -8223969, -13465086, 28432343, -1176353, -13068804, -12297348, -22380984, 6618999 }, - { -1538174, 11685646, 12944378, 13682314, -24389511, -14413193, 8044829, -13817328, 32239829, -5652762 }, + {9378160, -13140186, -22845982, -12745264, 28198281, -7244098, + -2399684, -717351, 690426, 14876244}, + {24977353, -314384, -8223969, -13465086, 28432343, -1176353, + -13068804, -12297348, -22380984, 6618999}, + {-1538174, 11685646, 12944378, 13682314, -24389511, -14413193, + 8044829, -13817328, 32239829, -5652762}, }, { - { -18603066, 4762990, -926250, 8885304, -28412480, -3187315, 9781647, -10350059, 32779359, 5095274 }, - { -33008130, -5214506, -32264887, -3685216, 9460461, -9327423, -24601656, 14506724, 21639561, -2630236 }, - { -16400943, -13112215, 25239338, 15531969, 3987758, -4499318, -1289502, -6863535, 17874574, 558605 }, + {-18603066, 4762990, -926250, 8885304, -28412480, -3187315, 9781647, + -10350059, 32779359, 5095274}, + {-33008130, -5214506, -32264887, -3685216, 9460461, -9327423, + -24601656, 14506724, 21639561, -2630236}, + {-16400943, -13112215, 25239338, 15531969, 3987758, -4499318, + -1289502, -6863535, 17874574, 558605}, }, { - { -13600129, 10240081, 9171883, 16131053, -20869254, 9599700, 33499487, 5080151, 2085892, 5119761 }, - { -22205145, -2519528, -16381601, 414691, -25019550, 2170430, 30634760, -8363614, -31999993, -5759884 }, - { -6845704, 15791202, 8550074, -1312654, 29928809, -12092256, 27534430, -7192145, -22351378, 12961482 }, + {-13600129, 10240081, 9171883, 16131053, -20869254, 9599700, + 33499487, 5080151, 2085892, 5119761}, + {-22205145, -2519528, -16381601, 414691, -25019550, 2170430, + 30634760, -8363614, -31999993, -5759884}, + {-6845704, 15791202, 8550074, -1312654, 29928809, -12092256, + 27534430, -7192145, -22351378, 12961482}, }, { - { -24492060, -9570771, 10368194, 11582341, -23397293, -2245287, 16533930, 8206996, -30194652, -5159638 }, - { -11121496, -3382234, 2307366, 6362031, -135455, 8868177, -16835630, 7031275, 7589640, 8945490 }, - { -32152748, 8917967, 6661220, -11677616, -1192060, -15793393, 7251489, -11182180, 24099109, -14456170 }, + {-24492060, -9570771, 10368194, 11582341, -23397293, -2245287, + 16533930, 8206996, -30194652, -5159638}, + {-11121496, -3382234, 2307366, 6362031, -135455, 8868177, -16835630, + 7031275, 7589640, 8945490}, + {-32152748, 8917967, 6661220, -11677616, -1192060, -15793393, + 7251489, -11182180, 24099109, -14456170}, }, { - { 5019558, -7907470, 4244127, -14714356, -26933272, 6453165, -19118182, -13289025, -6231896, -10280736 }, - { 10853594, 10721687, 26480089, 5861829, -22995819, 1972175, -1866647, -10557898, -3363451, -6441124 }, - { -17002408, 5906790, 221599, -6563147, 7828208, -13248918, 24362661, -2008168, -13866408, 7421392 }, + {5019558, -7907470, 4244127, -14714356, -26933272, 6453165, + -19118182, -13289025, -6231896, -10280736}, + {10853594, 10721687, 26480089, 5861829, -22995819, 1972175, + -1866647, -10557898, -3363451, -6441124}, + {-17002408, 5906790, 221599, -6563147, 7828208, -13248918, 24362661, + -2008168, -13866408, 7421392}, }, { - { 8139927, -6546497, 32257646, -5890546, 30375719, 1886181, -21175108, 15441252, 28826358, -4123029 }, - { 6267086, 9695052, 7709135, -16603597, -32869068, -1886135, 14795160, -7840124, 13746021, -1742048 }, - { 28584902, 7787108, -6732942, -15050729, 22846041, -7571236, -3181936, -363524, 4771362, -8419958 }, + {8139927, -6546497, 32257646, -5890546, 30375719, 1886181, + -21175108, 15441252, 28826358, -4123029}, + {6267086, 9695052, 7709135, -16603597, -32869068, -1886135, + 14795160, -7840124, 13746021, -1742048}, + {28584902, 7787108, -6732942, -15050729, 22846041, -7571236, + -3181936, -363524, 4771362, -8419958}, }, }, { { - { 24949256, 6376279, -27466481, -8174608, -18646154, -9930606, 33543569, -12141695, 3569627, 11342593 }, - { 26514989, 4740088, 27912651, 3697550, 19331575, -11472339, 6809886, 4608608, 7325975, -14801071 }, - { -11618399, -14554430, -24321212, 7655128, -1369274, 5214312, -27400540, 10258390, -17646694, -8186692 }, + {24949256, 6376279, -27466481, -8174608, -18646154, -9930606, + 33543569, -12141695, 3569627, 11342593}, + {26514989, 4740088, 27912651, 3697550, 19331575, -11472339, 6809886, + 4608608, 7325975, -14801071}, + {-11618399, -14554430, -24321212, 7655128, -1369274, 5214312, + -27400540, 10258390, -17646694, -8186692}, }, { - { 11431204, 15823007, 26570245, 14329124, 18029990, 4796082, -31446179, 15580664, 9280358, -3973687 }, - { -160783, -10326257, -22855316, -4304997, -20861367, -13621002, -32810901, -11181622, -15545091, 4387441 }, - { -20799378, 12194512, 3937617, -5805892, -27154820, 9340370, -24513992, 8548137, 20617071, -7482001 }, + {11431204, 15823007, 26570245, 14329124, 18029990, 4796082, + -31446179, 15580664, 9280358, -3973687}, + {-160783, -10326257, -22855316, -4304997, -20861367, -13621002, + -32810901, -11181622, -15545091, 4387441}, + {-20799378, 12194512, 3937617, -5805892, -27154820, 9340370, + -24513992, 8548137, 20617071, -7482001}, }, { - { -938825, -3930586, -8714311, 16124718, 24603125, -6225393, -13775352, -11875822, 24345683, 10325460 }, - { -19855277, -1568885, -22202708, 8714034, 14007766, 6928528, 16318175, -1010689, 4766743, 3552007 }, - { -21751364, -16730916, 1351763, -803421, -4009670, 3950935, 3217514, 14481909, 10988822, -3994762 }, + {-938825, -3930586, -8714311, 16124718, 24603125, -6225393, + -13775352, -11875822, 24345683, 10325460}, + {-19855277, -1568885, -22202708, 8714034, 14007766, 6928528, + 16318175, -1010689, 4766743, 3552007}, + {-21751364, -16730916, 1351763, -803421, -4009670, 3950935, 3217514, + 14481909, 10988822, -3994762}, }, { - { 15564307, -14311570, 3101243, 5684148, 30446780, -8051356, 12677127, -6505343, -8295852, 13296005 }, - { -9442290, 6624296, -30298964, -11913677, -4670981, -2057379, 31521204, 9614054, -30000824, 12074674 }, - { 4771191, -135239, 14290749, -13089852, 27992298, 14998318, -1413936, -1556716, 29832613, -16391035 }, + {15564307, -14311570, 3101243, 5684148, 30446780, -8051356, + 12677127, -6505343, -8295852, 13296005}, + {-9442290, 6624296, -30298964, -11913677, -4670981, -2057379, + 31521204, 9614054, -30000824, 12074674}, + {4771191, -135239, 14290749, -13089852, 27992298, 14998318, + -1413936, -1556716, 29832613, -16391035}, }, { - { 7064884, -7541174, -19161962, -5067537, -18891269, -2912736, 25825242, 5293297, -27122660, 13101590 }, - { -2298563, 2439670, -7466610, 1719965, -27267541, -16328445, 32512469, -5317593, -30356070, -4190957 }, - { -30006540, 10162316, -33180176, 3981723, -16482138, -13070044, 14413974, 9515896, 19568978, 9628812 }, + {7064884, -7541174, -19161962, -5067537, -18891269, -2912736, + 25825242, 5293297, -27122660, 13101590}, + {-2298563, 2439670, -7466610, 1719965, -27267541, -16328445, + 32512469, -5317593, -30356070, -4190957}, + {-30006540, 10162316, -33180176, 3981723, -16482138, -13070044, + 14413974, 9515896, 19568978, 9628812}, }, { - { 33053803, 199357, 15894591, 1583059, 27380243, -4580435, -17838894, -6106839, -6291786, 3437740 }, - { -18978877, 3884493, 19469877, 12726490, 15913552, 13614290, -22961733, 70104, 7463304, 4176122 }, - { -27124001, 10659917, 11482427, -16070381, 12771467, -6635117, -32719404, -5322751, 24216882, 5944158 }, + {33053803, 199357, 15894591, 1583059, 27380243, -4580435, -17838894, + -6106839, -6291786, 3437740}, + {-18978877, 3884493, 19469877, 12726490, 15913552, 13614290, + -22961733, 70104, 7463304, 4176122}, + {-27124001, 10659917, 11482427, -16070381, 12771467, -6635117, + -32719404, -5322751, 24216882, 5944158}, }, { - { 8894125, 7450974, -2664149, -9765752, -28080517, -12389115, 19345746, 14680796, 11632993, 5847885 }, - { 26942781, -2315317, 9129564, -4906607, 26024105, 11769399, -11518837, 6367194, -9727230, 4782140 }, - { 19916461, -4828410, -22910704, -11414391, 25606324, -5972441, 33253853, 8220911, 6358847, -1873857 }, + {8894125, 7450974, -2664149, -9765752, -28080517, -12389115, + 19345746, 14680796, 11632993, 5847885}, + {26942781, -2315317, 9129564, -4906607, 26024105, 11769399, + -11518837, 6367194, -9727230, 4782140}, + {19916461, -4828410, -22910704, -11414391, 25606324, -5972441, + 33253853, 8220911, 6358847, -1873857}, }, { - { 801428, -2081702, 16569428, 11065167, 29875704, 96627, 7908388, -4480480, -13538503, 1387155 }, - { 19646058, 5720633, -11416706, 12814209, 11607948, 12749789, 14147075, 15156355, -21866831, 11835260 }, - { 19299512, 1155910, 28703737, 14890794, 2925026, 7269399, 26121523, 15467869, -26560550, 5052483 }, + {801428, -2081702, 16569428, 11065167, 29875704, 96627, 7908388, + -4480480, -13538503, 1387155}, + {19646058, 5720633, -11416706, 12814209, 11607948, 12749789, + 14147075, 15156355, -21866831, 11835260}, + {19299512, 1155910, 28703737, 14890794, 2925026, 7269399, 26121523, + 15467869, -26560550, 5052483}, }, }, { { - { -3017432, 10058206, 1980837, 3964243, 22160966, 12322533, -6431123, -12618185, 12228557, -7003677 }, - { 32944382, 14922211, -22844894, 5188528, 21913450, -8719943, 4001465, 13238564, -6114803, 8653815 }, - { 22865569, -4652735, 27603668, -12545395, 14348958, 8234005, 24808405, 5719875, 28483275, 2841751 }, + {-3017432, 10058206, 1980837, 3964243, 22160966, 12322533, -6431123, + -12618185, 12228557, -7003677}, + {32944382, 14922211, -22844894, 5188528, 21913450, -8719943, + 4001465, 13238564, -6114803, 8653815}, + {22865569, -4652735, 27603668, -12545395, 14348958, 8234005, + 24808405, 5719875, 28483275, 2841751}, }, { - { -16420968, -1113305, -327719, -12107856, 21886282, -15552774, -1887966, -315658, 19932058, -12739203 }, - { -11656086, 10087521, -8864888, -5536143, -19278573, -3055912, 3999228, 13239134, -4777469, -13910208 }, - { 1382174, -11694719, 17266790, 9194690, -13324356, 9720081, 20403944, 11284705, -14013818, 3093230 }, + {-16420968, -1113305, -327719, -12107856, 21886282, -15552774, + -1887966, -315658, 19932058, -12739203}, + {-11656086, 10087521, -8864888, -5536143, -19278573, -3055912, + 3999228, 13239134, -4777469, -13910208}, + {1382174, -11694719, 17266790, 9194690, -13324356, 9720081, + 20403944, 11284705, -14013818, 3093230}, }, { - { 16650921, -11037932, -1064178, 1570629, -8329746, 7352753, -302424, 16271225, -24049421, -6691850 }, - { -21911077, -5927941, -4611316, -5560156, -31744103, -10785293, 24123614, 15193618, -21652117, -16739389 }, - { -9935934, -4289447, -25279823, 4372842, 2087473, 10399484, 31870908, 14690798, 17361620, 11864968 }, + {16650921, -11037932, -1064178, 1570629, -8329746, 7352753, -302424, + 16271225, -24049421, -6691850}, + {-21911077, -5927941, -4611316, -5560156, -31744103, -10785293, + 24123614, 15193618, -21652117, -16739389}, + {-9935934, -4289447, -25279823, 4372842, 2087473, 10399484, + 31870908, 14690798, 17361620, 11864968}, }, { - { -11307610, 6210372, 13206574, 5806320, -29017692, -13967200, -12331205, -7486601, -25578460, -16240689 }, - { 14668462, -12270235, 26039039, 15305210, 25515617, 4542480, 10453892, 6577524, 9145645, -6443880 }, - { 5974874, 3053895, -9433049, -10385191, -31865124, 3225009, -7972642, 3936128, -5652273, -3050304 }, + {-11307610, 6210372, 13206574, 5806320, -29017692, -13967200, + -12331205, -7486601, -25578460, -16240689}, + {14668462, -12270235, 26039039, 15305210, 25515617, 4542480, + 10453892, 6577524, 9145645, -6443880}, + {5974874, 3053895, -9433049, -10385191, -31865124, 3225009, + -7972642, 3936128, -5652273, -3050304}, }, { - { 30625386, -4729400, -25555961, -12792866, -20484575, 7695099, 17097188, -16303496, -27999779, 1803632 }, - { -3553091, 9865099, -5228566, 4272701, -5673832, -16689700, 14911344, 12196514, -21405489, 7047412 }, - { 20093277, 9920966, -11138194, -5343857, 13161587, 12044805, -32856851, 4124601, -32343828, -10257566 }, + {30625386, -4729400, -25555961, -12792866, -20484575, 7695099, + 17097188, -16303496, -27999779, 1803632}, + {-3553091, 9865099, -5228566, 4272701, -5673832, -16689700, + 14911344, 12196514, -21405489, 7047412}, + {20093277, 9920966, -11138194, -5343857, 13161587, 12044805, + -32856851, 4124601, -32343828, -10257566}, }, { - { -20788824, 14084654, -13531713, 7842147, 19119038, -13822605, 4752377, -8714640, -21679658, 2288038 }, - { -26819236, -3283715, 29965059, 3039786, -14473765, 2540457, 29457502, 14625692, -24819617, 12570232 }, - { -1063558, -11551823, 16920318, 12494842, 1278292, -5869109, -21159943, -3498680, -11974704, 4724943 }, + {-20788824, 14084654, -13531713, 7842147, 19119038, -13822605, + 4752377, -8714640, -21679658, 2288038}, + {-26819236, -3283715, 29965059, 3039786, -14473765, 2540457, + 29457502, 14625692, -24819617, 12570232}, + {-1063558, -11551823, 16920318, 12494842, 1278292, -5869109, + -21159943, -3498680, -11974704, 4724943}, }, { - { 17960970, -11775534, -4140968, -9702530, -8876562, -1410617, -12907383, -8659932, -29576300, 1903856 }, - { 23134274, -14279132, -10681997, -1611936, 20684485, 15770816, -12989750, 3190296, 26955097, 14109738 }, - { 15308788, 5320727, -30113809, -14318877, 22902008, 7767164, 29425325, -11277562, 31960942, 11934971 }, + {17960970, -11775534, -4140968, -9702530, -8876562, -1410617, + -12907383, -8659932, -29576300, 1903856}, + {23134274, -14279132, -10681997, -1611936, 20684485, 15770816, + -12989750, 3190296, 26955097, 14109738}, + {15308788, 5320727, -30113809, -14318877, 22902008, 7767164, + 29425325, -11277562, 31960942, 11934971}, }, { - { -27395711, 8435796, 4109644, 12222639, -24627868, 14818669, 20638173, 4875028, 10491392, 1379718 }, - { -13159415, 9197841, 3875503, -8936108, -1383712, -5879801, 33518459, 16176658, 21432314, 12180697 }, - { -11787308, 11500838, 13787581, -13832590, -22430679, 10140205, 1465425, 12689540, -10301319, -13872883 }, + {-27395711, 8435796, 4109644, 12222639, -24627868, 14818669, + 20638173, 4875028, 10491392, 1379718}, + {-13159415, 9197841, 3875503, -8936108, -1383712, -5879801, + 33518459, 16176658, 21432314, 12180697}, + {-11787308, 11500838, 13787581, -13832590, -22430679, 10140205, + 1465425, 12689540, -10301319, -13872883}, }, }, { { - { 5414091, -15386041, -21007664, 9643570, 12834970, 1186149, -2622916, -1342231, 26128231, 6032912 }, - { -26337395, -13766162, 32496025, -13653919, 17847801, -12669156, 3604025, 8316894, -25875034, -10437358 }, - { 3296484, 6223048, 24680646, -12246460, -23052020, 5903205, -8862297, -4639164, 12376617, 3188849 }, + {5414091, -15386041, -21007664, 9643570, 12834970, 1186149, + -2622916, -1342231, 26128231, 6032912}, + {-26337395, -13766162, 32496025, -13653919, 17847801, -12669156, + 3604025, 8316894, -25875034, -10437358}, + {3296484, 6223048, 24680646, -12246460, -23052020, 5903205, + -8862297, -4639164, 12376617, 3188849}, }, { - { 29190488, -14659046, 27549113, -1183516, 3520066, -10697301, 32049515, -7309113, -16109234, -9852307 }, - { -14744486, -9309156, 735818, -598978, -20407687, -5057904, 25246078, -15795669, 18640741, -960977 }, - { -6928835, -16430795, 10361374, 5642961, 4910474, 12345252, -31638386, -494430, 10530747, 1053335 }, + {29190488, -14659046, 27549113, -1183516, 3520066, -10697301, + 32049515, -7309113, -16109234, -9852307}, + {-14744486, -9309156, 735818, -598978, -20407687, -5057904, + 25246078, -15795669, 18640741, -960977}, + {-6928835, -16430795, 10361374, 5642961, 4910474, 12345252, + -31638386, -494430, 10530747, 1053335}, }, { - { -29265967, -14186805, -13538216, -12117373, -19457059, -10655384, -31462369, -2948985, 24018831, 15026644 }, - { -22592535, -3145277, -2289276, 5953843, -13440189, 9425631, 25310643, 13003497, -2314791, -15145616 }, - { -27419985, -603321, -8043984, -1669117, -26092265, 13987819, -27297622, 187899, -23166419, -2531735 }, + {-29265967, -14186805, -13538216, -12117373, -19457059, -10655384, + -31462369, -2948985, 24018831, 15026644}, + {-22592535, -3145277, -2289276, 5953843, -13440189, 9425631, + 25310643, 13003497, -2314791, -15145616}, + {-27419985, -603321, -8043984, -1669117, -26092265, 13987819, + -27297622, 187899, -23166419, -2531735}, }, { - { -21744398, -13810475, 1844840, 5021428, -10434399, -15911473, 9716667, 16266922, -5070217, 726099 }, - { 29370922, -6053998, 7334071, -15342259, 9385287, 2247707, -13661962, -4839461, 30007388, -15823341 }, - { -936379, 16086691, 23751945, -543318, -1167538, -5189036, 9137109, 730663, 9835848, 4555336 }, + {-21744398, -13810475, 1844840, 5021428, -10434399, -15911473, + 9716667, 16266922, -5070217, 726099}, + {29370922, -6053998, 7334071, -15342259, 9385287, 2247707, + -13661962, -4839461, 30007388, -15823341}, + {-936379, 16086691, 23751945, -543318, -1167538, -5189036, 9137109, + 730663, 9835848, 4555336}, }, { - { -23376435, 1410446, -22253753, -12899614, 30867635, 15826977, 17693930, 544696, -11985298, 12422646 }, - { 31117226, -12215734, -13502838, 6561947, -9876867, -12757670, -5118685, -4096706, 29120153, 13924425 }, - { -17400879, -14233209, 19675799, -2734756, -11006962, -5858820, -9383939, -11317700, 7240931, -237388 }, + {-23376435, 1410446, -22253753, -12899614, 30867635, 15826977, + 17693930, 544696, -11985298, 12422646}, + {31117226, -12215734, -13502838, 6561947, -9876867, -12757670, + -5118685, -4096706, 29120153, 13924425}, + {-17400879, -14233209, 19675799, -2734756, -11006962, -5858820, + -9383939, -11317700, 7240931, -237388}, }, { - { -31361739, -11346780, -15007447, -5856218, -22453340, -12152771, 1222336, 4389483, 3293637, -15551743 }, - { -16684801, -14444245, 11038544, 11054958, -13801175, -3338533, -24319580, 7733547, 12796905, -6335822 }, - { -8759414, -10817836, -25418864, 10783769, -30615557, -9746811, -28253339, 3647836, 3222231, -11160462 }, + {-31361739, -11346780, -15007447, -5856218, -22453340, -12152771, + 1222336, 4389483, 3293637, -15551743}, + {-16684801, -14444245, 11038544, 11054958, -13801175, -3338533, + -24319580, 7733547, 12796905, -6335822}, + {-8759414, -10817836, -25418864, 10783769, -30615557, -9746811, + -28253339, 3647836, 3222231, -11160462}, }, { - { 18606113, 1693100, -25448386, -15170272, 4112353, 10045021, 23603893, -2048234, -7550776, 2484985 }, - { 9255317, -3131197, -12156162, -1004256, 13098013, -9214866, 16377220, -2102812, -19802075, -3034702 }, - { -22729289, 7496160, -5742199, 11329249, 19991973, -3347502, -31718148, 9936966, -30097688, -10618797 }, + {18606113, 1693100, -25448386, -15170272, 4112353, 10045021, + 23603893, -2048234, -7550776, 2484985}, + {9255317, -3131197, -12156162, -1004256, 13098013, -9214866, + 16377220, -2102812, -19802075, -3034702}, + {-22729289, 7496160, -5742199, 11329249, 19991973, -3347502, + -31718148, 9936966, -30097688, -10618797}, }, { - { 21878590, -5001297, 4338336, 13643897, -3036865, 13160960, 19708896, 5415497, -7360503, -4109293 }, - { 27736861, 10103576, 12500508, 8502413, -3413016, -9633558, 10436918, -1550276, -23659143, -8132100 }, - { 19492550, -12104365, -29681976, -852630, -3208171, 12403437, 30066266, 8367329, 13243957, 8709688 }, + {21878590, -5001297, 4338336, 13643897, -3036865, 13160960, + 19708896, 5415497, -7360503, -4109293}, + {27736861, 10103576, 12500508, 8502413, -3413016, -9633558, + 10436918, -1550276, -23659143, -8132100}, + {19492550, -12104365, -29681976, -852630, -3208171, 12403437, + 30066266, 8367329, 13243957, 8709688}, }, }, { { - { 12015105, 2801261, 28198131, 10151021, 24818120, -4743133, -11194191, -5645734, 5150968, 7274186 }, - { 2831366, -12492146, 1478975, 6122054, 23825128, -12733586, 31097299, 6083058, 31021603, -9793610 }, - { -2529932, -2229646, 445613, 10720828, -13849527, -11505937, -23507731, 16354465, 15067285, -14147707 }, + {12015105, 2801261, 28198131, 10151021, 24818120, -4743133, + -11194191, -5645734, 5150968, 7274186}, + {2831366, -12492146, 1478975, 6122054, 23825128, -12733586, + 31097299, 6083058, 31021603, -9793610}, + {-2529932, -2229646, 445613, 10720828, -13849527, -11505937, + -23507731, 16354465, 15067285, -14147707}, }, { - { 7840942, 14037873, -33364863, 15934016, -728213, -3642706, 21403988, 1057586, -19379462, -12403220 }, - { 915865, -16469274, 15608285, -8789130, -24357026, 6060030, -17371319, 8410997, -7220461, 16527025 }, - { 32922597, -556987, 20336074, -16184568, 10903705, -5384487, 16957574, 52992, 23834301, 6588044 }, + {7840942, 14037873, -33364863, 15934016, -728213, -3642706, + 21403988, 1057586, -19379462, -12403220}, + {915865, -16469274, 15608285, -8789130, -24357026, 6060030, + -17371319, 8410997, -7220461, 16527025}, + {32922597, -556987, 20336074, -16184568, 10903705, -5384487, + 16957574, 52992, 23834301, 6588044}, }, { - { 32752030, 11232950, 3381995, -8714866, 22652988, -10744103, 17159699, 16689107, -20314580, -1305992 }, - { -4689649, 9166776, -25710296, -10847306, 11576752, 12733943, 7924251, -2752281, 1976123, -7249027 }, - { 21251222, 16309901, -2983015, -6783122, 30810597, 12967303, 156041, -3371252, 12331345, -8237197 }, + {32752030, 11232950, 3381995, -8714866, 22652988, -10744103, + 17159699, 16689107, -20314580, -1305992}, + {-4689649, 9166776, -25710296, -10847306, 11576752, 12733943, + 7924251, -2752281, 1976123, -7249027}, + {21251222, 16309901, -2983015, -6783122, 30810597, 12967303, 156041, + -3371252, 12331345, -8237197}, }, { - { 8651614, -4477032, -16085636, -4996994, 13002507, 2950805, 29054427, -5106970, 10008136, -4667901 }, - { 31486080, 15114593, -14261250, 12951354, 14369431, -7387845, 16347321, -13662089, 8684155, -10532952 }, - { 19443825, 11385320, 24468943, -9659068, -23919258, 2187569, -26263207, -6086921, 31316348, 14219878 }, + {8651614, -4477032, -16085636, -4996994, 13002507, 2950805, + 29054427, -5106970, 10008136, -4667901}, + {31486080, 15114593, -14261250, 12951354, 14369431, -7387845, + 16347321, -13662089, 8684155, -10532952}, + {19443825, 11385320, 24468943, -9659068, -23919258, 2187569, + -26263207, -6086921, 31316348, 14219878}, }, { - { -28594490, 1193785, 32245219, 11392485, 31092169, 15722801, 27146014, 6992409, 29126555, 9207390 }, - { 32382935, 1110093, 18477781, 11028262, -27411763, -7548111, -4980517, 10843782, -7957600, -14435730 }, - { 2814918, 7836403, 27519878, -7868156, -20894015, -11553689, -21494559, 8550130, 28346258, 1994730 }, + {-28594490, 1193785, 32245219, 11392485, 31092169, 15722801, + 27146014, 6992409, 29126555, 9207390}, + {32382935, 1110093, 18477781, 11028262, -27411763, -7548111, + -4980517, 10843782, -7957600, -14435730}, + {2814918, 7836403, 27519878, -7868156, -20894015, -11553689, + -21494559, 8550130, 28346258, 1994730}, }, { - { -19578299, 8085545, -14000519, -3948622, 2785838, -16231307, -19516951, 7174894, 22628102, 8115180 }, - { -30405132, 955511, -11133838, -15078069, -32447087, -13278079, -25651578, 3317160, -9943017, 930272 }, - { -15303681, -6833769, 28856490, 1357446, 23421993, 1057177, 24091212, -1388970, -22765376, -10650715 }, + {-19578299, 8085545, -14000519, -3948622, 2785838, -16231307, + -19516951, 7174894, 22628102, 8115180}, + {-30405132, 955511, -11133838, -15078069, -32447087, -13278079, + -25651578, 3317160, -9943017, 930272}, + {-15303681, -6833769, 28856490, 1357446, 23421993, 1057177, + 24091212, -1388970, -22765376, -10650715}, }, { - { -22751231, -5303997, -12907607, -12768866, -15811511, -7797053, -14839018, -16554220, -1867018, 8398970 }, - { -31969310, 2106403, -4736360, 1362501, 12813763, 16200670, 22981545, -6291273, 18009408, -15772772 }, - { -17220923, -9545221, -27784654, 14166835, 29815394, 7444469, 29551787, -3727419, 19288549, 1325865 }, + {-22751231, -5303997, -12907607, -12768866, -15811511, -7797053, + -14839018, -16554220, -1867018, 8398970}, + {-31969310, 2106403, -4736360, 1362501, 12813763, 16200670, + 22981545, -6291273, 18009408, -15772772}, + {-17220923, -9545221, -27784654, 14166835, 29815394, 7444469, + 29551787, -3727419, 19288549, 1325865}, }, { - { 15100157, -15835752, -23923978, -1005098, -26450192, 15509408, 12376730, -3479146, 33166107, -8042750 }, - { 20909231, 13023121, -9209752, 16251778, -5778415, -8094914, 12412151, 10018715, 2213263, -13878373 }, - { 32529814, -11074689, 30361439, -16689753, -9135940, 1513226, 22922121, 6382134, -5766928, 8371348 }, + {15100157, -15835752, -23923978, -1005098, -26450192, 15509408, + 12376730, -3479146, 33166107, -8042750}, + {20909231, 13023121, -9209752, 16251778, -5778415, -8094914, + 12412151, 10018715, 2213263, -13878373}, + {32529814, -11074689, 30361439, -16689753, -9135940, 1513226, + 22922121, 6382134, -5766928, 8371348}, }, }, { { - { 9923462, 11271500, 12616794, 3544722, -29998368, -1721626, 12891687, -8193132, -26442943, 10486144 }, - { -22597207, -7012665, 8587003, -8257861, 4084309, -12970062, 361726, 2610596, -23921530, -11455195 }, - { 5408411, -1136691, -4969122, 10561668, 24145918, 14240566, 31319731, -4235541, 19985175, -3436086 }, + {9923462, 11271500, 12616794, 3544722, -29998368, -1721626, + 12891687, -8193132, -26442943, 10486144}, + {-22597207, -7012665, 8587003, -8257861, 4084309, -12970062, 361726, + 2610596, -23921530, -11455195}, + {5408411, -1136691, -4969122, 10561668, 24145918, 14240566, + 31319731, -4235541, 19985175, -3436086}, }, { - { -13994457, 16616821, 14549246, 3341099, 32155958, 13648976, -17577068, 8849297, 65030, 8370684 }, - { -8320926, -12049626, 31204563, 5839400, -20627288, -1057277, -19442942, 6922164, 12743482, -9800518 }, - { -2361371, 12678785, 28815050, 4759974, -23893047, 4884717, 23783145, 11038569, 18800704, 255233 }, + {-13994457, 16616821, 14549246, 3341099, 32155958, 13648976, + -17577068, 8849297, 65030, 8370684}, + {-8320926, -12049626, 31204563, 5839400, -20627288, -1057277, + -19442942, 6922164, 12743482, -9800518}, + {-2361371, 12678785, 28815050, 4759974, -23893047, 4884717, + 23783145, 11038569, 18800704, 255233}, }, { - { -5269658, -1773886, 13957886, 7990715, 23132995, 728773, 13393847, 9066957, 19258688, -14753793 }, - { -2936654, -10827535, -10432089, 14516793, -3640786, 4372541, -31934921, 2209390, -1524053, 2055794 }, - { 580882, 16705327, 5468415, -2683018, -30926419, -14696000, -7203346, -8994389, -30021019, 7394435 }, + {-5269658, -1773886, 13957886, 7990715, 23132995, 728773, 13393847, + 9066957, 19258688, -14753793}, + {-2936654, -10827535, -10432089, 14516793, -3640786, 4372541, + -31934921, 2209390, -1524053, 2055794}, + {580882, 16705327, 5468415, -2683018, -30926419, -14696000, + -7203346, -8994389, -30021019, 7394435}, }, { - { 23838809, 1822728, -15738443, 15242727, 8318092, -3733104, -21672180, -3492205, -4821741, 14799921 }, - { 13345610, 9759151, 3371034, -16137791, 16353039, 8577942, 31129804, 13496856, -9056018, 7402518 }, - { 2286874, -4435931, -20042458, -2008336, -13696227, 5038122, 11006906, -15760352, 8205061, 1607563 }, + {23838809, 1822728, -15738443, 15242727, 8318092, -3733104, + -21672180, -3492205, -4821741, 14799921}, + {13345610, 9759151, 3371034, -16137791, 16353039, 8577942, 31129804, + 13496856, -9056018, 7402518}, + {2286874, -4435931, -20042458, -2008336, -13696227, 5038122, + 11006906, -15760352, 8205061, 1607563}, }, { - { 14414086, -8002132, 3331830, -3208217, 22249151, -5594188, 18364661, -2906958, 30019587, -9029278 }, - { -27688051, 1585953, -10775053, 931069, -29120221, -11002319, -14410829, 12029093, 9944378, 8024 }, - { 4368715, -3709630, 29874200, -15022983, -20230386, -11410704, -16114594, -999085, -8142388, 5640030 }, + {14414086, -8002132, 3331830, -3208217, 22249151, -5594188, + 18364661, -2906958, 30019587, -9029278}, + {-27688051, 1585953, -10775053, 931069, -29120221, -11002319, + -14410829, 12029093, 9944378, 8024}, + {4368715, -3709630, 29874200, -15022983, -20230386, -11410704, + -16114594, -999085, -8142388, 5640030}, }, { - { 10299610, 13746483, 11661824, 16234854, 7630238, 5998374, 9809887, -16694564, 15219798, -14327783 }, - { 27425505, -5719081, 3055006, 10660664, 23458024, 595578, -15398605, -1173195, -18342183, 9742717 }, - { 6744077, 2427284, 26042789, 2720740, -847906, 1118974, 32324614, 7406442, 12420155, 1994844 }, + {10299610, 13746483, 11661824, 16234854, 7630238, 5998374, 9809887, + -16694564, 15219798, -14327783}, + {27425505, -5719081, 3055006, 10660664, 23458024, 595578, -15398605, + -1173195, -18342183, 9742717}, + {6744077, 2427284, 26042789, 2720740, -847906, 1118974, 32324614, + 7406442, 12420155, 1994844}, }, { - { 14012521, -5024720, -18384453, -9578469, -26485342, -3936439, -13033478, -10909803, 24319929, -6446333 }, - { 16412690, -4507367, 10772641, 15929391, -17068788, -4658621, 10555945, -10484049, -30102368, -4739048 }, - { 22397382, -7767684, -9293161, -12792868, 17166287, -9755136, -27333065, 6199366, 21880021, -12250760 }, + {14012521, -5024720, -18384453, -9578469, -26485342, -3936439, + -13033478, -10909803, 24319929, -6446333}, + {16412690, -4507367, 10772641, 15929391, -17068788, -4658621, + 10555945, -10484049, -30102368, -4739048}, + {22397382, -7767684, -9293161, -12792868, 17166287, -9755136, + -27333065, 6199366, 21880021, -12250760}, }, { - { -4283307, 5368523, -31117018, 8163389, -30323063, 3209128, 16557151, 8890729, 8840445, 4957760 }, - { -15447727, 709327, -6919446, -10870178, -29777922, 6522332, -21720181, 12130072, -14796503, 5005757 }, - { -2114751, -14308128, 23019042, 15765735, -25269683, 6002752, 10183197, -13239326, -16395286, -2176112 }, + {-4283307, 5368523, -31117018, 8163389, -30323063, 3209128, + 16557151, 8890729, 8840445, 4957760}, + {-15447727, 709327, -6919446, -10870178, -29777922, 6522332, + -21720181, 12130072, -14796503, 5005757}, + {-2114751, -14308128, 23019042, 15765735, -25269683, 6002752, + 10183197, -13239326, -16395286, -2176112}, }, }, { { - { -19025756, 1632005, 13466291, -7995100, -23640451, 16573537, -32013908, -3057104, 22208662, 2000468 }, - { 3065073, -1412761, -25598674, -361432, -17683065, -5703415, -8164212, 11248527, -3691214, -7414184 }, - { 10379208, -6045554, 8877319, 1473647, -29291284, -12507580, 16690915, 2553332, -3132688, 16400289 }, + {-19025756, 1632005, 13466291, -7995100, -23640451, 16573537, + -32013908, -3057104, 22208662, 2000468}, + {3065073, -1412761, -25598674, -361432, -17683065, -5703415, + -8164212, 11248527, -3691214, -7414184}, + {10379208, -6045554, 8877319, 1473647, -29291284, -12507580, + 16690915, 2553332, -3132688, 16400289}, }, { - { 15716668, 1254266, -18472690, 7446274, -8448918, 6344164, -22097271, -7285580, 26894937, 9132066 }, - { 24158887, 12938817, 11085297, -8177598, -28063478, -4457083, -30576463, 64452, -6817084, -2692882 }, - { 13488534, 7794716, 22236231, 5989356, 25426474, -12578208, 2350710, -3418511, -4688006, 2364226 }, + {15716668, 1254266, -18472690, 7446274, -8448918, 6344164, + -22097271, -7285580, 26894937, 9132066}, + {24158887, 12938817, 11085297, -8177598, -28063478, -4457083, + -30576463, 64452, -6817084, -2692882}, + {13488534, 7794716, 22236231, 5989356, 25426474, -12578208, 2350710, + -3418511, -4688006, 2364226}, }, { - { 16335052, 9132434, 25640582, 6678888, 1725628, 8517937, -11807024, -11697457, 15445875, -7798101 }, - { 29004207, -7867081, 28661402, -640412, -12794003, -7943086, 31863255, -4135540, -278050, -15759279 }, - { -6122061, -14866665, -28614905, 14569919, -10857999, -3591829, 10343412, -6976290, -29828287, -10815811 }, + {16335052, 9132434, 25640582, 6678888, 1725628, 8517937, -11807024, + -11697457, 15445875, -7798101}, + {29004207, -7867081, 28661402, -640412, -12794003, -7943086, + 31863255, -4135540, -278050, -15759279}, + {-6122061, -14866665, -28614905, 14569919, -10857999, -3591829, + 10343412, -6976290, -29828287, -10815811}, }, { - { 27081650, 3463984, 14099042, -4517604, 1616303, -6205604, 29542636, 15372179, 17293797, 960709 }, - { 20263915, 11434237, -5765435, 11236810, 13505955, -10857102, -16111345, 6493122, -19384511, 7639714 }, - { -2830798, -14839232, 25403038, -8215196, -8317012, -16173699, 18006287, -16043750, 29994677, -15808121 }, + {27081650, 3463984, 14099042, -4517604, 1616303, -6205604, 29542636, + 15372179, 17293797, 960709}, + {20263915, 11434237, -5765435, 11236810, 13505955, -10857102, + -16111345, 6493122, -19384511, 7639714}, + {-2830798, -14839232, 25403038, -8215196, -8317012, -16173699, + 18006287, -16043750, 29994677, -15808121}, }, { - { 9769828, 5202651, -24157398, -13631392, -28051003, -11561624, -24613141, -13860782, -31184575, 709464 }, - { 12286395, 13076066, -21775189, -1176622, -25003198, 4057652, -32018128, -8890874, 16102007, 13205847 }, - { 13733362, 5599946, 10557076, 3195751, -5557991, 8536970, -25540170, 8525972, 10151379, 10394400 }, + {9769828, 5202651, -24157398, -13631392, -28051003, -11561624, + -24613141, -13860782, -31184575, 709464}, + {12286395, 13076066, -21775189, -1176622, -25003198, 4057652, + -32018128, -8890874, 16102007, 13205847}, + {13733362, 5599946, 10557076, 3195751, -5557991, 8536970, -25540170, + 8525972, 10151379, 10394400}, }, { - { 4024660, -16137551, 22436262, 12276534, -9099015, -2686099, 19698229, 11743039, -33302334, 8934414 }, - { -15879800, -4525240, -8580747, -2934061, 14634845, -698278, -9449077, 3137094, -11536886, 11721158 }, - { 17555939, -5013938, 8268606, 2331751, -22738815, 9761013, 9319229, 8835153, -9205489, -1280045 }, + {4024660, -16137551, 22436262, 12276534, -9099015, -2686099, + 19698229, 11743039, -33302334, 8934414}, + {-15879800, -4525240, -8580747, -2934061, 14634845, -698278, + -9449077, 3137094, -11536886, 11721158}, + {17555939, -5013938, 8268606, 2331751, -22738815, 9761013, 9319229, + 8835153, -9205489, -1280045}, }, { - { -461409, -7830014, 20614118, 16688288, -7514766, -4807119, 22300304, 505429, 6108462, -6183415 }, - { -5070281, 12367917, -30663534, 3234473, 32617080, -8422642, 29880583, -13483331, -26898490, -7867459 }, - { -31975283, 5726539, 26934134, 10237677, -3173717, -605053, 24199304, 3795095, 7592688, -14992079 }, + {-461409, -7830014, 20614118, 16688288, -7514766, -4807119, + 22300304, 505429, 6108462, -6183415}, + {-5070281, 12367917, -30663534, 3234473, 32617080, -8422642, + 29880583, -13483331, -26898490, -7867459}, + {-31975283, 5726539, 26934134, 10237677, -3173717, -605053, + 24199304, 3795095, 7592688, -14992079}, }, { - { 21594432, -14964228, 17466408, -4077222, 32537084, 2739898, 6407723, 12018833, -28256052, 4298412 }, - { -20650503, -11961496, -27236275, 570498, 3767144, -1717540, 13891942, -1569194, 13717174, 10805743 }, - { -14676630, -15644296, 15287174, 11927123, 24177847, -8175568, -796431, 14860609, -26938930, -5863836 }, + {21594432, -14964228, 17466408, -4077222, 32537084, 2739898, + 6407723, 12018833, -28256052, 4298412}, + {-20650503, -11961496, -27236275, 570498, 3767144, -1717540, + 13891942, -1569194, 13717174, 10805743}, + {-14676630, -15644296, 15287174, 11927123, 24177847, -8175568, + -796431, 14860609, -26938930, -5863836}, }, }, { { - { 12962541, 5311799, -10060768, 11658280, 18855286, -7954201, 13286263, -12808704, -4381056, 9882022 }, - { 18512079, 11319350, -20123124, 15090309, 18818594, 5271736, -22727904, 3666879, -23967430, -3299429 }, - { -6789020, -3146043, 16192429, 13241070, 15898607, -14206114, -10084880, -6661110, -2403099, 5276065 }, + {12962541, 5311799, -10060768, 11658280, 18855286, -7954201, + 13286263, -12808704, -4381056, 9882022}, + {18512079, 11319350, -20123124, 15090309, 18818594, 5271736, + -22727904, 3666879, -23967430, -3299429}, + {-6789020, -3146043, 16192429, 13241070, 15898607, -14206114, + -10084880, -6661110, -2403099, 5276065}, }, { - { 30169808, -5317648, 26306206, -11750859, 27814964, 7069267, 7152851, 3684982, 1449224, 13082861 }, - { 10342826, 3098505, 2119311, 193222, 25702612, 12233820, 23697382, 15056736, -21016438, -8202000 }, - { -33150110, 3261608, 22745853, 7948688, 19370557, -15177665, -26171976, 6482814, -10300080, -11060101 }, + {30169808, -5317648, 26306206, -11750859, 27814964, 7069267, + 7152851, 3684982, 1449224, 13082861}, + {10342826, 3098505, 2119311, 193222, 25702612, 12233820, 23697382, + 15056736, -21016438, -8202000}, + {-33150110, 3261608, 22745853, 7948688, 19370557, -15177665, + -26171976, 6482814, -10300080, -11060101}, }, { - { 32869458, -5408545, 25609743, 15678670, -10687769, -15471071, 26112421, 2521008, -22664288, 6904815 }, - { 29506923, 4457497, 3377935, -9796444, -30510046, 12935080, 1561737, 3841096, -29003639, -6657642 }, - { 10340844, -6630377, -18656632, -2278430, 12621151, -13339055, 30878497, -11824370, -25584551, 5181966 }, + {32869458, -5408545, 25609743, 15678670, -10687769, -15471071, + 26112421, 2521008, -22664288, 6904815}, + {29506923, 4457497, 3377935, -9796444, -30510046, 12935080, 1561737, + 3841096, -29003639, -6657642}, + {10340844, -6630377, -18656632, -2278430, 12621151, -13339055, + 30878497, -11824370, -25584551, 5181966}, }, { - { 25940115, -12658025, 17324188, -10307374, -8671468, 15029094, 24396252, -16450922, -2322852, -12388574 }, - { -21765684, 9916823, -1300409, 4079498, -1028346, 11909559, 1782390, 12641087, 20603771, -6561742 }, - { -18882287, -11673380, 24849422, 11501709, 13161720, -4768874, 1925523, 11914390, 4662781, 7820689 }, + {25940115, -12658025, 17324188, -10307374, -8671468, 15029094, + 24396252, -16450922, -2322852, -12388574}, + {-21765684, 9916823, -1300409, 4079498, -1028346, 11909559, 1782390, + 12641087, 20603771, -6561742}, + {-18882287, -11673380, 24849422, 11501709, 13161720, -4768874, + 1925523, 11914390, 4662781, 7820689}, }, { - { 12241050, -425982, 8132691, 9393934, 32846760, -1599620, 29749456, 12172924, 16136752, 15264020 }, - { -10349955, -14680563, -8211979, 2330220, -17662549, -14545780, 10658213, 6671822, 19012087, 3772772 }, - { 3753511, -3421066, 10617074, 2028709, 14841030, -6721664, 28718732, -15762884, 20527771, 12988982 }, + {12241050, -425982, 8132691, 9393934, 32846760, -1599620, 29749456, + 12172924, 16136752, 15264020}, + {-10349955, -14680563, -8211979, 2330220, -17662549, -14545780, + 10658213, 6671822, 19012087, 3772772}, + {3753511, -3421066, 10617074, 2028709, 14841030, -6721664, 28718732, + -15762884, 20527771, 12988982}, }, { - { -14822485, -5797269, -3707987, 12689773, -898983, -10914866, -24183046, -10564943, 3299665, -12424953 }, - { -16777703, -15253301, -9642417, 4978983, 3308785, 8755439, 6943197, 6461331, -25583147, 8991218 }, - { -17226263, 1816362, -1673288, -6086439, 31783888, -8175991, -32948145, 7417950, -30242287, 1507265 }, + {-14822485, -5797269, -3707987, 12689773, -898983, -10914866, + -24183046, -10564943, 3299665, -12424953}, + {-16777703, -15253301, -9642417, 4978983, 3308785, 8755439, 6943197, + 6461331, -25583147, 8991218}, + {-17226263, 1816362, -1673288, -6086439, 31783888, -8175991, + -32948145, 7417950, -30242287, 1507265}, }, { - { 29692663, 6829891, -10498800, 4334896, 20945975, -11906496, -28887608, 8209391, 14606362, -10647073 }, - { -3481570, 8707081, 32188102, 5672294, 22096700, 1711240, -33020695, 9761487, 4170404, -2085325 }, - { -11587470, 14855945, -4127778, -1531857, -26649089, 15084046, 22186522, 16002000, -14276837, -8400798 }, + {29692663, 6829891, -10498800, 4334896, 20945975, -11906496, + -28887608, 8209391, 14606362, -10647073}, + {-3481570, 8707081, 32188102, 5672294, 22096700, 1711240, -33020695, + 9761487, 4170404, -2085325}, + {-11587470, 14855945, -4127778, -1531857, -26649089, 15084046, + 22186522, 16002000, -14276837, -8400798}, }, { - { -4811456, 13761029, -31703877, -2483919, -3312471, 7869047, -7113572, -9620092, 13240845, 10965870 }, - { -7742563, -8256762, -14768334, -13656260, -23232383, 12387166, 4498947, 14147411, 29514390, 4302863 }, - { -13413405, -12407859, 20757302, -13801832, 14785143, 8976368, -5061276, -2144373, 17846988, -13971927 }, + {-4811456, 13761029, -31703877, -2483919, -3312471, 7869047, + -7113572, -9620092, 13240845, 10965870}, + {-7742563, -8256762, -14768334, -13656260, -23232383, 12387166, + 4498947, 14147411, 29514390, 4302863}, + {-13413405, -12407859, 20757302, -13801832, 14785143, 8976368, + -5061276, -2144373, 17846988, -13971927}, }, }, { { - { -2244452, -754728, -4597030, -1066309, -6247172, 1455299, -21647728, -9214789, -5222701, 12650267 }, - { -9906797, -16070310, 21134160, 12198166, -27064575, 708126, 387813, 13770293, -19134326, 10958663 }, - { 22470984, 12369526, 23446014, -5441109, -21520802, -9698723, -11772496, -11574455, -25083830, 4271862 }, + {-2244452, -754728, -4597030, -1066309, -6247172, 1455299, + -21647728, -9214789, -5222701, 12650267}, + {-9906797, -16070310, 21134160, 12198166, -27064575, 708126, 387813, + 13770293, -19134326, 10958663}, + {22470984, 12369526, 23446014, -5441109, -21520802, -9698723, + -11772496, -11574455, -25083830, 4271862}, }, { - { -25169565, -10053642, -19909332, 15361595, -5984358, 2159192, 75375, -4278529, -32526221, 8469673 }, - { 15854970, 4148314, -8893890, 7259002, 11666551, 13824734, -30531198, 2697372, 24154791, -9460943 }, - { 15446137, -15806644, 29759747, 14019369, 30811221, -9610191, -31582008, 12840104, 24913809, 9815020 }, + {-25169565, -10053642, -19909332, 15361595, -5984358, 2159192, + 75375, -4278529, -32526221, 8469673}, + {15854970, 4148314, -8893890, 7259002, 11666551, 13824734, + -30531198, 2697372, 24154791, -9460943}, + {15446137, -15806644, 29759747, 14019369, 30811221, -9610191, + -31582008, 12840104, 24913809, 9815020}, }, { - { -4709286, -5614269, -31841498, -12288893, -14443537, 10799414, -9103676, 13438769, 18735128, 9466238 }, - { 11933045, 9281483, 5081055, -5183824, -2628162, -4905629, -7727821, -10896103, -22728655, 16199064 }, - { 14576810, 379472, -26786533, -8317236, -29426508, -10812974, -102766, 1876699, 30801119, 2164795 }, + {-4709286, -5614269, -31841498, -12288893, -14443537, 10799414, + -9103676, 13438769, 18735128, 9466238}, + {11933045, 9281483, 5081055, -5183824, -2628162, -4905629, -7727821, + -10896103, -22728655, 16199064}, + {14576810, 379472, -26786533, -8317236, -29426508, -10812974, + -102766, 1876699, 30801119, 2164795}, }, { - { 15995086, 3199873, 13672555, 13712240, -19378835, -4647646, -13081610, -15496269, -13492807, 1268052 }, - { -10290614, -3659039, -3286592, 10948818, 23037027, 3794475, -3470338, -12600221, -17055369, 3565904 }, - { 29210088, -9419337, -5919792, -4952785, 10834811, -13327726, -16512102, -10820713, -27162222, -14030531 }, + {15995086, 3199873, 13672555, 13712240, -19378835, -4647646, + -13081610, -15496269, -13492807, 1268052}, + {-10290614, -3659039, -3286592, 10948818, 23037027, 3794475, + -3470338, -12600221, -17055369, 3565904}, + {29210088, -9419337, -5919792, -4952785, 10834811, -13327726, + -16512102, -10820713, -27162222, -14030531}, }, { - { -13161890, 15508588, 16663704, -8156150, -28349942, 9019123, -29183421, -3769423, 2244111, -14001979 }, - { -5152875, -3800936, -9306475, -6071583, 16243069, 14684434, -25673088, -16180800, 13491506, 4641841 }, - { 10813417, 643330, -19188515, -728916, 30292062, -16600078, 27548447, -7721242, 14476989, -12767431 }, + {-13161890, 15508588, 16663704, -8156150, -28349942, 9019123, + -29183421, -3769423, 2244111, -14001979}, + {-5152875, -3800936, -9306475, -6071583, 16243069, 14684434, + -25673088, -16180800, 13491506, 4641841}, + {10813417, 643330, -19188515, -728916, 30292062, -16600078, + 27548447, -7721242, 14476989, -12767431}, }, { - { 10292079, 9984945, 6481436, 8279905, -7251514, 7032743, 27282937, -1644259, -27912810, 12651324 }, - { -31185513, -813383, 22271204, 11835308, 10201545, 15351028, 17099662, 3988035, 21721536, -3148940 }, - { 10202177, -6545839, -31373232, -9574638, -32150642, -8119683, -12906320, 3852694, 13216206, 14842320 }, + {10292079, 9984945, 6481436, 8279905, -7251514, 7032743, 27282937, + -1644259, -27912810, 12651324}, + {-31185513, -813383, 22271204, 11835308, 10201545, 15351028, + 17099662, 3988035, 21721536, -3148940}, + {10202177, -6545839, -31373232, -9574638, -32150642, -8119683, + -12906320, 3852694, 13216206, 14842320}, }, { - { -15815640, -10601066, -6538952, -7258995, -6984659, -6581778, -31500847, 13765824, -27434397, 9900184 }, - { 14465505, -13833331, -32133984, -14738873, -27443187, 12990492, 33046193, 15796406, -7051866, -8040114 }, - { 30924417, -8279620, 6359016, -12816335, 16508377, 9071735, -25488601, 15413635, 9524356, -7018878 }, + {-15815640, -10601066, -6538952, -7258995, -6984659, -6581778, + -31500847, 13765824, -27434397, 9900184}, + {14465505, -13833331, -32133984, -14738873, -27443187, 12990492, + 33046193, 15796406, -7051866, -8040114}, + {30924417, -8279620, 6359016, -12816335, 16508377, 9071735, + -25488601, 15413635, 9524356, -7018878}, }, { - { 12274201, -13175547, 32627641, -1785326, 6736625, 13267305, 5237659, -5109483, 15663516, 4035784 }, - { -2951309, 8903985, 17349946, 601635, -16432815, -4612556, -13732739, -15889334, -22258478, 4659091 }, - { -16916263, -4952973, -30393711, -15158821, 20774812, 15897498, 5736189, 15026997, -2178256, -13455585 }, + {12274201, -13175547, 32627641, -1785326, 6736625, 13267305, + 5237659, -5109483, 15663516, 4035784}, + {-2951309, 8903985, 17349946, 601635, -16432815, -4612556, + -13732739, -15889334, -22258478, 4659091}, + {-16916263, -4952973, -30393711, -15158821, 20774812, 15897498, + 5736189, 15026997, -2178256, -13455585}, }, }, { { - { -8858980, -2219056, 28571666, -10155518, -474467, -10105698, -3801496, 278095, 23440562, -290208 }, - { 10226241, -5928702, 15139956, 120818, -14867693, 5218603, 32937275, 11551483, -16571960, -7442864 }, - { 17932739, -12437276, -24039557, 10749060, 11316803, 7535897, 22503767, 5561594, -3646624, 3898661 }, + {-8858980, -2219056, 28571666, -10155518, -474467, -10105698, + -3801496, 278095, 23440562, -290208}, + {10226241, -5928702, 15139956, 120818, -14867693, 5218603, 32937275, + 11551483, -16571960, -7442864}, + {17932739, -12437276, -24039557, 10749060, 11316803, 7535897, + 22503767, 5561594, -3646624, 3898661}, }, { - { 7749907, -969567, -16339731, -16464, -25018111, 15122143, -1573531, 7152530, 21831162, 1245233 }, - { 26958459, -14658026, 4314586, 8346991, -5677764, 11960072, -32589295, -620035, -30402091, -16716212 }, - { -12165896, 9166947, 33491384, 13673479, 29787085, 13096535, 6280834, 14587357, -22338025, 13987525 }, + {7749907, -969567, -16339731, -16464, -25018111, 15122143, -1573531, + 7152530, 21831162, 1245233}, + {26958459, -14658026, 4314586, 8346991, -5677764, 11960072, + -32589295, -620035, -30402091, -16716212}, + {-12165896, 9166947, 33491384, 13673479, 29787085, 13096535, + 6280834, 14587357, -22338025, 13987525}, }, { - { -24349909, 7778775, 21116000, 15572597, -4833266, -5357778, -4300898, -5124639, -7469781, -2858068 }, - { 9681908, -6737123, -31951644, 13591838, -6883821, 386950, 31622781, 6439245, -14581012, 4091397 }, - { -8426427, 1470727, -28109679, -1596990, 3978627, -5123623, -19622683, 12092163, 29077877, -14741988 }, + {-24349909, 7778775, 21116000, 15572597, -4833266, -5357778, + -4300898, -5124639, -7469781, -2858068}, + {9681908, -6737123, -31951644, 13591838, -6883821, 386950, 31622781, + 6439245, -14581012, 4091397}, + {-8426427, 1470727, -28109679, -1596990, 3978627, -5123623, + -19622683, 12092163, 29077877, -14741988}, }, { - { 5269168, -6859726, -13230211, -8020715, 25932563, 1763552, -5606110, -5505881, -20017847, 2357889 }, - { 32264008, -15407652, -5387735, -1160093, -2091322, -3946900, 23104804, -12869908, 5727338, 189038 }, - { 14609123, -8954470, -6000566, -16622781, -14577387, -7743898, -26745169, 10942115, -25888931, -14884697 }, + {5269168, -6859726, -13230211, -8020715, 25932563, 1763552, + -5606110, -5505881, -20017847, 2357889}, + {32264008, -15407652, -5387735, -1160093, -2091322, -3946900, + 23104804, -12869908, 5727338, 189038}, + {14609123, -8954470, -6000566, -16622781, -14577387, -7743898, + -26745169, 10942115, -25888931, -14884697}, }, { - { 20513500, 5557931, -15604613, 7829531, 26413943, -2019404, -21378968, 7471781, 13913677, -5137875 }, - { -25574376, 11967826, 29233242, 12948236, -6754465, 4713227, -8940970, 14059180, 12878652, 8511905 }, - { -25656801, 3393631, -2955415, -7075526, -2250709, 9366908, -30223418, 6812974, 5568676, -3127656 }, + {20513500, 5557931, -15604613, 7829531, 26413943, -2019404, + -21378968, 7471781, 13913677, -5137875}, + {-25574376, 11967826, 29233242, 12948236, -6754465, 4713227, + -8940970, 14059180, 12878652, 8511905}, + {-25656801, 3393631, -2955415, -7075526, -2250709, 9366908, + -30223418, 6812974, 5568676, -3127656}, }, { - { 11630004, 12144454, 2116339, 13606037, 27378885, 15676917, -17408753, -13504373, -14395196, 8070818 }, - { 27117696, -10007378, -31282771, -5570088, 1127282, 12772488, -29845906, 10483306, -11552749, -1028714 }, - { 10637467, -5688064, 5674781, 1072708, -26343588, -6982302, -1683975, 9177853, -27493162, 15431203 }, + {11630004, 12144454, 2116339, 13606037, 27378885, 15676917, + -17408753, -13504373, -14395196, 8070818}, + {27117696, -10007378, -31282771, -5570088, 1127282, 12772488, + -29845906, 10483306, -11552749, -1028714}, + {10637467, -5688064, 5674781, 1072708, -26343588, -6982302, + -1683975, 9177853, -27493162, 15431203}, }, { - { 20525145, 10892566, -12742472, 12779443, -29493034, 16150075, -28240519, 14943142, -15056790, -7935931 }, - { -30024462, 5626926, -551567, -9981087, 753598, 11981191, 25244767, -3239766, -3356550, 9594024 }, - { -23752644, 2636870, -5163910, -10103818, 585134, 7877383, 11345683, -6492290, 13352335, -10977084 }, + {20525145, 10892566, -12742472, 12779443, -29493034, 16150075, + -28240519, 14943142, -15056790, -7935931}, + {-30024462, 5626926, -551567, -9981087, 753598, 11981191, 25244767, + -3239766, -3356550, 9594024}, + {-23752644, 2636870, -5163910, -10103818, 585134, 7877383, 11345683, + -6492290, 13352335, -10977084}, }, { - { -1931799, -5407458, 3304649, -12884869, 17015806, -4877091, -29783850, -7752482, -13215537, -319204 }, - { 20239939, 6607058, 6203985, 3483793, -18386976, -779229, -20723742, 15077870, -22750759, 14523817 }, - { 27406042, -6041657, 27423596, -4497394, 4996214, 10002360, -28842031, -4545494, -30172742, -4805667 }, + {-1931799, -5407458, 3304649, -12884869, 17015806, -4877091, + -29783850, -7752482, -13215537, -319204}, + {20239939, 6607058, 6203985, 3483793, -18386976, -779229, -20723742, + 15077870, -22750759, 14523817}, + {27406042, -6041657, 27423596, -4497394, 4996214, 10002360, + -28842031, -4545494, -30172742, -4805667}, }, }, { { - { 11374242, 12660715, 17861383, -12540833, 10935568, 1099227, -13886076, -9091740, -27727044, 11358504 }, - { -12730809, 10311867, 1510375, 10778093, -2119455, -9145702, 32676003, 11149336, -26123651, 4985768 }, - { -19096303, 341147, -6197485, -239033, 15756973, -8796662, -983043, 13794114, -19414307, -15621255 }, + {11374242, 12660715, 17861383, -12540833, 10935568, 1099227, + -13886076, -9091740, -27727044, 11358504}, + {-12730809, 10311867, 1510375, 10778093, -2119455, -9145702, + 32676003, 11149336, -26123651, 4985768}, + {-19096303, 341147, -6197485, -239033, 15756973, -8796662, -983043, + 13794114, -19414307, -15621255}, }, { - { 6490081, 11940286, 25495923, -7726360, 8668373, -8751316, 3367603, 6970005, -1691065, -9004790 }, - { 1656497, 13457317, 15370807, 6364910, 13605745, 8362338, -19174622, -5475723, -16796596, -5031438 }, - { -22273315, -13524424, -64685, -4334223, -18605636, -10921968, -20571065, -7007978, -99853, -10237333 }, + {6490081, 11940286, 25495923, -7726360, 8668373, -8751316, 3367603, + 6970005, -1691065, -9004790}, + {1656497, 13457317, 15370807, 6364910, 13605745, 8362338, -19174622, + -5475723, -16796596, -5031438}, + {-22273315, -13524424, -64685, -4334223, -18605636, -10921968, + -20571065, -7007978, -99853, -10237333}, }, { - { 17747465, 10039260, 19368299, -4050591, -20630635, -16041286, 31992683, -15857976, -29260363, -5511971 }, - { 31932027, -4986141, -19612382, 16366580, 22023614, 88450, 11371999, -3744247, 4882242, -10626905 }, - { 29796507, 37186, 19818052, 10115756, -11829032, 3352736, 18551198, 3272828, -5190932, -4162409 }, + {17747465, 10039260, 19368299, -4050591, -20630635, -16041286, + 31992683, -15857976, -29260363, -5511971}, + {31932027, -4986141, -19612382, 16366580, 22023614, 88450, 11371999, + -3744247, 4882242, -10626905}, + {29796507, 37186, 19818052, 10115756, -11829032, 3352736, 18551198, + 3272828, -5190932, -4162409}, }, { - { 12501286, 4044383, -8612957, -13392385, -32430052, 5136599, -19230378, -3529697, 330070, -3659409 }, - { 6384877, 2899513, 17807477, 7663917, -2358888, 12363165, 25366522, -8573892, -271295, 12071499 }, - { -8365515, -4042521, 25133448, -4517355, -6211027, 2265927, -32769618, 1936675, -5159697, 3829363 }, + {12501286, 4044383, -8612957, -13392385, -32430052, 5136599, + -19230378, -3529697, 330070, -3659409}, + {6384877, 2899513, 17807477, 7663917, -2358888, 12363165, 25366522, + -8573892, -271295, 12071499}, + {-8365515, -4042521, 25133448, -4517355, -6211027, 2265927, + -32769618, 1936675, -5159697, 3829363}, }, { - { 28425966, -5835433, -577090, -4697198, -14217555, 6870930, 7921550, -6567787, 26333140, 14267664 }, - { -11067219, 11871231, 27385719, -10559544, -4585914, -11189312, 10004786, -8709488, -21761224, 8930324 }, - { -21197785, -16396035, 25654216, -1725397, 12282012, 11008919, 1541940, 4757911, -26491501, -16408940 }, + {28425966, -5835433, -577090, -4697198, -14217555, 6870930, 7921550, + -6567787, 26333140, 14267664}, + {-11067219, 11871231, 27385719, -10559544, -4585914, -11189312, + 10004786, -8709488, -21761224, 8930324}, + {-21197785, -16396035, 25654216, -1725397, 12282012, 11008919, + 1541940, 4757911, -26491501, -16408940}, }, { - { 13537262, -7759490, -20604840, 10961927, -5922820, -13218065, -13156584, 6217254, -15943699, 13814990 }, - { -17422573, 15157790, 18705543, 29619, 24409717, -260476, 27361681, 9257833, -1956526, -1776914 }, - { -25045300, -10191966, 15366585, 15166509, -13105086, 8423556, -29171540, 12361135, -18685978, 4578290 }, + {13537262, -7759490, -20604840, 10961927, -5922820, -13218065, + -13156584, 6217254, -15943699, 13814990}, + {-17422573, 15157790, 18705543, 29619, 24409717, -260476, 27361681, + 9257833, -1956526, -1776914}, + {-25045300, -10191966, 15366585, 15166509, -13105086, 8423556, + -29171540, 12361135, -18685978, 4578290}, }, { - { 24579768, 3711570, 1342322, -11180126, -27005135, 14124956, -22544529, 14074919, 21964432, 8235257 }, - { -6528613, -2411497, 9442966, -5925588, 12025640, -1487420, -2981514, -1669206, 13006806, 2355433 }, - { -16304899, -13605259, -6632427, -5142349, 16974359, -10911083, 27202044, 1719366, 1141648, -12796236 }, + {24579768, 3711570, 1342322, -11180126, -27005135, 14124956, + -22544529, 14074919, 21964432, 8235257}, + {-6528613, -2411497, 9442966, -5925588, 12025640, -1487420, + -2981514, -1669206, 13006806, 2355433}, + {-16304899, -13605259, -6632427, -5142349, 16974359, -10911083, + 27202044, 1719366, 1141648, -12796236}, }, { - { -12863944, -13219986, -8318266, -11018091, -6810145, -4843894, 13475066, -3133972, 32674895, 13715045 }, - { 11423335, -5468059, 32344216, 8962751, 24989809, 9241752, -13265253, 16086212, -28740881, -15642093 }, - { -1409668, 12530728, -6368726, 10847387, 19531186, -14132160, -11709148, 7791794, -27245943, 4383347 }, + {-12863944, -13219986, -8318266, -11018091, -6810145, -4843894, + 13475066, -3133972, 32674895, 13715045}, + {11423335, -5468059, 32344216, 8962751, 24989809, 9241752, + -13265253, 16086212, -28740881, -15642093}, + {-1409668, 12530728, -6368726, 10847387, 19531186, -14132160, + -11709148, 7791794, -27245943, 4383347}, }, }, { { - { -28970898, 5271447, -1266009, -9736989, -12455236, 16732599, -4862407, -4906449, 27193557, 6245191 }, - { -15193956, 5362278, -1783893, 2695834, 4960227, 12840725, 23061898, 3260492, 22510453, 8577507 }, - { -12632451, 11257346, -32692994, 13548177, -721004, 10879011, 31168030, 13952092, -29571492, -3635906 }, + {-28970898, 5271447, -1266009, -9736989, -12455236, 16732599, + -4862407, -4906449, 27193557, 6245191}, + {-15193956, 5362278, -1783893, 2695834, 4960227, 12840725, 23061898, + 3260492, 22510453, 8577507}, + {-12632451, 11257346, -32692994, 13548177, -721004, 10879011, + 31168030, 13952092, -29571492, -3635906}, }, { - { 3877321, -9572739, 32416692, 5405324, -11004407, -13656635, 3759769, 11935320, 5611860, 8164018 }, - { -16275802, 14667797, 15906460, 12155291, -22111149, -9039718, 32003002, -8832289, 5773085, -8422109 }, - { -23788118, -8254300, 1950875, 8937633, 18686727, 16459170, -905725, 12376320, 31632953, 190926 }, + {3877321, -9572739, 32416692, 5405324, -11004407, -13656635, + 3759769, 11935320, 5611860, 8164018}, + {-16275802, 14667797, 15906460, 12155291, -22111149, -9039718, + 32003002, -8832289, 5773085, -8422109}, + {-23788118, -8254300, 1950875, 8937633, 18686727, 16459170, -905725, + 12376320, 31632953, 190926}, }, { - { -24593607, -16138885, -8423991, 13378746, 14162407, 6901328, -8288749, 4508564, -25341555, -3627528 }, - { 8884438, -5884009, 6023974, 10104341, -6881569, -4941533, 18722941, -14786005, -1672488, 827625 }, - { -32720583, -16289296, -32503547, 7101210, 13354605, 2659080, -1800575, -14108036, -24878478, 1541286 }, + {-24593607, -16138885, -8423991, 13378746, 14162407, 6901328, + -8288749, 4508564, -25341555, -3627528}, + {8884438, -5884009, 6023974, 10104341, -6881569, -4941533, 18722941, + -14786005, -1672488, 827625}, + {-32720583, -16289296, -32503547, 7101210, 13354605, 2659080, + -1800575, -14108036, -24878478, 1541286}, }, { - { 2901347, -1117687, 3880376, -10059388, -17620940, -3612781, -21802117, -3567481, 20456845, -1885033 }, - { 27019610, 12299467, -13658288, -1603234, -12861660, -4861471, -19540150, -5016058, 29439641, 15138866 }, - { 21536104, -6626420, -32447818, -10690208, -22408077, 5175814, -5420040, -16361163, 7779328, 109896 }, + {2901347, -1117687, 3880376, -10059388, -17620940, -3612781, + -21802117, -3567481, 20456845, -1885033}, + {27019610, 12299467, -13658288, -1603234, -12861660, -4861471, + -19540150, -5016058, 29439641, 15138866}, + {21536104, -6626420, -32447818, -10690208, -22408077, 5175814, + -5420040, -16361163, 7779328, 109896}, }, { - { 30279744, 14648750, -8044871, 6425558, 13639621, -743509, 28698390, 12180118, 23177719, -554075 }, - { 26572847, 3405927, -31701700, 12890905, -19265668, 5335866, -6493768, 2378492, 4439158, -13279347 }, - { -22716706, 3489070, -9225266, -332753, 18875722, -1140095, 14819434, -12731527, -17717757, -5461437 }, + {30279744, 14648750, -8044871, 6425558, 13639621, -743509, 28698390, + 12180118, 23177719, -554075}, + {26572847, 3405927, -31701700, 12890905, -19265668, 5335866, + -6493768, 2378492, 4439158, -13279347}, + {-22716706, 3489070, -9225266, -332753, 18875722, -1140095, + 14819434, -12731527, -17717757, -5461437}, }, { - { -5056483, 16566551, 15953661, 3767752, -10436499, 15627060, -820954, 2177225, 8550082, -15114165 }, - { -18473302, 16596775, -381660, 15663611, 22860960, 15585581, -27844109, -3582739, -23260460, -8428588 }, - { -32480551, 15707275, -8205912, -5652081, 29464558, 2713815, -22725137, 15860482, -21902570, 1494193 }, + {-5056483, 16566551, 15953661, 3767752, -10436499, 15627060, + -820954, 2177225, 8550082, -15114165}, + {-18473302, 16596775, -381660, 15663611, 22860960, 15585581, + -27844109, -3582739, -23260460, -8428588}, + {-32480551, 15707275, -8205912, -5652081, 29464558, 2713815, + -22725137, 15860482, -21902570, 1494193}, }, { - { -19562091, -14087393, -25583872, -9299552, 13127842, 759709, 21923482, 16529112, 8742704, 12967017 }, - { -28464899, 1553205, 32536856, -10473729, -24691605, -406174, -8914625, -2933896, -29903758, 15553883 }, - { 21877909, 3230008, 9881174, 10539357, -4797115, 2841332, 11543572, 14513274, 19375923, -12647961 }, + {-19562091, -14087393, -25583872, -9299552, 13127842, 759709, + 21923482, 16529112, 8742704, 12967017}, + {-28464899, 1553205, 32536856, -10473729, -24691605, -406174, + -8914625, -2933896, -29903758, 15553883}, + {21877909, 3230008, 9881174, 10539357, -4797115, 2841332, 11543572, + 14513274, 19375923, -12647961}, }, { - { 8832269, -14495485, 13253511, 5137575, 5037871, 4078777, 24880818, -6222716, 2862653, 9455043 }, - { 29306751, 5123106, 20245049, -14149889, 9592566, 8447059, -2077124, -2990080, 15511449, 4789663 }, - { -20679756, 7004547, 8824831, -9434977, -4045704, -3750736, -5754762, 108893, 23513200, 16652362 }, + {8832269, -14495485, 13253511, 5137575, 5037871, 4078777, 24880818, + -6222716, 2862653, 9455043}, + {29306751, 5123106, 20245049, -14149889, 9592566, 8447059, -2077124, + -2990080, 15511449, 4789663}, + {-20679756, 7004547, 8824831, -9434977, -4045704, -3750736, + -5754762, 108893, 23513200, 16652362}, }, }, { { - { -33256173, 4144782, -4476029, -6579123, 10770039, -7155542, -6650416, -12936300, -18319198, 10212860 }, - { 2756081, 8598110, 7383731, -6859892, 22312759, -1105012, 21179801, 2600940, -9988298, -12506466 }, - { -24645692, 13317462, -30449259, -15653928, 21365574, -10869657, 11344424, 864440, -2499677, -16710063 }, + {-33256173, 4144782, -4476029, -6579123, 10770039, -7155542, + -6650416, -12936300, -18319198, 10212860}, + {2756081, 8598110, 7383731, -6859892, 22312759, -1105012, 21179801, + 2600940, -9988298, -12506466}, + {-24645692, 13317462, -30449259, -15653928, 21365574, -10869657, + 11344424, 864440, -2499677, -16710063}, }, { - { -26432803, 6148329, -17184412, -14474154, 18782929, -275997, -22561534, 211300, 2719757, 4940997 }, - { -1323882, 3911313, -6948744, 14759765, -30027150, 7851207, 21690126, 8518463, 26699843, 5276295 }, - { -13149873, -6429067, 9396249, 365013, 24703301, -10488939, 1321586, 149635, -15452774, 7159369 }, + {-26432803, 6148329, -17184412, -14474154, 18782929, -275997, + -22561534, 211300, 2719757, 4940997}, + {-1323882, 3911313, -6948744, 14759765, -30027150, 7851207, + 21690126, 8518463, 26699843, 5276295}, + {-13149873, -6429067, 9396249, 365013, 24703301, -10488939, 1321586, + 149635, -15452774, 7159369}, }, { - { 9987780, -3404759, 17507962, 9505530, 9731535, -2165514, 22356009, 8312176, 22477218, -8403385 }, - { 18155857, -16504990, 19744716, 9006923, 15154154, -10538976, 24256460, -4864995, -22548173, 9334109 }, - { 2986088, -4911893, 10776628, -3473844, 10620590, -7083203, -21413845, 14253545, -22587149, 536906 }, + {9987780, -3404759, 17507962, 9505530, 9731535, -2165514, 22356009, + 8312176, 22477218, -8403385}, + {18155857, -16504990, 19744716, 9006923, 15154154, -10538976, + 24256460, -4864995, -22548173, 9334109}, + {2986088, -4911893, 10776628, -3473844, 10620590, -7083203, + -21413845, 14253545, -22587149, 536906}, }, { - { 4377756, 8115836, 24567078, 15495314, 11625074, 13064599, 7390551, 10589625, 10838060, -15420424 }, - { -19342404, 867880, 9277171, -3218459, -14431572, -1986443, 19295826, -15796950, 6378260, 699185 }, - { 7895026, 4057113, -7081772, -13077756, -17886831, -323126, -716039, 15693155, -5045064, -13373962 }, + {4377756, 8115836, 24567078, 15495314, 11625074, 13064599, 7390551, + 10589625, 10838060, -15420424}, + {-19342404, 867880, 9277171, -3218459, -14431572, -1986443, + 19295826, -15796950, 6378260, 699185}, + {7895026, 4057113, -7081772, -13077756, -17886831, -323126, -716039, + 15693155, -5045064, -13373962}, }, { - { -7737563, -5869402, -14566319, -7406919, 11385654, 13201616, 31730678, -10962840, -3918636, -9669325 }, - { 10188286, -15770834, -7336361, 13427543, 22223443, 14896287, 30743455, 7116568, -21786507, 5427593 }, - { 696102, 13206899, 27047647, -10632082, 15285305, -9853179, 10798490, -4578720, 19236243, 12477404 }, + {-7737563, -5869402, -14566319, -7406919, 11385654, 13201616, + 31730678, -10962840, -3918636, -9669325}, + {10188286, -15770834, -7336361, 13427543, 22223443, 14896287, + 30743455, 7116568, -21786507, 5427593}, + {696102, 13206899, 27047647, -10632082, 15285305, -9853179, + 10798490, -4578720, 19236243, 12477404}, }, { - { -11229439, 11243796, -17054270, -8040865, -788228, -8167967, -3897669, 11180504, -23169516, 7733644 }, - { 17800790, -14036179, -27000429, -11766671, 23887827, 3149671, 23466177, -10538171, 10322027, 15313801 }, - { 26246234, 11968874, 32263343, -5468728, 6830755, -13323031, -15794704, -101982, -24449242, 10890804 }, + {-11229439, 11243796, -17054270, -8040865, -788228, -8167967, + -3897669, 11180504, -23169516, 7733644}, + {17800790, -14036179, -27000429, -11766671, 23887827, 3149671, + 23466177, -10538171, 10322027, 15313801}, + {26246234, 11968874, 32263343, -5468728, 6830755, -13323031, + -15794704, -101982, -24449242, 10890804}, }, { - { -31365647, 10271363, -12660625, -6267268, 16690207, -13062544, -14982212, 16484931, 25180797, -5334884 }, - { -586574, 10376444, -32586414, -11286356, 19801893, 10997610, 2276632, 9482883, 316878, 13820577 }, - { -9882808, -4510367, -2115506, 16457136, -11100081, 11674996, 30756178, -7515054, 30696930, -3712849 }, + {-31365647, 10271363, -12660625, -6267268, 16690207, -13062544, + -14982212, 16484931, 25180797, -5334884}, + {-586574, 10376444, -32586414, -11286356, 19801893, 10997610, + 2276632, 9482883, 316878, 13820577}, + {-9882808, -4510367, -2115506, 16457136, -11100081, 11674996, + 30756178, -7515054, 30696930, -3712849}, }, { - { 32988917, -9603412, 12499366, 7910787, -10617257, -11931514, -7342816, -9985397, -32349517, 7392473 }, - { -8855661, 15927861, 9866406, -3649411, -2396914, -16655781, -30409476, -9134995, 25112947, -2926644 }, - { -2504044, -436966, 25621774, -5678772, 15085042, -5479877, -24884878, -13526194, 5537438, -13914319 }, + {32988917, -9603412, 12499366, 7910787, -10617257, -11931514, + -7342816, -9985397, -32349517, 7392473}, + {-8855661, 15927861, 9866406, -3649411, -2396914, -16655781, + -30409476, -9134995, 25112947, -2926644}, + {-2504044, -436966, 25621774, -5678772, 15085042, -5479877, + -24884878, -13526194, 5537438, -13914319}, }, }, { { - { -11225584, 2320285, -9584280, 10149187, -33444663, 5808648, -14876251, -1729667, 31234590, 6090599 }, - { -9633316, 116426, 26083934, 2897444, -6364437, -2688086, 609721, 15878753, -6970405, -9034768 }, - { -27757857, 247744, -15194774, -9002551, 23288161, -10011936, -23869595, 6503646, 20650474, 1804084 }, + {-11225584, 2320285, -9584280, 10149187, -33444663, 5808648, + -14876251, -1729667, 31234590, 6090599}, + {-9633316, 116426, 26083934, 2897444, -6364437, -2688086, 609721, + 15878753, -6970405, -9034768}, + {-27757857, 247744, -15194774, -9002551, 23288161, -10011936, + -23869595, 6503646, 20650474, 1804084}, }, { - { -27589786, 15456424, 8972517, 8469608, 15640622, 4439847, 3121995, -10329713, 27842616, -202328 }, - { -15306973, 2839644, 22530074, 10026331, 4602058, 5048462, 28248656, 5031932, -11375082, 12714369 }, - { 20807691, -7270825, 29286141, 11421711, -27876523, -13868230, -21227475, 1035546, -19733229, 12796920 }, + {-27589786, 15456424, 8972517, 8469608, 15640622, 4439847, 3121995, + -10329713, 27842616, -202328}, + {-15306973, 2839644, 22530074, 10026331, 4602058, 5048462, 28248656, + 5031932, -11375082, 12714369}, + {20807691, -7270825, 29286141, 11421711, -27876523, -13868230, + -21227475, 1035546, -19733229, 12796920}, }, { - { 12076899, -14301286, -8785001, -11848922, -25012791, 16400684, -17591495, -12899438, 3480665, -15182815 }, - { -32361549, 5457597, 28548107, 7833186, 7303070, -11953545, -24363064, -15921875, -33374054, 2771025 }, - { -21389266, 421932, 26597266, 6860826, 22486084, -6737172, -17137485, -4210226, -24552282, 15673397 }, + {12076899, -14301286, -8785001, -11848922, -25012791, 16400684, + -17591495, -12899438, 3480665, -15182815}, + {-32361549, 5457597, 28548107, 7833186, 7303070, -11953545, + -24363064, -15921875, -33374054, 2771025}, + {-21389266, 421932, 26597266, 6860826, 22486084, -6737172, + -17137485, -4210226, -24552282, 15673397}, }, { - { -20184622, 2338216, 19788685, -9620956, -4001265, -8740893, -20271184, 4733254, 3727144, -12934448 }, - { 6120119, 814863, -11794402, -622716, 6812205, -15747771, 2019594, 7975683, 31123697, -10958981 }, - { 30069250, -11435332, 30434654, 2958439, 18399564, -976289, 12296869, 9204260, -16432438, 9648165 }, + {-20184622, 2338216, 19788685, -9620956, -4001265, -8740893, + -20271184, 4733254, 3727144, -12934448}, + {6120119, 814863, -11794402, -622716, 6812205, -15747771, 2019594, + 7975683, 31123697, -10958981}, + {30069250, -11435332, 30434654, 2958439, 18399564, -976289, + 12296869, 9204260, -16432438, 9648165}, }, { - { 32705432, -1550977, 30705658, 7451065, -11805606, 9631813, 3305266, 5248604, -26008332, -11377501 }, - { 17219865, 2375039, -31570947, -5575615, -19459679, 9219903, 294711, 15298639, 2662509, -16297073 }, - { -1172927, -7558695, -4366770, -4287744, -21346413, -8434326, 32087529, -1222777, 32247248, -14389861 }, + {32705432, -1550977, 30705658, 7451065, -11805606, 9631813, 3305266, + 5248604, -26008332, -11377501}, + {17219865, 2375039, -31570947, -5575615, -19459679, 9219903, 294711, + 15298639, 2662509, -16297073}, + {-1172927, -7558695, -4366770, -4287744, -21346413, -8434326, + 32087529, -1222777, 32247248, -14389861}, }, { - { 14312628, 1221556, 17395390, -8700143, -4945741, -8684635, -28197744, -9637817, -16027623, -13378845 }, - { -1428825, -9678990, -9235681, 6549687, -7383069, -468664, 23046502, 9803137, 17597934, 2346211 }, - { 18510800, 15337574, 26171504, 981392, -22241552, 7827556, -23491134, -11323352, 3059833, -11782870 }, + {14312628, 1221556, 17395390, -8700143, -4945741, -8684635, + -28197744, -9637817, -16027623, -13378845}, + {-1428825, -9678990, -9235681, 6549687, -7383069, -468664, 23046502, + 9803137, 17597934, 2346211}, + {18510800, 15337574, 26171504, 981392, -22241552, 7827556, + -23491134, -11323352, 3059833, -11782870}, }, { - { 10141598, 6082907, 17829293, -1947643, 9830092, 13613136, -25556636, -5544586, -33502212, 3592096 }, - { 33114168, -15889352, -26525686, -13343397, 33076705, 8716171, 1151462, 1521897, -982665, -6837803 }, - { -32939165, -4255815, 23947181, -324178, -33072974, -12305637, -16637686, 3891704, 26353178, 693168 }, + {10141598, 6082907, 17829293, -1947643, 9830092, 13613136, + -25556636, -5544586, -33502212, 3592096}, + {33114168, -15889352, -26525686, -13343397, 33076705, 8716171, + 1151462, 1521897, -982665, -6837803}, + {-32939165, -4255815, 23947181, -324178, -33072974, -12305637, + -16637686, 3891704, 26353178, 693168}, }, { - { 30374239, 1595580, -16884039, 13186931, 4600344, 406904, 9585294, -400668, 31375464, 14369965 }, - { -14370654, -7772529, 1510301, 6434173, -18784789, -6262728, 32732230, -13108839, 17901441, 16011505 }, - { 18171223, -11934626, -12500402, 15197122, -11038147, -15230035, -19172240, -16046376, 8764035, 12309598 }, + {30374239, 1595580, -16884039, 13186931, 4600344, 406904, 9585294, + -400668, 31375464, 14369965}, + {-14370654, -7772529, 1510301, 6434173, -18784789, -6262728, + 32732230, -13108839, 17901441, 16011505}, + {18171223, -11934626, -12500402, 15197122, -11038147, -15230035, + -19172240, -16046376, 8764035, 12309598}, }, }, { { - { 5975908, -5243188, -19459362, -9681747, -11541277, 14015782, -23665757, 1228319, 17544096, -10593782 }, - { 5811932, -1715293, 3442887, -2269310, -18367348, -8359541, -18044043, -15410127, -5565381, 12348900 }, - { -31399660, 11407555, 25755363, 6891399, -3256938, 14872274, -24849353, 8141295, -10632534, -585479 }, + {5975908, -5243188, -19459362, -9681747, -11541277, 14015782, + -23665757, 1228319, 17544096, -10593782}, + {5811932, -1715293, 3442887, -2269310, -18367348, -8359541, + -18044043, -15410127, -5565381, 12348900}, + {-31399660, 11407555, 25755363, 6891399, -3256938, 14872274, + -24849353, 8141295, -10632534, -585479}, }, { - { -12675304, 694026, -5076145, 13300344, 14015258, -14451394, -9698672, -11329050, 30944593, 1130208 }, - { 8247766, -6710942, -26562381, -7709309, -14401939, -14648910, 4652152, 2488540, 23550156, -271232 }, - { 17294316, -3788438, 7026748, 15626851, 22990044, 113481, 2267737, -5908146, -408818, -137719 }, + {-12675304, 694026, -5076145, 13300344, 14015258, -14451394, + -9698672, -11329050, 30944593, 1130208}, + {8247766, -6710942, -26562381, -7709309, -14401939, -14648910, + 4652152, 2488540, 23550156, -271232}, + {17294316, -3788438, 7026748, 15626851, 22990044, 113481, 2267737, + -5908146, -408818, -137719}, }, { - { 16091085, -16253926, 18599252, 7340678, 2137637, -1221657, -3364161, 14550936, 3260525, -7166271 }, - { -4910104, -13332887, 18550887, 10864893, -16459325, -7291596, -23028869, -13204905, -12748722, 2701326 }, - { -8574695, 16099415, 4629974, -16340524, -20786213, -6005432, -10018363, 9276971, 11329923, 1862132 }, + {16091085, -16253926, 18599252, 7340678, 2137637, -1221657, + -3364161, 14550936, 3260525, -7166271}, + {-4910104, -13332887, 18550887, 10864893, -16459325, -7291596, + -23028869, -13204905, -12748722, 2701326}, + {-8574695, 16099415, 4629974, -16340524, -20786213, -6005432, + -10018363, 9276971, 11329923, 1862132}, }, { - { 14763076, -15903608, -30918270, 3689867, 3511892, 10313526, -21951088, 12219231, -9037963, -940300 }, - { 8894987, -3446094, 6150753, 3013931, 301220, 15693451, -31981216, -2909717, -15438168, 11595570 }, - { 15214962, 3537601, -26238722, -14058872, 4418657, -15230761, 13947276, 10730794, -13489462, -4363670 }, + {14763076, -15903608, -30918270, 3689867, 3511892, 10313526, + -21951088, 12219231, -9037963, -940300}, + {8894987, -3446094, 6150753, 3013931, 301220, 15693451, -31981216, + -2909717, -15438168, 11595570}, + {15214962, 3537601, -26238722, -14058872, 4418657, -15230761, + 13947276, 10730794, -13489462, -4363670}, }, { - { -2538306, 7682793, 32759013, 263109, -29984731, -7955452, -22332124, -10188635, 977108, 699994 }, - { -12466472, 4195084, -9211532, 550904, -15565337, 12917920, 19118110, -439841, -30534533, -14337913 }, - { 31788461, -14507657, 4799989, 7372237, 8808585, -14747943, 9408237, -10051775, 12493932, -5409317 }, + {-2538306, 7682793, 32759013, 263109, -29984731, -7955452, + -22332124, -10188635, 977108, 699994}, + {-12466472, 4195084, -9211532, 550904, -15565337, 12917920, + 19118110, -439841, -30534533, -14337913}, + {31788461, -14507657, 4799989, 7372237, 8808585, -14747943, 9408237, + -10051775, 12493932, -5409317}, }, { - { -25680606, 5260744, -19235809, -6284470, -3695942, 16566087, 27218280, 2607121, 29375955, 6024730 }, - { 842132, -2794693, -4763381, -8722815, 26332018, -12405641, 11831880, 6985184, -9940361, 2854096 }, - { -4847262, -7969331, 2516242, -5847713, 9695691, -7221186, 16512645, 960770, 12121869, 16648078 }, + {-25680606, 5260744, -19235809, -6284470, -3695942, 16566087, + 27218280, 2607121, 29375955, 6024730}, + {842132, -2794693, -4763381, -8722815, 26332018, -12405641, + 11831880, 6985184, -9940361, 2854096}, + {-4847262, -7969331, 2516242, -5847713, 9695691, -7221186, 16512645, + 960770, 12121869, 16648078}, }, { - { -15218652, 14667096, -13336229, 2013717, 30598287, -464137, -31504922, -7882064, 20237806, 2838411 }, - { -19288047, 4453152, 15298546, -16178388, 22115043, -15972604, 12544294, -13470457, 1068881, -12499905 }, - { -9558883, -16518835, 33238498, 13506958, 30505848, -1114596, -8486907, -2630053, 12521378, 4845654 }, + {-15218652, 14667096, -13336229, 2013717, 30598287, -464137, + -31504922, -7882064, 20237806, 2838411}, + {-19288047, 4453152, 15298546, -16178388, 22115043, -15972604, + 12544294, -13470457, 1068881, -12499905}, + {-9558883, -16518835, 33238498, 13506958, 30505848, -1114596, + -8486907, -2630053, 12521378, 4845654}, }, { - { -28198521, 10744108, -2958380, 10199664, 7759311, -13088600, 3409348, -873400, -6482306, -12885870 }, - { -23561822, 6230156, -20382013, 10655314, -24040585, -11621172, 10477734, -1240216, -3113227, 13974498 }, - { 12966261, 15550616, -32038948, -1615346, 21025980, -629444, 5642325, 7188737, 18895762, 12629579 }, + {-28198521, 10744108, -2958380, 10199664, 7759311, -13088600, + 3409348, -873400, -6482306, -12885870}, + {-23561822, 6230156, -20382013, 10655314, -24040585, -11621172, + 10477734, -1240216, -3113227, 13974498}, + {12966261, 15550616, -32038948, -1615346, 21025980, -629444, + 5642325, 7188737, 18895762, 12629579}, }, }, { { - { 14741879, -14946887, 22177208, -11721237, 1279741, 8058600, 11758140, 789443, 32195181, 3895677 }, - { 10758205, 15755439, -4509950, 9243698, -4879422, 6879879, -2204575, -3566119, -8982069, 4429647 }, - { -2453894, 15725973, -20436342, -10410672, -5803908, -11040220, -7135870, -11642895, 18047436, -15281743 }, + {14741879, -14946887, 22177208, -11721237, 1279741, 8058600, + 11758140, 789443, 32195181, 3895677}, + {10758205, 15755439, -4509950, 9243698, -4879422, 6879879, -2204575, + -3566119, -8982069, 4429647}, + {-2453894, 15725973, -20436342, -10410672, -5803908, -11040220, + -7135870, -11642895, 18047436, -15281743}, }, { - { -25173001, -11307165, 29759956, 11776784, -22262383, -15820455, 10993114, -12850837, -17620701, -9408468 }, - { 21987233, 700364, -24505048, 14972008, -7774265, -5718395, 32155026, 2581431, -29958985, 8773375 }, - { -25568350, 454463, -13211935, 16126715, 25240068, 8594567, 20656846, 12017935, -7874389, -13920155 }, + {-25173001, -11307165, 29759956, 11776784, -22262383, -15820455, + 10993114, -12850837, -17620701, -9408468}, + {21987233, 700364, -24505048, 14972008, -7774265, -5718395, + 32155026, 2581431, -29958985, 8773375}, + {-25568350, 454463, -13211935, 16126715, 25240068, 8594567, + 20656846, 12017935, -7874389, -13920155}, }, { - { 6028182, 6263078, -31011806, -11301710, -818919, 2461772, -31841174, -5468042, -1721788, -2776725 }, - { -12278994, 16624277, 987579, -5922598, 32908203, 1248608, 7719845, -4166698, 28408820, 6816612 }, - { -10358094, -8237829, 19549651, -12169222, 22082623, 16147817, 20613181, 13982702, -10339570, 5067943 }, + {6028182, 6263078, -31011806, -11301710, -818919, 2461772, + -31841174, -5468042, -1721788, -2776725}, + {-12278994, 16624277, 987579, -5922598, 32908203, 1248608, 7719845, + -4166698, 28408820, 6816612}, + {-10358094, -8237829, 19549651, -12169222, 22082623, 16147817, + 20613181, 13982702, -10339570, 5067943}, }, { - { -30505967, -3821767, 12074681, 13582412, -19877972, 2443951, -19719286, 12746132, 5331210, -10105944 }, - { 30528811, 3601899, -1957090, 4619785, -27361822, -15436388, 24180793, -12570394, 27679908, -1648928 }, - { 9402404, -13957065, 32834043, 10838634, -26580150, -13237195, 26653274, -8685565, 22611444, -12715406 }, + {-30505967, -3821767, 12074681, 13582412, -19877972, 2443951, + -19719286, 12746132, 5331210, -10105944}, + {30528811, 3601899, -1957090, 4619785, -27361822, -15436388, + 24180793, -12570394, 27679908, -1648928}, + {9402404, -13957065, 32834043, 10838634, -26580150, -13237195, + 26653274, -8685565, 22611444, -12715406}, }, { - { 22190590, 1118029, 22736441, 15130463, -30460692, -5991321, 19189625, -4648942, 4854859, 6622139 }, - { -8310738, -2953450, -8262579, -3388049, -10401731, -271929, 13424426, -3567227, 26404409, 13001963 }, - { -31241838, -15415700, -2994250, 8939346, 11562230, -12840670, -26064365, -11621720, -15405155, 11020693 }, + {22190590, 1118029, 22736441, 15130463, -30460692, -5991321, + 19189625, -4648942, 4854859, 6622139}, + {-8310738, -2953450, -8262579, -3388049, -10401731, -271929, + 13424426, -3567227, 26404409, 13001963}, + {-31241838, -15415700, -2994250, 8939346, 11562230, -12840670, + -26064365, -11621720, -15405155, 11020693}, }, { - { 1866042, -7949489, -7898649, -10301010, 12483315, 13477547, 3175636, -12424163, 28761762, 1406734 }, - { -448555, -1777666, 13018551, 3194501, -9580420, -11161737, 24760585, -4347088, 25577411, -13378680 }, - { -24290378, 4759345, -690653, -1852816, 2066747, 10693769, -29595790, 9884936, -9368926, 4745410 }, + {1866042, -7949489, -7898649, -10301010, 12483315, 13477547, + 3175636, -12424163, 28761762, 1406734}, + {-448555, -1777666, 13018551, 3194501, -9580420, -11161737, + 24760585, -4347088, 25577411, -13378680}, + {-24290378, 4759345, -690653, -1852816, 2066747, 10693769, + -29595790, 9884936, -9368926, 4745410}, }, { - { -9141284, 6049714, -19531061, -4341411, -31260798, 9944276, -15462008, -11311852, 10931924, -11931931 }, - { -16561513, 14112680, -8012645, 4817318, -8040464, -11414606, -22853429, 10856641, -20470770, 13434654 }, - { 22759489, -10073434, -16766264, -1871422, 13637442, -10168091, 1765144, -12654326, 28445307, -5364710 }, + {-9141284, 6049714, -19531061, -4341411, -31260798, 9944276, + -15462008, -11311852, 10931924, -11931931}, + {-16561513, 14112680, -8012645, 4817318, -8040464, -11414606, + -22853429, 10856641, -20470770, 13434654}, + {22759489, -10073434, -16766264, -1871422, 13637442, -10168091, + 1765144, -12654326, 28445307, -5364710}, }, { - { 29875063, 12493613, 2795536, -3786330, 1710620, 15181182, -10195717, -8788675, 9074234, 1167180 }, - { -26205683, 11014233, -9842651, -2635485, -26908120, 7532294, -18716888, -9535498, 3843903, 9367684 }, - { -10969595, -6403711, 9591134, 9582310, 11349256, 108879, 16235123, 8601684, -139197, 4242895 }, + {29875063, 12493613, 2795536, -3786330, 1710620, 15181182, + -10195717, -8788675, 9074234, 1167180}, + {-26205683, 11014233, -9842651, -2635485, -26908120, 7532294, + -18716888, -9535498, 3843903, 9367684}, + {-10969595, -6403711, 9591134, 9582310, 11349256, 108879, 16235123, + 8601684, -139197, 4242895}, }, }, { { - { 22092954, -13191123, -2042793, -11968512, 32186753, -11517388, -6574341, 2470660, -27417366, 16625501 }, - { -11057722, 3042016, 13770083, -9257922, 584236, -544855, -7770857, 2602725, -27351616, 14247413 }, - { 6314175, -10264892, -32772502, 15957557, -10157730, 168750, -8618807, 14290061, 27108877, -1180880 }, + {22092954, -13191123, -2042793, -11968512, 32186753, -11517388, + -6574341, 2470660, -27417366, 16625501}, + {-11057722, 3042016, 13770083, -9257922, 584236, -544855, -7770857, + 2602725, -27351616, 14247413}, + {6314175, -10264892, -32772502, 15957557, -10157730, 168750, + -8618807, 14290061, 27108877, -1180880}, }, { - { -8586597, -7170966, 13241782, 10960156, -32991015, -13794596, 33547976, -11058889, -27148451, 981874 }, - { 22833440, 9293594, -32649448, -13618667, -9136966, 14756819, -22928859, -13970780, -10479804, -16197962 }, - { -7768587, 3326786, -28111797, 10783824, 19178761, 14905060, 22680049, 13906969, -15933690, 3797899 }, + {-8586597, -7170966, 13241782, 10960156, -32991015, -13794596, + 33547976, -11058889, -27148451, 981874}, + {22833440, 9293594, -32649448, -13618667, -9136966, 14756819, + -22928859, -13970780, -10479804, -16197962}, + {-7768587, 3326786, -28111797, 10783824, 19178761, 14905060, + 22680049, 13906969, -15933690, 3797899}, }, { - { 21721356, -4212746, -12206123, 9310182, -3882239, -13653110, 23740224, -2709232, 20491983, -8042152 }, - { 9209270, -15135055, -13256557, -6167798, -731016, 15289673, 25947805, 15286587, 30997318, -6703063 }, - { 7392032, 16618386, 23946583, -8039892, -13265164, -1533858, -14197445, -2321576, 17649998, -250080 }, + {21721356, -4212746, -12206123, 9310182, -3882239, -13653110, + 23740224, -2709232, 20491983, -8042152}, + {9209270, -15135055, -13256557, -6167798, -731016, 15289673, + 25947805, 15286587, 30997318, -6703063}, + {7392032, 16618386, 23946583, -8039892, -13265164, -1533858, + -14197445, -2321576, 17649998, -250080}, }, { - { -9301088, -14193827, 30609526, -3049543, -25175069, -1283752, -15241566, -9525724, -2233253, 7662146 }, - { -17558673, 1763594, -33114336, 15908610, -30040870, -12174295, 7335080, -8472199, -3174674, 3440183 }, - { -19889700, -5977008, -24111293, -9688870, 10799743, -16571957, 40450, -4431835, 4862400, 1133 }, + {-9301088, -14193827, 30609526, -3049543, -25175069, -1283752, + -15241566, -9525724, -2233253, 7662146}, + {-17558673, 1763594, -33114336, 15908610, -30040870, -12174295, + 7335080, -8472199, -3174674, 3440183}, + {-19889700, -5977008, -24111293, -9688870, 10799743, -16571957, + 40450, -4431835, 4862400, 1133}, }, { - { -32856209, -7873957, -5422389, 14860950, -16319031, 7956142, 7258061, 311861, -30594991, -7379421 }, - { -3773428, -1565936, 28985340, 7499440, 24445838, 9325937, 29727763, 16527196, 18278453, 15405622 }, - { -4381906, 8508652, -19898366, -3674424, -5984453, 15149970, -13313598, 843523, -21875062, 13626197 }, + {-32856209, -7873957, -5422389, 14860950, -16319031, 7956142, + 7258061, 311861, -30594991, -7379421}, + {-3773428, -1565936, 28985340, 7499440, 24445838, 9325937, 29727763, + 16527196, 18278453, 15405622}, + {-4381906, 8508652, -19898366, -3674424, -5984453, 15149970, + -13313598, 843523, -21875062, 13626197}, }, { - { 2281448, -13487055, -10915418, -2609910, 1879358, 16164207, -10783882, 3953792, 13340839, 15928663 }, - { 31727126, -7179855, -18437503, -8283652, 2875793, -16390330, -25269894, -7014826, -23452306, 5964753 }, - { 4100420, -5959452, -17179337, 6017714, -18705837, 12227141, -26684835, 11344144, 2538215, -7570755 }, + {2281448, -13487055, -10915418, -2609910, 1879358, 16164207, + -10783882, 3953792, 13340839, 15928663}, + {31727126, -7179855, -18437503, -8283652, 2875793, -16390330, + -25269894, -7014826, -23452306, 5964753}, + {4100420, -5959452, -17179337, 6017714, -18705837, 12227141, + -26684835, 11344144, 2538215, -7570755}, }, { - { -9433605, 6123113, 11159803, -2156608, 30016280, 14966241, -20474983, 1485421, -629256, -15958862 }, - { -26804558, 4260919, 11851389, 9658551, -32017107, 16367492, -20205425, -13191288, 11659922, -11115118 }, - { 26180396, 10015009, -30844224, -8581293, 5418197, 9480663, 2231568, -10170080, 33100372, -1306171 }, + {-9433605, 6123113, 11159803, -2156608, 30016280, 14966241, + -20474983, 1485421, -629256, -15958862}, + {-26804558, 4260919, 11851389, 9658551, -32017107, 16367492, + -20205425, -13191288, 11659922, -11115118}, + {26180396, 10015009, -30844224, -8581293, 5418197, 9480663, 2231568, + -10170080, 33100372, -1306171}, }, { - { 15121113, -5201871, -10389905, 15427821, -27509937, -15992507, 21670947, 4486675, -5931810, -14466380 }, - { 16166486, -9483733, -11104130, 6023908, -31926798, -1364923, 2340060, -16254968, -10735770, -10039824 }, - { 28042865, -3557089, -12126526, 12259706, -3717498, -6945899, 6766453, -8689599, 18036436, 5803270 }, + {15121113, -5201871, -10389905, 15427821, -27509937, -15992507, + 21670947, 4486675, -5931810, -14466380}, + {16166486, -9483733, -11104130, 6023908, -31926798, -1364923, + 2340060, -16254968, -10735770, -10039824}, + {28042865, -3557089, -12126526, 12259706, -3717498, -6945899, + 6766453, -8689599, 18036436, 5803270}, }, }, { { - { -817581, 6763912, 11803561, 1585585, 10958447, -2671165, 23855391, 4598332, -6159431, -14117438 }, - { -31031306, -14256194, 17332029, -2383520, 31312682, -5967183, 696309, 50292, -20095739, 11763584 }, - { -594563, -2514283, -32234153, 12643980, 12650761, 14811489, 665117, -12613632, -19773211, -10713562 }, + {-817581, 6763912, 11803561, 1585585, 10958447, -2671165, 23855391, + 4598332, -6159431, -14117438}, + {-31031306, -14256194, 17332029, -2383520, 31312682, -5967183, + 696309, 50292, -20095739, 11763584}, + {-594563, -2514283, -32234153, 12643980, 12650761, 14811489, 665117, + -12613632, -19773211, -10713562}, }, { - { 30464590, -11262872, -4127476, -12734478, 19835327, -7105613, -24396175, 2075773, -17020157, 992471 }, - { 18357185, -6994433, 7766382, 16342475, -29324918, 411174, 14578841, 8080033, -11574335, -10601610 }, - { 19598397, 10334610, 12555054, 2555664, 18821899, -10339780, 21873263, 16014234, 26224780, 16452269 }, + {30464590, -11262872, -4127476, -12734478, 19835327, -7105613, + -24396175, 2075773, -17020157, 992471}, + {18357185, -6994433, 7766382, 16342475, -29324918, 411174, 14578841, + 8080033, -11574335, -10601610}, + {19598397, 10334610, 12555054, 2555664, 18821899, -10339780, + 21873263, 16014234, 26224780, 16452269}, }, { - { -30223925, 5145196, 5944548, 16385966, 3976735, 2009897, -11377804, -7618186, -20533829, 3698650 }, - { 14187449, 3448569, -10636236, -10810935, -22663880, -3433596, 7268410, -10890444, 27394301, 12015369 }, - { 19695761, 16087646, 28032085, 12999827, 6817792, 11427614, 20244189, -1312777, -13259127, -3402461 }, + {-30223925, 5145196, 5944548, 16385966, 3976735, 2009897, -11377804, + -7618186, -20533829, 3698650}, + {14187449, 3448569, -10636236, -10810935, -22663880, -3433596, + 7268410, -10890444, 27394301, 12015369}, + {19695761, 16087646, 28032085, 12999827, 6817792, 11427614, + 20244189, -1312777, -13259127, -3402461}, }, { - { 30860103, 12735208, -1888245, -4699734, -16974906, 2256940, -8166013, 12298312, -8550524, -10393462 }, - { -5719826, -11245325, -1910649, 15569035, 26642876, -7587760, -5789354, -15118654, -4976164, 12651793 }, - { -2848395, 9953421, 11531313, -5282879, 26895123, -12697089, -13118820, -16517902, 9768698, -2533218 }, + {30860103, 12735208, -1888245, -4699734, -16974906, 2256940, + -8166013, 12298312, -8550524, -10393462}, + {-5719826, -11245325, -1910649, 15569035, 26642876, -7587760, + -5789354, -15118654, -4976164, 12651793}, + {-2848395, 9953421, 11531313, -5282879, 26895123, -12697089, + -13118820, -16517902, 9768698, -2533218}, }, { - { -24719459, 1894651, -287698, -4704085, 15348719, -8156530, 32767513, 12765450, 4940095, 10678226 }, - { 18860224, 15980149, -18987240, -1562570, -26233012, -11071856, -7843882, 13944024, -24372348, 16582019 }, - { -15504260, 4970268, -29893044, 4175593, -20993212, -2199756, -11704054, 15444560, -11003761, 7989037 }, + {-24719459, 1894651, -287698, -4704085, 15348719, -8156530, + 32767513, 12765450, 4940095, 10678226}, + {18860224, 15980149, -18987240, -1562570, -26233012, -11071856, + -7843882, 13944024, -24372348, 16582019}, + {-15504260, 4970268, -29893044, 4175593, -20993212, -2199756, + -11704054, 15444560, -11003761, 7989037}, }, { - { 31490452, 5568061, -2412803, 2182383, -32336847, 4531686, -32078269, 6200206, -19686113, -14800171 }, - { -17308668, -15879940, -31522777, -2831, -32887382, 16375549, 8680158, -16371713, 28550068, -6857132 }, - { -28126887, -5688091, 16837845, -1820458, -6850681, 12700016, -30039981, 4364038, 1155602, 5988841 }, + {31490452, 5568061, -2412803, 2182383, -32336847, 4531686, + -32078269, 6200206, -19686113, -14800171}, + {-17308668, -15879940, -31522777, -2831, -32887382, 16375549, + 8680158, -16371713, 28550068, -6857132}, + {-28126887, -5688091, 16837845, -1820458, -6850681, 12700016, + -30039981, 4364038, 1155602, 5988841}, }, { - { 21890435, -13272907, -12624011, 12154349, -7831873, 15300496, 23148983, -4470481, 24618407, 8283181 }, - { -33136107, -10512751, 9975416, 6841041, -31559793, 16356536, 3070187, -7025928, 1466169, 10740210 }, - { -1509399, -15488185, -13503385, -10655916, 32799044, 909394, -13938903, -5779719, -32164649, -15327040 }, + {21890435, -13272907, -12624011, 12154349, -7831873, 15300496, + 23148983, -4470481, 24618407, 8283181}, + {-33136107, -10512751, 9975416, 6841041, -31559793, 16356536, + 3070187, -7025928, 1466169, 10740210}, + {-1509399, -15488185, -13503385, -10655916, 32799044, 909394, + -13938903, -5779719, -32164649, -15327040}, }, { - { 3960823, -14267803, -28026090, -15918051, -19404858, 13146868, 15567327, 951507, -3260321, -573935 }, - { 24740841, 5052253, -30094131, 8961361, 25877428, 6165135, -24368180, 14397372, -7380369, -6144105 }, - { -28888365, 3510803, -28103278, -1158478, -11238128, -10631454, -15441463, -14453128, -1625486, -6494814 }, + {3960823, -14267803, -28026090, -15918051, -19404858, 13146868, + 15567327, 951507, -3260321, -573935}, + {24740841, 5052253, -30094131, 8961361, 25877428, 6165135, + -24368180, 14397372, -7380369, -6144105}, + {-28888365, 3510803, -28103278, -1158478, -11238128, -10631454, + -15441463, -14453128, -1625486, -6494814}, }, }, { { - { 793299, -9230478, 8836302, -6235707, -27360908, -2369593, 33152843, -4885251, -9906200, -621852 }, - { 5666233, 525582, 20782575, -8038419, -24538499, 14657740, 16099374, 1468826, -6171428, -15186581 }, - { -4859255, -3779343, -2917758, -6748019, 7778750, 11688288, -30404353, -9871238, -1558923, -9863646 }, + {793299, -9230478, 8836302, -6235707, -27360908, -2369593, 33152843, + -4885251, -9906200, -621852}, + {5666233, 525582, 20782575, -8038419, -24538499, 14657740, 16099374, + 1468826, -6171428, -15186581}, + {-4859255, -3779343, -2917758, -6748019, 7778750, 11688288, + -30404353, -9871238, -1558923, -9863646}, }, { - { 10896332, -7719704, 824275, 472601, -19460308, 3009587, 25248958, 14783338, -30581476, -15757844 }, - { 10566929, 12612572, -31944212, 11118703, -12633376, 12362879, 21752402, 8822496, 24003793, 14264025 }, - { 27713862, -7355973, -11008240, 9227530, 27050101, 2504721, 23886875, -13117525, 13958495, -5732453 }, + {10896332, -7719704, 824275, 472601, -19460308, 3009587, 25248958, + 14783338, -30581476, -15757844}, + {10566929, 12612572, -31944212, 11118703, -12633376, 12362879, + 21752402, 8822496, 24003793, 14264025}, + {27713862, -7355973, -11008240, 9227530, 27050101, 2504721, + 23886875, -13117525, 13958495, -5732453}, }, { - { -23481610, 4867226, -27247128, 3900521, 29838369, -8212291, -31889399, -10041781, 7340521, -15410068 }, - { 4646514, -8011124, -22766023, -11532654, 23184553, 8566613, 31366726, -1381061, -15066784, -10375192 }, - { -17270517, 12723032, -16993061, 14878794, 21619651, -6197576, 27584817, 3093888, -8843694, 3849921 }, + {-23481610, 4867226, -27247128, 3900521, 29838369, -8212291, + -31889399, -10041781, 7340521, -15410068}, + {4646514, -8011124, -22766023, -11532654, 23184553, 8566613, + 31366726, -1381061, -15066784, -10375192}, + {-17270517, 12723032, -16993061, 14878794, 21619651, -6197576, + 27584817, 3093888, -8843694, 3849921}, }, { - { -9064912, 2103172, 25561640, -15125738, -5239824, 9582958, 32477045, -9017955, 5002294, -15550259 }, - { -12057553, -11177906, 21115585, -13365155, 8808712, -12030708, 16489530, 13378448, -25845716, 12741426 }, - { -5946367, 10645103, -30911586, 15390284, -3286982, -7118677, 24306472, 15852464, 28834118, -7646072 }, + {-9064912, 2103172, 25561640, -15125738, -5239824, 9582958, + 32477045, -9017955, 5002294, -15550259}, + {-12057553, -11177906, 21115585, -13365155, 8808712, -12030708, + 16489530, 13378448, -25845716, 12741426}, + {-5946367, 10645103, -30911586, 15390284, -3286982, -7118677, + 24306472, 15852464, 28834118, -7646072}, }, { - { -17335748, -9107057, -24531279, 9434953, -8472084, -583362, -13090771, 455841, 20461858, 5491305 }, - { 13669248, -16095482, -12481974, -10203039, -14569770, -11893198, -24995986, 11293807, -28588204, -9421832 }, - { 28497928, 6272777, -33022994, 14470570, 8906179, -1225630, 18504674, -14165166, 29867745, -8795943 }, + {-17335748, -9107057, -24531279, 9434953, -8472084, -583362, + -13090771, 455841, 20461858, 5491305}, + {13669248, -16095482, -12481974, -10203039, -14569770, -11893198, + -24995986, 11293807, -28588204, -9421832}, + {28497928, 6272777, -33022994, 14470570, 8906179, -1225630, + 18504674, -14165166, 29867745, -8795943}, }, { - { -16207023, 13517196, -27799630, -13697798, 24009064, -6373891, -6367600, -13175392, 22853429, -4012011 }, - { 24191378, 16712145, -13931797, 15217831, 14542237, 1646131, 18603514, -11037887, 12876623, -2112447 }, - { 17902668, 4518229, -411702, -2829247, 26878217, 5258055, -12860753, 608397, 16031844, 3723494 }, + {-16207023, 13517196, -27799630, -13697798, 24009064, -6373891, + -6367600, -13175392, 22853429, -4012011}, + {24191378, 16712145, -13931797, 15217831, 14542237, 1646131, + 18603514, -11037887, 12876623, -2112447}, + {17902668, 4518229, -411702, -2829247, 26878217, 5258055, -12860753, + 608397, 16031844, 3723494}, }, { - { -28632773, 12763728, -20446446, 7577504, 33001348, -13017745, 17558842, -7872890, 23896954, -4314245 }, - { -20005381, -12011952, 31520464, 605201, 2543521, 5991821, -2945064, 7229064, -9919646, -8826859 }, - { 28816045, 298879, -28165016, -15920938, 19000928, -1665890, -12680833, -2949325, -18051778, -2082915 }, + {-28632773, 12763728, -20446446, 7577504, 33001348, -13017745, + 17558842, -7872890, 23896954, -4314245}, + {-20005381, -12011952, 31520464, 605201, 2543521, 5991821, -2945064, + 7229064, -9919646, -8826859}, + {28816045, 298879, -28165016, -15920938, 19000928, -1665890, + -12680833, -2949325, -18051778, -2082915}, }, { - { 16000882, -344896, 3493092, -11447198, -29504595, -13159789, 12577740, 16041268, -19715240, 7847707 }, - { 10151868, 10572098, 27312476, 7922682, 14825339, 4723128, -32855931, -6519018, -10020567, 3852848 }, - { -11430470, 15697596, -21121557, -4420647, 5386314, 15063598, 16514493, -15932110, 29330899, -15076224 }, + {16000882, -344896, 3493092, -11447198, -29504595, -13159789, + 12577740, 16041268, -19715240, 7847707}, + {10151868, 10572098, 27312476, 7922682, 14825339, 4723128, + -32855931, -6519018, -10020567, 3852848}, + {-11430470, 15697596, -21121557, -4420647, 5386314, 15063598, + 16514493, -15932110, 29330899, -15076224}, }, }, { { - { -25499735, -4378794, -15222908, -6901211, 16615731, 2051784, 3303702, 15490, -27548796, 12314391 }, - { 15683520, -6003043, 18109120, -9980648, 15337968, -5997823, -16717435, 15921866, 16103996, -3731215 }, - { -23169824, -10781249, 13588192, -1628807, -3798557, -1074929, -19273607, 5402699, -29815713, -9841101 }, + {-25499735, -4378794, -15222908, -6901211, 16615731, 2051784, + 3303702, 15490, -27548796, 12314391}, + {15683520, -6003043, 18109120, -9980648, 15337968, -5997823, + -16717435, 15921866, 16103996, -3731215}, + {-23169824, -10781249, 13588192, -1628807, -3798557, -1074929, + -19273607, 5402699, -29815713, -9841101}, }, { - { 23190676, 2384583, -32714340, 3462154, -29903655, -1529132, -11266856, 8911517, -25205859, 2739713 }, - { 21374101, -3554250, -33524649, 9874411, 15377179, 11831242, -33529904, 6134907, 4931255, 11987849 }, - { -7732, -2978858, -16223486, 7277597, 105524, -322051, -31480539, 13861388, -30076310, 10117930 }, + {23190676, 2384583, -32714340, 3462154, -29903655, -1529132, + -11266856, 8911517, -25205859, 2739713}, + {21374101, -3554250, -33524649, 9874411, 15377179, 11831242, + -33529904, 6134907, 4931255, 11987849}, + {-7732, -2978858, -16223486, 7277597, 105524, -322051, -31480539, + 13861388, -30076310, 10117930}, }, { - { -29501170, -10744872, -26163768, 13051539, -25625564, 5089643, -6325503, 6704079, 12890019, 15728940 }, - { -21972360, -11771379, -951059, -4418840, 14704840, 2695116, 903376, -10428139, 12885167, 8311031 }, - { -17516482, 5352194, 10384213, -13811658, 7506451, 13453191, 26423267, 4384730, 1888765, -5435404 }, + {-29501170, -10744872, -26163768, 13051539, -25625564, 5089643, + -6325503, 6704079, 12890019, 15728940}, + {-21972360, -11771379, -951059, -4418840, 14704840, 2695116, 903376, + -10428139, 12885167, 8311031}, + {-17516482, 5352194, 10384213, -13811658, 7506451, 13453191, + 26423267, 4384730, 1888765, -5435404}, }, { - { -25817338, -3107312, -13494599, -3182506, 30896459, -13921729, -32251644, -12707869, -19464434, -3340243 }, - { -23607977, -2665774, -526091, 4651136, 5765089, 4618330, 6092245, 14845197, 17151279, -9854116 }, - { -24830458, -12733720, -15165978, 10367250, -29530908, -265356, 22825805, -7087279, -16866484, 16176525 }, + {-25817338, -3107312, -13494599, -3182506, 30896459, -13921729, + -32251644, -12707869, -19464434, -3340243}, + {-23607977, -2665774, -526091, 4651136, 5765089, 4618330, 6092245, + 14845197, 17151279, -9854116}, + {-24830458, -12733720, -15165978, 10367250, -29530908, -265356, + 22825805, -7087279, -16866484, 16176525}, }, { - { -23583256, 6564961, 20063689, 3798228, -4740178, 7359225, 2006182, -10363426, -28746253, -10197509 }, - { -10626600, -4486402, -13320562, -5125317, 3432136, -6393229, 23632037, -1940610, 32808310, 1099883 }, - { 15030977, 5768825, -27451236, -2887299, -6427378, -15361371, -15277896, -6809350, 2051441, -15225865 }, + {-23583256, 6564961, 20063689, 3798228, -4740178, 7359225, 2006182, + -10363426, -28746253, -10197509}, + {-10626600, -4486402, -13320562, -5125317, 3432136, -6393229, + 23632037, -1940610, 32808310, 1099883}, + {15030977, 5768825, -27451236, -2887299, -6427378, -15361371, + -15277896, -6809350, 2051441, -15225865}, }, { - { -3362323, -7239372, 7517890, 9824992, 23555850, 295369, 5148398, -14154188, -22686354, 16633660 }, - { 4577086, -16752288, 13249841, -15304328, 19958763, -14537274, 18559670, -10759549, 8402478, -9864273 }, - { -28406330, -1051581, -26790155, -907698, -17212414, -11030789, 9453451, -14980072, 17983010, 9967138 }, + {-3362323, -7239372, 7517890, 9824992, 23555850, 295369, 5148398, + -14154188, -22686354, 16633660}, + {4577086, -16752288, 13249841, -15304328, 19958763, -14537274, + 18559670, -10759549, 8402478, -9864273}, + {-28406330, -1051581, -26790155, -907698, -17212414, -11030789, + 9453451, -14980072, 17983010, 9967138}, }, { - { -25762494, 6524722, 26585488, 9969270, 24709298, 1220360, -1677990, 7806337, 17507396, 3651560 }, - { -10420457, -4118111, 14584639, 15971087, -15768321, 8861010, 26556809, -5574557, -18553322, -11357135 }, - { 2839101, 14284142, 4029895, 3472686, 14402957, 12689363, -26642121, 8459447, -5605463, -7621941 }, + {-25762494, 6524722, 26585488, 9969270, 24709298, 1220360, -1677990, + 7806337, 17507396, 3651560}, + {-10420457, -4118111, 14584639, 15971087, -15768321, 8861010, + 26556809, -5574557, -18553322, -11357135}, + {2839101, 14284142, 4029895, 3472686, 14402957, 12689363, -26642121, + 8459447, -5605463, -7621941}, }, { - { -4839289, -3535444, 9744961, 2871048, 25113978, 3187018, -25110813, -849066, 17258084, -7977739 }, - { 18164541, -10595176, -17154882, -1542417, 19237078, -9745295, 23357533, -15217008, 26908270, 12150756 }, - { -30264870, -7647865, 5112249, -7036672, -1499807, -6974257, 43168, -5537701, -32302074, 16215819 }, + {-4839289, -3535444, 9744961, 2871048, 25113978, 3187018, -25110813, + -849066, 17258084, -7977739}, + {18164541, -10595176, -17154882, -1542417, 19237078, -9745295, + 23357533, -15217008, 26908270, 12150756}, + {-30264870, -7647865, 5112249, -7036672, -1499807, -6974257, 43168, + -5537701, -32302074, 16215819}, }, }, { { - { -6898905, 9824394, -12304779, -4401089, -31397141, -6276835, 32574489, 12532905, -7503072, -8675347 }, - { -27343522, -16515468, -27151524, -10722951, 946346, 16291093, 254968, 7168080, 21676107, -1943028 }, - { 21260961, -8424752, -16831886, -11920822, -23677961, 3968121, -3651949, -6215466, -3556191, -7913075 }, + {-6898905, 9824394, -12304779, -4401089, -31397141, -6276835, + 32574489, 12532905, -7503072, -8675347}, + {-27343522, -16515468, -27151524, -10722951, 946346, 16291093, + 254968, 7168080, 21676107, -1943028}, + {21260961, -8424752, -16831886, -11920822, -23677961, 3968121, + -3651949, -6215466, -3556191, -7913075}, }, { - { 16544754, 13250366, -16804428, 15546242, -4583003, 12757258, -2462308, -8680336, -18907032, -9662799 }, - { -2415239, -15577728, 18312303, 4964443, -15272530, -12653564, 26820651, 16690659, 25459437, -4564609 }, - { -25144690, 11425020, 28423002, -11020557, -6144921, -15826224, 9142795, -2391602, -6432418, -1644817 }, + {16544754, 13250366, -16804428, 15546242, -4583003, 12757258, + -2462308, -8680336, -18907032, -9662799}, + {-2415239, -15577728, 18312303, 4964443, -15272530, -12653564, + 26820651, 16690659, 25459437, -4564609}, + {-25144690, 11425020, 28423002, -11020557, -6144921, -15826224, + 9142795, -2391602, -6432418, -1644817}, }, { - { -23104652, 6253476, 16964147, -3768872, -25113972, -12296437, -27457225, -16344658, 6335692, 7249989 }, - { -30333227, 13979675, 7503222, -12368314, -11956721, -4621693, -30272269, 2682242, 25993170, -12478523 }, - { 4364628, 5930691, 32304656, -10044554, -8054781, 15091131, 22857016, -10598955, 31820368, 15075278 }, + {-23104652, 6253476, 16964147, -3768872, -25113972, -12296437, + -27457225, -16344658, 6335692, 7249989}, + {-30333227, 13979675, 7503222, -12368314, -11956721, -4621693, + -30272269, 2682242, 25993170, -12478523}, + {4364628, 5930691, 32304656, -10044554, -8054781, 15091131, + 22857016, -10598955, 31820368, 15075278}, }, { - { 31879134, -8918693, 17258761, 90626, -8041836, -4917709, 24162788, -9650886, -17970238, 12833045 }, - { 19073683, 14851414, -24403169, -11860168, 7625278, 11091125, -19619190, 2074449, -9413939, 14905377 }, - { 24483667, -11935567, -2518866, -11547418, -1553130, 15355506, -25282080, 9253129, 27628530, -7555480 }, + {31879134, -8918693, 17258761, 90626, -8041836, -4917709, 24162788, + -9650886, -17970238, 12833045}, + {19073683, 14851414, -24403169, -11860168, 7625278, 11091125, + -19619190, 2074449, -9413939, 14905377}, + {24483667, -11935567, -2518866, -11547418, -1553130, 15355506, + -25282080, 9253129, 27628530, -7555480}, }, { - { 17597607, 8340603, 19355617, 552187, 26198470, -3176583, 4593324, -9157582, -14110875, 15297016 }, - { 510886, 14337390, -31785257, 16638632, 6328095, 2713355, -20217417, -11864220, 8683221, 2921426 }, - { 18606791, 11874196, 27155355, -5281482, -24031742, 6265446, -25178240, -1278924, 4674690, 13890525 }, + {17597607, 8340603, 19355617, 552187, 26198470, -3176583, 4593324, + -9157582, -14110875, 15297016}, + {510886, 14337390, -31785257, 16638632, 6328095, 2713355, -20217417, + -11864220, 8683221, 2921426}, + {18606791, 11874196, 27155355, -5281482, -24031742, 6265446, + -25178240, -1278924, 4674690, 13890525}, }, { - { 13609624, 13069022, -27372361, -13055908, 24360586, 9592974, 14977157, 9835105, 4389687, 288396 }, - { 9922506, -519394, 13613107, 5883594, -18758345, -434263, -12304062, 8317628, 23388070, 16052080 }, - { 12720016, 11937594, -31970060, -5028689, 26900120, 8561328, -20155687, -11632979, -14754271, -10812892 }, + {13609624, 13069022, -27372361, -13055908, 24360586, 9592974, + 14977157, 9835105, 4389687, 288396}, + {9922506, -519394, 13613107, 5883594, -18758345, -434263, -12304062, + 8317628, 23388070, 16052080}, + {12720016, 11937594, -31970060, -5028689, 26900120, 8561328, + -20155687, -11632979, -14754271, -10812892}, }, { - { 15961858, 14150409, 26716931, -665832, -22794328, 13603569, 11829573, 7467844, -28822128, 929275 }, - { 11038231, -11582396, -27310482, -7316562, -10498527, -16307831, -23479533, -9371869, -21393143, 2465074 }, - { 20017163, -4323226, 27915242, 1529148, 12396362, 15675764, 13817261, -9658066, 2463391, -4622140 }, + {15961858, 14150409, 26716931, -665832, -22794328, 13603569, + 11829573, 7467844, -28822128, 929275}, + {11038231, -11582396, -27310482, -7316562, -10498527, -16307831, + -23479533, -9371869, -21393143, 2465074}, + {20017163, -4323226, 27915242, 1529148, 12396362, 15675764, + 13817261, -9658066, 2463391, -4622140}, }, { - { -16358878, -12663911, -12065183, 4996454, -1256422, 1073572, 9583558, 12851107, 4003896, 12673717 }, - { -1731589, -15155870, -3262930, 16143082, 19294135, 13385325, 14741514, -9103726, 7903886, 2348101 }, - { 24536016, -16515207, 12715592, -3862155, 1511293, 10047386, -3842346, -7129159, -28377538, 10048127 }, + {-16358878, -12663911, -12065183, 4996454, -1256422, 1073572, + 9583558, 12851107, 4003896, 12673717}, + {-1731589, -15155870, -3262930, 16143082, 19294135, 13385325, + 14741514, -9103726, 7903886, 2348101}, + {24536016, -16515207, 12715592, -3862155, 1511293, 10047386, + -3842346, -7129159, -28377538, 10048127}, }, }, { { - { -12622226, -6204820, 30718825, 2591312, -10617028, 12192840, 18873298, -7297090, -32297756, 15221632 }, - { -26478122, -11103864, 11546244, -1852483, 9180880, 7656409, -21343950, 2095755, 29769758, 6593415 }, - { -31994208, -2907461, 4176912, 3264766, 12538965, -868111, 26312345, -6118678, 30958054, 8292160 }, + {-12622226, -6204820, 30718825, 2591312, -10617028, 12192840, + 18873298, -7297090, -32297756, 15221632}, + {-26478122, -11103864, 11546244, -1852483, 9180880, 7656409, + -21343950, 2095755, 29769758, 6593415}, + {-31994208, -2907461, 4176912, 3264766, 12538965, -868111, 26312345, + -6118678, 30958054, 8292160}, }, { - { 31429822, -13959116, 29173532, 15632448, 12174511, -2760094, 32808831, 3977186, 26143136, -3148876 }, - { 22648901, 1402143, -22799984, 13746059, 7936347, 365344, -8668633, -1674433, -3758243, -2304625 }, - { -15491917, 8012313, -2514730, -12702462, -23965846, -10254029, -1612713, -1535569, -16664475, 8194478 }, + {31429822, -13959116, 29173532, 15632448, 12174511, -2760094, + 32808831, 3977186, 26143136, -3148876}, + {22648901, 1402143, -22799984, 13746059, 7936347, 365344, -8668633, + -1674433, -3758243, -2304625}, + {-15491917, 8012313, -2514730, -12702462, -23965846, -10254029, + -1612713, -1535569, -16664475, 8194478}, }, { - { 27338066, -7507420, -7414224, 10140405, -19026427, -6589889, 27277191, 8855376, 28572286, 3005164 }, - { 26287124, 4821776, 25476601, -4145903, -3764513, -15788984, -18008582, 1182479, -26094821, -13079595 }, - { -7171154, 3178080, 23970071, 6201893, -17195577, -4489192, -21876275, -13982627, 32208683, -1198248 }, + {27338066, -7507420, -7414224, 10140405, -19026427, -6589889, + 27277191, 8855376, 28572286, 3005164}, + {26287124, 4821776, 25476601, -4145903, -3764513, -15788984, + -18008582, 1182479, -26094821, -13079595}, + {-7171154, 3178080, 23970071, 6201893, -17195577, -4489192, + -21876275, -13982627, 32208683, -1198248}, }, { - { -16657702, 2817643, -10286362, 14811298, 6024667, 13349505, -27315504, -10497842, -27672585, -11539858 }, - { 15941029, -9405932, -21367050, 8062055, 31876073, -238629, -15278393, -1444429, 15397331, -4130193 }, - { 8934485, -13485467, -23286397, -13423241, -32446090, 14047986, 31170398, -1441021, -27505566, 15087184 }, + {-16657702, 2817643, -10286362, 14811298, 6024667, 13349505, + -27315504, -10497842, -27672585, -11539858}, + {15941029, -9405932, -21367050, 8062055, 31876073, -238629, + -15278393, -1444429, 15397331, -4130193}, + {8934485, -13485467, -23286397, -13423241, -32446090, 14047986, + 31170398, -1441021, -27505566, 15087184}, }, { - { -18357243, -2156491, 24524913, -16677868, 15520427, -6360776, -15502406, 11461896, 16788528, -5868942 }, - { -1947386, 16013773, 21750665, 3714552, -17401782, -16055433, -3770287, -10323320, 31322514, -11615635 }, - { 21426655, -5650218, -13648287, -5347537, -28812189, -4920970, -18275391, -14621414, 13040862, -12112948 }, + {-18357243, -2156491, 24524913, -16677868, 15520427, -6360776, + -15502406, 11461896, 16788528, -5868942}, + {-1947386, 16013773, 21750665, 3714552, -17401782, -16055433, + -3770287, -10323320, 31322514, -11615635}, + {21426655, -5650218, -13648287, -5347537, -28812189, -4920970, + -18275391, -14621414, 13040862, -12112948}, }, { - { 11293895, 12478086, -27136401, 15083750, -29307421, 14748872, 14555558, -13417103, 1613711, 4896935 }, - { -25894883, 15323294, -8489791, -8057900, 25967126, -13425460, 2825960, -4897045, -23971776, -11267415 }, - { -15924766, -5229880, -17443532, 6410664, 3622847, 10243618, 20615400, 12405433, -23753030, -8436416 }, + {11293895, 12478086, -27136401, 15083750, -29307421, 14748872, + 14555558, -13417103, 1613711, 4896935}, + {-25894883, 15323294, -8489791, -8057900, 25967126, -13425460, + 2825960, -4897045, -23971776, -11267415}, + {-15924766, -5229880, -17443532, 6410664, 3622847, 10243618, + 20615400, 12405433, -23753030, -8436416}, }, { - { -7091295, 12556208, -20191352, 9025187, -17072479, 4333801, 4378436, 2432030, 23097949, -566018 }, - { 4565804, -16025654, 20084412, -7842817, 1724999, 189254, 24767264, 10103221, -18512313, 2424778 }, - { 366633, -11976806, 8173090, -6890119, 30788634, 5745705, -7168678, 1344109, -3642553, 12412659 }, + {-7091295, 12556208, -20191352, 9025187, -17072479, 4333801, + 4378436, 2432030, 23097949, -566018}, + {4565804, -16025654, 20084412, -7842817, 1724999, 189254, 24767264, + 10103221, -18512313, 2424778}, + {366633, -11976806, 8173090, -6890119, 30788634, 5745705, -7168678, + 1344109, -3642553, 12412659}, }, { - { -24001791, 7690286, 14929416, -168257, -32210835, -13412986, 24162697, -15326504, -3141501, 11179385 }, - { 18289522, -14724954, 8056945, 16430056, -21729724, 7842514, -6001441, -1486897, -18684645, -11443503 }, - { 476239, 6601091, -6152790, -9723375, 17503545, -4863900, 27672959, 13403813, 11052904, 5219329 }, + {-24001791, 7690286, 14929416, -168257, -32210835, -13412986, + 24162697, -15326504, -3141501, 11179385}, + {18289522, -14724954, 8056945, 16430056, -21729724, 7842514, + -6001441, -1486897, -18684645, -11443503}, + {476239, 6601091, -6152790, -9723375, 17503545, -4863900, 27672959, + 13403813, 11052904, 5219329}, }, }, { { - { 20678546, -8375738, -32671898, 8849123, -5009758, 14574752, 31186971, -3973730, 9014762, -8579056 }, - { -13644050, -10350239, -15962508, 5075808, -1514661, -11534600, -33102500, 9160280, 8473550, -3256838 }, - { 24900749, 14435722, 17209120, -15292541, -22592275, 9878983, -7689309, -16335821, -24568481, 11788948 }, + {20678546, -8375738, -32671898, 8849123, -5009758, 14574752, + 31186971, -3973730, 9014762, -8579056}, + {-13644050, -10350239, -15962508, 5075808, -1514661, -11534600, + -33102500, 9160280, 8473550, -3256838}, + {24900749, 14435722, 17209120, -15292541, -22592275, 9878983, + -7689309, -16335821, -24568481, 11788948}, }, { - { -3118155, -11395194, -13802089, 14797441, 9652448, -6845904, -20037437, 10410733, -24568470, -1458691 }, - { -15659161, 16736706, -22467150, 10215878, -9097177, 7563911, 11871841, -12505194, -18513325, 8464118 }, - { -23400612, 8348507, -14585951, -861714, -3950205, -6373419, 14325289, 8628612, 33313881, -8370517 }, + {-3118155, -11395194, -13802089, 14797441, 9652448, -6845904, + -20037437, 10410733, -24568470, -1458691}, + {-15659161, 16736706, -22467150, 10215878, -9097177, 7563911, + 11871841, -12505194, -18513325, 8464118}, + {-23400612, 8348507, -14585951, -861714, -3950205, -6373419, + 14325289, 8628612, 33313881, -8370517}, }, { - { -20186973, -4967935, 22367356, 5271547, -1097117, -4788838, -24805667, -10236854, -8940735, -5818269 }, - { -6948785, -1795212, -32625683, -16021179, 32635414, -7374245, 15989197, -12838188, 28358192, -4253904 }, - { -23561781, -2799059, -32351682, -1661963, -9147719, 10429267, -16637684, 4072016, -5351664, 5596589 }, + {-20186973, -4967935, 22367356, 5271547, -1097117, -4788838, + -24805667, -10236854, -8940735, -5818269}, + {-6948785, -1795212, -32625683, -16021179, 32635414, -7374245, + 15989197, -12838188, 28358192, -4253904}, + {-23561781, -2799059, -32351682, -1661963, -9147719, 10429267, + -16637684, 4072016, -5351664, 5596589}, }, { - { -28236598, -3390048, 12312896, 6213178, 3117142, 16078565, 29266239, 2557221, 1768301, 15373193 }, - { -7243358, -3246960, -4593467, -7553353, -127927, -912245, -1090902, -4504991, -24660491, 3442910 }, - { -30210571, 5124043, 14181784, 8197961, 18964734, -11939093, 22597931, 7176455, -18585478, 13365930 }, + {-28236598, -3390048, 12312896, 6213178, 3117142, 16078565, + 29266239, 2557221, 1768301, 15373193}, + {-7243358, -3246960, -4593467, -7553353, -127927, -912245, -1090902, + -4504991, -24660491, 3442910}, + {-30210571, 5124043, 14181784, 8197961, 18964734, -11939093, + 22597931, 7176455, -18585478, 13365930}, }, { - { -7877390, -1499958, 8324673, 4690079, 6261860, 890446, 24538107, -8570186, -9689599, -3031667 }, - { 25008904, -10771599, -4305031, -9638010, 16265036, 15721635, 683793, -11823784, 15723479, -15163481 }, - { -9660625, 12374379, -27006999, -7026148, -7724114, -12314514, 11879682, 5400171, 519526, -1235876 }, + {-7877390, -1499958, 8324673, 4690079, 6261860, 890446, 24538107, + -8570186, -9689599, -3031667}, + {25008904, -10771599, -4305031, -9638010, 16265036, 15721635, + 683793, -11823784, 15723479, -15163481}, + {-9660625, 12374379, -27006999, -7026148, -7724114, -12314514, + 11879682, 5400171, 519526, -1235876}, }, { - { 22258397, -16332233, -7869817, 14613016, -22520255, -2950923, -20353881, 7315967, 16648397, 7605640 }, - { -8081308, -8464597, -8223311, 9719710, 19259459, -15348212, 23994942, -5281555, -9468848, 4763278 }, - { -21699244, 9220969, -15730624, 1084137, -25476107, -2852390, 31088447, -7764523, -11356529, 728112 }, + {22258397, -16332233, -7869817, 14613016, -22520255, -2950923, + -20353881, 7315967, 16648397, 7605640}, + {-8081308, -8464597, -8223311, 9719710, 19259459, -15348212, + 23994942, -5281555, -9468848, 4763278}, + {-21699244, 9220969, -15730624, 1084137, -25476107, -2852390, + 31088447, -7764523, -11356529, 728112}, }, { - { 26047220, -11751471, -6900323, -16521798, 24092068, 9158119, -4273545, -12555558, -29365436, -5498272 }, - { 17510331, -322857, 5854289, 8403524, 17133918, -3112612, -28111007, 12327945, 10750447, 10014012 }, - { -10312768, 3936952, 9156313, -8897683, 16498692, -994647, -27481051, -666732, 3424691, 7540221 }, + {26047220, -11751471, -6900323, -16521798, 24092068, 9158119, + -4273545, -12555558, -29365436, -5498272}, + {17510331, -322857, 5854289, 8403524, 17133918, -3112612, -28111007, + 12327945, 10750447, 10014012}, + {-10312768, 3936952, 9156313, -8897683, 16498692, -994647, + -27481051, -666732, 3424691, 7540221}, }, { - { 30322361, -6964110, 11361005, -4143317, 7433304, 4989748, -7071422, -16317219, -9244265, 15258046 }, - { 13054562, -2779497, 19155474, 469045, -12482797, 4566042, 5631406, 2711395, 1062915, -5136345 }, - { -19240248, -11254599, -29509029, -7499965, -5835763, 13005411, -6066489, 12194497, 32960380, 1459310 }, + {30322361, -6964110, 11361005, -4143317, 7433304, 4989748, -7071422, + -16317219, -9244265, 15258046}, + {13054562, -2779497, 19155474, 469045, -12482797, 4566042, 5631406, + 2711395, 1062915, -5136345}, + {-19240248, -11254599, -29509029, -7499965, -5835763, 13005411, + -6066489, 12194497, 32960380, 1459310}, }, }, { { - { 19852034, 7027924, 23669353, 10020366, 8586503, -6657907, 394197, -6101885, 18638003, -11174937 }, - { 31395534, 15098109, 26581030, 8030562, -16527914, -5007134, 9012486, -7584354, -6643087, -5442636 }, - { -9192165, -2347377, -1997099, 4529534, 25766844, 607986, -13222, 9677543, -32294889, -6456008 }, + {19852034, 7027924, 23669353, 10020366, 8586503, -6657907, 394197, + -6101885, 18638003, -11174937}, + {31395534, 15098109, 26581030, 8030562, -16527914, -5007134, + 9012486, -7584354, -6643087, -5442636}, + {-9192165, -2347377, -1997099, 4529534, 25766844, 607986, -13222, + 9677543, -32294889, -6456008}, }, { - { -2444496, -149937, 29348902, 8186665, 1873760, 12489863, -30934579, -7839692, -7852844, -8138429 }, - { -15236356, -15433509, 7766470, 746860, 26346930, -10221762, -27333451, 10754588, -9431476, 5203576 }, - { 31834314, 14135496, -770007, 5159118, 20917671, -16768096, -7467973, -7337524, 31809243, 7347066 }, + {-2444496, -149937, 29348902, 8186665, 1873760, 12489863, -30934579, + -7839692, -7852844, -8138429}, + {-15236356, -15433509, 7766470, 746860, 26346930, -10221762, + -27333451, 10754588, -9431476, 5203576}, + {31834314, 14135496, -770007, 5159118, 20917671, -16768096, + -7467973, -7337524, 31809243, 7347066}, }, { - { -9606723, -11874240, 20414459, 13033986, 13716524, -11691881, 19797970, -12211255, 15192876, -2087490 }, - { -12663563, -2181719, 1168162, -3804809, 26747877, -14138091, 10609330, 12694420, 33473243, -13382104 }, - { 33184999, 11180355, 15832085, -11385430, -1633671, 225884, 15089336, -11023903, -6135662, 14480053 }, + {-9606723, -11874240, 20414459, 13033986, 13716524, -11691881, + 19797970, -12211255, 15192876, -2087490}, + {-12663563, -2181719, 1168162, -3804809, 26747877, -14138091, + 10609330, 12694420, 33473243, -13382104}, + {33184999, 11180355, 15832085, -11385430, -1633671, 225884, + 15089336, -11023903, -6135662, 14480053}, }, { - { 31308717, -5619998, 31030840, -1897099, 15674547, -6582883, 5496208, 13685227, 27595050, 8737275 }, - { -20318852, -15150239, 10933843, -16178022, 8335352, -7546022, -31008351, -12610604, 26498114, 66511 }, - { 22644454, -8761729, -16671776, 4884562, -3105614, -13559366, 30540766, -4286747, -13327787, -7515095 }, + {31308717, -5619998, 31030840, -1897099, 15674547, -6582883, + 5496208, 13685227, 27595050, 8737275}, + {-20318852, -15150239, 10933843, -16178022, 8335352, -7546022, + -31008351, -12610604, 26498114, 66511}, + {22644454, -8761729, -16671776, 4884562, -3105614, -13559366, + 30540766, -4286747, -13327787, -7515095}, }, { - { -28017847, 9834845, 18617207, -2681312, -3401956, -13307506, 8205540, 13585437, -17127465, 15115439 }, - { 23711543, -672915, 31206561, -8362711, 6164647, -9709987, -33535882, -1426096, 8236921, 16492939 }, - { -23910559, -13515526, -26299483, -4503841, 25005590, -7687270, 19574902, 10071562, 6708380, -6222424 }, + {-28017847, 9834845, 18617207, -2681312, -3401956, -13307506, + 8205540, 13585437, -17127465, 15115439}, + {23711543, -672915, 31206561, -8362711, 6164647, -9709987, + -33535882, -1426096, 8236921, 16492939}, + {-23910559, -13515526, -26299483, -4503841, 25005590, -7687270, + 19574902, 10071562, 6708380, -6222424}, }, { - { 2101391, -4930054, 19702731, 2367575, -15427167, 1047675, 5301017, 9328700, 29955601, -11678310 }, - { 3096359, 9271816, -21620864, -15521844, -14847996, -7592937, -25892142, -12635595, -9917575, 6216608 }, - { -32615849, 338663, -25195611, 2510422, -29213566, -13820213, 24822830, -6146567, -26767480, 7525079 }, + {2101391, -4930054, 19702731, 2367575, -15427167, 1047675, 5301017, + 9328700, 29955601, -11678310}, + {3096359, 9271816, -21620864, -15521844, -14847996, -7592937, + -25892142, -12635595, -9917575, 6216608}, + {-32615849, 338663, -25195611, 2510422, -29213566, -13820213, + 24822830, -6146567, -26767480, 7525079}, }, { - { -23066649, -13985623, 16133487, -7896178, -3389565, 778788, -910336, -2782495, -19386633, 11994101 }, - { 21691500, -13624626, -641331, -14367021, 3285881, -3483596, -25064666, 9718258, -7477437, 13381418 }, - { 18445390, -4202236, 14979846, 11622458, -1727110, -3582980, 23111648, -6375247, 28535282, 15779576 }, + {-23066649, -13985623, 16133487, -7896178, -3389565, 778788, + -910336, -2782495, -19386633, 11994101}, + {21691500, -13624626, -641331, -14367021, 3285881, -3483596, + -25064666, 9718258, -7477437, 13381418}, + {18445390, -4202236, 14979846, 11622458, -1727110, -3582980, + 23111648, -6375247, 28535282, 15779576}, }, { - { 30098053, 3089662, -9234387, 16662135, -21306940, 11308411, -14068454, 12021730, 9955285, -16303356 }, - { 9734894, -14576830, -7473633, -9138735, 2060392, 11313496, -18426029, 9924399, 20194861, 13380996 }, - { -26378102, -7965207, -22167821, 15789297, -18055342, -6168792, -1984914, 15707771, 26342023, 10146099 }, + {30098053, 3089662, -9234387, 16662135, -21306940, 11308411, + -14068454, 12021730, 9955285, -16303356}, + {9734894, -14576830, -7473633, -9138735, 2060392, 11313496, + -18426029, 9924399, 20194861, 13380996}, + {-26378102, -7965207, -22167821, 15789297, -18055342, -6168792, + -1984914, 15707771, 26342023, 10146099}, }, }, { { - { -26016874, -219943, 21339191, -41388, 19745256, -2878700, -29637280, 2227040, 21612326, -545728 }, - { -13077387, 1184228, 23562814, -5970442, -20351244, -6348714, 25764461, 12243797, -20856566, 11649658 }, - { -10031494, 11262626, 27384172, 2271902, 26947504, -15997771, 39944, 6114064, 33514190, 2333242 }, + {-26016874, -219943, 21339191, -41388, 19745256, -2878700, + -29637280, 2227040, 21612326, -545728}, + {-13077387, 1184228, 23562814, -5970442, -20351244, -6348714, + 25764461, 12243797, -20856566, 11649658}, + {-10031494, 11262626, 27384172, 2271902, 26947504, -15997771, 39944, + 6114064, 33514190, 2333242}, }, { - { -21433588, -12421821, 8119782, 7219913, -21830522, -9016134, -6679750, -12670638, 24350578, -13450001 }, - { -4116307, -11271533, -23886186, 4843615, -30088339, 690623, -31536088, -10406836, 8317860, 12352766 }, - { 18200138, -14475911, -33087759, -2696619, -23702521, -9102511, -23552096, -2287550, 20712163, 6719373 }, + {-21433588, -12421821, 8119782, 7219913, -21830522, -9016134, + -6679750, -12670638, 24350578, -13450001}, + {-4116307, -11271533, -23886186, 4843615, -30088339, 690623, + -31536088, -10406836, 8317860, 12352766}, + {18200138, -14475911, -33087759, -2696619, -23702521, -9102511, + -23552096, -2287550, 20712163, 6719373}, }, { - { 26656208, 6075253, -7858556, 1886072, -28344043, 4262326, 11117530, -3763210, 26224235, -3297458 }, - { -17168938, -14854097, -3395676, -16369877, -19954045, 14050420, 21728352, 9493610, 18620611, -16428628 }, - { -13323321, 13325349, 11432106, 5964811, 18609221, 6062965, -5269471, -9725556, -30701573, -16479657 }, + {26656208, 6075253, -7858556, 1886072, -28344043, 4262326, 11117530, + -3763210, 26224235, -3297458}, + {-17168938, -14854097, -3395676, -16369877, -19954045, 14050420, + 21728352, 9493610, 18620611, -16428628}, + {-13323321, 13325349, 11432106, 5964811, 18609221, 6062965, + -5269471, -9725556, -30701573, -16479657}, }, { - { -23860538, -11233159, 26961357, 1640861, -32413112, -16737940, 12248509, -5240639, 13735342, 1934062 }, - { 25089769, 6742589, 17081145, -13406266, 21909293, -16067981, -15136294, -3765346, -21277997, 5473616 }, - { 31883677, -7961101, 1083432, -11572403, 22828471, 13290673, -7125085, 12469656, 29111212, -5451014 }, + {-23860538, -11233159, 26961357, 1640861, -32413112, -16737940, + 12248509, -5240639, 13735342, 1934062}, + {25089769, 6742589, 17081145, -13406266, 21909293, -16067981, + -15136294, -3765346, -21277997, 5473616}, + {31883677, -7961101, 1083432, -11572403, 22828471, 13290673, + -7125085, 12469656, 29111212, -5451014}, }, { - { 24244947, -15050407, -26262976, 2791540, -14997599, 16666678, 24367466, 6388839, -10295587, 452383 }, - { -25640782, -3417841, 5217916, 16224624, 19987036, -4082269, -24236251, -5915248, 15766062, 8407814 }, - { -20406999, 13990231, 15495425, 16395525, 5377168, 15166495, -8917023, -4388953, -8067909, 2276718 }, + {24244947, -15050407, -26262976, 2791540, -14997599, 16666678, + 24367466, 6388839, -10295587, 452383}, + {-25640782, -3417841, 5217916, 16224624, 19987036, -4082269, + -24236251, -5915248, 15766062, 8407814}, + {-20406999, 13990231, 15495425, 16395525, 5377168, 15166495, + -8917023, -4388953, -8067909, 2276718}, }, { - { 30157918, 12924066, -17712050, 9245753, 19895028, 3368142, -23827587, 5096219, 22740376, -7303417 }, - { 2041139, -14256350, 7783687, 13876377, -25946985, -13352459, 24051124, 13742383, -15637599, 13295222 }, - { 33338237, -8505733, 12532113, 7977527, 9106186, -1715251, -17720195, -4612972, -4451357, -14669444 }, + {30157918, 12924066, -17712050, 9245753, 19895028, 3368142, + -23827587, 5096219, 22740376, -7303417}, + {2041139, -14256350, 7783687, 13876377, -25946985, -13352459, + 24051124, 13742383, -15637599, 13295222}, + {33338237, -8505733, 12532113, 7977527, 9106186, -1715251, + -17720195, -4612972, -4451357, -14669444}, }, { - { -20045281, 5454097, -14346548, 6447146, 28862071, 1883651, -2469266, -4141880, 7770569, 9620597 }, - { 23208068, 7979712, 33071466, 8149229, 1758231, -10834995, 30945528, -1694323, -33502340, -14767970 }, - { 1439958, -16270480, -1079989, -793782, 4625402, 10647766, -5043801, 1220118, 30494170, -11440799 }, + {-20045281, 5454097, -14346548, 6447146, 28862071, 1883651, + -2469266, -4141880, 7770569, 9620597}, + {23208068, 7979712, 33071466, 8149229, 1758231, -10834995, 30945528, + -1694323, -33502340, -14767970}, + {1439958, -16270480, -1079989, -793782, 4625402, 10647766, -5043801, + 1220118, 30494170, -11440799}, }, { - { -5037580, -13028295, -2970559, -3061767, 15640974, -6701666, -26739026, 926050, -1684339, -13333647 }, - { 13908495, -3549272, 30919928, -6273825, -21521863, 7989039, 9021034, 9078865, 3353509, 4033511 }, - { -29663431, -15113610, 32259991, -344482, 24295849, -12912123, 23161163, 8839127, 27485041, 7356032 }, + {-5037580, -13028295, -2970559, -3061767, 15640974, -6701666, + -26739026, 926050, -1684339, -13333647}, + {13908495, -3549272, 30919928, -6273825, -21521863, 7989039, + 9021034, 9078865, 3353509, 4033511}, + {-29663431, -15113610, 32259991, -344482, 24295849, -12912123, + 23161163, 8839127, 27485041, 7356032}, }, }, { { - { 9661027, 705443, 11980065, -5370154, -1628543, 14661173, -6346142, 2625015, 28431036, -16771834 }, - { -23839233, -8311415, -25945511, 7480958, -17681669, -8354183, -22545972, 14150565, 15970762, 4099461 }, - { 29262576, 16756590, 26350592, -8793563, 8529671, -11208050, 13617293, -9937143, 11465739, 8317062 }, + {9661027, 705443, 11980065, -5370154, -1628543, 14661173, -6346142, + 2625015, 28431036, -16771834}, + {-23839233, -8311415, -25945511, 7480958, -17681669, -8354183, + -22545972, 14150565, 15970762, 4099461}, + {29262576, 16756590, 26350592, -8793563, 8529671, -11208050, + 13617293, -9937143, 11465739, 8317062}, }, { - { -25493081, -6962928, 32500200, -9419051, -23038724, -2302222, 14898637, 3848455, 20969334, -5157516 }, - { -20384450, -14347713, -18336405, 13884722, -33039454, 2842114, -21610826, -3649888, 11177095, 14989547 }, - { -24496721, -11716016, 16959896, 2278463, 12066309, 10137771, 13515641, 2581286, -28487508, 9930240 }, + {-25493081, -6962928, 32500200, -9419051, -23038724, -2302222, + 14898637, 3848455, 20969334, -5157516}, + {-20384450, -14347713, -18336405, 13884722, -33039454, 2842114, + -21610826, -3649888, 11177095, 14989547}, + {-24496721, -11716016, 16959896, 2278463, 12066309, 10137771, + 13515641, 2581286, -28487508, 9930240}, }, { - { -17751622, -2097826, 16544300, -13009300, -15914807, -14949081, 18345767, -13403753, 16291481, -5314038 }, - { -33229194, 2553288, 32678213, 9875984, 8534129, 6889387, -9676774, 6957617, 4368891, 9788741 }, - { 16660756, 7281060, -10830758, 12911820, 20108584, -8101676, -21722536, -8613148, 16250552, -11111103 }, + {-17751622, -2097826, 16544300, -13009300, -15914807, -14949081, + 18345767, -13403753, 16291481, -5314038}, + {-33229194, 2553288, 32678213, 9875984, 8534129, 6889387, -9676774, + 6957617, 4368891, 9788741}, + {16660756, 7281060, -10830758, 12911820, 20108584, -8101676, + -21722536, -8613148, 16250552, -11111103}, }, { - { -19765507, 2390526, -16551031, 14161980, 1905286, 6414907, 4689584, 10604807, -30190403, 4782747 }, - { -1354539, 14736941, -7367442, -13292886, 7710542, -14155590, -9981571, 4383045, 22546403, 437323 }, - { 31665577, -12180464, -16186830, 1491339, -18368625, 3294682, 27343084, 2786261, -30633590, -14097016 }, + {-19765507, 2390526, -16551031, 14161980, 1905286, 6414907, 4689584, + 10604807, -30190403, 4782747}, + {-1354539, 14736941, -7367442, -13292886, 7710542, -14155590, + -9981571, 4383045, 22546403, 437323}, + {31665577, -12180464, -16186830, 1491339, -18368625, 3294682, + 27343084, 2786261, -30633590, -14097016}, }, { - { -14467279, -683715, -33374107, 7448552, 19294360, 14334329, -19690631, 2355319, -19284671, -6114373 }, - { 15121312, -15796162, 6377020, -6031361, -10798111, -12957845, 18952177, 15496498, -29380133, 11754228 }, - { -2637277, -13483075, 8488727, -14303896, 12728761, -1622493, 7141596, 11724556, 22761615, -10134141 }, + {-14467279, -683715, -33374107, 7448552, 19294360, 14334329, + -19690631, 2355319, -19284671, -6114373}, + {15121312, -15796162, 6377020, -6031361, -10798111, -12957845, + 18952177, 15496498, -29380133, 11754228}, + {-2637277, -13483075, 8488727, -14303896, 12728761, -1622493, + 7141596, 11724556, 22761615, -10134141}, }, { - { 16918416, 11729663, -18083579, 3022987, -31015732, -13339659, -28741185, -12227393, 32851222, 11717399 }, - { 11166634, 7338049, -6722523, 4531520, -29468672, -7302055, 31474879, 3483633, -1193175, -4030831 }, - { -185635, 9921305, 31456609, -13536438, -12013818, 13348923, 33142652, 6546660, -19985279, -3948376 }, + {16918416, 11729663, -18083579, 3022987, -31015732, -13339659, + -28741185, -12227393, 32851222, 11717399}, + {11166634, 7338049, -6722523, 4531520, -29468672, -7302055, + 31474879, 3483633, -1193175, -4030831}, + {-185635, 9921305, 31456609, -13536438, -12013818, 13348923, + 33142652, 6546660, -19985279, -3948376}, }, { - { -32460596, 11266712, -11197107, -7899103, 31703694, 3855903, -8537131, -12833048, -30772034, -15486313 }, - { -18006477, 12709068, 3991746, -6479188, -21491523, -10550425, -31135347, -16049879, 10928917, 3011958 }, - { -6957757, -15594337, 31696059, 334240, 29576716, 14796075, -30831056, -12805180, 18008031, 10258577 }, + {-32460596, 11266712, -11197107, -7899103, 31703694, 3855903, + -8537131, -12833048, -30772034, -15486313}, + {-18006477, 12709068, 3991746, -6479188, -21491523, -10550425, + -31135347, -16049879, 10928917, 3011958}, + {-6957757, -15594337, 31696059, 334240, 29576716, 14796075, + -30831056, -12805180, 18008031, 10258577}, }, { - { -22448644, 15655569, 7018479, -4410003, -30314266, -1201591, -1853465, 1367120, 25127874, 6671743 }, - { 29701166, -14373934, -10878120, 9279288, -17568, 13127210, 21382910, 11042292, 25838796, 4642684 }, - { -20430234, 14955537, -24126347, 8124619, -5369288, -5990470, 30468147, -13900640, 18423289, 4177476 }, + {-22448644, 15655569, 7018479, -4410003, -30314266, -1201591, + -1853465, 1367120, 25127874, 6671743}, + {29701166, -14373934, -10878120, 9279288, -17568, 13127210, + 21382910, 11042292, 25838796, 4642684}, + {-20430234, 14955537, -24126347, 8124619, -5369288, -5990470, + 30468147, -13900640, 18423289, 4177476}, }, }, }; diff --git a/sm/src/ed25519/sc.c b/sm/src/ed25519/sc.c index ca5bad2ca..25c342e97 100644 --- a/sm/src/ed25519/sc.c +++ b/sm/src/ed25519/sc.c @@ -1,25 +1,28 @@ -#include "fixedint.h" #include "sc.h" -static uint64_t load_3(const unsigned char *in) { - uint64_t result; +#include "fixedint.h" + +static uint64_t +load_3(const unsigned char* in) { + uint64_t result; - result = (uint64_t) in[0]; - result |= ((uint64_t) in[1]) << 8; - result |= ((uint64_t) in[2]) << 16; + result = (uint64_t)in[0]; + result |= ((uint64_t)in[1]) << 8; + result |= ((uint64_t)in[2]) << 16; - return result; + return result; } -static uint64_t load_4(const unsigned char *in) { - uint64_t result; +static uint64_t +load_4(const unsigned char* in) { + uint64_t result; + + result = (uint64_t)in[0]; + result |= ((uint64_t)in[1]) << 8; + result |= ((uint64_t)in[2]) << 16; + result |= ((uint64_t)in[3]) << 24; - result = (uint64_t) in[0]; - result |= ((uint64_t) in[1]) << 8; - result |= ((uint64_t) in[2]) << 16; - result |= ((uint64_t) in[3]) << 24; - - return result; + return result; } /* @@ -32,322 +35,321 @@ static uint64_t load_4(const unsigned char *in) { Overwrites s in place. */ -void sc_reduce(unsigned char *s) { - int64_t s0 = 2097151 & load_3(s); - int64_t s1 = 2097151 & (load_4(s + 2) >> 5); - int64_t s2 = 2097151 & (load_3(s + 5) >> 2); - int64_t s3 = 2097151 & (load_4(s + 7) >> 7); - int64_t s4 = 2097151 & (load_4(s + 10) >> 4); - int64_t s5 = 2097151 & (load_3(s + 13) >> 1); - int64_t s6 = 2097151 & (load_4(s + 15) >> 6); - int64_t s7 = 2097151 & (load_3(s + 18) >> 3); - int64_t s8 = 2097151 & load_3(s + 21); - int64_t s9 = 2097151 & (load_4(s + 23) >> 5); - int64_t s10 = 2097151 & (load_3(s + 26) >> 2); - int64_t s11 = 2097151 & (load_4(s + 28) >> 7); - int64_t s12 = 2097151 & (load_4(s + 31) >> 4); - int64_t s13 = 2097151 & (load_3(s + 34) >> 1); - int64_t s14 = 2097151 & (load_4(s + 36) >> 6); - int64_t s15 = 2097151 & (load_3(s + 39) >> 3); - int64_t s16 = 2097151 & load_3(s + 42); - int64_t s17 = 2097151 & (load_4(s + 44) >> 5); - int64_t s18 = 2097151 & (load_3(s + 47) >> 2); - int64_t s19 = 2097151 & (load_4(s + 49) >> 7); - int64_t s20 = 2097151 & (load_4(s + 52) >> 4); - int64_t s21 = 2097151 & (load_3(s + 55) >> 1); - int64_t s22 = 2097151 & (load_4(s + 57) >> 6); - int64_t s23 = (load_4(s + 60) >> 3); - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - int64_t carry10; - int64_t carry11; - int64_t carry12; - int64_t carry13; - int64_t carry14; - int64_t carry15; - int64_t carry16; +void +sc_reduce(unsigned char* s) { + int64_t s0 = 2097151 & load_3(s); + int64_t s1 = 2097151 & (load_4(s + 2) >> 5); + int64_t s2 = 2097151 & (load_3(s + 5) >> 2); + int64_t s3 = 2097151 & (load_4(s + 7) >> 7); + int64_t s4 = 2097151 & (load_4(s + 10) >> 4); + int64_t s5 = 2097151 & (load_3(s + 13) >> 1); + int64_t s6 = 2097151 & (load_4(s + 15) >> 6); + int64_t s7 = 2097151 & (load_3(s + 18) >> 3); + int64_t s8 = 2097151 & load_3(s + 21); + int64_t s9 = 2097151 & (load_4(s + 23) >> 5); + int64_t s10 = 2097151 & (load_3(s + 26) >> 2); + int64_t s11 = 2097151 & (load_4(s + 28) >> 7); + int64_t s12 = 2097151 & (load_4(s + 31) >> 4); + int64_t s13 = 2097151 & (load_3(s + 34) >> 1); + int64_t s14 = 2097151 & (load_4(s + 36) >> 6); + int64_t s15 = 2097151 & (load_3(s + 39) >> 3); + int64_t s16 = 2097151 & load_3(s + 42); + int64_t s17 = 2097151 & (load_4(s + 44) >> 5); + int64_t s18 = 2097151 & (load_3(s + 47) >> 2); + int64_t s19 = 2097151 & (load_4(s + 49) >> 7); + int64_t s20 = 2097151 & (load_4(s + 52) >> 4); + int64_t s21 = 2097151 & (load_3(s + 55) >> 1); + int64_t s22 = 2097151 & (load_4(s + 57) >> 6); + int64_t s23 = (load_4(s + 60) >> 3); + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + int64_t carry10; + int64_t carry11; + int64_t carry12; + int64_t carry13; + int64_t carry14; + int64_t carry15; + int64_t carry16; - s11 += s23 * 666643; - s12 += s23 * 470296; - s13 += s23 * 654183; - s14 -= s23 * 997805; - s15 += s23 * 136657; - s16 -= s23 * 683901; - s23 = 0; - s10 += s22 * 666643; - s11 += s22 * 470296; - s12 += s22 * 654183; - s13 -= s22 * 997805; - s14 += s22 * 136657; - s15 -= s22 * 683901; - s22 = 0; - s9 += s21 * 666643; - s10 += s21 * 470296; - s11 += s21 * 654183; - s12 -= s21 * 997805; - s13 += s21 * 136657; - s14 -= s21 * 683901; - s21 = 0; - s8 += s20 * 666643; - s9 += s20 * 470296; - s10 += s20 * 654183; - s11 -= s20 * 997805; - s12 += s20 * 136657; - s13 -= s20 * 683901; - s20 = 0; - s7 += s19 * 666643; - s8 += s19 * 470296; - s9 += s19 * 654183; - s10 -= s19 * 997805; - s11 += s19 * 136657; - s12 -= s19 * 683901; - s19 = 0; - s6 += s18 * 666643; - s7 += s18 * 470296; - s8 += s18 * 654183; - s9 -= s18 * 997805; - s10 += s18 * 136657; - s11 -= s18 * 683901; - s18 = 0; - carry6 = (s6 + (1 << 20)) >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry8 = (s8 + (1 << 20)) >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry10 = (s10 + (1 << 20)) >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry12 = (s12 + (1 << 20)) >> 21; - s13 += carry12; - s12 -= carry12 << 21; - carry14 = (s14 + (1 << 20)) >> 21; - s15 += carry14; - s14 -= carry14 << 21; - carry16 = (s16 + (1 << 20)) >> 21; - s17 += carry16; - s16 -= carry16 << 21; - carry7 = (s7 + (1 << 20)) >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry9 = (s9 + (1 << 20)) >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry11 = (s11 + (1 << 20)) >> 21; - s12 += carry11; - s11 -= carry11 << 21; - carry13 = (s13 + (1 << 20)) >> 21; - s14 += carry13; - s13 -= carry13 << 21; - carry15 = (s15 + (1 << 20)) >> 21; - s16 += carry15; - s15 -= carry15 << 21; - s5 += s17 * 666643; - s6 += s17 * 470296; - s7 += s17 * 654183; - s8 -= s17 * 997805; - s9 += s17 * 136657; - s10 -= s17 * 683901; - s17 = 0; - s4 += s16 * 666643; - s5 += s16 * 470296; - s6 += s16 * 654183; - s7 -= s16 * 997805; - s8 += s16 * 136657; - s9 -= s16 * 683901; - s16 = 0; - s3 += s15 * 666643; - s4 += s15 * 470296; - s5 += s15 * 654183; - s6 -= s15 * 997805; - s7 += s15 * 136657; - s8 -= s15 * 683901; - s15 = 0; - s2 += s14 * 666643; - s3 += s14 * 470296; - s4 += s14 * 654183; - s5 -= s14 * 997805; - s6 += s14 * 136657; - s7 -= s14 * 683901; - s14 = 0; - s1 += s13 * 666643; - s2 += s13 * 470296; - s3 += s13 * 654183; - s4 -= s13 * 997805; - s5 += s13 * 136657; - s6 -= s13 * 683901; - s13 = 0; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = (s0 + (1 << 20)) >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry2 = (s2 + (1 << 20)) >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry4 = (s4 + (1 << 20)) >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry6 = (s6 + (1 << 20)) >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry8 = (s8 + (1 << 20)) >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry10 = (s10 + (1 << 20)) >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry1 = (s1 + (1 << 20)) >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry3 = (s3 + (1 << 20)) >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry5 = (s5 + (1 << 20)) >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry7 = (s7 + (1 << 20)) >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry9 = (s9 + (1 << 20)) >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry11 = (s11 + (1 << 20)) >> 21; - s12 += carry11; - s11 -= carry11 << 21; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = s0 >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry1 = s1 >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry2 = s2 >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry3 = s3 >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry4 = s4 >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry5 = s5 >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry6 = s6 >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry7 = s7 >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry8 = s8 >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry9 = s9 >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry10 = s10 >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry11 = s11 >> 21; - s12 += carry11; - s11 -= carry11 << 21; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = s0 >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry1 = s1 >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry2 = s2 >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry3 = s3 >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry4 = s4 >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry5 = s5 >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry6 = s6 >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry7 = s7 >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry8 = s8 >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry9 = s9 >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry10 = s10 >> 21; - s11 += carry10; - s10 -= carry10 << 21; + s11 += s23 * 666643; + s12 += s23 * 470296; + s13 += s23 * 654183; + s14 -= s23 * 997805; + s15 += s23 * 136657; + s16 -= s23 * 683901; + s23 = 0; + s10 += s22 * 666643; + s11 += s22 * 470296; + s12 += s22 * 654183; + s13 -= s22 * 997805; + s14 += s22 * 136657; + s15 -= s22 * 683901; + s22 = 0; + s9 += s21 * 666643; + s10 += s21 * 470296; + s11 += s21 * 654183; + s12 -= s21 * 997805; + s13 += s21 * 136657; + s14 -= s21 * 683901; + s21 = 0; + s8 += s20 * 666643; + s9 += s20 * 470296; + s10 += s20 * 654183; + s11 -= s20 * 997805; + s12 += s20 * 136657; + s13 -= s20 * 683901; + s20 = 0; + s7 += s19 * 666643; + s8 += s19 * 470296; + s9 += s19 * 654183; + s10 -= s19 * 997805; + s11 += s19 * 136657; + s12 -= s19 * 683901; + s19 = 0; + s6 += s18 * 666643; + s7 += s18 * 470296; + s8 += s18 * 654183; + s9 -= s18 * 997805; + s10 += s18 * 136657; + s11 -= s18 * 683901; + s18 = 0; + carry6 = (s6 + (1 << 20)) >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry12 = (s12 + (1 << 20)) >> 21; + s13 += carry12; + s12 -= carry12 << 21; + carry14 = (s14 + (1 << 20)) >> 21; + s15 += carry14; + s14 -= carry14 << 21; + carry16 = (s16 + (1 << 20)) >> 21; + s17 += carry16; + s16 -= carry16 << 21; + carry7 = (s7 + (1 << 20)) >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; + s12 += carry11; + s11 -= carry11 << 21; + carry13 = (s13 + (1 << 20)) >> 21; + s14 += carry13; + s13 -= carry13 << 21; + carry15 = (s15 + (1 << 20)) >> 21; + s16 += carry15; + s15 -= carry15 << 21; + s5 += s17 * 666643; + s6 += s17 * 470296; + s7 += s17 * 654183; + s8 -= s17 * 997805; + s9 += s17 * 136657; + s10 -= s17 * 683901; + s17 = 0; + s4 += s16 * 666643; + s5 += s16 * 470296; + s6 += s16 * 654183; + s7 -= s16 * 997805; + s8 += s16 * 136657; + s9 -= s16 * 683901; + s16 = 0; + s3 += s15 * 666643; + s4 += s15 * 470296; + s5 += s15 * 654183; + s6 -= s15 * 997805; + s7 += s15 * 136657; + s8 -= s15 * 683901; + s15 = 0; + s2 += s14 * 666643; + s3 += s14 * 470296; + s4 += s14 * 654183; + s5 -= s14 * 997805; + s6 += s14 * 136657; + s7 -= s14 * 683901; + s14 = 0; + s1 += s13 * 666643; + s2 += s13 * 470296; + s3 += s13 * 654183; + s4 -= s13 * 997805; + s5 += s13 * 136657; + s6 -= s13 * 683901; + s13 = 0; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = (s0 + (1 << 20)) >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry2 = (s2 + (1 << 20)) >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry4 = (s4 + (1 << 20)) >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry6 = (s6 + (1 << 20)) >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry1 = (s1 + (1 << 20)) >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry3 = (s3 + (1 << 20)) >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry5 = (s5 + (1 << 20)) >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry7 = (s7 + (1 << 20)) >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; + s12 += carry11; + s11 -= carry11 << 21; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = s0 >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry1 = s1 >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry2 = s2 >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry3 = s3 >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry4 = s4 >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry5 = s5 >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry6 = s6 >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry7 = s7 >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry8 = s8 >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry9 = s9 >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry10 = s10 >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry11 = s11 >> 21; + s12 += carry11; + s11 -= carry11 << 21; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = s0 >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry1 = s1 >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry2 = s2 >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry3 = s3 >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry4 = s4 >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry5 = s5 >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry6 = s6 >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry7 = s7 >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry8 = s8 >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry9 = s9 >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry10 = s10 >> 21; + s11 += carry10; + s10 -= carry10 << 21; - s[0] = (unsigned char) (s0 >> 0); - s[1] = (unsigned char) (s0 >> 8); - s[2] = (unsigned char) ((s0 >> 16) | (s1 << 5)); - s[3] = (unsigned char) (s1 >> 3); - s[4] = (unsigned char) (s1 >> 11); - s[5] = (unsigned char) ((s1 >> 19) | (s2 << 2)); - s[6] = (unsigned char) (s2 >> 6); - s[7] = (unsigned char) ((s2 >> 14) | (s3 << 7)); - s[8] = (unsigned char) (s3 >> 1); - s[9] = (unsigned char) (s3 >> 9); - s[10] = (unsigned char) ((s3 >> 17) | (s4 << 4)); - s[11] = (unsigned char) (s4 >> 4); - s[12] = (unsigned char) (s4 >> 12); - s[13] = (unsigned char) ((s4 >> 20) | (s5 << 1)); - s[14] = (unsigned char) (s5 >> 7); - s[15] = (unsigned char) ((s5 >> 15) | (s6 << 6)); - s[16] = (unsigned char) (s6 >> 2); - s[17] = (unsigned char) (s6 >> 10); - s[18] = (unsigned char) ((s6 >> 18) | (s7 << 3)); - s[19] = (unsigned char) (s7 >> 5); - s[20] = (unsigned char) (s7 >> 13); - s[21] = (unsigned char) (s8 >> 0); - s[22] = (unsigned char) (s8 >> 8); - s[23] = (unsigned char) ((s8 >> 16) | (s9 << 5)); - s[24] = (unsigned char) (s9 >> 3); - s[25] = (unsigned char) (s9 >> 11); - s[26] = (unsigned char) ((s9 >> 19) | (s10 << 2)); - s[27] = (unsigned char) (s10 >> 6); - s[28] = (unsigned char) ((s10 >> 14) | (s11 << 7)); - s[29] = (unsigned char) (s11 >> 1); - s[30] = (unsigned char) (s11 >> 9); - s[31] = (unsigned char) (s11 >> 17); + s[0] = (unsigned char)(s0 >> 0); + s[1] = (unsigned char)(s0 >> 8); + s[2] = (unsigned char)((s0 >> 16) | (s1 << 5)); + s[3] = (unsigned char)(s1 >> 3); + s[4] = (unsigned char)(s1 >> 11); + s[5] = (unsigned char)((s1 >> 19) | (s2 << 2)); + s[6] = (unsigned char)(s2 >> 6); + s[7] = (unsigned char)((s2 >> 14) | (s3 << 7)); + s[8] = (unsigned char)(s3 >> 1); + s[9] = (unsigned char)(s3 >> 9); + s[10] = (unsigned char)((s3 >> 17) | (s4 << 4)); + s[11] = (unsigned char)(s4 >> 4); + s[12] = (unsigned char)(s4 >> 12); + s[13] = (unsigned char)((s4 >> 20) | (s5 << 1)); + s[14] = (unsigned char)(s5 >> 7); + s[15] = (unsigned char)((s5 >> 15) | (s6 << 6)); + s[16] = (unsigned char)(s6 >> 2); + s[17] = (unsigned char)(s6 >> 10); + s[18] = (unsigned char)((s6 >> 18) | (s7 << 3)); + s[19] = (unsigned char)(s7 >> 5); + s[20] = (unsigned char)(s7 >> 13); + s[21] = (unsigned char)(s8 >> 0); + s[22] = (unsigned char)(s8 >> 8); + s[23] = (unsigned char)((s8 >> 16) | (s9 << 5)); + s[24] = (unsigned char)(s9 >> 3); + s[25] = (unsigned char)(s9 >> 11); + s[26] = (unsigned char)((s9 >> 19) | (s10 << 2)); + s[27] = (unsigned char)(s10 >> 6); + s[28] = (unsigned char)((s10 >> 14) | (s11 << 7)); + s[29] = (unsigned char)(s11 >> 1); + s[30] = (unsigned char)(s11 >> 9); + s[31] = (unsigned char)(s11 >> 17); } - - /* Input: a[0]+256*a[1]+...+256^31*a[31] = a @@ -359,451 +361,463 @@ void sc_reduce(unsigned char *s) { where l = 2^252 + 27742317777372353535851937790883648493. */ -void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c) { - int64_t a0 = 2097151 & load_3(a); - int64_t a1 = 2097151 & (load_4(a + 2) >> 5); - int64_t a2 = 2097151 & (load_3(a + 5) >> 2); - int64_t a3 = 2097151 & (load_4(a + 7) >> 7); - int64_t a4 = 2097151 & (load_4(a + 10) >> 4); - int64_t a5 = 2097151 & (load_3(a + 13) >> 1); - int64_t a6 = 2097151 & (load_4(a + 15) >> 6); - int64_t a7 = 2097151 & (load_3(a + 18) >> 3); - int64_t a8 = 2097151 & load_3(a + 21); - int64_t a9 = 2097151 & (load_4(a + 23) >> 5); - int64_t a10 = 2097151 & (load_3(a + 26) >> 2); - int64_t a11 = (load_4(a + 28) >> 7); - int64_t b0 = 2097151 & load_3(b); - int64_t b1 = 2097151 & (load_4(b + 2) >> 5); - int64_t b2 = 2097151 & (load_3(b + 5) >> 2); - int64_t b3 = 2097151 & (load_4(b + 7) >> 7); - int64_t b4 = 2097151 & (load_4(b + 10) >> 4); - int64_t b5 = 2097151 & (load_3(b + 13) >> 1); - int64_t b6 = 2097151 & (load_4(b + 15) >> 6); - int64_t b7 = 2097151 & (load_3(b + 18) >> 3); - int64_t b8 = 2097151 & load_3(b + 21); - int64_t b9 = 2097151 & (load_4(b + 23) >> 5); - int64_t b10 = 2097151 & (load_3(b + 26) >> 2); - int64_t b11 = (load_4(b + 28) >> 7); - int64_t c0 = 2097151 & load_3(c); - int64_t c1 = 2097151 & (load_4(c + 2) >> 5); - int64_t c2 = 2097151 & (load_3(c + 5) >> 2); - int64_t c3 = 2097151 & (load_4(c + 7) >> 7); - int64_t c4 = 2097151 & (load_4(c + 10) >> 4); - int64_t c5 = 2097151 & (load_3(c + 13) >> 1); - int64_t c6 = 2097151 & (load_4(c + 15) >> 6); - int64_t c7 = 2097151 & (load_3(c + 18) >> 3); - int64_t c8 = 2097151 & load_3(c + 21); - int64_t c9 = 2097151 & (load_4(c + 23) >> 5); - int64_t c10 = 2097151 & (load_3(c + 26) >> 2); - int64_t c11 = (load_4(c + 28) >> 7); - int64_t s0; - int64_t s1; - int64_t s2; - int64_t s3; - int64_t s4; - int64_t s5; - int64_t s6; - int64_t s7; - int64_t s8; - int64_t s9; - int64_t s10; - int64_t s11; - int64_t s12; - int64_t s13; - int64_t s14; - int64_t s15; - int64_t s16; - int64_t s17; - int64_t s18; - int64_t s19; - int64_t s20; - int64_t s21; - int64_t s22; - int64_t s23; - int64_t carry0; - int64_t carry1; - int64_t carry2; - int64_t carry3; - int64_t carry4; - int64_t carry5; - int64_t carry6; - int64_t carry7; - int64_t carry8; - int64_t carry9; - int64_t carry10; - int64_t carry11; - int64_t carry12; - int64_t carry13; - int64_t carry14; - int64_t carry15; - int64_t carry16; - int64_t carry17; - int64_t carry18; - int64_t carry19; - int64_t carry20; - int64_t carry21; - int64_t carry22; +void +sc_muladd( + unsigned char* s, const unsigned char* a, const unsigned char* b, + const unsigned char* c) { + int64_t a0 = 2097151 & load_3(a); + int64_t a1 = 2097151 & (load_4(a + 2) >> 5); + int64_t a2 = 2097151 & (load_3(a + 5) >> 2); + int64_t a3 = 2097151 & (load_4(a + 7) >> 7); + int64_t a4 = 2097151 & (load_4(a + 10) >> 4); + int64_t a5 = 2097151 & (load_3(a + 13) >> 1); + int64_t a6 = 2097151 & (load_4(a + 15) >> 6); + int64_t a7 = 2097151 & (load_3(a + 18) >> 3); + int64_t a8 = 2097151 & load_3(a + 21); + int64_t a9 = 2097151 & (load_4(a + 23) >> 5); + int64_t a10 = 2097151 & (load_3(a + 26) >> 2); + int64_t a11 = (load_4(a + 28) >> 7); + int64_t b0 = 2097151 & load_3(b); + int64_t b1 = 2097151 & (load_4(b + 2) >> 5); + int64_t b2 = 2097151 & (load_3(b + 5) >> 2); + int64_t b3 = 2097151 & (load_4(b + 7) >> 7); + int64_t b4 = 2097151 & (load_4(b + 10) >> 4); + int64_t b5 = 2097151 & (load_3(b + 13) >> 1); + int64_t b6 = 2097151 & (load_4(b + 15) >> 6); + int64_t b7 = 2097151 & (load_3(b + 18) >> 3); + int64_t b8 = 2097151 & load_3(b + 21); + int64_t b9 = 2097151 & (load_4(b + 23) >> 5); + int64_t b10 = 2097151 & (load_3(b + 26) >> 2); + int64_t b11 = (load_4(b + 28) >> 7); + int64_t c0 = 2097151 & load_3(c); + int64_t c1 = 2097151 & (load_4(c + 2) >> 5); + int64_t c2 = 2097151 & (load_3(c + 5) >> 2); + int64_t c3 = 2097151 & (load_4(c + 7) >> 7); + int64_t c4 = 2097151 & (load_4(c + 10) >> 4); + int64_t c5 = 2097151 & (load_3(c + 13) >> 1); + int64_t c6 = 2097151 & (load_4(c + 15) >> 6); + int64_t c7 = 2097151 & (load_3(c + 18) >> 3); + int64_t c8 = 2097151 & load_3(c + 21); + int64_t c9 = 2097151 & (load_4(c + 23) >> 5); + int64_t c10 = 2097151 & (load_3(c + 26) >> 2); + int64_t c11 = (load_4(c + 28) >> 7); + int64_t s0; + int64_t s1; + int64_t s2; + int64_t s3; + int64_t s4; + int64_t s5; + int64_t s6; + int64_t s7; + int64_t s8; + int64_t s9; + int64_t s10; + int64_t s11; + int64_t s12; + int64_t s13; + int64_t s14; + int64_t s15; + int64_t s16; + int64_t s17; + int64_t s18; + int64_t s19; + int64_t s20; + int64_t s21; + int64_t s22; + int64_t s23; + int64_t carry0; + int64_t carry1; + int64_t carry2; + int64_t carry3; + int64_t carry4; + int64_t carry5; + int64_t carry6; + int64_t carry7; + int64_t carry8; + int64_t carry9; + int64_t carry10; + int64_t carry11; + int64_t carry12; + int64_t carry13; + int64_t carry14; + int64_t carry15; + int64_t carry16; + int64_t carry17; + int64_t carry18; + int64_t carry19; + int64_t carry20; + int64_t carry21; + int64_t carry22; + + s0 = c0 + a0 * b0; + s1 = c1 + a0 * b1 + a1 * b0; + s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0; + s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0; + s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0; + s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0; + s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0; + s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 + + a6 * b1 + a7 * b0; + s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 + + a6 * b2 + a7 * b1 + a8 * b0; + s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 + + a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0; + s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 + + a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0; + s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 + + a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0; + s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 + a7 * b5 + + a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1; + s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 + a8 * b5 + + a9 * b4 + a10 * b3 + a11 * b2; + s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 + a9 * b5 + + a10 * b4 + a11 * b3; + s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 + a10 * b5 + + a11 * b4; + s16 = a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5; + s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6; + s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7; + s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8; + s20 = a9 * b11 + a10 * b10 + a11 * b9; + s21 = a10 * b11 + a11 * b10; + s22 = a11 * b11; + s23 = 0; + carry0 = (s0 + (1 << 20)) >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry2 = (s2 + (1 << 20)) >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry4 = (s4 + (1 << 20)) >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry6 = (s6 + (1 << 20)) >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry12 = (s12 + (1 << 20)) >> 21; + s13 += carry12; + s12 -= carry12 << 21; + carry14 = (s14 + (1 << 20)) >> 21; + s15 += carry14; + s14 -= carry14 << 21; + carry16 = (s16 + (1 << 20)) >> 21; + s17 += carry16; + s16 -= carry16 << 21; + carry18 = (s18 + (1 << 20)) >> 21; + s19 += carry18; + s18 -= carry18 << 21; + carry20 = (s20 + (1 << 20)) >> 21; + s21 += carry20; + s20 -= carry20 << 21; + carry22 = (s22 + (1 << 20)) >> 21; + s23 += carry22; + s22 -= carry22 << 21; + carry1 = (s1 + (1 << 20)) >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry3 = (s3 + (1 << 20)) >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry5 = (s5 + (1 << 20)) >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry7 = (s7 + (1 << 20)) >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; + s12 += carry11; + s11 -= carry11 << 21; + carry13 = (s13 + (1 << 20)) >> 21; + s14 += carry13; + s13 -= carry13 << 21; + carry15 = (s15 + (1 << 20)) >> 21; + s16 += carry15; + s15 -= carry15 << 21; + carry17 = (s17 + (1 << 20)) >> 21; + s18 += carry17; + s17 -= carry17 << 21; + carry19 = (s19 + (1 << 20)) >> 21; + s20 += carry19; + s19 -= carry19 << 21; + carry21 = (s21 + (1 << 20)) >> 21; + s22 += carry21; + s21 -= carry21 << 21; + s11 += s23 * 666643; + s12 += s23 * 470296; + s13 += s23 * 654183; + s14 -= s23 * 997805; + s15 += s23 * 136657; + s16 -= s23 * 683901; + s23 = 0; + s10 += s22 * 666643; + s11 += s22 * 470296; + s12 += s22 * 654183; + s13 -= s22 * 997805; + s14 += s22 * 136657; + s15 -= s22 * 683901; + s22 = 0; + s9 += s21 * 666643; + s10 += s21 * 470296; + s11 += s21 * 654183; + s12 -= s21 * 997805; + s13 += s21 * 136657; + s14 -= s21 * 683901; + s21 = 0; + s8 += s20 * 666643; + s9 += s20 * 470296; + s10 += s20 * 654183; + s11 -= s20 * 997805; + s12 += s20 * 136657; + s13 -= s20 * 683901; + s20 = 0; + s7 += s19 * 666643; + s8 += s19 * 470296; + s9 += s19 * 654183; + s10 -= s19 * 997805; + s11 += s19 * 136657; + s12 -= s19 * 683901; + s19 = 0; + s6 += s18 * 666643; + s7 += s18 * 470296; + s8 += s18 * 654183; + s9 -= s18 * 997805; + s10 += s18 * 136657; + s11 -= s18 * 683901; + s18 = 0; + carry6 = (s6 + (1 << 20)) >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry12 = (s12 + (1 << 20)) >> 21; + s13 += carry12; + s12 -= carry12 << 21; + carry14 = (s14 + (1 << 20)) >> 21; + s15 += carry14; + s14 -= carry14 << 21; + carry16 = (s16 + (1 << 20)) >> 21; + s17 += carry16; + s16 -= carry16 << 21; + carry7 = (s7 + (1 << 20)) >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; + s12 += carry11; + s11 -= carry11 << 21; + carry13 = (s13 + (1 << 20)) >> 21; + s14 += carry13; + s13 -= carry13 << 21; + carry15 = (s15 + (1 << 20)) >> 21; + s16 += carry15; + s15 -= carry15 << 21; + s5 += s17 * 666643; + s6 += s17 * 470296; + s7 += s17 * 654183; + s8 -= s17 * 997805; + s9 += s17 * 136657; + s10 -= s17 * 683901; + s17 = 0; + s4 += s16 * 666643; + s5 += s16 * 470296; + s6 += s16 * 654183; + s7 -= s16 * 997805; + s8 += s16 * 136657; + s9 -= s16 * 683901; + s16 = 0; + s3 += s15 * 666643; + s4 += s15 * 470296; + s5 += s15 * 654183; + s6 -= s15 * 997805; + s7 += s15 * 136657; + s8 -= s15 * 683901; + s15 = 0; + s2 += s14 * 666643; + s3 += s14 * 470296; + s4 += s14 * 654183; + s5 -= s14 * 997805; + s6 += s14 * 136657; + s7 -= s14 * 683901; + s14 = 0; + s1 += s13 * 666643; + s2 += s13 * 470296; + s3 += s13 * 654183; + s4 -= s13 * 997805; + s5 += s13 * 136657; + s6 -= s13 * 683901; + s13 = 0; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = (s0 + (1 << 20)) >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry2 = (s2 + (1 << 20)) >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry4 = (s4 + (1 << 20)) >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry6 = (s6 + (1 << 20)) >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry1 = (s1 + (1 << 20)) >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry3 = (s3 + (1 << 20)) >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry5 = (s5 + (1 << 20)) >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry7 = (s7 + (1 << 20)) >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; + s12 += carry11; + s11 -= carry11 << 21; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = s0 >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry1 = s1 >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry2 = s2 >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry3 = s3 >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry4 = s4 >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry5 = s5 >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry6 = s6 >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry7 = s7 >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry8 = s8 >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry9 = s9 >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry10 = s10 >> 21; + s11 += carry10; + s10 -= carry10 << 21; + carry11 = s11 >> 21; + s12 += carry11; + s11 -= carry11 << 21; + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + carry0 = s0 >> 21; + s1 += carry0; + s0 -= carry0 << 21; + carry1 = s1 >> 21; + s2 += carry1; + s1 -= carry1 << 21; + carry2 = s2 >> 21; + s3 += carry2; + s2 -= carry2 << 21; + carry3 = s3 >> 21; + s4 += carry3; + s3 -= carry3 << 21; + carry4 = s4 >> 21; + s5 += carry4; + s4 -= carry4 << 21; + carry5 = s5 >> 21; + s6 += carry5; + s5 -= carry5 << 21; + carry6 = s6 >> 21; + s7 += carry6; + s6 -= carry6 << 21; + carry7 = s7 >> 21; + s8 += carry7; + s7 -= carry7 << 21; + carry8 = s8 >> 21; + s9 += carry8; + s8 -= carry8 << 21; + carry9 = s9 >> 21; + s10 += carry9; + s9 -= carry9 << 21; + carry10 = s10 >> 21; + s11 += carry10; + s10 -= carry10 << 21; - s0 = c0 + a0 * b0; - s1 = c1 + a0 * b1 + a1 * b0; - s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0; - s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0; - s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0; - s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0; - s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0; - s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 + a6 * b1 + a7 * b0; - s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 + a6 * b2 + a7 * b1 + a8 * b0; - s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 + a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0; - s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 + a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0; - s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 + a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0; - s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 + a7 * b5 + a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1; - s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 + a8 * b5 + a9 * b4 + a10 * b3 + a11 * b2; - s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 + a9 * b5 + a10 * b4 + a11 * b3; - s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 + a10 * b5 + a11 * b4; - s16 = a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5; - s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6; - s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7; - s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8; - s20 = a9 * b11 + a10 * b10 + a11 * b9; - s21 = a10 * b11 + a11 * b10; - s22 = a11 * b11; - s23 = 0; - carry0 = (s0 + (1 << 20)) >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry2 = (s2 + (1 << 20)) >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry4 = (s4 + (1 << 20)) >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry6 = (s6 + (1 << 20)) >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry8 = (s8 + (1 << 20)) >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry10 = (s10 + (1 << 20)) >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry12 = (s12 + (1 << 20)) >> 21; - s13 += carry12; - s12 -= carry12 << 21; - carry14 = (s14 + (1 << 20)) >> 21; - s15 += carry14; - s14 -= carry14 << 21; - carry16 = (s16 + (1 << 20)) >> 21; - s17 += carry16; - s16 -= carry16 << 21; - carry18 = (s18 + (1 << 20)) >> 21; - s19 += carry18; - s18 -= carry18 << 21; - carry20 = (s20 + (1 << 20)) >> 21; - s21 += carry20; - s20 -= carry20 << 21; - carry22 = (s22 + (1 << 20)) >> 21; - s23 += carry22; - s22 -= carry22 << 21; - carry1 = (s1 + (1 << 20)) >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry3 = (s3 + (1 << 20)) >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry5 = (s5 + (1 << 20)) >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry7 = (s7 + (1 << 20)) >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry9 = (s9 + (1 << 20)) >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry11 = (s11 + (1 << 20)) >> 21; - s12 += carry11; - s11 -= carry11 << 21; - carry13 = (s13 + (1 << 20)) >> 21; - s14 += carry13; - s13 -= carry13 << 21; - carry15 = (s15 + (1 << 20)) >> 21; - s16 += carry15; - s15 -= carry15 << 21; - carry17 = (s17 + (1 << 20)) >> 21; - s18 += carry17; - s17 -= carry17 << 21; - carry19 = (s19 + (1 << 20)) >> 21; - s20 += carry19; - s19 -= carry19 << 21; - carry21 = (s21 + (1 << 20)) >> 21; - s22 += carry21; - s21 -= carry21 << 21; - s11 += s23 * 666643; - s12 += s23 * 470296; - s13 += s23 * 654183; - s14 -= s23 * 997805; - s15 += s23 * 136657; - s16 -= s23 * 683901; - s23 = 0; - s10 += s22 * 666643; - s11 += s22 * 470296; - s12 += s22 * 654183; - s13 -= s22 * 997805; - s14 += s22 * 136657; - s15 -= s22 * 683901; - s22 = 0; - s9 += s21 * 666643; - s10 += s21 * 470296; - s11 += s21 * 654183; - s12 -= s21 * 997805; - s13 += s21 * 136657; - s14 -= s21 * 683901; - s21 = 0; - s8 += s20 * 666643; - s9 += s20 * 470296; - s10 += s20 * 654183; - s11 -= s20 * 997805; - s12 += s20 * 136657; - s13 -= s20 * 683901; - s20 = 0; - s7 += s19 * 666643; - s8 += s19 * 470296; - s9 += s19 * 654183; - s10 -= s19 * 997805; - s11 += s19 * 136657; - s12 -= s19 * 683901; - s19 = 0; - s6 += s18 * 666643; - s7 += s18 * 470296; - s8 += s18 * 654183; - s9 -= s18 * 997805; - s10 += s18 * 136657; - s11 -= s18 * 683901; - s18 = 0; - carry6 = (s6 + (1 << 20)) >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry8 = (s8 + (1 << 20)) >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry10 = (s10 + (1 << 20)) >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry12 = (s12 + (1 << 20)) >> 21; - s13 += carry12; - s12 -= carry12 << 21; - carry14 = (s14 + (1 << 20)) >> 21; - s15 += carry14; - s14 -= carry14 << 21; - carry16 = (s16 + (1 << 20)) >> 21; - s17 += carry16; - s16 -= carry16 << 21; - carry7 = (s7 + (1 << 20)) >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry9 = (s9 + (1 << 20)) >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry11 = (s11 + (1 << 20)) >> 21; - s12 += carry11; - s11 -= carry11 << 21; - carry13 = (s13 + (1 << 20)) >> 21; - s14 += carry13; - s13 -= carry13 << 21; - carry15 = (s15 + (1 << 20)) >> 21; - s16 += carry15; - s15 -= carry15 << 21; - s5 += s17 * 666643; - s6 += s17 * 470296; - s7 += s17 * 654183; - s8 -= s17 * 997805; - s9 += s17 * 136657; - s10 -= s17 * 683901; - s17 = 0; - s4 += s16 * 666643; - s5 += s16 * 470296; - s6 += s16 * 654183; - s7 -= s16 * 997805; - s8 += s16 * 136657; - s9 -= s16 * 683901; - s16 = 0; - s3 += s15 * 666643; - s4 += s15 * 470296; - s5 += s15 * 654183; - s6 -= s15 * 997805; - s7 += s15 * 136657; - s8 -= s15 * 683901; - s15 = 0; - s2 += s14 * 666643; - s3 += s14 * 470296; - s4 += s14 * 654183; - s5 -= s14 * 997805; - s6 += s14 * 136657; - s7 -= s14 * 683901; - s14 = 0; - s1 += s13 * 666643; - s2 += s13 * 470296; - s3 += s13 * 654183; - s4 -= s13 * 997805; - s5 += s13 * 136657; - s6 -= s13 * 683901; - s13 = 0; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = (s0 + (1 << 20)) >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry2 = (s2 + (1 << 20)) >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry4 = (s4 + (1 << 20)) >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry6 = (s6 + (1 << 20)) >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry8 = (s8 + (1 << 20)) >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry10 = (s10 + (1 << 20)) >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry1 = (s1 + (1 << 20)) >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry3 = (s3 + (1 << 20)) >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry5 = (s5 + (1 << 20)) >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry7 = (s7 + (1 << 20)) >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry9 = (s9 + (1 << 20)) >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry11 = (s11 + (1 << 20)) >> 21; - s12 += carry11; - s11 -= carry11 << 21; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = s0 >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry1 = s1 >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry2 = s2 >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry3 = s3 >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry4 = s4 >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry5 = s5 >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry6 = s6 >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry7 = s7 >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry8 = s8 >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry9 = s9 >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry10 = s10 >> 21; - s11 += carry10; - s10 -= carry10 << 21; - carry11 = s11 >> 21; - s12 += carry11; - s11 -= carry11 << 21; - s0 += s12 * 666643; - s1 += s12 * 470296; - s2 += s12 * 654183; - s3 -= s12 * 997805; - s4 += s12 * 136657; - s5 -= s12 * 683901; - s12 = 0; - carry0 = s0 >> 21; - s1 += carry0; - s0 -= carry0 << 21; - carry1 = s1 >> 21; - s2 += carry1; - s1 -= carry1 << 21; - carry2 = s2 >> 21; - s3 += carry2; - s2 -= carry2 << 21; - carry3 = s3 >> 21; - s4 += carry3; - s3 -= carry3 << 21; - carry4 = s4 >> 21; - s5 += carry4; - s4 -= carry4 << 21; - carry5 = s5 >> 21; - s6 += carry5; - s5 -= carry5 << 21; - carry6 = s6 >> 21; - s7 += carry6; - s6 -= carry6 << 21; - carry7 = s7 >> 21; - s8 += carry7; - s7 -= carry7 << 21; - carry8 = s8 >> 21; - s9 += carry8; - s8 -= carry8 << 21; - carry9 = s9 >> 21; - s10 += carry9; - s9 -= carry9 << 21; - carry10 = s10 >> 21; - s11 += carry10; - s10 -= carry10 << 21; - - s[0] = (unsigned char) (s0 >> 0); - s[1] = (unsigned char) (s0 >> 8); - s[2] = (unsigned char) ((s0 >> 16) | (s1 << 5)); - s[3] = (unsigned char) (s1 >> 3); - s[4] = (unsigned char) (s1 >> 11); - s[5] = (unsigned char) ((s1 >> 19) | (s2 << 2)); - s[6] = (unsigned char) (s2 >> 6); - s[7] = (unsigned char) ((s2 >> 14) | (s3 << 7)); - s[8] = (unsigned char) (s3 >> 1); - s[9] = (unsigned char) (s3 >> 9); - s[10] = (unsigned char) ((s3 >> 17) | (s4 << 4)); - s[11] = (unsigned char) (s4 >> 4); - s[12] = (unsigned char) (s4 >> 12); - s[13] = (unsigned char) ((s4 >> 20) | (s5 << 1)); - s[14] = (unsigned char) (s5 >> 7); - s[15] = (unsigned char) ((s5 >> 15) | (s6 << 6)); - s[16] = (unsigned char) (s6 >> 2); - s[17] = (unsigned char) (s6 >> 10); - s[18] = (unsigned char) ((s6 >> 18) | (s7 << 3)); - s[19] = (unsigned char) (s7 >> 5); - s[20] = (unsigned char) (s7 >> 13); - s[21] = (unsigned char) (s8 >> 0); - s[22] = (unsigned char) (s8 >> 8); - s[23] = (unsigned char) ((s8 >> 16) | (s9 << 5)); - s[24] = (unsigned char) (s9 >> 3); - s[25] = (unsigned char) (s9 >> 11); - s[26] = (unsigned char) ((s9 >> 19) | (s10 << 2)); - s[27] = (unsigned char) (s10 >> 6); - s[28] = (unsigned char) ((s10 >> 14) | (s11 << 7)); - s[29] = (unsigned char) (s11 >> 1); - s[30] = (unsigned char) (s11 >> 9); - s[31] = (unsigned char) (s11 >> 17); + s[0] = (unsigned char)(s0 >> 0); + s[1] = (unsigned char)(s0 >> 8); + s[2] = (unsigned char)((s0 >> 16) | (s1 << 5)); + s[3] = (unsigned char)(s1 >> 3); + s[4] = (unsigned char)(s1 >> 11); + s[5] = (unsigned char)((s1 >> 19) | (s2 << 2)); + s[6] = (unsigned char)(s2 >> 6); + s[7] = (unsigned char)((s2 >> 14) | (s3 << 7)); + s[8] = (unsigned char)(s3 >> 1); + s[9] = (unsigned char)(s3 >> 9); + s[10] = (unsigned char)((s3 >> 17) | (s4 << 4)); + s[11] = (unsigned char)(s4 >> 4); + s[12] = (unsigned char)(s4 >> 12); + s[13] = (unsigned char)((s4 >> 20) | (s5 << 1)); + s[14] = (unsigned char)(s5 >> 7); + s[15] = (unsigned char)((s5 >> 15) | (s6 << 6)); + s[16] = (unsigned char)(s6 >> 2); + s[17] = (unsigned char)(s6 >> 10); + s[18] = (unsigned char)((s6 >> 18) | (s7 << 3)); + s[19] = (unsigned char)(s7 >> 5); + s[20] = (unsigned char)(s7 >> 13); + s[21] = (unsigned char)(s8 >> 0); + s[22] = (unsigned char)(s8 >> 8); + s[23] = (unsigned char)((s8 >> 16) | (s9 << 5)); + s[24] = (unsigned char)(s9 >> 3); + s[25] = (unsigned char)(s9 >> 11); + s[26] = (unsigned char)((s9 >> 19) | (s10 << 2)); + s[27] = (unsigned char)(s10 >> 6); + s[28] = (unsigned char)((s10 >> 14) | (s11 << 7)); + s[29] = (unsigned char)(s11 >> 1); + s[30] = (unsigned char)(s11 >> 9); + s[31] = (unsigned char)(s11 >> 17); } diff --git a/sm/src/ed25519/sc.h b/sm/src/ed25519/sc.h index e29e7fa5a..7f212a7b6 100644 --- a/sm/src/ed25519/sc.h +++ b/sm/src/ed25519/sc.h @@ -6,7 +6,11 @@ The set of scalars is \Z/l where l = 2^252 + 27742317777372353535851937790883648493. */ -void sc_reduce(unsigned char *s); -void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b, const unsigned char *c); +void +sc_reduce(unsigned char* s); +void +sc_muladd( + unsigned char* s, const unsigned char* a, const unsigned char* b, + const unsigned char* c); #endif diff --git a/sm/src/ed25519/sign.c b/sm/src/ed25519/sign.c index c7e6e90a5..9a9f53f73 100644 --- a/sm/src/ed25519/sign.c +++ b/sm/src/ed25519/sign.c @@ -1,31 +1,32 @@ -#include "ed25519.h" #include "../sha3/sha3.h" +#include "ed25519.h" #include "ge.h" #include "sc.h" +void +ed25519_sign( + unsigned char* signature, const unsigned char* message, size_t message_len, + const unsigned char* public_key, const unsigned char* private_key) { + sha3_ctx_t hash; + unsigned char hram[64]; + unsigned char r[64]; + ge_p3 R; -void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key) { - sha3_ctx_t hash; - unsigned char hram[64]; - unsigned char r[64]; - ge_p3 R; - - - sha3_init(&hash, 64); - sha3_update(&hash, private_key + 32, 32); - sha3_update(&hash, message, message_len); - sha3_final(r, &hash); + sha3_init(&hash, 64); + sha3_update(&hash, private_key + 32, 32); + sha3_update(&hash, message, message_len); + sha3_final(r, &hash); - sc_reduce(r); - ge_scalarmult_base(&R, r); - ge_p3_tobytes(signature, &R); + sc_reduce(r); + ge_scalarmult_base(&R, r); + ge_p3_tobytes(signature, &R); - sha3_init(&hash, 64); - sha3_update(&hash, signature, 32); - sha3_update(&hash, public_key, 32); - sha3_update(&hash, message, message_len); - sha3_final(hram, &hash); + sha3_init(&hash, 64); + sha3_update(&hash, signature, 32); + sha3_update(&hash, public_key, 32); + sha3_update(&hash, message, message_len); + sha3_final(hram, &hash); - sc_reduce(hram); - sc_muladd(signature + 32, hram, private_key, r); + sc_reduce(hram); + sc_muladd(signature + 32, hram, private_key, r); } diff --git a/sm/src/enclave.c b/sm/src/enclave.c index 3ec9c5d73..1386d0301 100644 --- a/sm/src/enclave.c +++ b/sm/src/enclave.c @@ -3,25 +3,30 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include "enclave.h" -#include "mprv.h" -#include "pmp.h" -#include "page.h" -#include "cpu.h" -#include "platform-hook.h" -#include + #include #include #include +#include + +#include "cpu.h" +#include "mprv.h" +#include "page.h" +#include "platform-hook.h" +#include "pmp.h" -#define ENCL_MAX 16 +#define ENCL_MAX 16 struct enclave enclaves[ENCL_MAX]; -#define ENCLAVE_EXISTS(eid) (eid >= 0 && eid < ENCL_MAX && enclaves[eid].state >= 0) +#define ENCLAVE_EXISTS(eid) \ + (eid >= 0 && eid < ENCL_MAX && enclaves[eid].state >= 0) static spinlock_t encl_lock = SPIN_LOCK_INITIALIZER; -extern void save_host_regs(void); -extern void restore_host_regs(void); +extern void +save_host_regs(void); +extern void +restore_host_regs(void); extern byte dev_public_key[PUBLIC_KEY_SIZE]; /**************************** @@ -37,10 +42,10 @@ extern byte dev_public_key[PUBLIC_KEY_SIZE]; * Used by resume_enclave and run_enclave. * * Expects that eid has already been valided, and it is OK to run this enclave -*/ -static inline void context_switch_to_enclave(struct sbi_trap_regs* regs, - enclave_id eid, - int load_parameters){ + */ +static inline void +context_switch_to_enclave( + struct sbi_trap_regs* regs, enclave_id eid, int load_parameters) { /* save host context */ swap_prev_state(&enclaves[eid].threads[0], regs, 1); swap_prev_mepc(&enclaves[eid].threads[0], regs, regs->mepc); @@ -49,25 +54,26 @@ static inline void context_switch_to_enclave(struct sbi_trap_regs* regs, uintptr_t interrupts = 0; csr_write(mideleg, interrupts); - if(load_parameters) { + if (load_parameters) { // passing parameters for a first run - csr_write(sepc, (uintptr_t) enclaves[eid].params.user_entry); - regs->mepc = (uintptr_t) enclaves[eid].params.runtime_entry - 4; // regs->mepc will be +4 before sbi_ecall_handler return + csr_write(sepc, (uintptr_t)enclaves[eid].params.user_entry); + regs->mepc = (uintptr_t)enclaves[eid].params.runtime_entry - + 4; // regs->mepc will be +4 before sbi_ecall_handler return regs->mstatus = (1 << MSTATUS_MPP_SHIFT); // $a1: (PA) DRAM base, - regs->a1 = (uintptr_t) enclaves[eid].pa_params.dram_base; + regs->a1 = (uintptr_t)enclaves[eid].pa_params.dram_base; // $a2: (PA) DRAM size, - regs->a2 = (uintptr_t) enclaves[eid].pa_params.dram_size; + regs->a2 = (uintptr_t)enclaves[eid].pa_params.dram_size; // $a3: (PA) kernel location, - regs->a3 = (uintptr_t) enclaves[eid].pa_params.runtime_base; + regs->a3 = (uintptr_t)enclaves[eid].pa_params.runtime_base; // $a4: (PA) user location, - regs->a4 = (uintptr_t) enclaves[eid].pa_params.user_base; + regs->a4 = (uintptr_t)enclaves[eid].pa_params.user_base; // $a5: (PA) freemem location, - regs->a5 = (uintptr_t) enclaves[eid].pa_params.free_base; + regs->a5 = (uintptr_t)enclaves[eid].pa_params.free_base; // $a6: (VA) utm base, - regs->a6 = (uintptr_t) enclaves[eid].params.untrusted_ptr; + regs->a6 = (uintptr_t)enclaves[eid].params.untrusted_ptr; // $a7: (size_t) utm size - regs->a7 = (uintptr_t) enclaves[eid].params.untrusted_size; + regs->a7 = (uintptr_t)enclaves[eid].params.untrusted_size; // switch to the initial enclave page table csr_write(satp, enclaves[eid].encl_satp); @@ -78,8 +84,8 @@ static inline void context_switch_to_enclave(struct sbi_trap_regs* regs, // set PMP osm_pmp_set(PMP_NO_PERM); int memid; - for(memid=0; memid < ENCLAVE_REGIONS_MAX; memid++) { - if(enclaves[eid].regions[memid].type != REGION_INVALID) { + for (memid = 0; memid < ENCLAVE_REGIONS_MAX; memid++) { + if (enclaves[eid].regions[memid].type != REGION_INVALID) { pmp_set_keystone(enclaves[eid].regions[memid].pmp_rid, PMP_ALL_PERM); } } @@ -89,14 +95,13 @@ static inline void context_switch_to_enclave(struct sbi_trap_regs* regs, cpu_enter_enclave_context(eid); } -static inline void context_switch_to_host(struct sbi_trap_regs *regs, - enclave_id eid, - int return_on_resume){ - +static inline void +context_switch_to_host( + struct sbi_trap_regs* regs, enclave_id eid, int return_on_resume) { // set PMP int memid; - for(memid=0; memid < ENCLAVE_REGIONS_MAX; memid++) { - if(enclaves[eid].regions[memid].type != REGION_INVALID) { + for (memid = 0; memid < ENCLAVE_REGIONS_MAX; memid++) { + if (enclaves[eid].regions[memid].type != REGION_INVALID) { pmp_set_keystone(enclaves[eid].regions[memid].pmp_rid, PMP_NO_PERM); } } @@ -135,34 +140,32 @@ static inline void context_switch_to_host(struct sbi_trap_regs *regs, return; } - // TODO: This function is externally used. // refactoring needed /* * Init all metadata as needed for keeping track of enclaves * Called once by the SM on startup */ -void enclave_init_metadata(){ +void +enclave_init_metadata() { enclave_id eid; - int i=0; + int i = 0; /* Assumes eids are incrementing values, which they are for now */ - for(eid=0; eid < ENCL_MAX; eid++){ + for (eid = 0; eid < ENCL_MAX; eid++) { enclaves[eid].state = INVALID; // Clear out regions - for(i=0; i < ENCLAVE_REGIONS_MAX; i++){ + for (i = 0; i < ENCLAVE_REGIONS_MAX; i++) { enclaves[eid].regions[i].type = REGION_INVALID; } /* Fire all platform specific init for each enclave */ platform_init_enclave(&(enclaves[eid])); } - } -static unsigned long clean_enclave_memory(uintptr_t utbase, uintptr_t utsize) -{ - +static unsigned long +clean_enclave_memory(uintptr_t utbase, uintptr_t utsize) { // This function is quite temporary. See issue #38 // Zero out the untrusted memory region, since it may be in @@ -172,44 +175,42 @@ static unsigned long clean_enclave_memory(uintptr_t utbase, uintptr_t utsize) return SBI_ERR_SM_ENCLAVE_SUCCESS; } -static unsigned long encl_alloc_eid(enclave_id* _eid) -{ +static unsigned long +encl_alloc_eid(enclave_id* _eid) { enclave_id eid; spin_lock(&encl_lock); - for(eid=0; eidepm_region.paddr, */ /* args->epm_region.size, */ /* args->utm_region.paddr, */ @@ -287,37 +291,28 @@ static int is_create_args_valid(struct keystone_sbi_create* args) /* args->free_paddr); */ // check if physical addresses are valid - if (args->epm_region.size <= 0) - return 0; + if (args->epm_region.size <= 0) return 0; // check if overflow - if (args->epm_region.paddr >= - args->epm_region.paddr + args->epm_region.size) + if (args->epm_region.paddr >= args->epm_region.paddr + args->epm_region.size) return 0; - if (args->utm_region.paddr >= - args->utm_region.paddr + args->utm_region.size) + if (args->utm_region.paddr >= args->utm_region.paddr + args->utm_region.size) return 0; epm_start = args->epm_region.paddr; - epm_end = args->epm_region.paddr + args->epm_region.size; + epm_end = args->epm_region.paddr + args->epm_region.size; // check if physical addresses are in the range - if (args->runtime_paddr < epm_start || - args->runtime_paddr >= epm_end) + if (args->runtime_paddr < epm_start || args->runtime_paddr >= epm_end) return 0; - if (args->user_paddr < epm_start || - args->user_paddr >= epm_end) - return 0; - if (args->free_paddr < epm_start || - args->free_paddr > epm_end) - // note: free_paddr == epm_end if there's no free memory + if (args->user_paddr < epm_start || args->user_paddr >= epm_end) return 0; + if (args->free_paddr < epm_start || args->free_paddr > epm_end) + // note: free_paddr == epm_end if there's no free memory return 0; // check the order of physical addresses - if (args->runtime_paddr > args->user_paddr) - return 0; - if (args->user_paddr > args->free_paddr) - return 0; + if (args->runtime_paddr > args->user_paddr) return 0; + if (args->user_paddr > args->free_paddr) return 0; return 1; } @@ -329,74 +324,71 @@ static int is_create_args_valid(struct keystone_sbi_create* args) * *********************************/ - /* This handles creation of a new enclave, based on arguments provided * by the untrusted host. * * This may fail if: it cannot allocate PMP regions, EIDs, etc */ -unsigned long create_enclave(unsigned long *eidptr, struct keystone_sbi_create create_args) -{ +unsigned long +create_enclave(unsigned long* eidptr, struct keystone_sbi_create create_args) { /* EPM and UTM parameters */ - uintptr_t base = create_args.epm_region.paddr; - size_t size = create_args.epm_region.size; + uintptr_t base = create_args.epm_region.paddr; + size_t size = create_args.epm_region.size; uintptr_t utbase = create_args.utm_region.paddr; - size_t utsize = create_args.utm_region.size; + size_t utsize = create_args.utm_region.size; enclave_id eid; unsigned long ret; int region, shared_region; /* Runtime parameters */ - if(!is_create_args_valid(&create_args)) + if (!is_create_args_valid(&create_args)) return SBI_ERR_SM_ENCLAVE_ILLEGAL_ARGUMENT; /* set va params */ struct runtime_va_params_t params = create_args.params; struct runtime_pa_params pa_params; - pa_params.dram_base = base; - pa_params.dram_size = size; + pa_params.dram_base = base; + pa_params.dram_size = size; pa_params.runtime_base = create_args.runtime_paddr; - pa_params.user_base = create_args.user_paddr; - pa_params.free_base = create_args.free_paddr; - + pa_params.user_base = create_args.user_paddr; + pa_params.free_base = create_args.free_paddr; // allocate eid ret = SBI_ERR_SM_ENCLAVE_NO_FREE_RESOURCE; - if (encl_alloc_eid(&eid) != SBI_ERR_SM_ENCLAVE_SUCCESS) - goto error; + if (encl_alloc_eid(&eid) != SBI_ERR_SM_ENCLAVE_SUCCESS) goto error; // create a PMP region bound to the enclave ret = SBI_ERR_SM_ENCLAVE_PMP_FAILURE; - if(pmp_region_init_atomic(base, size, PMP_PRI_ANY, ®ion, 0)) + if (pmp_region_init_atomic(base, size, PMP_PRI_ANY, ®ion, 0)) goto free_encl_idx; // create PMP region for shared memory - if(pmp_region_init_atomic(utbase, utsize, PMP_PRI_BOTTOM, &shared_region, 0)) + if (pmp_region_init_atomic(utbase, utsize, PMP_PRI_BOTTOM, &shared_region, 0)) goto free_region; // set pmp registers for private region (not shared) - if(pmp_set_global(region, PMP_NO_PERM)) - goto free_shared_region; + if (pmp_set_global(region, PMP_NO_PERM)) goto free_shared_region; // cleanup some memory regions for sanity See issue #38 clean_enclave_memory(utbase, utsize); - // initialize enclave metadata enclaves[eid].eid = eid; enclaves[eid].regions[0].pmp_rid = region; - enclaves[eid].regions[0].type = REGION_EPM; + enclaves[eid].regions[0].type = REGION_EPM; enclaves[eid].regions[1].pmp_rid = shared_region; - enclaves[eid].regions[1].type = REGION_UTM; + enclaves[eid].regions[1].type = REGION_UTM; #if __riscv_xlen == 32 - enclaves[eid].encl_satp = ((base >> RISCV_PGSHIFT) | (SATP_MODE_SV32 << HGATP_MODE_SHIFT)); + enclaves[eid].encl_satp = + ((base >> RISCV_PGSHIFT) | (SATP_MODE_SV32 << HGATP_MODE_SHIFT)); #else - enclaves[eid].encl_satp = ((base >> RISCV_PGSHIFT) | (SATP_MODE_SV39 << HGATP_MODE_SHIFT)); + enclaves[eid].encl_satp = + ((base >> RISCV_PGSHIFT) | (SATP_MODE_SV39 << HGATP_MODE_SHIFT)); #endif - enclaves[eid].n_thread = 0; - enclaves[eid].params = params; + enclaves[eid].n_thread = 0; + enclaves[eid].params = params; enclaves[eid].pa_params = pa_params; /* Init enclave state (regs etc) */ @@ -405,15 +397,14 @@ unsigned long create_enclave(unsigned long *eidptr, struct keystone_sbi_create c /* Platform create happens as the last thing before hashing/etc since it may modify the enclave struct */ ret = platform_create_enclave(&enclaves[eid]); - if (ret) - goto unset_region; + if (ret) goto unset_region; /* Validate memory, prepare hash and signature for attestation */ - spin_lock(&encl_lock); // FIXME This should error for second enter. + spin_lock(&encl_lock); // FIXME This should error for second enter. ret = validate_and_hash_enclave(&enclaves[eid]); - /* The enclave is fresh if it has been validated and hashed but not run yet. */ - if (ret) - goto unlock; + /* The enclave is fresh if it has been validated and hashed but not run yet. + */ + if (ret) goto unlock; enclaves[eid].state = FRESH; /* EIDs are unsigned int in size, copy via simple copy */ @@ -424,7 +415,7 @@ unsigned long create_enclave(unsigned long *eidptr, struct keystone_sbi_create c unlock: spin_unlock(&encl_lock); -// free_platform: + // free_platform: platform_destroy_enclave(&enclaves[eid]); unset_region: pmp_unset_global(region); @@ -443,58 +434,52 @@ unsigned long create_enclave(unsigned long *eidptr, struct keystone_sbi_create c * Deallocates EID, clears epm, etc * Fails only if the enclave isn't running. */ -unsigned long destroy_enclave(enclave_id eid) -{ +unsigned long +destroy_enclave(enclave_id eid) { int destroyable; spin_lock(&encl_lock); - destroyable = (ENCLAVE_EXISTS(eid) - && enclaves[eid].state <= STOPPED); + destroyable = (ENCLAVE_EXISTS(eid) && enclaves[eid].state <= STOPPED); /* update the enclave state first so that * no SM can run the enclave any longer */ - if(destroyable) - enclaves[eid].state = DESTROYING; + if (destroyable) enclaves[eid].state = DESTROYING; spin_unlock(&encl_lock); - if(!destroyable) - return SBI_ERR_SM_ENCLAVE_NOT_DESTROYABLE; - + if (!destroyable) return SBI_ERR_SM_ENCLAVE_NOT_DESTROYABLE; // 0. Let the platform specifics do cleanup/modifications platform_destroy_enclave(&enclaves[eid]); - // 1. clear all the data in the enclave pages // requires no lock (single runner) int i; void* base; size_t size; region_id rid; - for(i = 0; i < ENCLAVE_REGIONS_MAX; i++){ - if(enclaves[eid].regions[i].type == REGION_INVALID || - enclaves[eid].regions[i].type == REGION_UTM) + for (i = 0; i < ENCLAVE_REGIONS_MAX; i++) { + if (enclaves[eid].regions[i].type == REGION_INVALID || + enclaves[eid].regions[i].type == REGION_UTM) continue; - //1.a Clear all pages - rid = enclaves[eid].regions[i].pmp_rid; - base = (void*) pmp_region_get_addr(rid); - size = (size_t) pmp_region_get_size(rid); - sbi_memset((void*) base, 0, size); + // 1.a Clear all pages + rid = enclaves[eid].regions[i].pmp_rid; + base = (void*)pmp_region_get_addr(rid); + size = (size_t)pmp_region_get_size(rid); + sbi_memset((void*)base, 0, size); - //1.b free pmp region + // 1.b free pmp region pmp_unset_global(rid); pmp_region_free_atomic(rid); } // 2. free pmp region for UTM rid = get_enclave_region_index(eid, REGION_UTM); - if(rid != -1) - pmp_region_free_atomic(enclaves[eid].regions[rid].pmp_rid); + if (rid != -1) pmp_region_free_atomic(enclaves[eid].regions[rid].pmp_rid); enclaves[eid].encl_satp = 0; - enclaves[eid].n_thread = 0; - enclaves[eid].params = (struct runtime_va_params_t) {0}; - enclaves[eid].pa_params = (struct runtime_pa_params) {0}; - for(i=0; i < ENCLAVE_REGIONS_MAX; i++){ + enclaves[eid].n_thread = 0; + enclaves[eid].params = (struct runtime_va_params_t){0}; + enclaves[eid].pa_params = (struct runtime_pa_params){0}; + for (i = 0; i < ENCLAVE_REGIONS_MAX; i++) { enclaves[eid].regions[i].type = REGION_INVALID; } @@ -504,21 +489,19 @@ unsigned long destroy_enclave(enclave_id eid) return SBI_ERR_SM_ENCLAVE_SUCCESS; } - -unsigned long run_enclave(struct sbi_trap_regs *regs, enclave_id eid) -{ +unsigned long +run_enclave(struct sbi_trap_regs* regs, enclave_id eid) { int runable; spin_lock(&encl_lock); - runable = (ENCLAVE_EXISTS(eid) - && enclaves[eid].state == FRESH); - if(runable) { + runable = (ENCLAVE_EXISTS(eid) && enclaves[eid].state == FRESH); + if (runable) { enclaves[eid].state = RUNNING; enclaves[eid].n_thread++; } spin_unlock(&encl_lock); - if(!runable) { + if (!runable) { return SBI_ERR_SM_ENCLAVE_NOT_FRESH; } @@ -528,65 +511,62 @@ unsigned long run_enclave(struct sbi_trap_regs *regs, enclave_id eid) return SBI_ERR_SM_ENCLAVE_SUCCESS; } -unsigned long exit_enclave(struct sbi_trap_regs *regs, enclave_id eid) -{ +unsigned long +exit_enclave(struct sbi_trap_regs* regs, enclave_id eid) { int exitable; spin_lock(&encl_lock); exitable = enclaves[eid].state == RUNNING; if (exitable) { enclaves[eid].n_thread--; - if(enclaves[eid].n_thread == 0) - enclaves[eid].state = STOPPED; + if (enclaves[eid].n_thread == 0) enclaves[eid].state = STOPPED; } spin_unlock(&encl_lock); - if(!exitable) - return SBI_ERR_SM_ENCLAVE_NOT_RUNNING; + if (!exitable) return SBI_ERR_SM_ENCLAVE_NOT_RUNNING; context_switch_to_host(regs, eid, 0); return SBI_ERR_SM_ENCLAVE_SUCCESS; } -unsigned long stop_enclave(struct sbi_trap_regs *regs, uint64_t request, enclave_id eid) -{ +unsigned long +stop_enclave(struct sbi_trap_regs* regs, uint64_t request, enclave_id eid) { int stoppable; spin_lock(&encl_lock); stoppable = enclaves[eid].state == RUNNING; if (stoppable) { enclaves[eid].n_thread--; - if(enclaves[eid].n_thread == 0) - enclaves[eid].state = STOPPED; + if (enclaves[eid].n_thread == 0) enclaves[eid].state = STOPPED; } spin_unlock(&encl_lock); - if(!stoppable) - return SBI_ERR_SM_ENCLAVE_NOT_RUNNING; + if (!stoppable) return SBI_ERR_SM_ENCLAVE_NOT_RUNNING; context_switch_to_host(regs, eid, request == STOP_EDGE_CALL_HOST); - switch(request) { - case(STOP_TIMER_INTERRUPT): + switch (request) { + case (STOP_TIMER_INTERRUPT): return SBI_ERR_SM_ENCLAVE_INTERRUPTED; - case(STOP_EDGE_CALL_HOST): + case (STOP_EDGE_CALL_HOST): return SBI_ERR_SM_ENCLAVE_EDGE_CALL_HOST; default: return SBI_ERR_SM_ENCLAVE_UNKNOWN_ERROR; } } -unsigned long resume_enclave(struct sbi_trap_regs *regs, enclave_id eid) -{ +unsigned long +resume_enclave(struct sbi_trap_regs* regs, enclave_id eid) { int resumable; spin_lock(&encl_lock); - resumable = (ENCLAVE_EXISTS(eid) - && (enclaves[eid].state == RUNNING || enclaves[eid].state == STOPPED) - && enclaves[eid].n_thread < MAX_ENCL_THREADS); + resumable = + (ENCLAVE_EXISTS(eid) && + (enclaves[eid].state == RUNNING || enclaves[eid].state == STOPPED) && + enclaves[eid].n_thread < MAX_ENCL_THREADS); - if(!resumable) { + if (!resumable) { spin_unlock(&encl_lock); return SBI_ERR_SM_ENCLAVE_NOT_RESUMABLE; } else { @@ -601,27 +581,25 @@ unsigned long resume_enclave(struct sbi_trap_regs *regs, enclave_id eid) return SBI_ERR_SM_ENCLAVE_SUCCESS; } -unsigned long attest_enclave(uintptr_t report_ptr, uintptr_t data, uintptr_t size, enclave_id eid) -{ +unsigned long +attest_enclave( + uintptr_t report_ptr, uintptr_t data, uintptr_t size, enclave_id eid) { int attestable; struct report report; int ret; - if (size > ATTEST_DATA_MAXLEN) - return SBI_ERR_SM_ENCLAVE_ILLEGAL_ARGUMENT; + if (size > ATTEST_DATA_MAXLEN) return SBI_ERR_SM_ENCLAVE_ILLEGAL_ARGUMENT; spin_lock(&encl_lock); - attestable = (ENCLAVE_EXISTS(eid) - && (enclaves[eid].state >= FRESH)); + attestable = (ENCLAVE_EXISTS(eid) && (enclaves[eid].state >= FRESH)); - if(!attestable) { + if (!attestable) { ret = SBI_ERR_SM_ENCLAVE_NOT_INITIALIZED; goto err_unlock; } /* copy data to be signed */ - ret = copy_enclave_data(&enclaves[eid], report.enclave.data, - data, size); + ret = copy_enclave_data(&enclaves[eid], report.enclave.data, data, size); report.enclave.data_len = size; if (ret) { @@ -629,25 +607,23 @@ unsigned long attest_enclave(uintptr_t report_ptr, uintptr_t data, uintptr_t siz goto err_unlock; } - spin_unlock(&encl_lock); // Don't need to wait while signing, which might take some time + spin_unlock(&encl_lock); // Don't need to wait while signing, which might + // take some time sbi_memcpy(report.dev_public_key, dev_public_key, PUBLIC_KEY_SIZE); sbi_memcpy(report.sm.hash, sm_hash, MDSIZE); sbi_memcpy(report.sm.public_key, sm_public_key, PUBLIC_KEY_SIZE); sbi_memcpy(report.sm.signature, sm_signature, SIGNATURE_SIZE); sbi_memcpy(report.enclave.hash, enclaves[eid].hash, MDSIZE); - sm_sign(report.enclave.signature, - &report.enclave, - sizeof(struct enclave_report) - - SIGNATURE_SIZE - - ATTEST_DATA_MAXLEN + size); + sm_sign( + report.enclave.signature, &report.enclave, + sizeof(struct enclave_report) - SIGNATURE_SIZE - ATTEST_DATA_MAXLEN + + size); spin_lock(&encl_lock); /* copy report to the enclave */ - ret = copy_enclave_report(&enclaves[eid], - report_ptr, - &report); + ret = copy_enclave_report(&enclaves[eid], report_ptr, &report); if (ret) { ret = SBI_ERR_SM_ENCLAVE_ILLEGAL_ARGUMENT; @@ -661,22 +637,22 @@ unsigned long attest_enclave(uintptr_t report_ptr, uintptr_t data, uintptr_t siz return ret; } -unsigned long get_sealing_key(uintptr_t sealing_key, uintptr_t key_ident, - size_t key_ident_size, enclave_id eid) -{ - struct sealing_key *key_struct = (struct sealing_key *)sealing_key; +unsigned long +get_sealing_key( + uintptr_t sealing_key, uintptr_t key_ident, size_t key_ident_size, + enclave_id eid) { + struct sealing_key* key_struct = (struct sealing_key*)sealing_key; int ret; /* derive key */ - ret = sm_derive_sealing_key((unsigned char *)key_struct->key, - (const unsigned char *)key_ident, key_ident_size, - (const unsigned char *)enclaves[eid].hash); - if (ret) - return SBI_ERR_SM_ENCLAVE_UNKNOWN_ERROR; + ret = sm_derive_sealing_key( + (unsigned char*)key_struct->key, (const unsigned char*)key_ident, + key_ident_size, (const unsigned char*)enclaves[eid].hash); + if (ret) return SBI_ERR_SM_ENCLAVE_UNKNOWN_ERROR; /* sign derived key */ - sm_sign((void *)key_struct->signature, (void *)key_struct->key, - SEALING_KEY_SIZE); + sm_sign( + (void*)key_struct->signature, (void*)key_struct->key, SEALING_KEY_SIZE); return SBI_ERR_SM_ENCLAVE_SUCCESS; } diff --git a/sm/src/enclave.h b/sm/src/enclave.h index 807f4024b..699e54693 100644 --- a/sm/src/enclave.h +++ b/sm/src/enclave.h @@ -9,21 +9,21 @@ #error "SM requires a defined platform to build" #endif -#include "sm.h" +#include "crypto.h" #include "pmp.h" +#include "sm.h" #include "thread.h" -#include "crypto.h" // Special target platform header, set by configure script #include TARGET_PLATFORM_HEADER -#define ATTEST_DATA_MAXLEN 1024 +#define ATTEST_DATA_MAXLEN 1024 #define ENCLAVE_REGIONS_MAX 8 /* TODO: does not support multithreaded enclave yet */ #define MAX_ENCL_THREADS 1 typedef enum { - INVALID = -1, + INVALID = -1, DESTROYING = 0, ALLOCATED, FRESH, @@ -32,9 +32,9 @@ typedef enum { } enclave_state; /* Enclave stop reasons requested */ -#define STOP_TIMER_INTERRUPT 0 -#define STOP_EDGE_CALL_HOST 1 -#define STOP_EXIT_ENCLAVE 2 +#define STOP_TIMER_INTERRUPT 0 +#define STOP_EDGE_CALL_HOST 1 +#define STOP_EXIT_ENCLAVE 2 /* For now, eid's are a simple unsigned int */ typedef unsigned int enclave_id; @@ -45,26 +45,25 @@ typedef unsigned int enclave_id; * OTHER is managed by some other component (e.g. platform_) * INVALID is an unused index */ -enum enclave_region_type{ +enum enclave_region_type { REGION_INVALID, REGION_EPM, REGION_UTM, REGION_OTHER, }; -struct enclave_region -{ +struct enclave_region { region_id pmp_rid; enum enclave_region_type type; }; /* enclave metadata */ -struct enclave -{ - //spinlock_t lock; //local enclave lock. we don't need this until we have multithreaded enclave - enclave_id eid; //enclave id - unsigned long encl_satp; // enclave's page table base - enclave_state state; // global state of the enclave +struct enclave { + // spinlock_t lock; //local enclave lock. we don't need this until we have + // multithreaded enclave + enclave_id eid; // enclave id + unsigned long encl_satp; // enclave's page table base + enclave_state state; // global state of the enclave /* Physical memory regions associate with this enclave */ struct enclave_region regions[ENCLAVE_REGIONS_MAX]; @@ -85,21 +84,18 @@ struct enclave }; /* attestation reports */ -struct enclave_report -{ +struct enclave_report { byte hash[MDSIZE]; uint64_t data_len; byte data[ATTEST_DATA_MAXLEN]; byte signature[SIGNATURE_SIZE]; }; -struct sm_report -{ +struct sm_report { byte hash[MDSIZE]; byte public_key[PUBLIC_KEY_SIZE]; byte signature[SIGNATURE_SIZE]; }; -struct report -{ +struct report { struct enclave_report enclave; struct sm_report sm; byte dev_public_key[PUBLIC_KEY_SIZE]; @@ -107,29 +103,45 @@ struct report /* sealing key structure */ #define SEALING_KEY_SIZE 128 -struct sealing_key -{ +struct sealing_key { uint8_t key[SEALING_KEY_SIZE]; uint8_t signature[SIGNATURE_SIZE]; }; /*** SBI functions & external functions ***/ // callables from the host -unsigned long create_enclave(unsigned long *eid, struct keystone_sbi_create create_args); -unsigned long destroy_enclave(enclave_id eid); -unsigned long run_enclave(struct sbi_trap_regs *regs, enclave_id eid); -unsigned long resume_enclave(struct sbi_trap_regs *regs, enclave_id eid); +unsigned long +create_enclave(unsigned long* eid, struct keystone_sbi_create create_args); +unsigned long +destroy_enclave(enclave_id eid); +unsigned long +run_enclave(struct sbi_trap_regs* regs, enclave_id eid); +unsigned long +resume_enclave(struct sbi_trap_regs* regs, enclave_id eid); // callables from the enclave -unsigned long exit_enclave(struct sbi_trap_regs *regs, enclave_id eid); -unsigned long stop_enclave(struct sbi_trap_regs *regs, uint64_t request, enclave_id eid); -unsigned long attest_enclave(uintptr_t report, uintptr_t data, uintptr_t size, enclave_id eid); +unsigned long +exit_enclave(struct sbi_trap_regs* regs, enclave_id eid); +unsigned long +stop_enclave(struct sbi_trap_regs* regs, uint64_t request, enclave_id eid); +unsigned long +attest_enclave( + uintptr_t report, uintptr_t data, uintptr_t size, enclave_id eid); /* attestation and virtual mapping validation */ -unsigned long validate_and_hash_enclave(struct enclave* enclave); +unsigned long +validate_and_hash_enclave(struct enclave* enclave); // TODO: These functions are supposed to be internal functions. -void enclave_init_metadata(); -unsigned long copy_enclave_create_args(uintptr_t src, struct keystone_sbi_create* dest); -int get_enclave_region_index(enclave_id eid, enum enclave_region_type type); -uintptr_t get_enclave_region_base(enclave_id eid, int memid); -uintptr_t get_enclave_region_size(enclave_id eid, int memid); -unsigned long get_sealing_key(uintptr_t seal_key, uintptr_t key_ident, size_t key_ident_size, enclave_id eid); +void +enclave_init_metadata(); +unsigned long +copy_enclave_create_args(uintptr_t src, struct keystone_sbi_create* dest); +int +get_enclave_region_index(enclave_id eid, enum enclave_region_type type); +uintptr_t +get_enclave_region_base(enclave_id eid, int memid); +uintptr_t +get_enclave_region_size(enclave_id eid, int memid); +unsigned long +get_sealing_key( + uintptr_t seal_key, uintptr_t key_ident, size_t key_ident_size, + enclave_id eid); #endif diff --git a/sm/src/hkdf_sha3_512/hkdf_sha3_512.c b/sm/src/hkdf_sha3_512/hkdf_sha3_512.c index 991a736b7..6857dd86f 100644 --- a/sm/src/hkdf_sha3_512/hkdf_sha3_512.c +++ b/sm/src/hkdf_sha3_512/hkdf_sha3_512.c @@ -13,20 +13,22 @@ */ #include "hkdf_sha3_512.h" -#include "../hmac_sha3/hmac_sha3.h" + #include +#include "../hmac_sha3/hmac_sha3.h" + /* * Function div_ceil: * * Calculates ceil(op1 / op2) */ -static int div_ceil(int op1, int op2) -{ - if (op1 % op2 == 0) - return op1 / op2; - else - return (op1 / op2) + 1; +static int +div_ceil(int op1, int op2) { + if (op1 % op2 == 0) + return op1 / op2; + else + return (op1 / op2) + 1; } /* @@ -50,20 +52,20 @@ static int div_ceil(int op1, int op2) * * Return value: 0 if function has performed correctly */ -int hkdf_sha3_512(const unsigned char *salt, int salt_len, - const unsigned char *ikm, int ikm_len, - const unsigned char *info, int info_len, - unsigned char *okm, int okm_len) -{ - unsigned char prk[SHA3_512_HASH_LEN]; +int +hkdf_sha3_512( + const unsigned char* salt, int salt_len, const unsigned char* ikm, + int ikm_len, const unsigned char* info, int info_len, unsigned char* okm, + int okm_len) { + unsigned char prk[SHA3_512_HASH_LEN]; - if (okm_len > 255 * SHA3_512_HASH_LEN) { - return -1; - } + if (okm_len > 255 * SHA3_512_HASH_LEN) { + return -1; + } - hkdf_extract(salt, salt_len, ikm, ikm_len, prk); + hkdf_extract(salt, salt_len, ikm, ikm_len, prk); - return hkdf_expand(prk, SHA3_512_HASH_LEN, info, info_len, okm, okm_len); + return hkdf_expand(prk, SHA3_512_HASH_LEN, info, info_len, okm, okm_len); } /* @@ -81,19 +83,19 @@ int hkdf_sha3_512(const unsigned char *salt, int salt_len, * prk: Output buffer for the pseudo random key * with length SHA3_512_HASH_LEN */ -void hkdf_extract(const unsigned char *salt, int salt_len, - const unsigned char *ikm, int ikm_len, - unsigned char *prk) -{ - unsigned char nullsalt[SHA3_512_HASH_LEN]; - - if (salt == NULL || salt_len == 0) { - sbi_memset(nullsalt, 0x00, SHA3_512_HASH_LEN); - salt = nullsalt; - salt_len = SHA3_512_HASH_LEN; - } - - hmac_sha3(salt, salt_len, ikm, ikm_len, prk); +void +hkdf_extract( + const unsigned char* salt, int salt_len, const unsigned char* ikm, + int ikm_len, unsigned char* prk) { + unsigned char nullsalt[SHA3_512_HASH_LEN]; + + if (salt == NULL || salt_len == 0) { + sbi_memset(nullsalt, 0x00, SHA3_512_HASH_LEN); + salt = nullsalt; + salt_len = SHA3_512_HASH_LEN; + } + + hmac_sha3(salt, salt_len, ikm, ikm_len, prk); } /* @@ -116,38 +118,38 @@ void hkdf_extract(const unsigned char *salt, int salt_len, * * Return value: 0 if function has performed correctly */ -int hkdf_expand(const unsigned char *prk, int prk_len, - const unsigned char *info, int info_len, - unsigned char *okm, int okm_len) -{ - int n = div_ceil(okm_len, SHA3_512_HASH_LEN); - unsigned char t[SHA3_512_HASH_LEN]; - hmac_sha3_ctx_t ctx; - - if (prk_len < SHA3_512_HASH_LEN) { - return -1; - } - if (okm_len > 255 * SHA3_512_HASH_LEN) { - return -1; - } - - // Compute T(1) - T(n) and copy resulting key to okm - for (unsigned char i = 1; i <= n; i++) { - hmac_sha3_init(&ctx, prk, prk_len); - - if (i > 1) - hmac_sha3_update(&ctx, t, SHA3_512_HASH_LEN); - - hmac_sha3_update(&ctx, info, info_len); - hmac_sha3_update(&ctx, &i, 1); - hmac_sha3_final(&ctx, t); - - if (i < n) - sbi_memcpy(okm + (i - 1) * SHA3_512_HASH_LEN, t, SHA3_512_HASH_LEN); - else - sbi_memcpy(okm + (i - 1) * SHA3_512_HASH_LEN, t, - okm_len - (i - 1) * SHA3_512_HASH_LEN); - } - - return 0; +int +hkdf_expand( + const unsigned char* prk, int prk_len, const unsigned char* info, + int info_len, unsigned char* okm, int okm_len) { + int n = div_ceil(okm_len, SHA3_512_HASH_LEN); + unsigned char t[SHA3_512_HASH_LEN]; + hmac_sha3_ctx_t ctx; + + if (prk_len < SHA3_512_HASH_LEN) { + return -1; + } + if (okm_len > 255 * SHA3_512_HASH_LEN) { + return -1; + } + + // Compute T(1) - T(n) and copy resulting key to okm + for (unsigned char i = 1; i <= n; i++) { + hmac_sha3_init(&ctx, prk, prk_len); + + if (i > 1) hmac_sha3_update(&ctx, t, SHA3_512_HASH_LEN); + + hmac_sha3_update(&ctx, info, info_len); + hmac_sha3_update(&ctx, &i, 1); + hmac_sha3_final(&ctx, t); + + if (i < n) + sbi_memcpy(okm + (i - 1) * SHA3_512_HASH_LEN, t, SHA3_512_HASH_LEN); + else + sbi_memcpy( + okm + (i - 1) * SHA3_512_HASH_LEN, t, + okm_len - (i - 1) * SHA3_512_HASH_LEN); + } + + return 0; } diff --git a/sm/src/hkdf_sha3_512/hkdf_sha3_512.h b/sm/src/hkdf_sha3_512/hkdf_sha3_512.h index 8a39c5898..1cf4a2e4b 100644 --- a/sm/src/hkdf_sha3_512/hkdf_sha3_512.h +++ b/sm/src/hkdf_sha3_512/hkdf_sha3_512.h @@ -12,15 +12,18 @@ #ifndef HDKF_SHA3_512_H #define HDKF_SHA3_512_H -int hkdf_sha3_512(const unsigned char *salt, int salt_len, - const unsigned char *in_key, int in_key_len, - const unsigned char *info, int info_len, - unsigned char *out_key, int out_key_length); -void hkdf_extract(const unsigned char *salt, int salt_len, - const unsigned char *in_key, int in_key_len, - unsigned char *prk); -int hkdf_expand(const unsigned char *prk, int prk_len, - const unsigned char *info, int info_len, - unsigned char *out_key, int out_key_len); +int +hkdf_sha3_512( + const unsigned char* salt, int salt_len, const unsigned char* in_key, + int in_key_len, const unsigned char* info, int info_len, + unsigned char* out_key, int out_key_length); +void +hkdf_extract( + const unsigned char* salt, int salt_len, const unsigned char* in_key, + int in_key_len, unsigned char* prk); +int +hkdf_expand( + const unsigned char* prk, int prk_len, const unsigned char* info, + int info_len, unsigned char* out_key, int out_key_len); #endif /* HDKF_SHA3_512_H */ diff --git a/sm/src/hmac_sha3/hmac_sha3.c b/sm/src/hmac_sha3/hmac_sha3.c index b4d05ab36..94b393101 100644 --- a/sm/src/hmac_sha3/hmac_sha3.c +++ b/sm/src/hmac_sha3/hmac_sha3.c @@ -13,6 +13,7 @@ */ #include "hmac_sha3.h" + #include /* @@ -33,22 +34,21 @@ * should be written to !(has to be SHA3_512_BLOCK_LEN bytes * long)! */ -static void prepare_key(const unsigned char *key, int key_len, - unsigned char *new_key) -{ - sha3_ctx_t ctx; - - if (key_len > SHA3_512_BLOCK_LEN) { - sha3_init(&ctx, SHA3_512_HASH_LEN); - sha3_update(&ctx, (void *)key, key_len); - sha3_final(new_key, &ctx); - - key_len = SHA3_512_HASH_LEN; - } else { - sbi_memcpy(new_key, key, key_len); - } - - sbi_memset(new_key + key_len, 0x00, SHA3_512_BLOCK_LEN - key_len); +static void +prepare_key(const unsigned char* key, int key_len, unsigned char* new_key) { + sha3_ctx_t ctx; + + if (key_len > SHA3_512_BLOCK_LEN) { + sha3_init(&ctx, SHA3_512_HASH_LEN); + sha3_update(&ctx, (void*)key, key_len); + sha3_final(new_key, &ctx); + + key_len = SHA3_512_HASH_LEN; + } else { + sbi_memcpy(new_key, key, key_len); + } + + sbi_memset(new_key + key_len, 0x00, SHA3_512_BLOCK_LEN - key_len); } /* @@ -67,14 +67,15 @@ static void prepare_key(const unsigned char *key, int key_len, * * Return value: 0 if function has performed correctly */ -void hmac_sha3(const unsigned char *key, int key_len, - const unsigned char *text, int text_len, unsigned char *hmac) -{ - hmac_sha3_ctx_t ctx; - - hmac_sha3_init(&ctx, key, key_len); - hmac_sha3_update(&ctx, text, text_len); - hmac_sha3_final(&ctx, hmac); +void +hmac_sha3( + const unsigned char* key, int key_len, const unsigned char* text, + int text_len, unsigned char* hmac) { + hmac_sha3_ctx_t ctx; + + hmac_sha3_init(&ctx, key, key_len); + hmac_sha3_update(&ctx, text, text_len); + hmac_sha3_final(&ctx, hmac); } /* @@ -88,20 +89,19 @@ void hmac_sha3(const unsigned char *key, int key_len, * key: Pointer to the key * key_len: Size of the key */ -void hmac_sha3_init(hmac_sha3_ctx_t *ctx, - const unsigned char *key, int key_len) -{ - unsigned char temp_key[SHA3_512_BLOCK_LEN]; +void +hmac_sha3_init(hmac_sha3_ctx_t* ctx, const unsigned char* key, int key_len) { + unsigned char temp_key[SHA3_512_BLOCK_LEN]; - prepare_key(key, key_len, ctx->key); + prepare_key(key, key_len, ctx->key); - // XOR with ipad - for (int i = 0; i < SHA3_512_BLOCK_LEN; i++) { - temp_key[i] = ctx->key[i] ^ 0x36; - } + // XOR with ipad + for (int i = 0; i < SHA3_512_BLOCK_LEN; i++) { + temp_key[i] = ctx->key[i] ^ 0x36; + } - sha3_init(&(ctx->sha3_ctx), SHA3_512_HASH_LEN); - sha3_update(&(ctx->sha3_ctx), temp_key, SHA3_512_BLOCK_LEN); + sha3_init(&(ctx->sha3_ctx), SHA3_512_HASH_LEN); + sha3_update(&(ctx->sha3_ctx), temp_key, SHA3_512_BLOCK_LEN); } /* @@ -115,11 +115,10 @@ void hmac_sha3_init(hmac_sha3_ctx_t *ctx, * text: Pointer to the message * text_len: Size of the message */ -void hmac_sha3_update(hmac_sha3_ctx_t *ctx, - const unsigned char *text, int text_len) -{ - if (text_len > 0) - sha3_update(&(ctx->sha3_ctx), text, text_len); +void +hmac_sha3_update( + hmac_sha3_ctx_t* ctx, const unsigned char* text, int text_len) { + if (text_len > 0) sha3_update(&(ctx->sha3_ctx), text, text_len); } /* @@ -134,20 +133,20 @@ void hmac_sha3_update(hmac_sha3_ctx_t *ctx, * hash: Pointer to the memory location, where the resulting hash should * be written to !(has to be SHA3_512_HASH_LEN bytes long)! */ -void hmac_sha3_final(hmac_sha3_ctx_t *ctx, unsigned char *hash) -{ - unsigned char temp_key[SHA3_512_BLOCK_LEN]; - unsigned char inner_hash[SHA3_512_HASH_LEN]; - - sha3_final(inner_hash, &(ctx->sha3_ctx)); - - // XOR with opad - for (int i = 0; i < SHA3_512_BLOCK_LEN; i++) { - temp_key[i] = ctx->key[i] ^ 0x5C; - } - - sha3_init(&(ctx->sha3_ctx), SHA3_512_HASH_LEN); - sha3_update(&(ctx->sha3_ctx), temp_key, SHA3_512_BLOCK_LEN); - sha3_update(&(ctx->sha3_ctx), inner_hash, SHA3_512_HASH_LEN); - sha3_final(hash, &(ctx->sha3_ctx)); +void +hmac_sha3_final(hmac_sha3_ctx_t* ctx, unsigned char* hash) { + unsigned char temp_key[SHA3_512_BLOCK_LEN]; + unsigned char inner_hash[SHA3_512_HASH_LEN]; + + sha3_final(inner_hash, &(ctx->sha3_ctx)); + + // XOR with opad + for (int i = 0; i < SHA3_512_BLOCK_LEN; i++) { + temp_key[i] = ctx->key[i] ^ 0x5C; + } + + sha3_init(&(ctx->sha3_ctx), SHA3_512_HASH_LEN); + sha3_update(&(ctx->sha3_ctx), temp_key, SHA3_512_BLOCK_LEN); + sha3_update(&(ctx->sha3_ctx), inner_hash, SHA3_512_HASH_LEN); + sha3_final(hash, &(ctx->sha3_ctx)); } diff --git a/sm/src/hmac_sha3/hmac_sha3.h b/sm/src/hmac_sha3/hmac_sha3.h index f819480d6..3cb55ce01 100644 --- a/sm/src/hmac_sha3/hmac_sha3.h +++ b/sm/src/hmac_sha3/hmac_sha3.h @@ -20,16 +20,19 @@ #define SHA3_512_HASH_LEN 64 typedef struct { - sha3_ctx_t sha3_ctx; - unsigned char key[SHA3_512_BLOCK_LEN]; + sha3_ctx_t sha3_ctx; + unsigned char key[SHA3_512_BLOCK_LEN]; } hmac_sha3_ctx_t; -void hmac_sha3(const unsigned char *key, int key_len, - const unsigned char *text, int text_len, unsigned char *hash); -void hmac_sha3_init(hmac_sha3_ctx_t *ctx, - const unsigned char *key, int key_len); -void hmac_sha3_update(hmac_sha3_ctx_t *ctx, - const unsigned char *text, int text_len); -void hmac_sha3_final(hmac_sha3_ctx_t *ctx, unsigned char *hash); +void +hmac_sha3( + const unsigned char* key, int key_len, const unsigned char* text, + int text_len, unsigned char* hash); +void +hmac_sha3_init(hmac_sha3_ctx_t* ctx, const unsigned char* key, int key_len); +void +hmac_sha3_update(hmac_sha3_ctx_t* ctx, const unsigned char* text, int text_len); +void +hmac_sha3_final(hmac_sha3_ctx_t* ctx, unsigned char* hash); #endif /* HMAC_SHA3_H */ diff --git a/sm/src/ipi.c b/sm/src/ipi.c index 4527ebee0..60ec3d4fe 100644 --- a/sm/src/ipi.c +++ b/sm/src/ipi.c @@ -1,32 +1,34 @@ +#include "ipi.h" + +#include +#include #include +#include #include -#include #include -#include -#include -#include -#include "ipi.h" +#include + #include "pmp.h" -void sbi_pmp_ipi_local_update(struct sbi_tlb_info *__info) -{ - struct sbi_pmp_ipi_info* info = (struct sbi_pmp_ipi_info *) __info; +void +sbi_pmp_ipi_local_update(struct sbi_tlb_info* __info) { + struct sbi_pmp_ipi_info* info = (struct sbi_pmp_ipi_info*)__info; if (info->type == SBI_PMP_IPI_TYPE_SET) { - pmp_set_keystone(info->rid, (uint8_t) info->perm); + pmp_set_keystone(info->rid, (uint8_t)info->perm); } else { pmp_unset(info->rid); } } -void send_and_sync_pmp_ipi(int region_idx, int type, uint8_t perm) -{ - ulong mask = 0; +void +send_and_sync_pmp_ipi(int region_idx, int type, uint8_t perm) { + ulong mask = 0; ulong source_hart = current_hartid(); struct sbi_tlb_info tlb_info; sbi_hsm_hart_interruptible_mask(sbi_domain_thishart_ptr(), 0, &mask); - SBI_TLB_INFO_INIT(&tlb_info, type, 0, region_idx, perm, - sbi_pmp_ipi_local_update, source_hart); + SBI_TLB_INFO_INIT( + &tlb_info, type, 0, region_idx, perm, sbi_pmp_ipi_local_update, + source_hart); sbi_tlb_request(mask, 0, &tlb_info); } - diff --git a/sm/src/ipi.h b/sm/src/ipi.h index 77acf8bf5..2c0b73938 100644 --- a/sm/src/ipi.h +++ b/sm/src/ipi.h @@ -1,12 +1,12 @@ #ifndef __PMP_IPI_H__ #define __PMP_IPI_H__ -#include #include +#include #include -#define SBI_PMP_IPI_TYPE_SET 0 -#define SBI_PMP_IPI_TYPE_UNSET 1 +#define SBI_PMP_IPI_TYPE_SET 0 +#define SBI_PMP_IPI_TYPE_UNSET 1 struct sbi_pmp_ipi_info { unsigned long type; @@ -15,13 +15,17 @@ struct sbi_pmp_ipi_info { unsigned long perm; }; -void sbi_pmp_ipi_local_update(struct sbi_tlb_info *info); +void +sbi_pmp_ipi_local_update(struct sbi_tlb_info* info); #define SBI_PMP_IPI_INFO_SIZE sizeof(struct sbi_pmp_ipi_info) -int sbi_pmp_ipi_init(struct sbi_scratch* scratch, bool cold_boot); +int +sbi_pmp_ipi_init(struct sbi_scratch* scratch, bool cold_boot); -int sbi_pmp_ipi_request(ulong hmask, ulong hbase, struct sbi_pmp_ipi_info* info); +int +sbi_pmp_ipi_request(ulong hmask, ulong hbase, struct sbi_pmp_ipi_info* info); -void send_and_sync_pmp_ipi(int region_idx, int type, uint8_t perm); +void +send_and_sync_pmp_ipi(int region_idx, int type, uint8_t perm); #endif diff --git a/sm/src/mprv.h b/sm/src/mprv.h index 4344e5f67..d7f1be195 100644 --- a/sm/src/mprv.h +++ b/sm/src/mprv.h @@ -1,103 +1,105 @@ #pragma once #include -typedef struct { size_t words[8]; } mprv_block; - -int copy1_from_sm(uintptr_t dst, const uint8_t *src); -int copy_word_from_sm(uintptr_t dst, const uintptr_t *src); -int copy_block_from_sm(uintptr_t dst, const mprv_block *src); - -int copy1_to_sm(uint8_t *dst, uintptr_t src); -int copy_word_to_sm(uintptr_t *dst, uintptr_t src); -int copy_block_to_sm(mprv_block *dst, uintptr_t src); +typedef struct { + size_t words[8]; +} mprv_block; + +int +copy1_from_sm(uintptr_t dst, const uint8_t* src); +int +copy_word_from_sm(uintptr_t dst, const uintptr_t* src); +int +copy_block_from_sm(uintptr_t dst, const mprv_block* src); + +int +copy1_to_sm(uint8_t* dst, uintptr_t src); +int +copy_word_to_sm(uintptr_t* dst, uintptr_t src); +int +copy_block_to_sm(mprv_block* dst, uintptr_t src); #if __riscv_xlen == 64 -# define STORE sd -# define LOAD ld -# define LOG_REGBYTES 3 +#define STORE sd +#define LOAD ld +#define LOG_REGBYTES 3 #elif __riscv_xlen == 32 -# define STORE sw -# define LOAD lw -# define LOG_REGBYTES 2 +#define STORE sw +#define LOAD lw +#define LOG_REGBYTES 2 #endif #define REGBYTES (1 << LOG_REGBYTES) #define MPRV_BLOCK (REGBYTES * 8) -static inline int copy_from_sm(uintptr_t dst, void *src_buf, size_t len) -{ - uintptr_t src = (uintptr_t)src_buf; - - if (src % REGBYTES == 0 && dst % REGBYTES == 0) { - while (len >= MPRV_BLOCK) { - int res = copy_block_from_sm(dst, (mprv_block *)src); - if (res) - return res; - - src += MPRV_BLOCK; - dst += MPRV_BLOCK; - len -= MPRV_BLOCK; - } - - while (len >= REGBYTES) { - int res = copy_word_from_sm(dst, (uintptr_t *)src); - if (res) - return res; - - src += REGBYTES; - dst += REGBYTES; - len -= REGBYTES; - } +static inline int +copy_from_sm(uintptr_t dst, void* src_buf, size_t len) { + uintptr_t src = (uintptr_t)src_buf; + + if (src % REGBYTES == 0 && dst % REGBYTES == 0) { + while (len >= MPRV_BLOCK) { + int res = copy_block_from_sm(dst, (mprv_block*)src); + if (res) return res; + + src += MPRV_BLOCK; + dst += MPRV_BLOCK; + len -= MPRV_BLOCK; } - while (len > 0) { - int res = copy1_from_sm(dst, (uint8_t *)src); - if (res) - return res; + while (len >= REGBYTES) { + int res = copy_word_from_sm(dst, (uintptr_t*)src); + if (res) return res; - src++; - dst++; - len--; + src += REGBYTES; + dst += REGBYTES; + len -= REGBYTES; } + } + + while (len > 0) { + int res = copy1_from_sm(dst, (uint8_t*)src); + if (res) return res; - return 0; + src++; + dst++; + len--; + } + + return 0; } -static inline int copy_to_sm(void *dst_buf, uintptr_t src, size_t len) -{ - uintptr_t dst = (uintptr_t)dst_buf; - - if (src % REGBYTES == 0 && dst % REGBYTES == 0) { - while (len >= MPRV_BLOCK) { - int res = copy_block_to_sm((mprv_block *)dst, src); - if (res) - return res; - - src += MPRV_BLOCK; - dst += MPRV_BLOCK; - len -= MPRV_BLOCK; - } - - while (len >= REGBYTES) { - int res = copy_word_to_sm((uintptr_t *)dst, src); - if (res) - return res; - - src += REGBYTES; - dst += REGBYTES; - len -= REGBYTES; - } +static inline int +copy_to_sm(void* dst_buf, uintptr_t src, size_t len) { + uintptr_t dst = (uintptr_t)dst_buf; + + if (src % REGBYTES == 0 && dst % REGBYTES == 0) { + while (len >= MPRV_BLOCK) { + int res = copy_block_to_sm((mprv_block*)dst, src); + if (res) return res; + + src += MPRV_BLOCK; + dst += MPRV_BLOCK; + len -= MPRV_BLOCK; } - while (len > 0) { - int res = copy1_to_sm((uint8_t *)dst, src); - if (res) - return res; + while (len >= REGBYTES) { + int res = copy_word_to_sm((uintptr_t*)dst, src); + if (res) return res; - src++; - dst++; - len--; + src += REGBYTES; + dst += REGBYTES; + len -= REGBYTES; } + } + + while (len > 0) { + int res = copy1_to_sm((uint8_t*)dst, src); + if (res) return res; + + src++; + dst++; + len--; + } - return 0; + return 0; } diff --git a/sm/src/page.h b/sm/src/page.h index a75bab0b1..86227ebdf 100644 --- a/sm/src/page.h +++ b/sm/src/page.h @@ -5,37 +5,36 @@ #ifndef _SM_PAGE_H_ #define _SM_PAGE_H_ -#include -#include #include +#include +#include -#define RISCV_PGSIZE PAGE_SIZE -#define RISCV_PGSHIFT PAGE_SHIFT +#define RISCV_PGSIZE PAGE_SIZE +#define RISCV_PGSHIFT PAGE_SHIFT /* page table entry (PTE) fields */ -#define PTE_V _UL(0x001) /* Valid */ -#define PTE_R _UL(0x002) /* Read */ -#define PTE_W _UL(0x004) /* Write */ -#define PTE_X _UL(0x008) /* Execute */ -#define PTE_U _UL(0x010) /* User */ -#define PTE_G _UL(0x020) /* Global */ -#define PTE_A _UL(0x040) /* Accessed */ -#define PTE_D _UL(0x080) /* Dirty */ -#define PTE_SOFT _UL(0x300) /* Reserved for Software */ +#define PTE_V _UL(0x001) /* Valid */ +#define PTE_R _UL(0x002) /* Read */ +#define PTE_W _UL(0x004) /* Write */ +#define PTE_X _UL(0x008) /* Execute */ +#define PTE_U _UL(0x010) /* User */ +#define PTE_G _UL(0x020) /* Global */ +#define PTE_A _UL(0x040) /* Accessed */ +#define PTE_D _UL(0x080) /* Dirty */ +#define PTE_SOFT _UL(0x300) /* Reserved for Software */ #if __riscv_xlen == 64 -# define RISCV_PGLEVEL_MASK 0x1ff -# define RISCV_PGTABLE_HIGHEST_BIT 0x100 -# define RISCV_PGLEVEL_BITS 9 +#define RISCV_PGLEVEL_MASK 0x1ff +#define RISCV_PGTABLE_HIGHEST_BIT 0x100 +#define RISCV_PGLEVEL_BITS 9 #else -# define RISCV_PGLEVEL_MASK 0x3ff -# define RISCV_PGTABLE_HIGHEST_BIT 0x300 -# define RISCV_PGLEVEL_BITS 10 +#define RISCV_PGLEVEL_MASK 0x3ff +#define RISCV_PGTABLE_HIGHEST_BIT 0x300 +#define RISCV_PGLEVEL_BITS 10 #endif #define PTE_PPN_SHIFT 10 #define VA_BITS 39 -#define RISCV_PGLEVEL_TOP ((VA_BITS - RISCV_PGSHIFT)/RISCV_PGLEVEL_BITS) +#define RISCV_PGLEVEL_TOP ((VA_BITS - RISCV_PGSHIFT) / RISCV_PGLEVEL_BITS) #endif - diff --git a/sm/src/platform-hook.h b/sm/src/platform-hook.h index c69135200..4aeabaa00 100644 --- a/sm/src/platform-hook.h +++ b/sm/src/platform-hook.h @@ -8,24 +8,31 @@ /* This fires once FOR EACH sm supported enclave during init of enclave metadata. It may not fail currently. */ -void platform_init_enclave(struct enclave* enclave); +void +platform_init_enclave(struct enclave* enclave); /* This fires once GLOBALLY before any other platform init */ -unsigned long platform_init_global_once(); +unsigned long +platform_init_global_once(); /* Fires once per-hart after global_once */ -unsigned long platform_init_global(); +unsigned long +platform_init_global(); /* This fires once each time an enclave is created by the sm */ -unsigned long platform_create_enclave(struct enclave* enclave); +unsigned long +platform_create_enclave(struct enclave* enclave); /* This fires once each time an enclave is destroyed by the sm */ -void platform_destroy_enclave(struct enclave* enclave); +void +platform_destroy_enclave(struct enclave* enclave); /* This fires when context switching INTO an enclave from the OS */ -void platform_switch_to_enclave(struct enclave* enclave); +void +platform_switch_to_enclave(struct enclave* enclave); /* This fires when context switching OUT of an enclave into the OS */ -void platform_switch_from_enclave(struct enclave* enclave); +void +platform_switch_from_enclave(struct enclave* enclave); /* Future version: This fires when context switching from enclave A to enclave B */ @@ -35,6 +42,7 @@ void platform_switch_from_enclave(struct enclave* enclave); /* This is a required feature, it must return 64bits of random data on demand and never fail. If it would fail it may power off instead. */ -uint64_t platform_random(); +uint64_t +platform_random(); #endif /* _PLATFORM_HOOK_H_ */ diff --git a/sm/src/platform/generic/platform.c b/sm/src/platform/generic/platform.c index 16416fbe5..a61edc5da 100644 --- a/sm/src/platform/generic/platform.c +++ b/sm/src/platform/generic/platform.c @@ -1,44 +1,52 @@ /* Default platform does nothing special here */ #include "../../enclave.h" -unsigned long platform_init_global_once(){ +unsigned long +platform_init_global_once() { return SBI_ERR_SM_ENCLAVE_SUCCESS; } -unsigned long platform_init_global(){ +unsigned long +platform_init_global() { return SBI_ERR_SM_ENCLAVE_SUCCESS; } -void platform_init_enclave(struct enclave* enclave){ +void +platform_init_enclave(struct enclave* enclave) { return; } -void platform_destroy_enclave(struct enclave* enclave){ +void +platform_destroy_enclave(struct enclave* enclave) { return; } -unsigned long platform_create_enclave(struct enclave* enclave){ +unsigned long +platform_create_enclave(struct enclave* enclave) { return SBI_ERR_SM_ENCLAVE_SUCCESS; } -void platform_switch_to_enclave(struct enclave* enclave){ +void +platform_switch_to_enclave(struct enclave* enclave) { return; } -void platform_switch_from_enclave(struct enclave* enclave){ +void +platform_switch_from_enclave(struct enclave* enclave) { return; } -uint64_t platform_random(){ +uint64_t +platform_random() { #pragma message("Platform has no entropy source, this is unsafe. TEST ONLY") static uint64_t w = 0, s = 0xb5ad4eceda1ce2a9; unsigned long cycles; - asm volatile ("rdcycle %0" : "=r" (cycles)); + asm volatile("rdcycle %0" : "=r"(cycles)); // from Middle Square Weyl Sequence algorithm uint64_t x = cycles; x *= x; x += (w += s); - return (x>>32) | (x<<32); + return (x >> 32) | (x << 32); } diff --git a/sm/src/platform/generic/platform.h b/sm/src/platform/generic/platform.h index f6eaab3bc..9b6b356be 100644 --- a/sm/src/platform/generic/platform.h +++ b/sm/src/platform/generic/platform.h @@ -1,5 +1,3 @@ // No special data needed for default platform -struct platform_enclave_data{ - -}; +struct platform_enclave_data {}; diff --git a/sm/src/platform/mpfs/platform.c b/sm/src/platform/mpfs/platform.c index f8781efd0..db79d4b3a 100644 --- a/sm/src/platform/mpfs/platform.c +++ b/sm/src/platform/mpfs/platform.c @@ -1,40 +1,48 @@ /* Default platform does nothing special here */ -#include "platform-hook.h" -#include "../../enclave.h" -#include "../../../plat/mpfs/drivers/mss_sys_services/mss_sys_services.h" -#include #include +#include + +#include "../../../plat/mpfs/drivers/mss_sys_services/mss_sys_services.h" +#include "../../enclave.h" +#include "platform-hook.h" -unsigned long platform_init_global_once(void){ +unsigned long +platform_init_global_once(void) { return SBI_ERR_SM_ENCLAVE_SUCCESS; } -unsigned long platform_init_global(void){ +unsigned long +platform_init_global(void) { return SBI_ERR_SM_ENCLAVE_SUCCESS; } -void platform_init_enclave(struct enclave* enclave){ +void +platform_init_enclave(struct enclave* enclave) { return; } -void platform_destroy_enclave(struct enclave* enclave){ +void +platform_destroy_enclave(struct enclave* enclave) { return; } -unsigned long platform_create_enclave(struct enclave* enclave){ +unsigned long +platform_create_enclave(struct enclave* enclave) { return SBI_ERR_SM_ENCLAVE_SUCCESS; } -void platform_switch_to_enclave(struct enclave* enclave){ +void +platform_switch_to_enclave(struct enclave* enclave) { return; } -void platform_switch_from_enclave(struct enclave* enclave){ +void +platform_switch_from_enclave(struct enclave* enclave) { return; } -#define NONCE_BYTES (256/8) -#define RAND_STATE_WORDS (NONCE_BYTES/sizeof(uint64_t)) +#define NONCE_BYTES (256 / 8) +#define RAND_STATE_WORDS (NONCE_BYTES / sizeof(uint64_t)) struct random { uint64_t data[RAND_STATE_WORDS]; uint8_t words_left; @@ -42,13 +50,14 @@ struct random { static spinlock_t rand_state_lock = SPIN_LOCK_INITIALIZER; static struct random rand_state; -uint64_t platform_random(void){ +uint64_t +platform_random(void) { spin_lock(&rand_state_lock); if (!rand_state.words_left) { // This service provides 256 bits of real random data // It might be a bit slow to query though. - int ret = MSS_SYS_nonce_service((uint8_t *)&rand_state.data, 0); + int ret = MSS_SYS_nonce_service((uint8_t*)&rand_state.data, 0); sm_assert(ret == 0); rand_state.words_left = RAND_STATE_WORDS; } diff --git a/sm/src/platform/mpfs/platform.h b/sm/src/platform/mpfs/platform.h index f6eaab3bc..9b6b356be 100644 --- a/sm/src/platform/mpfs/platform.h +++ b/sm/src/platform/mpfs/platform.h @@ -1,5 +1,3 @@ // No special data needed for default platform -struct platform_enclave_data{ - -}; +struct platform_enclave_data {}; diff --git a/sm/src/platform/sifive/fu540/fu540_internal.c b/sm/src/platform/sifive/fu540/fu540_internal.c index f9752cdc5..0ed539762 100644 --- a/sm/src/platform/sifive/fu540/fu540_internal.c +++ b/sm/src/platform/sifive/fu540/fu540_internal.c @@ -1,17 +1,19 @@ -#include +#include #include -#include "platform-hook.h" -#include "sm-sbi.h" -#include "pmp.h" +#include +#include + #include "enclave.h" -#include #include "page.h" -#include +#include "platform-hook.h" #include "platform.h" +#include "pmp.h" +#include "sm-sbi.h" #include "sm.h" -unsigned long scratch_init(){ - if(scratchpad_allocated_ways != 0){ +unsigned long +scratch_init() { + if (scratchpad_allocated_ways != 0) { return SBI_ERR_SM_ENCLAVE_SUCCESS; } @@ -23,7 +25,7 @@ unsigned long scratch_init(){ waymask_apply_allocated_mask(scratchpad_allocated_ways, core); waymask_t invert_mask = WM_FLIP_MASK(scratchpad_allocated_ways); - _wm_assign_mask(invert_mask, core*2+1); + _wm_assign_mask(invert_mask, core * 2 + 1); /* This section is quite delicate, and may need to be re-written in assembly. Fundamentally, we are going to create a scratchpad @@ -36,25 +38,22 @@ unsigned long scratch_init(){ Zero Device that total the size of the allocated ways, they don't really matter */ uintptr_t scratch_start = L2_SCRATCH_START; - uintptr_t scratch_stop = L2_SCRATCH_START + (8 * L2_WAY_SIZE); + uintptr_t scratch_stop = L2_SCRATCH_START + (8 * L2_WAY_SIZE); waymask_t tmp_mask; uintptr_t addr; addr = scratch_start; /* We will be directly setting the master d$ mask to avoid any cache pollution issues */ - waymask_t* master_mask = WM_REG_ADDR(core*2); + waymask_t* master_mask = WM_REG_ADDR(core * 2); /* Go through the mask one way at a time to control the allocations */ - for(tmp_mask=0x80; - tmp_mask <= scratchpad_allocated_ways; - tmp_mask = tmp_mask << 1){ - uintptr_t way_end = addr + L2_WAY_SIZE; + for (tmp_mask = 0x80; tmp_mask <= scratchpad_allocated_ways; + tmp_mask = tmp_mask << 1) { + uintptr_t way_end = addr + L2_WAY_SIZE; /* Assign a temporary mask of 1 way to the d$ */ *master_mask = tmp_mask; /* Write a known value to every L2_LINE_SIZE offset */ - for(; - addr < way_end; - addr+= L2_LINE_SIZE){ + for (; addr < way_end; addr += L2_LINE_SIZE) { *(uintptr_t*)addr = 64; } /* Disable as soon as possible */ @@ -67,8 +66,8 @@ unsigned long scratch_init(){ /* We try and check it now, any error SHOULD be immediately detectable. */ /* If there was a mistake, the scratchpad will never be safe to use again... */ - for(addr = scratch_start; addr < scratch_stop; addr += L2_LINE_SIZE){ - if(*(uintptr_t*)addr != 64){ + for (addr = scratch_start; addr < scratch_stop; addr += L2_LINE_SIZE) { + if (*(uintptr_t*)addr != 64) { sbi_printf("FATAL: Found a bad line %lx\r\n", addr); return SBI_ERR_SM_ENCLAVE_UNKNOWN_ERROR; } @@ -77,116 +76,120 @@ unsigned long scratch_init(){ return SBI_ERR_SM_ENCLAVE_SUCCESS; } -unsigned long platform_init_global_once(){ - +unsigned long +platform_init_global_once() { waymask_init(); scratchpad_allocated_ways = 0; /* PMP Lock the entire L2 controller */ - if(pmp_region_init_atomic(CACHE_CONTROLLER_ADDR_START, - CACHE_CONTROLLER_ADDR_END - CACHE_CONTROLLER_ADDR_START, - PMP_PRI_ANY, &l2_controller_rid, 1)){ + if (pmp_region_init_atomic( + CACHE_CONTROLLER_ADDR_START, + CACHE_CONTROLLER_ADDR_END - CACHE_CONTROLLER_ADDR_START, PMP_PRI_ANY, + &l2_controller_rid, 1)) { sbi_printf("FATAL CANNOT CREATE PMP FOR CONTROLLER\r\n"); return SBI_ERR_SM_ENCLAVE_NO_FREE_RESOURCE; } /* Create PMP region for scratchpad */ - if(pmp_region_init_atomic(L2_SCRATCH_START, - L2_SCRATCH_STOP - L2_SCRATCH_START, - PMP_PRI_ANY, &scratch_rid, 1)){ + if (pmp_region_init_atomic( + L2_SCRATCH_START, L2_SCRATCH_STOP - L2_SCRATCH_START, PMP_PRI_ANY, + &scratch_rid, 1)) { sbi_printf("FATAL CANNOT CREATE SCRATCH PMP\r\n"); return SBI_ERR_SM_ENCLAVE_NO_FREE_RESOURCE; } return SBI_ERR_SM_ENCLAVE_SUCCESS; } - -unsigned long platform_init_global(){ +unsigned long +platform_init_global() { pmp_set_keystone(l2_controller_rid, PMP_NO_PERM); pmp_set_keystone(scratch_rid, PMP_NO_PERM); return SBI_ERR_SM_ENCLAVE_SUCCESS; } -void platform_init_enclave(struct enclave* enclave){ - enclave->ped.num_ways = 0; // DISABLE waymasking - //ped->num_ways = WM_NUM_WAYS/2; - enclave->ped.saved_mask = 0; +void +platform_init_enclave(struct enclave* enclave) { + enclave->ped.num_ways = 0; // DISABLE waymasking + // ped->num_ways = WM_NUM_WAYS/2; + enclave->ped.saved_mask = 0; enclave->ped.use_scratch = 0; - } -unsigned long platform_create_enclave(struct enclave* enclave){ +unsigned long +platform_create_enclave(struct enclave* enclave) { enclave->ped.use_scratch = 0; - if(enclave->ped.use_scratch){ - - if(scratch_init() != SBI_ERR_SM_ENCLAVE_SUCCESS){ + if (enclave->ped.use_scratch) { + if (scratch_init() != SBI_ERR_SM_ENCLAVE_SUCCESS) { return SBI_ERR_SM_ENCLAVE_UNKNOWN_ERROR; } /* Swap regions */ int old_epm_idx = get_enclave_region_index(enclave->eid, REGION_EPM); - int new_idx = get_enclave_region_index(enclave->eid, REGION_INVALID); - if(old_epm_idx < 0 || new_idx < 0){ + int new_idx = get_enclave_region_index(enclave->eid, REGION_INVALID); + if (old_epm_idx < 0 || new_idx < 0) { return SBI_ERR_SM_ENCLAVE_NO_FREE_RESOURCE; } - enclave->regions[new_idx].pmp_rid = scratch_rid; - enclave->regions[new_idx].type = REGION_EPM; + enclave->regions[new_idx].pmp_rid = scratch_rid; + enclave->regions[new_idx].type = REGION_EPM; enclave->regions[old_epm_idx].type = REGION_OTHER; /* Copy the enclave over */ - uintptr_t old_epm_start = pmp_region_get_addr(enclave->regions[old_epm_idx].pmp_rid); + uintptr_t old_epm_start = + pmp_region_get_addr(enclave->regions[old_epm_idx].pmp_rid); uintptr_t scratch_epm_start = pmp_region_get_addr(scratch_rid); - size_t size = enclave->pa_params.free_base - old_epm_start; - size_t scratch_size = 8*L2_WAY_SIZE; + size_t size = enclave->pa_params.free_base - old_epm_start; + size_t scratch_size = 8 * L2_WAY_SIZE; - if(size > scratch_size){ + if (size > scratch_size) { sbi_printf("FATAL: Enclave too big for scratchpad!\r\n"); return SBI_ERR_SM_ENCLAVE_NO_FREE_RESOURCE; } - memcpy((unsigned long*)scratch_epm_start, - (unsigned long*)old_epm_start, - size); - sbi_printf("Performing copy from %lx to %lx\r\n", old_epm_start, scratch_epm_start); + memcpy( + (unsigned long*)scratch_epm_start, (unsigned long*)old_epm_start, size); + sbi_printf( + "Performing copy from %lx to %lx\r\n", old_epm_start, + scratch_epm_start); /* Change pa params to the new region */ enclave->pa_params.dram_base = scratch_epm_start; enclave->pa_params.dram_size = scratch_size; - enclave->pa_params.runtime_base = (scratch_epm_start + - (enclave->pa_params.runtime_base - - old_epm_start)); - enclave->pa_params.user_base = (scratch_epm_start + - (enclave->pa_params.user_base - - old_epm_start)); - enclave->pa_params.free_base = (scratch_epm_start + - size); - enclave->encl_satp =((scratch_epm_start >> RISCV_PGSHIFT) | (SATP_MODE_SV39 << HGATP_MODE_SHIFT)); - - /* sbi_printf("[new pa_params]: \r\n\tbase_addr: %llx\r\n\tbasesize: %llx\r\n\truntime_addr: %llx\r\n\tuser_addr: %llx\r\n\tfree_addr: %llx\r\n", */ - /* enclave->pa_params.dram_base, */ - /* enclave->pa_params.dram_size, */ - /* enclave->pa_params.runtime_base, */ - /* enclave->pa_params.user_base, */ - /* enclave->pa_params.free_base); */ - + enclave->pa_params.runtime_base = + (scratch_epm_start + (enclave->pa_params.runtime_base - old_epm_start)); + enclave->pa_params.user_base = + (scratch_epm_start + (enclave->pa_params.user_base - old_epm_start)); + enclave->pa_params.free_base = (scratch_epm_start + size); + enclave->encl_satp = + ((scratch_epm_start >> RISCV_PGSHIFT) | + (SATP_MODE_SV39 << HGATP_MODE_SHIFT)); + + /* sbi_printf("[new pa_params]: \r\n\tbase_addr: %llx\r\n\tbasesize: + * %llx\r\n\truntime_addr: %llx\r\n\tuser_addr: %llx\r\n\tfree_addr: + * %llx\r\n", */ + /* enclave->pa_params.dram_base, */ + /* enclave->pa_params.dram_size, */ + /* enclave->pa_params.runtime_base, */ + /* enclave->pa_params.user_base, */ + /* enclave->pa_params.free_base); */ } return SBI_ERR_SM_ENCLAVE_SUCCESS; - } -void platform_destroy_enclave(struct enclave* enclave){ - if(enclave->ped.use_scratch){ +void +platform_destroy_enclave(struct enclave* enclave) { + if (enclave->ped.use_scratch) { int scratch_epm_idx = get_enclave_region_index(enclave->eid, REGION_EPM); /* Clean out the region ourselves */ /* Should be safe to just write to the memory addresses we used to initialize */ uintptr_t addr; - uintptr_t scratch_start = pmp_region_get_addr(enclave->regions[scratch_epm_idx].pmp_rid); - uintptr_t scratch_stop = scratch_start + pmp_region_get_size(enclave->regions[scratch_epm_idx].pmp_rid); - for( addr = scratch_start; - addr < scratch_stop; - addr += sizeof(uintptr_t)){ + uintptr_t scratch_start = + pmp_region_get_addr(enclave->regions[scratch_epm_idx].pmp_rid); + uintptr_t scratch_stop = + scratch_start + + pmp_region_get_size(enclave->regions[scratch_epm_idx].pmp_rid); + for (addr = scratch_start; addr < scratch_stop; addr += sizeof(uintptr_t)) { *(uintptr_t*)addr = 0; } @@ -201,18 +204,18 @@ void platform_destroy_enclave(struct enclave* enclave){ enclave->ped.use_scratch = 0; } -void platform_switch_to_enclave(struct enclave* enclave){ - - if(enclave->ped.num_ways > 0){ +void +platform_switch_to_enclave(struct enclave* enclave) { + if (enclave->ped.num_ways > 0) { // Each hart gets special access to some unsigned int core = csr_read(mhartid); - //Allocate ways, fresh every time we enter - waymask_allocate_ways(enclave->ped.num_ways, - core, - &enclave->ped.saved_mask); + // Allocate ways, fresh every time we enter + waymask_allocate_ways( + enclave->ped.num_ways, core, &enclave->ped.saved_mask); - //sbi_printf("Chose ways: 0x%x, core 0x%x\r\n",enclave->ped.saved_mask, core); + // sbi_printf("Chose ways: 0x%x, core 0x%x\r\n",enclave->ped.saved_mask, + // core); /* Assign the ways to all cores */ waymask_apply_allocated_mask(enclave->ped.saved_mask, core); @@ -221,20 +224,20 @@ void platform_switch_to_enclave(struct enclave* enclave){ } /* Setup PMP region for scratchpad */ - if(enclave->ped.use_scratch != 0){ + if (enclave->ped.use_scratch != 0) { pmp_set_keystone(scratch_rid, PMP_ALL_PERM); - //sbi_printf("Switching to an enclave with scratchpad access\r\n"); + // sbi_printf("Switching to an enclave with scratchpad access\r\n"); } } -void platform_switch_from_enclave(struct enclave* enclave){ - if(enclave->ped.num_ways > 0){ +void +platform_switch_from_enclave(struct enclave* enclave) { + if (enclave->ped.num_ways > 0) { /* Free all our ways */ waymask_free_ways(enclave->ped.saved_mask); /* We don't need to clean them, see docs */ } - if(enclave->ped.use_scratch != 0){ + if (enclave->ped.use_scratch != 0) { pmp_set_keystone(scratch_rid, PMP_NO_PERM); } - } diff --git a/sm/src/platform/sifive/fu540/platform.c b/sm/src/platform/sifive/fu540/platform.c index ec29a9699..7940e8524 100644 --- a/sm/src/platform/sifive/fu540/platform.c +++ b/sm/src/platform/sifive/fu540/platform.c @@ -1,9 +1,10 @@ #include "fu540_internal.c" #include "waymasks.c" -uint64_t platform_random(){ +uint64_t +platform_random() { #pragma message("Platform has no entropy source, this is unsafe. TEST ONLY") unsigned long cycles; - asm volatile ("rdcycle %0" : "=r" (cycles)); + asm volatile("rdcycle %0" : "=r"(cycles)); return cycles; } diff --git a/sm/src/platform/sifive/fu540/waymasks.c b/sm/src/platform/sifive/fu540/waymasks.c index 73b0d6f86..0e0db9361 100644 --- a/sm/src/platform/sifive/fu540/waymasks.c +++ b/sm/src/platform/sifive/fu540/waymasks.c @@ -1,6 +1,7 @@ -#include #include "waymasks.h" +#include + /* Ways currently allocated to enclaves */ waymask_t enclave_allocated_ways; @@ -14,25 +15,28 @@ waymask_t allocated_ways; region_id scratch_rid; region_id l2_controller_rid; -void waymask_debug_printstatus(){ +void +waymask_debug_printstatus() { unsigned int hartid = csr_read(mhartid); - sbi_printf("mhartid: %x, coremasters: %x & %x\r\n",hartid, (hartid)*2, (hartid)*2 + 1); + sbi_printf( + "mhartid: %x, coremasters: %x & %x\r\n", hartid, (hartid)*2, + (hartid)*2 + 1); unsigned int master; - for(master=0;master 0 && way <= WM_MAX_FREE_WAY){ - if( !IS_WAY_ALLOCATED(way) ){ + while (n_ways > 0 && way <= WM_MAX_FREE_WAY) { + if (!IS_WAY_ALLOCATED(way)) { *mask |= (0x1 << way); n_ways--; } @@ -111,26 +115,26 @@ int _wm_choose_ways_for_hart(size_t n_ways, waymask_t* mask, unsigned int target } // This will DISABLE the given ways -int _wm_lockout_ways(waymask_t mask, unsigned int master){ - - if(master > WM_NUM_MASTERS){ - return -1; +int +_wm_lockout_ways(waymask_t mask, unsigned int master) { + if (master > WM_NUM_MASTERS) { + return -1; } - //Note that we DO allow entirely locking out a master - // Supposedly this isn't allowed, we'll see what happens. - // "At least one cache way must be enabled. " + // Note that we DO allow entirely locking out a master + // Supposedly this isn't allowed, we'll see what happens. + // "At least one cache way must be enabled. " waymask_t* master_mask = WM_REG_ADDR(master); waymask_t current_mask = *master_mask; - *master_mask = current_mask & WM_FLIP_MASK(mask); + *master_mask = current_mask & WM_FLIP_MASK(mask); return 0; } // This will GRANT ACCESS to the given ways -int _wm_grant_ways(waymask_t mask, unsigned int master){ - - if(master > WM_NUM_MASTERS){ - return -1; +int +_wm_grant_ways(waymask_t mask, unsigned int master) { + if (master > WM_NUM_MASTERS) { + return -1; } waymask_t* master_mask = WM_REG_ADDR(master); @@ -140,10 +144,10 @@ int _wm_grant_ways(waymask_t mask, unsigned int master){ } // Just hard set ways for a master -int _wm_assign_mask(waymask_t mask, unsigned int master){ - - if(master > WM_NUM_MASTERS){ - return -1; +int +_wm_assign_mask(waymask_t mask, unsigned int master) { + if (master > WM_NUM_MASTERS) { + return -1; } waymask_t* master_mask = WM_REG_ADDR(master); @@ -152,19 +156,20 @@ int _wm_assign_mask(waymask_t mask, unsigned int master){ return 0; } -void waymask_init(){ - allocated_ways = 0; - enclave_allocated_ways = 0; +void +waymask_init() { + allocated_ways = 0; + enclave_allocated_ways = 0; scratchpad_allocated_ways = 0; } -void waymask_allocate_scratchpad(){ - +void +waymask_allocate_scratchpad() { /* Avoid the 'special' ways we reserve for cores */ waymask_t mask = 0xF00 | 0x80 | 0x1000 | 0x2000 | 0x4000; /* tmp sanity check */ - if( (allocated_ways & mask) != 0){ + if ((allocated_ways & mask) != 0) { sbi_printf("Cannot allocate ways for scratchpad, in use!\r\n"); return; } @@ -173,35 +178,32 @@ void waymask_allocate_scratchpad(){ allocated_ways |= scratchpad_allocated_ways; } -void waymask_free_scratchpad(){ - +void +waymask_free_scratchpad() { allocated_ways &= WM_FLIP_MASK(scratchpad_allocated_ways); scratchpad_allocated_ways = 0; - } - /* TODO check this is the right way to clear */ -void waymask_clear_ways(waymask_t mask, unsigned int core){ - +void +waymask_clear_ways(waymask_t mask, unsigned int core) { /* L2 Scratchpad (L2 Zero Device) allows us to write to non-memory backed locations. We'll do one way at a time, writing once to each cache set */ int cur_mask = 0; - int i,j = 0; - for(i=0; i < WM_NUM_WAYS; i++){ - cur_mask = 1< #include +#include #define WM_NUM_MASTERS 21 #define WM_NUM_WAYS 16 #define WM_NUM_HARTS 4 #define WM_MIN_FREE_WAY WM_NUM_HARTS -#define WM_MAX_FREE_WAY WM_NUM_WAYS-2 /* We allocate 1 way for all non hart masters */ +#define WM_MAX_FREE_WAY \ + WM_NUM_WAYS - 2 /* We allocate 1 way for all non hart masters */ /* Waymasking is part of the dynamic way-allocation system. * @@ -24,7 +25,6 @@ * */ - /* Legal allocations ******************** * Way 0 : (FR) All non-hart masters, all untrusted execution @@ -52,35 +52,35 @@ extern region_id scratch_rid; extern region_id l2_controller_rid; // Waymask master IDs -#define WM_Hart_0_DCache_MMIO 0 -#define WM_Hart_0_ICache 1 -#define WM_Hart_1_DCache 2 -#define WM_Hart_1_ICache 3 -#define WM_Hart_2_DCache 4 -#define WM_Hart_2_ICache 5 -#define WM_Hart_3_DCache 6 -#define WM_Hart_3_ICache 7 -#define WM_Hart_4_DCache 8 -#define WM_Hart_4_ICache 9 -#define WM_DMA 10 +#define WM_Hart_0_DCache_MMIO 0 +#define WM_Hart_0_ICache 1 +#define WM_Hart_1_DCache 2 +#define WM_Hart_1_ICache 3 +#define WM_Hart_2_DCache 4 +#define WM_Hart_2_ICache 5 +#define WM_Hart_3_DCache 6 +#define WM_Hart_3_ICache 7 +#define WM_Hart_4_DCache 8 +#define WM_Hart_4_ICache 9 +#define WM_DMA 10 #define WM_Chiplink_Domain_1_7_Prefetch 11 -#define WM_ChipLink_Domain_0 12 -#define WM_ChipLink_Domain_1 13 -#define WM_ChipLink_Domain_2 14 -#define WM_ChipLink_Domain_3 15 -#define WM_ChipLink_Domain_4 16 -#define WM_ChipLink_Domain_5 17 -#define WM_ChipLink_Domain_6 18 -#define WM_ChipLink_Domain_7 19 -#define WM_GEMGXL_ID0 20 - +#define WM_ChipLink_Domain_0 12 +#define WM_ChipLink_Domain_1 13 +#define WM_ChipLink_Domain_2 14 +#define WM_ChipLink_Domain_3 15 +#define WM_ChipLink_Domain_4 16 +#define WM_ChipLink_Domain_5 17 +#define WM_ChipLink_Domain_6 18 +#define WM_ChipLink_Domain_7 19 +#define WM_GEMGXL_ID0 20 // Cache controller is mapped to this address for the FU540 #define CACHE_CONTROLLER_ADDR_START (uintptr_t)0x02010000 -#define CACHE_CONTROLLER_ADDR_END 0x02011000 // Not inclusive +#define CACHE_CONTROLLER_ADDR_END 0x02011000 // Not inclusive // WM Registers are 8 bytes apart, starting at 0x800 -#define WM_REG_OFFSET(id) (uintptr_t)(0x800+(8*id)) -#define WM_REG_ADDR(id) ((waymask_t*)( CACHE_CONTROLLER_ADDR_START + WM_REG_OFFSET(id))) +#define WM_REG_OFFSET(id) (uintptr_t)(0x800 + (8 * id)) +#define WM_REG_ADDR(id) \ + ((waymask_t*)(CACHE_CONTROLLER_ADDR_START + WM_REG_OFFSET(id))) // Only the lower 16 bits are used #define WM_MASK 0xFFFF @@ -91,47 +91,59 @@ extern region_id l2_controller_rid; // 64-bit address flush register #define L2_FLUSH64_REG ((uintptr_t*)(CACHE_CONTROLLER_ADDR_START + 0x200)) -#define IS_WAY_ALLOCATED( waynum ) ( allocated_ways & (0x1 << waynum)) +#define IS_WAY_ALLOCATED(waynum) (allocated_ways & (0x1 << waynum)) -#define IS_MASTER_RUNNING_UNTRUSTED( master ) (/* TODO */ 0) +#define IS_MASTER_RUNNING_UNTRUSTED(master) (/* TODO */ 0) -//NOTE: We ignore hart1, its a special hart and is disabled. There is -//no hart0? -#define GET_HART_WAY( hartnum ) ( hartnum - 2 ) +// NOTE: We ignore hart1, its a special hart and is disabled. There is +// no hart0? +#define GET_HART_WAY(hartnum) (hartnum - 2) -#define GET_CORE_DWAY( core ) ( core * 2 ) +#define GET_CORE_DWAY(core) (core * 2) // L2 Zero Device (Scratchpad) info #define L2_SCRATCH_START (0x0A000000) -#define L2_SCRATCH_STOP (0x0C000000) +#define L2_SCRATCH_STOP (0x0C000000) /* 2 MB */ -#define L2_SIZE (2*1024*1024) +#define L2_SIZE (2 * 1024 * 1024) // 512 sets per bank, 4 banks -#define L2_NUM_SETS 512*4 -#define L2_SET_SIZE (L2_SIZE/L2_NUM_SETS) +#define L2_NUM_SETS 512 * 4 +#define L2_SET_SIZE (L2_SIZE / L2_NUM_SETS) // Used for LIM/Zero Device -#define L2_WAY_SIZE (L2_SIZE/WM_NUM_WAYS) +#define L2_WAY_SIZE (L2_SIZE / WM_NUM_WAYS) #define L2_LINE_SIZE (64) /* Interface */ -size_t waymask_allocate_ways(size_t n_ways, unsigned int target_hart, - waymask_t* mask); -void waymask_apply_allocated_mask(waymask_t mask, unsigned int target_hart); -void waymask_free_ways(waymask_t _mask); -void waymask_init(); -void waymask_clear_ways(waymask_t mask, unsigned int core); - -void waymask_allocate_scratchpad(); -void waymask_free_scratchpad(); +size_t +waymask_allocate_ways(size_t n_ways, unsigned int target_hart, waymask_t* mask); +void +waymask_apply_allocated_mask(waymask_t mask, unsigned int target_hart); +void +waymask_free_ways(waymask_t _mask); +void +waymask_init(); +void +waymask_clear_ways(waymask_t mask, unsigned int core); + +void +waymask_allocate_scratchpad(); +void +waymask_free_scratchpad(); /* Internals */ -int _wm_choose_ways_for_hart(size_t n_ways, waymask_t* _mask, unsigned int target_hart); -int _wm_lockout_ways(waymask_t mask, unsigned int master); -int _wm_grant_ways(waymask_t mask, unsigned int hart); -int _wm_assign_mask(waymask_t mask, unsigned int master); -void waymask_debug_printstatus(); +int +_wm_choose_ways_for_hart( + size_t n_ways, waymask_t* _mask, unsigned int target_hart); +int +_wm_lockout_ways(waymask_t mask, unsigned int master); +int +_wm_grant_ways(waymask_t mask, unsigned int hart); +int +_wm_assign_mask(waymask_t mask, unsigned int master); +void +waymask_debug_printstatus(); #endif /* _WAYMASKS_H_ */ diff --git a/sm/src/plugins/multimem.c b/sm/src/plugins/multimem.c index 0c0d6d33b..e9cdfde3d 100644 --- a/sm/src/plugins/multimem.c +++ b/sm/src/plugins/multimem.c @@ -1,34 +1,33 @@ #include "plugins/multimem.h" -#include "sm.h" + #include + #include "mprv.h" +#include "sm.h" -uintptr_t multimem_get_other_region_size(enclave_id eid, size_t *size_out) -{ +uintptr_t +multimem_get_other_region_size(enclave_id eid, size_t* size_out) { int mem_id = get_enclave_region_index(eid, REGION_OTHER); - if (mem_id == -1) - return -1; + if (mem_id == -1) return -1; size_t out = get_enclave_region_size(eid, mem_id); return copy_word_from_sm((uintptr_t)size_out, &out); } -uintptr_t multimem_get_other_region_addr(enclave_id eid, size_t *size_out) -{ +uintptr_t +multimem_get_other_region_addr(enclave_id eid, size_t* size_out) { int mem_id = get_enclave_region_index(eid, REGION_OTHER); - if (mem_id == -1) - return -1; + if (mem_id == -1) return -1; size_t out = get_enclave_region_base(eid, mem_id); return copy_word_from_sm((uintptr_t)size_out, &out); } -uintptr_t do_sbi_multimem(enclave_id eid, uintptr_t call_id, uintptr_t arg0) -{ - switch(call_id) - { +uintptr_t +do_sbi_multimem(enclave_id eid, uintptr_t call_id, uintptr_t arg0) { + switch (call_id) { case MULTIMEM_GET_OTHER_REGION_SIZE: - return multimem_get_other_region_size(eid, (size_t *)arg0); + return multimem_get_other_region_size(eid, (size_t*)arg0); case MULTIMEM_GET_OTHER_REGION_ADDR: - return multimem_get_other_region_addr(eid, (size_t *)arg0); + return multimem_get_other_region_addr(eid, (size_t*)arg0); default: return 0; } diff --git a/sm/src/plugins/multimem.h b/sm/src/plugins/multimem.h index c18ada2c3..b1d658106 100644 --- a/sm/src/plugins/multimem.h +++ b/sm/src/plugins/multimem.h @@ -1,12 +1,13 @@ #ifndef __SM_MULTIMEM_H__ #define __SM_MULTIMEM_H__ -#include "plugins/plugins.h" #include "enclave.h" +#include "plugins/plugins.h" #define MULTIMEM_GET_OTHER_REGION_SIZE 0x1 #define MULTIMEM_GET_OTHER_REGION_ADDR 0x2 -uintptr_t do_sbi_multimem(enclave_id id, uintptr_t call_id, uintptr_t arg0); +uintptr_t +do_sbi_multimem(enclave_id id, uintptr_t call_id, uintptr_t arg0); #endif diff --git a/sm/src/plugins/plugins.c b/sm/src/plugins/plugins.c index 169b07029..e788451bb 100644 --- a/sm/src/plugins/plugins.c +++ b/sm/src/plugins/plugins.c @@ -1,18 +1,14 @@ #include "plugins.h" #ifdef PLUGIN_ENABLE_MULTIMEM - #include "multimem.c" +#include "multimem.c" #endif uintptr_t call_plugin( - enclave_id id, - uintptr_t plugin_id, - uintptr_t call_id, - uintptr_t arg0, - uintptr_t arg1) -{ - switch(plugin_id) { + enclave_id id, uintptr_t plugin_id, uintptr_t call_id, uintptr_t arg0, + uintptr_t arg1) { + switch (plugin_id) { #ifdef PLUGIN_ENABLE_MULTIMEM case PLUGIN_ID_MULTIMEM: return do_sbi_multimem(id, call_id, arg0); @@ -23,4 +19,3 @@ call_plugin( return SBI_ERR_SM_NOT_IMPLEMENTED; } } - diff --git a/sm/src/plugins/plugins.h b/sm/src/plugins/plugins.h index df391b36b..b101c74b2 100644 --- a/sm/src/plugins/plugins.h +++ b/sm/src/plugins/plugins.h @@ -1,23 +1,19 @@ #ifndef __SM_PLUGINS_H__ #define __SM_PLUGINS_H__ -#include "../sm.h" #include "../enclave.h" +#include "../sm.h" /* PLUGIN IDs */ -#define PLUGIN_ID_MULTIMEM 0x1 +#define PLUGIN_ID_MULTIMEM 0x1 #ifdef PLUGIN_ENABLE_MULTIMEM - #include "plugins/multimem.h" +#include "plugins/multimem.h" #endif uintptr_t call_plugin( - enclave_id id, - uintptr_t plugin_id, - uintptr_t call_id, - uintptr_t arg0, - uintptr_t arg1 - ); + enclave_id id, uintptr_t plugin_id, uintptr_t call_id, uintptr_t arg0, + uintptr_t arg1); #endif diff --git a/sm/src/pmp.c b/sm/src/pmp.c index 8d9f195f9..1254dd656 100644 --- a/sm/src/pmp.c +++ b/sm/src/pmp.c @@ -2,121 +2,121 @@ // Copyright (c) 2018, The Regents of the University of California (Regents). // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ -#include "assert.h" #include "pmp.h" + +#include +#include +#include +#include + +#include "assert.h" #include "cpu.h" +#include "ipi.h" +#include "page.h" #include "safe_math_util.h" #include "sm-sbi-opensbi.h" -#include "page.h" -#include "ipi.h" -#include -#include -#include -#include /* PMP global spin locks */ static spinlock_t pmp_lock = SPIN_LOCK_INITIALIZER; /* PMP region getter/setters */ static struct pmp_region regions[PMP_MAX_N_REGION]; -static uint32_t reg_bitmap = 0; +static uint32_t reg_bitmap = 0; static uint32_t region_def_bitmap = 0; -static inline int region_register_idx(region_id i) -{ +static inline int +region_register_idx(region_id i) { return regions[i].reg_idx; } -static inline int region_allows_overlap(region_id i) -{ +static inline int +region_allows_overlap(region_id i) { return regions[i].allow_overlap; } -static inline uintptr_t region_get_addr(region_id i) -{ +static inline uintptr_t +region_get_addr(region_id i) { return regions[i].addr; } -static inline uint64_t region_get_size(region_id i) -{ +static inline uint64_t +region_get_size(region_id i) { return regions[i].size; } -static inline int region_is_napot(region_id i) -{ +static inline int +region_is_napot(region_id i) { return regions[i].addrmode == PMP_A_NAPOT; } -static inline int region_is_tor(region_id i) -{ +static inline int +region_is_tor(region_id i) { return regions[i].addrmode == PMP_A_TOR; } -static inline int region_needs_two_entries(region_id i) -{ +static inline int +region_needs_two_entries(region_id i) { return region_is_tor(i) && regions[i].reg_idx > 0; } -static inline int region_is_napot_all(region_id i) -{ +static inline int +region_is_napot_all(region_id i) { return regions[i].addr == 0 && regions[i].size == -1UL; } -static inline uintptr_t region_pmpaddr_val(region_id i) -{ - if(region_is_napot_all(i)) +static inline uintptr_t +region_pmpaddr_val(region_id i) { + if (region_is_napot_all(i)) return (-1UL); - else if(region_is_napot(i)) - return (regions[i].addr | (regions[i].size/2-1)) >> 2; - else if(region_is_tor(i)) + else if (region_is_napot(i)) + return (regions[i].addr | (regions[i].size / 2 - 1)) >> 2; + else if (region_is_tor(i)) return (regions[i].addr + regions[i].size) >> 2; else return 0; } -static inline uintptr_t region_pmpcfg_val(region_id i, pmpreg_id reg_idx, uint8_t perm_bits) -{ - return (uintptr_t) (regions[i].addrmode | perm_bits) << (8*(reg_idx%PMP_PER_GROUP)); +static inline uintptr_t +region_pmpcfg_val(region_id i, pmpreg_id reg_idx, uint8_t perm_bits) { + return (uintptr_t)(regions[i].addrmode | perm_bits) + << (8 * (reg_idx % PMP_PER_GROUP)); } -static void region_clear_all(region_id i) -{ - regions[i].addr = 0; - regions[i].size = 0; - regions[i].addrmode = 0; +static void +region_clear_all(region_id i) { + regions[i].addr = 0; + regions[i].size = 0; + regions[i].addrmode = 0; regions[i].allow_overlap = 0; - regions[i].reg_idx = 0; + regions[i].reg_idx = 0; } -static void region_init(region_id i, - uintptr_t addr, - uint64_t size, - uint8_t addrmode, - int allow_overlap, - pmpreg_id reg_idx) -{ - regions[i].addr = addr; - regions[i].size = size; - regions[i].addrmode = addrmode; +static void +region_init( + region_id i, uintptr_t addr, uint64_t size, uint8_t addrmode, + int allow_overlap, pmpreg_id reg_idx) { + regions[i].addr = addr; + regions[i].size = size; + regions[i].addrmode = addrmode; regions[i].allow_overlap = allow_overlap; - regions[i].reg_idx = (addrmode == PMP_A_TOR && reg_idx > 0 ? reg_idx + 1 : reg_idx); + regions[i].reg_idx = + (addrmode == PMP_A_TOR && reg_idx > 0 ? reg_idx + 1 : reg_idx); } -static int is_pmp_region_valid(region_id region_idx) -{ +static int +is_pmp_region_valid(region_id region_idx) { return TEST_BIT(region_def_bitmap, region_idx); } -static int search_rightmost_unset(uint32_t bitmap, int max, uint32_t mask) -{ +static int +search_rightmost_unset(uint32_t bitmap, int max, uint32_t mask) { int i = 0; sm_assert(max < 32); sm_assert(!((mask + 1) & mask)); - while(mask < (1UL << max)) { - if((~bitmap & mask) == mask) - return i; + while (mask < (1UL << max)) { + if ((~bitmap & mask) == mask) return i; mask = mask << 1; i++; } @@ -124,18 +124,18 @@ static int search_rightmost_unset(uint32_t bitmap, int max, uint32_t mask) return -1; } -static region_id get_free_region_idx() -{ +static region_id +get_free_region_idx() { return search_rightmost_unset(region_def_bitmap, PMP_MAX_N_REGION, 0x1); } -static pmpreg_id get_free_reg_idx() -{ +static pmpreg_id +get_free_reg_idx() { return search_rightmost_unset(reg_bitmap, PMP_N_REG, 0x1); } -static pmpreg_id get_conseq_free_reg_idx() -{ +static pmpreg_id +get_conseq_free_reg_idx() { return search_rightmost_unset(reg_bitmap, PMP_N_REG, 0x3); } @@ -146,40 +146,38 @@ static pmpreg_id get_conseq_free_reg_idx() * On a failed addr + size overflow, we return failure, since this * cannot be a valid addr and size anyway. */ -static int detect_region_overlap(uintptr_t addr, uintptr_t size) -{ +static int +detect_region_overlap(uintptr_t addr, uintptr_t size) { void* epm_base; size_t epm_size; int region_overlap = 0, i; // Safety check the addr+size uintptr_t input_end; - if( CHECKED_ADD(addr, size, &input_end)){ + if (CHECKED_ADD(addr, size, &input_end)) { return 1; } - for(i=0; i addr); + region_overlap |= ((uintptr_t)epm_base < input_end) && + ((uintptr_t)epm_base + epm_size > addr); } return region_overlap; } -int pmp_detect_region_overlap_atomic(uintptr_t addr, uintptr_t size) -{ +int +pmp_detect_region_overlap_atomic(uintptr_t addr, uintptr_t size) { int region_overlap = 0; spin_lock(&pmp_lock); region_overlap = detect_region_overlap(addr, size); @@ -193,9 +191,9 @@ int pmp_detect_region_overlap_atomic(uintptr_t addr, uintptr_t size) * **********************************/ -int pmp_unset_global(int region_idx) -{ - if(!is_pmp_region_valid(region_idx)) +int +pmp_unset_global(int region_idx) { + if (!is_pmp_region_valid(region_idx)) PMP_ERROR(SBI_ERR_SM_PMP_REGION_INVALID, "Invalid PMP region index"); send_and_sync_pmp_ipi(region_idx, SBI_PMP_IPI_TYPE_UNSET, PMP_NO_PERM); @@ -204,9 +202,9 @@ int pmp_unset_global(int region_idx) } /* populate pmp set command to every other hart */ -int pmp_set_global(int region_idx, uint8_t perm) -{ - if(!is_pmp_region_valid(region_idx)) +int +pmp_set_global(int region_idx, uint8_t perm) { + if (!is_pmp_region_valid(region_idx)) PMP_ERROR(SBI_ERR_SM_PMP_REGION_INVALID, "Invalid PMP region index"); send_and_sync_pmp_ipi(region_idx, SBI_PMP_IPI_TYPE_SET, perm); @@ -214,97 +212,119 @@ int pmp_set_global(int region_idx, uint8_t perm) return SBI_ERR_SM_PMP_SUCCESS; } -void pmp_init() -{ +void +pmp_init() { uintptr_t pmpaddr = 0; - uintptr_t pmpcfg = 0; + uintptr_t pmpcfg = 0; int i; - for (i=0; i < PMP_N_REG; i++) - { - switch(i) { -#define X(n,g) case n: { PMP_SET(n, g, pmpaddr, pmpcfg); break; } + for (i = 0; i < PMP_N_REG; i++) { + switch (i) { +#define X(n, g) \ + case n: { \ + PMP_SET(n, g, pmpaddr, pmpcfg); \ + break; \ + } LIST_OF_PMP_REGS #undef X } } } -int pmp_set_keystone(int region_idx, uint8_t perm) -{ - if(!is_pmp_region_valid(region_idx)) +int +pmp_set_keystone(int region_idx, uint8_t perm) { + if (!is_pmp_region_valid(region_idx)) PMP_ERROR(SBI_ERR_SM_PMP_REGION_INVALID, "Invalid PMP region index"); uint8_t perm_bits = perm & PMP_ALL_PERM; pmpreg_id reg_idx = region_register_idx(region_idx); - uintptr_t pmpcfg = region_pmpcfg_val(region_idx, reg_idx, perm_bits); + uintptr_t pmpcfg = region_pmpcfg_val(region_idx, reg_idx, perm_bits); uintptr_t pmpaddr; pmpaddr = region_pmpaddr_val(region_idx); - //sbi_printf("pmp_set() [hart %d]: reg[%d], mode[%s], range[0x%lx-0x%lx], perm[0x%x]\r\n", - // current_hartid(), reg_idx, (region_is_tor(region_idx) ? "TOR":"NAPOT"), - // region_get_addr(region_idx), region_get_addr(region_idx) + region_get_size(region_idx), perm); - //sbi_printf(" pmp[%d] = pmpaddr: 0x%lx, pmpcfg: 0x%lx\r\n", reg_idx, pmpaddr, pmpcfg); - - int n=reg_idx; - - switch(n) { -#define X(n,g) case n: { PMP_SET(n, g, pmpaddr, pmpcfg); break; } - LIST_OF_PMP_REGS + // sbi_printf("pmp_set() [hart %d]: reg[%d], mode[%s], range[0x%lx-0x%lx], + // perm[0x%x]\r\n", + // current_hartid(), reg_idx, (region_is_tor(region_idx) ? + // "TOR":"NAPOT"), region_get_addr(region_idx), + // region_get_addr(region_idx) + region_get_size(region_idx), perm); + // sbi_printf(" pmp[%d] = pmpaddr: 0x%lx, pmpcfg: 0x%lx\r\n", reg_idx, + // pmpaddr, pmpcfg); + + int n = reg_idx; + + switch (n) { +#define X(n, g) \ + case n: { \ + PMP_SET(n, g, pmpaddr, pmpcfg); \ + break; \ + } + LIST_OF_PMP_REGS #undef X default: sm_assert(FALSE); } /* TOR decoding with 2 registers */ - if(region_needs_two_entries(region_idx)) - { + if (region_needs_two_entries(region_idx)) { n--; - pmpcfg = 0; + pmpcfg = 0; pmpaddr = region_get_addr(region_idx) >> 2; - switch(n) { -#define X(n,g) case n: { PMP_SET(n, g, pmpaddr, pmpcfg); break; } - LIST_OF_PMP_REGS + switch (n) { +#define X(n, g) \ + case n: { \ + PMP_SET(n, g, pmpaddr, pmpcfg); \ + break; \ + } + LIST_OF_PMP_REGS #undef X - default: - sm_assert(FALSE); + default: + sm_assert(FALSE); } } return SBI_ERR_SM_PMP_SUCCESS; } -int pmp_unset(int region_idx) -{ - if(!is_pmp_region_valid(region_idx)) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_INVALID,"Invalid PMP region index"); +int +pmp_unset(int region_idx) { + if (!is_pmp_region_valid(region_idx)) + PMP_ERROR(SBI_ERR_SM_PMP_REGION_INVALID, "Invalid PMP region index"); pmpreg_id reg_idx = region_register_idx(region_idx); - int n=reg_idx; - switch(n) { -#define X(n,g) case n: { PMP_UNSET(n, g); break;} - LIST_OF_PMP_REGS + int n = reg_idx; + switch (n) { +#define X(n, g) \ + case n: { \ + PMP_UNSET(n, g); \ + break; \ + } + LIST_OF_PMP_REGS #undef X default: sm_assert(FALSE); } - if(region_needs_two_entries(region_idx)) - { + if (region_needs_two_entries(region_idx)) { n--; - switch(n) { -#define X(n,g) case n: { PMP_UNSET(n,g); break; } - LIST_OF_PMP_REGS + switch (n) { +#define X(n, g) \ + case n: { \ + PMP_UNSET(n, g); \ + break; \ + } + LIST_OF_PMP_REGS #undef X - default: - sm_assert(FALSE); + default: + sm_assert(FALSE); } } return SBI_ERR_SM_PMP_SUCCESS; } -int pmp_region_init_atomic(uintptr_t start, uint64_t size, enum pmp_priority priority, region_id* rid, int allow_overlap) -{ +int +pmp_region_init_atomic( + uintptr_t start, uint64_t size, enum pmp_priority priority, region_id* rid, + int allow_overlap) { int ret; spin_lock(&pmp_lock); ret = pmp_region_init(start, size, priority, rid, allow_overlap); @@ -312,38 +332,45 @@ int pmp_region_init_atomic(uintptr_t start, uint64_t size, enum pmp_priority pri return ret; } -static int tor_region_init(uintptr_t start, uint64_t size, enum pmp_priority priority, region_id* rid, int allow_overlap) -{ - pmpreg_id reg_idx = -1; +static int +tor_region_init( + uintptr_t start, uint64_t size, enum pmp_priority priority, region_id* rid, + int allow_overlap) { + pmpreg_id reg_idx = -1; region_id region_idx = -1; sm_assert(size); - sm_assert(!(size & (RISCV_PGSIZE-1))); - sm_assert(!(start & (RISCV_PGSIZE-1))); + sm_assert(!(size & (RISCV_PGSIZE - 1))); + sm_assert(!(start & (RISCV_PGSIZE - 1))); sm_assert(rid); sm_assert(priority != PMP_PRI_BOTTOM); region_idx = get_free_region_idx(); - if(region_idx < 0 || region_idx > PMP_MAX_N_REGION) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_MAX_REACHED, "Reached the maximum number of PMP regions"); + if (region_idx < 0 || region_idx > PMP_MAX_N_REGION) + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_MAX_REACHED, + "Reached the maximum number of PMP regions"); *rid = region_idx; - switch(priority) - { - case(PMP_PRI_ANY): { + switch (priority) { + case (PMP_PRI_ANY): { reg_idx = get_conseq_free_reg_idx(); - if(reg_idx < 0) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_MAX_REACHED, "No available PMP register"); - if(TEST_BIT(reg_bitmap, reg_idx) || TEST_BIT(reg_bitmap, reg_idx + 1) || reg_idx + 1 >= PMP_N_REG) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_MAX_REACHED, "PMP register unavailable"); + if (reg_idx < 0) + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_MAX_REACHED, "No available PMP register"); + if (TEST_BIT(reg_bitmap, reg_idx) || TEST_BIT(reg_bitmap, reg_idx + 1) || + reg_idx + 1 >= PMP_N_REG) + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_MAX_REACHED, "PMP register unavailable"); break; } - case(PMP_PRI_TOP): { + case (PMP_PRI_TOP): { sm_assert(start == 0); reg_idx = 0; - if(TEST_BIT(reg_bitmap, reg_idx)) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_MAX_REACHED, "PMP register unavailable"); + if (TEST_BIT(reg_bitmap, reg_idx)) + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_MAX_REACHED, "PMP register unavailable"); break; } default: { @@ -356,52 +383,56 @@ static int tor_region_init(uintptr_t start, uint64_t size, enum pmp_priority pri SET_BIT(region_def_bitmap, region_idx); SET_BIT(reg_bitmap, reg_idx); - if(reg_idx > 0) - SET_BIT(reg_bitmap, reg_idx + 1); + if (reg_idx > 0) SET_BIT(reg_bitmap, reg_idx + 1); return SBI_ERR_SM_PMP_SUCCESS; } -static int napot_region_init(uintptr_t start, uint64_t size, enum pmp_priority priority, region_id* rid, int allow_overlap) -{ - pmpreg_id reg_idx = -1; +static int +napot_region_init( + uintptr_t start, uint64_t size, enum pmp_priority priority, region_id* rid, + int allow_overlap) { + pmpreg_id reg_idx = -1; region_id region_idx = -1; sm_assert(size); sm_assert(rid); - if(!(size == -1UL && start == 0)) - { - sm_assert(!(size & (size-1))); + if (!(size == -1UL && start == 0)) { + sm_assert(!(size & (size - 1))); sm_assert(!(start & (size - 1))); - sm_assert(!(size & (RISCV_PGSIZE-1))); - sm_assert(!(start & (RISCV_PGSIZE-1))); + sm_assert(!(size & (RISCV_PGSIZE - 1))); + sm_assert(!(start & (RISCV_PGSIZE - 1))); } - //find avaiable pmp region idx + // find avaiable pmp region idx region_idx = get_free_region_idx(); - if(region_idx < 0 || region_idx > PMP_MAX_N_REGION) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_MAX_REACHED, "Reached the maximum number of PMP regions"); + if (region_idx < 0 || region_idx > PMP_MAX_N_REGION) + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_MAX_REACHED, + "Reached the maximum number of PMP regions"); *rid = region_idx; - switch(priority) - { - case(PMP_PRI_ANY): { + switch (priority) { + case (PMP_PRI_ANY): { reg_idx = get_free_reg_idx(); - if(reg_idx < 0) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_MAX_REACHED, "No available PMP register"); - if(TEST_BIT(reg_bitmap, reg_idx) || reg_idx >= PMP_N_REG) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_MAX_REACHED, "PMP register unavailable"); + if (reg_idx < 0) + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_MAX_REACHED, "No available PMP register"); + if (TEST_BIT(reg_bitmap, reg_idx) || reg_idx >= PMP_N_REG) + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_MAX_REACHED, "PMP register unavailable"); break; } - case(PMP_PRI_TOP): { + case (PMP_PRI_TOP): { reg_idx = 0; - if(TEST_BIT(reg_bitmap, reg_idx)) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_MAX_REACHED, "PMP register unavailable"); + if (TEST_BIT(reg_bitmap, reg_idx)) + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_MAX_REACHED, "PMP register unavailable"); break; } - case(PMP_PRI_BOTTOM): { + case (PMP_PRI_BOTTOM): { /* the bottom register can be used by multiple regions, * so we don't check its availability */ reg_idx = PMP_N_REG - 1; @@ -420,13 +451,11 @@ static int napot_region_init(uintptr_t start, uint64_t size, enum pmp_priority p return SBI_ERR_SM_PMP_SUCCESS; } -int pmp_region_free_atomic(int region_idx) -{ - +int +pmp_region_free_atomic(int region_idx) { spin_lock(&pmp_lock); - if(!is_pmp_region_valid(region_idx)) - { + if (!is_pmp_region_valid(region_idx)) { spin_unlock(&pmp_lock); PMP_ERROR(SBI_ERR_SM_PMP_REGION_INVALID, "Invalid PMP region index"); } @@ -434,8 +463,7 @@ int pmp_region_free_atomic(int region_idx) pmpreg_id reg_idx = region_register_idx(region_idx); UNSET_BIT(region_def_bitmap, region_idx); UNSET_BIT(reg_bitmap, reg_idx); - if(region_needs_two_entries(region_idx)) - UNSET_BIT(reg_bitmap, reg_idx - 1); + if (region_needs_two_entries(region_idx)) UNSET_BIT(reg_bitmap, reg_idx - 1); region_clear_all(region_idx); @@ -444,10 +472,11 @@ int pmp_region_free_atomic(int region_idx) return SBI_ERR_SM_PMP_SUCCESS; } -int pmp_region_init(uintptr_t start, uint64_t size, enum pmp_priority priority, int* rid, int allow_overlap) -{ - if(!size) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_SIZE_INVALID, "Invalid PMP size"); +int +pmp_region_init( + uintptr_t start, uint64_t size, enum pmp_priority priority, int* rid, + int allow_overlap) { + if (!size) PMP_ERROR(SBI_ERR_SM_PMP_REGION_SIZE_INVALID, "Invalid PMP size"); /* overlap detection */ if (!allow_overlap) { @@ -457,37 +486,38 @@ int pmp_region_init(uintptr_t start, uint64_t size, enum pmp_priority priority, } /* PMP granularity check */ - if(size != -1UL && (size & (RISCV_PGSIZE - 1))) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_NOT_PAGE_GRANULARITY, "PMP granularity is RISCV_PGSIZE"); - if(start & (RISCV_PGSIZE - 1)) - PMP_ERROR(SBI_ERR_SM_PMP_REGION_NOT_PAGE_GRANULARITY, "PMP granularity is RISCV_PGSIZE"); + if (size != -1UL && (size & (RISCV_PGSIZE - 1))) + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_NOT_PAGE_GRANULARITY, + "PMP granularity is RISCV_PGSIZE"); + if (start & (RISCV_PGSIZE - 1)) + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_NOT_PAGE_GRANULARITY, + "PMP granularity is RISCV_PGSIZE"); /* if the address covers the entire RAM or it's NAPOT */ if ((size == -1UL && start == 0) || (!(size & (size - 1)) && !(start & (size - 1)))) { return napot_region_init(start, size, priority, rid, allow_overlap); - } - else - { - if(priority != PMP_PRI_ANY && - (priority != PMP_PRI_TOP || start != 0)) { - PMP_ERROR(SBI_ERR_SM_PMP_REGION_IMPOSSIBLE_TOR, "The top-priority TOR PMP entry must start from address 0"); + } else { + if (priority != PMP_PRI_ANY && (priority != PMP_PRI_TOP || start != 0)) { + PMP_ERROR( + SBI_ERR_SM_PMP_REGION_IMPOSSIBLE_TOR, + "The top-priority TOR PMP entry must start from address 0"); } return tor_region_init(start, size, priority, rid, allow_overlap); } } -uintptr_t pmp_region_get_addr(region_id i) -{ - if(is_pmp_region_valid(i)) - return region_get_addr(i); +uintptr_t +pmp_region_get_addr(region_id i) { + if (is_pmp_region_valid(i)) return region_get_addr(i); return 0; } -uint64_t pmp_region_get_size(region_id i) -{ - if(is_pmp_region_valid(i)) - return region_get_size(i); +uint64_t +pmp_region_get_size(region_id i) { + if (is_pmp_region_valid(i)) return region_get_size(i); return 0; } diff --git a/sm/src/pmp.h b/sm/src/pmp.h index f83aeb98d..17495a93c 100644 --- a/sm/src/pmp.h +++ b/sm/src/pmp.h @@ -5,11 +5,12 @@ #ifndef _PMP_H_ #define _PMP_H_ -#include "sm.h" #include -#define PMP_N_REG 8 //number of PMP registers -#define PMP_MAX_N_REGION 16 //maximum number of PMP regions +#include "sm.h" + +#define PMP_N_REG 8 // number of PMP registers +#define PMP_MAX_N_REGION 16 // maximum number of PMP regions #define SET_BIT(bitmap, n) (bitmap |= (0x1 << (n))) #define UNSET_BIT(bitmap, n) (bitmap &= ~(0x1 << (n))) @@ -21,63 +22,76 @@ enum pmp_priority { PMP_PRI_BOTTOM, }; -#define PMP_ALL_PERM (PMP_W | PMP_X | PMP_R) -#define PMP_NO_PERM 0 +#define PMP_ALL_PERM (PMP_W | PMP_X | PMP_R) +#define PMP_NO_PERM 0 #if __riscv_xlen == 64 -# define LIST_OF_PMP_REGS X(0,0) X(1,0) X(2,0) X(3,0) \ - X(4,0) X(5,0) X(6,0) X(7,0) \ - X(8,2) X(9,2) X(10,2) X(11,2) \ - X(12,2) X(13,2) X(14,2) X(15,2) -# define PMP_PER_GROUP 8 +#define LIST_OF_PMP_REGS \ + X(0, 0) \ + X(1, 0) X(2, 0) X(3, 0) X(4, 0) X(5, 0) X(6, 0) X(7, 0) X(8, 2) X(9, 2) \ + X(10, 2) X(11, 2) X(12, 2) X(13, 2) X(14, 2) X(15, 2) +#define PMP_PER_GROUP 8 #else -# define LIST_OF_PMP_REGS X(0,0) X(1,0) X(2,0) X(3,0) \ - X(4,1) X(5,1) X(6,1) X(7,1) \ - X(8,2) X(9,2) X(10,2) X(11,2) \ - X(12,3) X(13,3) X(14,3) X(15,3) -# define PMP_PER_GROUP 4 +#define LIST_OF_PMP_REGS \ + X(0, 0) \ + X(1, 0) X(2, 0) X(3, 0) X(4, 1) X(5, 1) X(6, 1) X(7, 1) X(8, 2) X(9, 2) \ + X(10, 2) X(11, 2) X(12, 3) X(13, 3) X(14, 3) X(15, 3) +#define PMP_PER_GROUP 4 #endif -#define PMP_SET(n, g, addr, pmpc) \ -{ uintptr_t oldcfg = csr_read(pmpcfg##g); \ - pmpc |= (oldcfg & ~((uintptr_t)0xff << (uintptr_t)8*(n%PMP_PER_GROUP))); \ - asm volatile ("la t0, 1f\n\t" \ - "csrrw t0, mtvec, t0\n\t" \ - "csrw pmpaddr"#n", %0\n\t" \ - "csrw pmpcfg"#g", %1\n\t" \ - "sfence.vma\n\t"\ - ".align 2\n\t" \ - "1: csrw mtvec, t0 \n\t" \ - : : "r" (addr), "r" (pmpc) : "t0"); \ -} - -#define PMP_UNSET(n, g) \ -{ uintptr_t pmpc = csr_read(pmpcfg##g); \ - pmpc &= ~((uintptr_t)0xff << (uintptr_t)8*(n%PMP_PER_GROUP)); \ - asm volatile ("la t0, 1f \n\t" \ - "csrrw t0, mtvec, t0 \n\t" \ - "csrw pmpaddr"#n", %0\n\t" \ - "csrw pmpcfg"#g", %1\n\t" \ - "sfence.vma\n\t"\ - ".align 2\n\t" \ - "1: csrw mtvec, t0" \ - : : "r" (0), "r" (pmpc) : "t0"); \ -} - -#define PMP_ERROR(error, msg) {\ - sbi_printf("%s:" msg "\n", __func__);\ - return error; \ -} +#define PMP_SET(n, g, addr, pmpc) \ + { \ + uintptr_t oldcfg = csr_read(pmpcfg##g); \ + pmpc |= \ + (oldcfg & ~((uintptr_t)0xff << (uintptr_t)8 * (n % PMP_PER_GROUP))); \ + asm volatile( \ + "la t0, 1f\n\t" \ + "csrrw t0, mtvec, t0\n\t" \ + "csrw pmpaddr" #n \ + ", %0\n\t" \ + "csrw pmpcfg" #g \ + ", %1\n\t" \ + "sfence.vma\n\t" \ + ".align 2\n\t" \ + "1: csrw mtvec, t0 \n\t" \ + : \ + : "r"(addr), "r"(pmpc) \ + : "t0"); \ + } + +#define PMP_UNSET(n, g) \ + { \ + uintptr_t pmpc = csr_read(pmpcfg##g); \ + pmpc &= ~((uintptr_t)0xff << (uintptr_t)8 * (n % PMP_PER_GROUP)); \ + asm volatile( \ + "la t0, 1f \n\t" \ + "csrrw t0, mtvec, t0 \n\t" \ + "csrw pmpaddr" #n \ + ", %0\n\t" \ + "csrw pmpcfg" #g \ + ", %1\n\t" \ + "sfence.vma\n\t" \ + ".align 2\n\t" \ + "1: csrw mtvec, t0" \ + : \ + : "r"(0), "r"(pmpc) \ + : "t0"); \ + } + +#define PMP_ERROR(error, msg) \ + { \ + sbi_printf("%s:" msg "\n", __func__); \ + return error; \ + } /* PMP IPI mailbox */ -struct ipi_msg{ +struct ipi_msg { atomic_t pending; uint8_t perm; }; /* PMP region type */ -struct pmp_region -{ +struct pmp_region { uint64_t size; uint8_t addrmode; uintptr_t addr; @@ -89,18 +103,34 @@ typedef int pmpreg_id; typedef int region_id; /* external functions */ -void pmp_init(); -int pmp_region_init_atomic(uintptr_t start, uint64_t size, enum pmp_priority pri, region_id* rid, int allow_overlap); -int pmp_region_init(uintptr_t start, uint64_t size, enum pmp_priority pri, region_id* rid, int allow_overlap); -int pmp_region_free_atomic(region_id region); -int pmp_set_keystone(region_id n, uint8_t perm); -int pmp_set_global(region_id n, uint8_t perm); -int pmp_unset(region_id n); -int pmp_unset_global(region_id n); -int pmp_detect_region_overlap_atomic(uintptr_t base, uintptr_t size); -void handle_pmp_ipi(); - -uintptr_t pmp_region_get_addr(region_id i); -uint64_t pmp_region_get_size(region_id i); +void +pmp_init(); +int +pmp_region_init_atomic( + uintptr_t start, uint64_t size, enum pmp_priority pri, region_id* rid, + int allow_overlap); +int +pmp_region_init( + uintptr_t start, uint64_t size, enum pmp_priority pri, region_id* rid, + int allow_overlap); +int +pmp_region_free_atomic(region_id region); +int +pmp_set_keystone(region_id n, uint8_t perm); +int +pmp_set_global(region_id n, uint8_t perm); +int +pmp_unset(region_id n); +int +pmp_unset_global(region_id n); +int +pmp_detect_region_overlap_atomic(uintptr_t base, uintptr_t size); +void +handle_pmp_ipi(); + +uintptr_t +pmp_region_get_addr(region_id i); +uint64_t +pmp_region_get_size(region_id i); #endif diff --git a/sm/src/safe_math_util.h b/sm/src/safe_math_util.h index 8c9586cd1..167360e36 100644 --- a/sm/src/safe_math_util.h +++ b/sm/src/safe_math_util.h @@ -5,9 +5,11 @@ // to add wrappers for other checked math functions. #if __riscv_xlen == 32 -#define CHECKED_ADD(a, b, out) (__builtin_uadd_overflow(a, b, (unsigned int*) out)) +#define CHECKED_ADD(a, b, out) \ + (__builtin_uadd_overflow(a, b, (unsigned int*)out)) #else -#define CHECKED_ADD(a, b, out) (__builtin_uaddl_overflow(a, b, (unsigned long int*) out)) +#define CHECKED_ADD(a, b, out) \ + (__builtin_uaddl_overflow(a, b, (unsigned long int*)out)) #endif #endif /* _SAFE_MATH_UTIL_H_ */ diff --git a/sm/src/sbi_trap_hack.c b/sm/src/sbi_trap_hack.c index 8f57a0557..8afaaf82a 100644 --- a/sm/src/sbi_trap_hack.c +++ b/sm/src/sbi_trap_hack.c @@ -1,4 +1,3 @@ -#include "enclave.h" #include #include #include @@ -11,59 +10,76 @@ #include #include -static void sbi_trap_error(const char *msg, int rc, - ulong mcause, ulong mtval, ulong mtval2, - ulong mtinst, struct sbi_trap_regs *regs) -{ - u32 hartid = current_hartid(); +#include "enclave.h" + +static void +sbi_trap_error( + const char* msg, int rc, ulong mcause, ulong mtval, ulong mtval2, + ulong mtinst, struct sbi_trap_regs* regs) { + u32 hartid = current_hartid(); - sbi_printf("%s: hart%d: %s (error %d)\n", __func__, hartid, msg, rc); - sbi_printf("%s: hart%d: mcause=0x%" PRILX " mtval=0x%" PRILX "\n", - __func__, hartid, mcause, mtval); - if (misa_extension('H')) { - sbi_printf("%s: hart%d: mtval2=0x%" PRILX - " mtinst=0x%" PRILX "\n", - __func__, hartid, mtval2, mtinst); - } - sbi_printf("%s: hart%d: mepc=0x%" PRILX " mstatus=0x%" PRILX "\n", - __func__, hartid, regs->mepc, regs->mstatus); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "ra", regs->ra, "sp", regs->sp); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "gp", regs->gp, "tp", regs->tp); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "s0", regs->s0, "s1", regs->s1); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "a0", regs->a0, "a1", regs->a1); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "a2", regs->a2, "a3", regs->a3); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "a4", regs->a4, "a5", regs->a5); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "a6", regs->a6, "a7", regs->a7); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "s2", regs->s2, "s3", regs->s3); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "s4", regs->s4, "s5", regs->s5); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "s6", regs->s6, "s7", regs->s7); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "s8", regs->s8, "s9", regs->s9); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "s10", regs->s10, "s11", regs->s11); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "t0", regs->t0, "t1", regs->t1); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "t2", regs->t2, "t3", regs->t3); - sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, - hartid, "t4", regs->t4, "t5", regs->t5); - sbi_printf("%s: hart%d: %s=0x%" PRILX "\n", __func__, hartid, "t6", - regs->t6); + sbi_printf("%s: hart%d: %s (error %d)\n", __func__, hartid, msg, rc); + sbi_printf( + "%s: hart%d: mcause=0x%" PRILX " mtval=0x%" PRILX "\n", __func__, hartid, + mcause, mtval); + if (misa_extension('H')) { + sbi_printf( + "%s: hart%d: mtval2=0x%" PRILX " mtinst=0x%" PRILX "\n", __func__, + hartid, mtval2, mtinst); + } + sbi_printf( + "%s: hart%d: mepc=0x%" PRILX " mstatus=0x%" PRILX "\n", __func__, hartid, + regs->mepc, regs->mstatus); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "ra", + regs->ra, "sp", regs->sp); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "gp", + regs->gp, "tp", regs->tp); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "s0", + regs->s0, "s1", regs->s1); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "a0", + regs->a0, "a1", regs->a1); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "a2", + regs->a2, "a3", regs->a3); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "a4", + regs->a4, "a5", regs->a5); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "a6", + regs->a6, "a7", regs->a7); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "s2", + regs->s2, "s3", regs->s3); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "s4", + regs->s4, "s5", regs->s5); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "s6", + regs->s6, "s7", regs->s7); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "s8", + regs->s8, "s9", regs->s9); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "s10", + regs->s10, "s11", regs->s11); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "t0", + regs->t0, "t1", regs->t1); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "t2", + regs->t2, "t3", regs->t3); + sbi_printf( + "%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__, hartid, "t4", + regs->t4, "t5", regs->t5); + sbi_printf("%s: hart%d: %s=0x%" PRILX "\n", __func__, hartid, "t6", regs->t6); sbi_sm_exit_enclave(regs, rc); } - /** * Handle trap/interrupt * @@ -80,73 +96,72 @@ static void sbi_trap_error(const char *msg, int rc, * * @param regs pointer to register state */ -void sbi_trap_handler_keystone_enclave(struct sbi_trap_regs *regs) -{ - int rc = SBI_ENOTSUPP; - const char *msg = "trap handler failed"; - ulong mcause = csr_read(CSR_MCAUSE); - ulong mtval = csr_read(CSR_MTVAL), mtval2 = 0, mtinst = 0; - struct sbi_trap_info trap; +void +sbi_trap_handler_keystone_enclave(struct sbi_trap_regs* regs) { + int rc = SBI_ENOTSUPP; + const char* msg = "trap handler failed"; + ulong mcause = csr_read(CSR_MCAUSE); + ulong mtval = csr_read(CSR_MTVAL), mtval2 = 0, mtinst = 0; + struct sbi_trap_info trap; - if (misa_extension('H')) { - mtval2 = csr_read(CSR_MTVAL2); - mtinst = csr_read(CSR_MTINST); - } + if (misa_extension('H')) { + mtval2 = csr_read(CSR_MTVAL2); + mtinst = csr_read(CSR_MTINST); + } - if (mcause & (1UL << (__riscv_xlen - 1))) { - mcause &= ~(1UL << (__riscv_xlen - 1)); - switch (mcause) { - case IRQ_M_TIMER: { - regs->mepc -= 4; - sbi_sm_stop_enclave(regs, STOP_TIMER_INTERRUPT); - regs->a0 = SBI_ERR_SM_ENCLAVE_INTERRUPTED; - regs->mepc += 4; - break; - } - case IRQ_M_SOFT: { - regs->mepc -= 4; - sbi_sm_stop_enclave(regs, STOP_TIMER_INTERRUPT); - regs->a0 = SBI_ERR_SM_ENCLAVE_INTERRUPTED; - regs->mepc += 4; - break; - } - default: - msg = "unhandled external interrupt"; - goto trap_error; - }; - return; - } + if (mcause & (1UL << (__riscv_xlen - 1))) { + mcause &= ~(1UL << (__riscv_xlen - 1)); + switch (mcause) { + case IRQ_M_TIMER: { + regs->mepc -= 4; + sbi_sm_stop_enclave(regs, STOP_TIMER_INTERRUPT); + regs->a0 = SBI_ERR_SM_ENCLAVE_INTERRUPTED; + regs->mepc += 4; + break; + } + case IRQ_M_SOFT: { + regs->mepc -= 4; + sbi_sm_stop_enclave(regs, STOP_TIMER_INTERRUPT); + regs->a0 = SBI_ERR_SM_ENCLAVE_INTERRUPTED; + regs->mepc += 4; + break; + } + default: + msg = "unhandled external interrupt"; + goto trap_error; + }; + return; + } - switch (mcause) { - case CAUSE_ILLEGAL_INSTRUCTION: - rc = sbi_illegal_insn_handler(mtval, regs); - msg = "illegal instruction handler failed"; - break; - case CAUSE_MISALIGNED_LOAD: - rc = sbi_misaligned_load_handler(mtval, mtval2, mtinst, regs); - msg = "misaligned load handler failed"; - break; - case CAUSE_MISALIGNED_STORE: - rc = sbi_misaligned_store_handler(mtval, mtval2, mtinst, regs); - msg = "misaligned store handler failed"; - break; - case CAUSE_SUPERVISOR_ECALL: - case CAUSE_MACHINE_ECALL: - rc = sbi_ecall_handler(regs); - msg = "ecall handler failed"; - break; - default: - /* If the trap came from S or U mode, redirect it there */ - trap.epc = regs->mepc; - trap.cause = mcause; - trap.tval = mtval; - trap.tval2 = mtval2; - trap.tinst = mtinst; - rc = sbi_trap_redirect(regs, &trap); - break; - }; + switch (mcause) { + case CAUSE_ILLEGAL_INSTRUCTION: + rc = sbi_illegal_insn_handler(mtval, regs); + msg = "illegal instruction handler failed"; + break; + case CAUSE_MISALIGNED_LOAD: + rc = sbi_misaligned_load_handler(mtval, mtval2, mtinst, regs); + msg = "misaligned load handler failed"; + break; + case CAUSE_MISALIGNED_STORE: + rc = sbi_misaligned_store_handler(mtval, mtval2, mtinst, regs); + msg = "misaligned store handler failed"; + break; + case CAUSE_SUPERVISOR_ECALL: + case CAUSE_MACHINE_ECALL: + rc = sbi_ecall_handler(regs); + msg = "ecall handler failed"; + break; + default: + /* If the trap came from S or U mode, redirect it there */ + trap.epc = regs->mepc; + trap.cause = mcause; + trap.tval = mtval; + trap.tval2 = mtval2; + trap.tinst = mtinst; + rc = sbi_trap_redirect(regs, &trap); + break; + }; trap_error: - if (rc) - sbi_trap_error(msg, rc, mcause, mtval, mtval2, mtinst, regs); + if (rc) sbi_trap_error(msg, rc, mcause, mtval, mtval2, mtinst, regs); } diff --git a/sm/src/sha3/sha3.c b/sm/src/sha3/sha3.c index 198a023bd..e6f89714d 100644 --- a/sm/src/sha3/sha3.c +++ b/sm/src/sha3/sha3.c @@ -8,158 +8,147 @@ // update the state with given number of rounds -void sha3_keccakf(uint64_t st[25]) -{ - // constants - const uint64_t keccakf_rndc[24] = { - 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, - 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, - 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, - 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, - 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, - 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, - 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, - 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 - }; - const int keccakf_rotc[24] = { - 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, - 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 - }; - const int keccakf_piln[24] = { - 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, - 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 - }; - - // variables - int i, j, r; - uint64_t t, bc[5]; +void +sha3_keccakf(uint64_t st[25]) { + // constants + const uint64_t keccakf_rndc[24] = { + 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, + 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, + 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, + 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, + 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, + 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, + 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, + 0x8000000000008080, 0x0000000080000001, 0x8000000080008008}; + const int keccakf_rotc[24] = {1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, + 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44}; + const int keccakf_piln[24] = {10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, + 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1}; + + // variables + int i, j, r; + uint64_t t, bc[5]; #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ - uint8_t *v; - - // endianess conversion. this is redundant on little-endian targets - for (i = 0; i < 25; i++) { - v = (uint8_t *) &st[i]; - st[i] = ((uint64_t) v[0]) | (((uint64_t) v[1]) << 8) | - (((uint64_t) v[2]) << 16) | (((uint64_t) v[3]) << 24) | - (((uint64_t) v[4]) << 32) | (((uint64_t) v[5]) << 40) | - (((uint64_t) v[6]) << 48) | (((uint64_t) v[7]) << 56); - } + uint8_t* v; + + // endianess conversion. this is redundant on little-endian targets + for (i = 0; i < 25; i++) { + v = (uint8_t*)&st[i]; + st[i] = ((uint64_t)v[0]) | (((uint64_t)v[1]) << 8) | + (((uint64_t)v[2]) << 16) | (((uint64_t)v[3]) << 24) | + (((uint64_t)v[4]) << 32) | (((uint64_t)v[5]) << 40) | + (((uint64_t)v[6]) << 48) | (((uint64_t)v[7]) << 56); + } #endif - // actual iteration - for (r = 0; r < KECCAKF_ROUNDS; r++) { - - // Theta - for (i = 0; i < 5; i++) - bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20]; - - for (i = 0; i < 5; i++) { - t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); - for (j = 0; j < 25; j += 5) - st[j + i] ^= t; - } - - // Rho Pi - t = st[1]; - for (i = 0; i < 24; i++) { - j = keccakf_piln[i]; - bc[0] = st[j]; - st[j] = ROTL64(t, keccakf_rotc[i]); - t = bc[0]; - } - - // Chi - for (j = 0; j < 25; j += 5) { - for (i = 0; i < 5; i++) - bc[i] = st[j + i]; - for (i = 0; i < 5; i++) - st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; - } - - // Iota - st[0] ^= keccakf_rndc[r]; + // actual iteration + for (r = 0; r < KECCAKF_ROUNDS; r++) { + // Theta + for (i = 0; i < 5; i++) + bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20]; + + for (i = 0; i < 5; i++) { + t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); + for (j = 0; j < 25; j += 5) st[j + i] ^= t; } -#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ - // endianess conversion. this is redundant on little-endian targets - for (i = 0; i < 25; i++) { - v = (uint8_t *) &st[i]; - t = st[i]; - v[0] = t & 0xFF; - v[1] = (t >> 8) & 0xFF; - v[2] = (t >> 16) & 0xFF; - v[3] = (t >> 24) & 0xFF; - v[4] = (t >> 32) & 0xFF; - v[5] = (t >> 40) & 0xFF; - v[6] = (t >> 48) & 0xFF; - v[7] = (t >> 56) & 0xFF; + // Rho Pi + t = st[1]; + for (i = 0; i < 24; i++) { + j = keccakf_piln[i]; + bc[0] = st[j]; + st[j] = ROTL64(t, keccakf_rotc[i]); + t = bc[0]; + } + + // Chi + for (j = 0; j < 25; j += 5) { + for (i = 0; i < 5; i++) bc[i] = st[j + i]; + for (i = 0; i < 5; i++) st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; } + + // Iota + st[0] ^= keccakf_rndc[r]; + } + +#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ + // endianess conversion. this is redundant on little-endian targets + for (i = 0; i < 25; i++) { + v = (uint8_t*)&st[i]; + t = st[i]; + v[0] = t & 0xFF; + v[1] = (t >> 8) & 0xFF; + v[2] = (t >> 16) & 0xFF; + v[3] = (t >> 24) & 0xFF; + v[4] = (t >> 32) & 0xFF; + v[5] = (t >> 40) & 0xFF; + v[6] = (t >> 48) & 0xFF; + v[7] = (t >> 56) & 0xFF; + } #endif } // Initialize the context for SHA3 -int sha3_init(sha3_ctx_t *c, int mdlen) -{ - int i; +int +sha3_init(sha3_ctx_t* c, int mdlen) { + int i; - for (i = 0; i < 25; i++) - c->st.q[i] = 0; - c->mdlen = mdlen; - c->rsiz = 200 - 2 * mdlen; - c->pt = 0; + for (i = 0; i < 25; i++) c->st.q[i] = 0; + c->mdlen = mdlen; + c->rsiz = 200 - 2 * mdlen; + c->pt = 0; - return 1; + return 1; } // update state with more data -int sha3_update(sha3_ctx_t *c, const void *data, size_t len) -{ - size_t i; - int j; - - j = c->pt; - for (i = 0; i < len; i++) { - c->st.b[j++] ^= ((const uint8_t *) data)[i]; - if (j >= c->rsiz) { - sha3_keccakf(c->st.q); - j = 0; - } +int +sha3_update(sha3_ctx_t* c, const void* data, size_t len) { + size_t i; + int j; + + j = c->pt; + for (i = 0; i < len; i++) { + c->st.b[j++] ^= ((const uint8_t*)data)[i]; + if (j >= c->rsiz) { + sha3_keccakf(c->st.q); + j = 0; } - c->pt = j; + } + c->pt = j; - return 1; + return 1; } // finalize and output a hash -int sha3_final(void *md, sha3_ctx_t *c) -{ - int i; +int +sha3_final(void* md, sha3_ctx_t* c) { + int i; - c->st.b[c->pt] ^= 0x06; - c->st.b[c->rsiz - 1] ^= 0x80; - sha3_keccakf(c->st.q); + c->st.b[c->pt] ^= 0x06; + c->st.b[c->rsiz - 1] ^= 0x80; + sha3_keccakf(c->st.q); - for (i = 0; i < c->mdlen; i++) { - ((uint8_t *) md)[i] = c->st.b[i]; - } + for (i = 0; i < c->mdlen; i++) { + ((uint8_t*)md)[i] = c->st.b[i]; + } - return 1; + return 1; } // compute a SHA-3 hash (md) of given byte length from "in" -void *sha3(const void *in, size_t inlen, void *md, int mdlen) -{ - sha3_ctx_t sha3; +void* +sha3(const void* in, size_t inlen, void* md, int mdlen) { + sha3_ctx_t sha3; - sha3_init(&sha3, mdlen); - sha3_update(&sha3, in, inlen); - sha3_final(md, &sha3); + sha3_init(&sha3, mdlen); + sha3_update(&sha3, in, inlen); + sha3_final(md, &sha3); - return md; + return md; } - diff --git a/sm/src/sha3/sha3.h b/sm/src/sha3/sha3.h index 5e359d002..8b65f94a9 100644 --- a/sm/src/sha3/sha3.h +++ b/sm/src/sha3/sha3.h @@ -7,8 +7,8 @@ #ifdef __riscv_xlen #include #else -#include #include +#include #endif #ifndef KECCAKF_ROUNDS @@ -21,23 +21,27 @@ // state context typedef struct { - union { // state: - uint8_t b[200]; // 8-bit bytes - uint64_t q[25]; // 64-bit words - } st; - int pt, rsiz, mdlen; // these don't overflow + union { // state: + uint8_t b[200]; // 8-bit bytes + uint64_t q[25]; // 64-bit words + } st; + int pt, rsiz, mdlen; // these don't overflow } sha3_ctx_t; // Compression function. -void sha3_keccakf(uint64_t st[25]); +void +sha3_keccakf(uint64_t st[25]); // OpenSSL - like interfece -int sha3_init(sha3_ctx_t *c, int mdlen); // mdlen = hash output in bytes -int sha3_update(sha3_ctx_t *c, const void *data, size_t len); -int sha3_final(void *md, sha3_ctx_t *c); // digest goes to md +int +sha3_init(sha3_ctx_t* c, int mdlen); // mdlen = hash output in bytes +int +sha3_update(sha3_ctx_t* c, const void* data, size_t len); +int +sha3_final(void* md, sha3_ctx_t* c); // digest goes to md // compute a sha3 hash (md) of given byte length from "in" -void *sha3(const void *in, size_t inlen, void *md, int mdlen); +void* +sha3(const void* in, size_t inlen, void* md, int mdlen); #endif - diff --git a/sm/src/sm-sbi-opensbi.c b/sm/src/sm-sbi-opensbi.c index e579fda24..204aca955 100644 --- a/sm/src/sm-sbi-opensbi.c +++ b/sm/src/sm-sbi-opensbi.c @@ -1,36 +1,33 @@ -#include -#include -#include -#include -#include +#include "sm-sbi-opensbi.h" + +#include #include #include -#include -#include #include -#include "sm-sbi-opensbi.h" +#include +#include +#include +#include +#include +#include + +#include "cpu.h" #include "pmp.h" #include "sm-sbi.h" #include "sm.h" -#include "cpu.h" -static int sbi_ecall_keystone_enclave_handler(unsigned long extid, unsigned long funcid, - const struct sbi_trap_regs *regs, - unsigned long *out_val, - struct sbi_trap_info *out_trap) -{ +static int +sbi_ecall_keystone_enclave_handler( + unsigned long extid, unsigned long funcid, const struct sbi_trap_regs* regs, + unsigned long* out_val, struct sbi_trap_info* out_trap) { uintptr_t retval; - if (funcid <= FID_RANGE_DEPRECATED) { return SBI_ERR_SM_DEPRECATED; } - else if (funcid <= FID_RANGE_HOST) - { - if (cpu_is_enclave_context()) - return SBI_ERR_SM_ENCLAVE_SBI_PROHIBITED; - } - else if (funcid <= FID_RANGE_ENCLAVE) - { - if (!cpu_is_enclave_context()) - return SBI_ERR_SM_ENCLAVE_SBI_PROHIBITED; + if (funcid <= FID_RANGE_DEPRECATED) { + return SBI_ERR_SM_DEPRECATED; + } else if (funcid <= FID_RANGE_HOST) { + if (cpu_is_enclave_context()) return SBI_ERR_SM_ENCLAVE_SBI_PROHIBITED; + } else if (funcid <= FID_RANGE_ENCLAVE) { + if (!cpu_is_enclave_context()) return SBI_ERR_SM_ENCLAVE_SBI_PROHIBITED; } switch (funcid) { @@ -41,16 +38,16 @@ static int sbi_ecall_keystone_enclave_handler(unsigned long extid, unsigned long retval = sbi_sm_destroy_enclave(regs->a0); break; case SBI_SM_RUN_ENCLAVE: - retval = sbi_sm_run_enclave((struct sbi_trap_regs*) regs, regs->a0); + retval = sbi_sm_run_enclave((struct sbi_trap_regs*)regs, regs->a0); __builtin_unreachable(); break; case SBI_SM_RESUME_ENCLAVE: - retval = sbi_sm_resume_enclave((struct sbi_trap_regs*) regs, regs->a0); + retval = sbi_sm_resume_enclave((struct sbi_trap_regs*)regs, regs->a0); __builtin_unreachable(); break; case SBI_SM_RANDOM: *out_val = sbi_sm_random(); - retval = 0; + retval = 0; break; case SBI_SM_ATTEST_ENCLAVE: retval = sbi_sm_attest_enclave(regs->a0, regs->a1, regs->a2); @@ -59,11 +56,11 @@ static int sbi_ecall_keystone_enclave_handler(unsigned long extid, unsigned long retval = sbi_sm_get_sealing_key(regs->a0, regs->a1, regs->a2); break; case SBI_SM_STOP_ENCLAVE: - retval = sbi_sm_stop_enclave((struct sbi_trap_regs*) regs, regs->a0); + retval = sbi_sm_stop_enclave((struct sbi_trap_regs*)regs, regs->a0); __builtin_unreachable(); break; case SBI_SM_EXIT_ENCLAVE: - retval = sbi_sm_exit_enclave((struct sbi_trap_regs*) regs, regs->a0); + retval = sbi_sm_exit_enclave((struct sbi_trap_regs*)regs, regs->a0); __builtin_unreachable(); break; case SBI_SM_CALL_PLUGIN: @@ -75,11 +72,10 @@ static int sbi_ecall_keystone_enclave_handler(unsigned long extid, unsigned long } return retval; - } struct sbi_ecall_extension ecall_keystone_enclave = { - .extid_start = SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE, - .extid_end = SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE, - .handle = sbi_ecall_keystone_enclave_handler, + .extid_start = SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE, + .extid_end = SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE, + .handle = sbi_ecall_keystone_enclave_handler, }; diff --git a/sm/src/sm-sbi-opensbi.h b/sm/src/sm-sbi-opensbi.h index 721759fe3..c6a92b047 100644 --- a/sm/src/sm-sbi-opensbi.h +++ b/sm/src/sm-sbi-opensbi.h @@ -2,19 +2,21 @@ #define _SM_SBI_OPENSBI_H_ #define SBI_SM_EVENT 0x0100 -#include "sbi/sbi_trap.h" +#include + #include "sbi/sbi_error.h" #include "sbi/sbi_scratch.h" -#include +#include "sbi/sbi_trap.h" /* Inbound interfaces */ extern struct sbi_ecall_extension ecall_keystone_enclave; -#define SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE 0x08424b45 // BKE (Berkeley Keystone Enclave) -//int sbi_sm_interface(struct sbi_scratch *scratch, unsigned long extension_id, -// struct sbi_trap_regs *regs, -// unsigned long *out_val, -// struct sbi_trap_info *out_trap); -//void sm_ipi_process(); +#define SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE \ + 0x08424b45 // BKE (Berkeley Keystone Enclave) +// int sbi_sm_interface(struct sbi_scratch *scratch, unsigned long extension_id, +// struct sbi_trap_regs *regs, +// unsigned long *out_val, +// struct sbi_trap_info *out_trap); +// void sm_ipi_process(); /* Outbound interfaces */ -//int sm_sbi_send_ipi(uintptr_t recipient_mask); +// int sm_sbi_send_ipi(uintptr_t recipient_mask); #endif /*_SM_SBI_OPENSBI_H_*/ diff --git a/sm/src/sm-sbi.c b/sm/src/sm-sbi.c index c3612cafb..ea57e5d57 100644 --- a/sm/src/sm-sbi.c +++ b/sm/src/sm-sbi.c @@ -3,58 +3,58 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include "sm-sbi.h" -#include "pmp.h" + +#include +#include + +#include "cpu.h" #include "enclave.h" #include "page.h" -#include "cpu.h" #include "platform-hook.h" #include "plugins/plugins.h" -#include -#include +#include "pmp.h" -unsigned long sbi_sm_create_enclave(unsigned long* eid, uintptr_t create_args) -{ +unsigned long +sbi_sm_create_enclave(unsigned long* eid, uintptr_t create_args) { struct keystone_sbi_create create_args_local; unsigned long ret; ret = copy_enclave_create_args(create_args, &create_args_local); - if (ret) - return ret; + if (ret) return ret; ret = create_enclave(eid, create_args_local); return ret; } -unsigned long sbi_sm_destroy_enclave(unsigned long eid) -{ +unsigned long +sbi_sm_destroy_enclave(unsigned long eid) { unsigned long ret; ret = destroy_enclave((unsigned int)eid); return ret; } -unsigned long sbi_sm_run_enclave(struct sbi_trap_regs *regs, unsigned long eid) -{ - regs->a0 = run_enclave(regs, (unsigned int) eid); +unsigned long +sbi_sm_run_enclave(struct sbi_trap_regs* regs, unsigned long eid) { + regs->a0 = run_enclave(regs, (unsigned int)eid); regs->mepc += 4; sbi_trap_exit(regs); return 0; } -unsigned long sbi_sm_resume_enclave(struct sbi_trap_regs *regs, unsigned long eid) -{ +unsigned long +sbi_sm_resume_enclave(struct sbi_trap_regs* regs, unsigned long eid) { unsigned long ret; - ret = resume_enclave(regs, (unsigned int) eid); - if (!regs->zero) - regs->a0 = ret; + ret = resume_enclave(regs, (unsigned int)eid); + if (!regs->zero) regs->a0 = ret; regs->mepc += 4; sbi_trap_exit(regs); return 0; } -unsigned long sbi_sm_exit_enclave(struct sbi_trap_regs *regs, unsigned long retval) -{ +unsigned long +sbi_sm_exit_enclave(struct sbi_trap_regs* regs, unsigned long retval) { regs->a0 = exit_enclave(regs, cpu_get_enclave_id()); regs->a1 = retval; regs->mepc += 4; @@ -62,37 +62,38 @@ unsigned long sbi_sm_exit_enclave(struct sbi_trap_regs *regs, unsigned long retv return 0; } -unsigned long sbi_sm_stop_enclave(struct sbi_trap_regs *regs, unsigned long request) -{ +unsigned long +sbi_sm_stop_enclave(struct sbi_trap_regs* regs, unsigned long request) { regs->a0 = stop_enclave(regs, request, cpu_get_enclave_id()); regs->mepc += 4; sbi_trap_exit(regs); return 0; } -unsigned long sbi_sm_attest_enclave(uintptr_t report, uintptr_t data, uintptr_t size) -{ +unsigned long +sbi_sm_attest_enclave(uintptr_t report, uintptr_t data, uintptr_t size) { unsigned long ret; ret = attest_enclave(report, data, size, cpu_get_enclave_id()); return ret; } -unsigned long sbi_sm_get_sealing_key(uintptr_t sealing_key, uintptr_t key_ident, - size_t key_ident_size) -{ +unsigned long +sbi_sm_get_sealing_key( + uintptr_t sealing_key, uintptr_t key_ident, size_t key_ident_size) { unsigned long ret; - ret = get_sealing_key(sealing_key, key_ident, key_ident_size, - cpu_get_enclave_id()); + ret = get_sealing_key( + sealing_key, key_ident, key_ident_size, cpu_get_enclave_id()); return ret; } -unsigned long sbi_sm_random() -{ - return (unsigned long) platform_random(); +unsigned long +sbi_sm_random() { + return (unsigned long)platform_random(); } -unsigned long sbi_sm_call_plugin(uintptr_t plugin_id, uintptr_t call_id, uintptr_t arg0, uintptr_t arg1) -{ +unsigned long +sbi_sm_call_plugin( + uintptr_t plugin_id, uintptr_t call_id, uintptr_t arg0, uintptr_t arg1) { unsigned long ret; ret = call_plugin(cpu_get_enclave_id(), plugin_id, call_id, arg0, arg1); return ret; diff --git a/sm/src/sm-sbi.h b/sm/src/sm-sbi.h index c8c1b02eb..e23ff717b 100644 --- a/sm/src/sm-sbi.h +++ b/sm/src/sm-sbi.h @@ -5,37 +5,39 @@ #ifndef _KEYSTONE_SBI_H_ #define _KEYSTONE_SBI_H_ -#include #include +#include unsigned long -sbi_sm_create_enclave(unsigned long *out_val, uintptr_t create_args); +sbi_sm_create_enclave(unsigned long* out_val, uintptr_t create_args); unsigned long sbi_sm_destroy_enclave(unsigned long eid); unsigned long -sbi_sm_run_enclave(struct sbi_trap_regs *regs, unsigned long eid); +sbi_sm_run_enclave(struct sbi_trap_regs* regs, unsigned long eid); unsigned long -sbi_sm_exit_enclave(struct sbi_trap_regs *regs, unsigned long retval); +sbi_sm_exit_enclave(struct sbi_trap_regs* regs, unsigned long retval); unsigned long -sbi_sm_stop_enclave(struct sbi_trap_regs *regs, unsigned long request); +sbi_sm_stop_enclave(struct sbi_trap_regs* regs, unsigned long request); unsigned long -sbi_sm_resume_enclave(struct sbi_trap_regs *regs, unsigned long eid); +sbi_sm_resume_enclave(struct sbi_trap_regs* regs, unsigned long eid); unsigned long sbi_sm_attest_enclave(uintptr_t report, uintptr_t data, uintptr_t size); unsigned long -sbi_sm_get_sealing_key(uintptr_t seal_key, uintptr_t key_ident, size_t key_ident_size); +sbi_sm_get_sealing_key( + uintptr_t seal_key, uintptr_t key_ident, size_t key_ident_size); unsigned long sbi_sm_random(); unsigned long -sbi_sm_call_plugin(uintptr_t plugin_id, uintptr_t call_id, uintptr_t arg0, uintptr_t arg1); +sbi_sm_call_plugin( + uintptr_t plugin_id, uintptr_t call_id, uintptr_t arg0, uintptr_t arg1); #endif diff --git a/sm/src/sm.c b/sm/src/sm.c index 2b278c454..9ea2fb112 100644 --- a/sm/src/sm.c +++ b/sm/src/sm.c @@ -2,18 +2,20 @@ // Copyright (c) 2018, The Regents of the University of California (Regents). // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ -#include "ipi.h" #include "sm.h" -#include "pmp.h" + +#include +#include +#include +#include +#include + #include "crypto.h" #include "enclave.h" +#include "ipi.h" #include "platform-hook.h" +#include "pmp.h" #include "sm-sbi-opensbi.h" -#include -#include -#include -#include -#include static int sm_init_done = 0; static int sm_region_id = 0, os_region_id = 0; @@ -25,47 +27,55 @@ extern byte sanctum_sm_secret_key[PRIVATE_KEY_SIZE]; extern byte sanctum_sm_public_key[PUBLIC_KEY_SIZE]; extern byte sanctum_dev_public_key[PUBLIC_KEY_SIZE]; -byte sm_hash[MDSIZE] = { 0, }; -byte sm_signature[SIGNATURE_SIZE] = { 0, }; -byte sm_public_key[PUBLIC_KEY_SIZE] = { 0, }; -byte sm_private_key[PRIVATE_KEY_SIZE] = { 0, }; -byte dev_public_key[PUBLIC_KEY_SIZE] = { 0, }; - -int osm_pmp_set(uint8_t perm) -{ +byte sm_hash[MDSIZE] = { + 0, +}; +byte sm_signature[SIGNATURE_SIZE] = { + 0, +}; +byte sm_public_key[PUBLIC_KEY_SIZE] = { + 0, +}; +byte sm_private_key[PRIVATE_KEY_SIZE] = { + 0, +}; +byte dev_public_key[PUBLIC_KEY_SIZE] = { + 0, +}; + +int +osm_pmp_set(uint8_t perm) { /* in case of OSM, PMP cfg is exactly the opposite.*/ return pmp_set_keystone(os_region_id, perm); } -int smm_init() -{ +int +smm_init() { int region = -1; int ret = pmp_region_init_atomic(SMM_BASE, SMM_SIZE, PMP_PRI_TOP, ®ion, 0); - if(ret) - return -1; + if (ret) return -1; return region; } -int osm_init() -{ +int +osm_init() { int region = -1; - int ret = pmp_region_init_atomic(0, -1UL, PMP_PRI_BOTTOM, ®ion, 1); - if(ret) - return -1; + int ret = pmp_region_init_atomic(0, -1UL, PMP_PRI_BOTTOM, ®ion, 1); + if (ret) return -1; return region; } -void sm_sign(void* signature, const void* data, size_t len) -{ +void +sm_sign(void* signature, const void* data, size_t len) { sign(signature, data, len, sm_public_key, sm_private_key); } -int sm_derive_sealing_key(unsigned char *key, const unsigned char *key_ident, - size_t key_ident_size, - const unsigned char *enclave_hash) -{ +int +sm_derive_sealing_key( + unsigned char* key, const unsigned char* key_ident, size_t key_ident_size, + const unsigned char* enclave_hash) { unsigned char info[MDSIZE + key_ident_size]; sbi_memcpy(info, enclave_hash, MDSIZE); @@ -75,13 +85,13 @@ int sm_derive_sealing_key(unsigned char *key, const unsigned char *key_ident, * The key is derived without a salt because we have no entropy source * available to generate the salt. */ - return kdf(NULL, 0, - (const unsigned char *)sm_private_key, PRIVATE_KEY_SIZE, - info, MDSIZE + key_ident_size, key, SEALING_KEY_SIZE); + return kdf( + NULL, 0, (const unsigned char*)sm_private_key, PRIVATE_KEY_SIZE, info, + MDSIZE + key_ident_size, key, SEALING_KEY_SIZE); } -void sm_copy_key() -{ +void +sm_copy_key() { sbi_memcpy(sm_hash, sanctum_sm_hash, MDSIZE); sbi_memcpy(sm_signature, sanctum_sm_signature, SIGNATURE_SIZE); sbi_memcpy(sm_public_key, sanctum_sm_public_key, PUBLIC_KEY_SIZE); @@ -89,11 +99,10 @@ void sm_copy_key() sbi_memcpy(dev_public_key, sanctum_dev_public_key, PUBLIC_KEY_SIZE); } -void sm_print_hash() -{ - for (int i=0; i #include + #include "pmp.h" #include "sm-sbi.h" -#include -#define SMM_BASE 0x80000000 -#define SMM_SIZE 0x200000 +#define SMM_BASE 0x80000000 +#define SMM_SIZE 0x200000 /* 0-1999 are not used (deprecated) */ -#define FID_RANGE_DEPRECATED 1999 +#define FID_RANGE_DEPRECATED 1999 /* 2000-2999 are called by host */ -#define SBI_SM_CREATE_ENCLAVE 2001 -#define SBI_SM_DESTROY_ENCLAVE 2002 -#define SBI_SM_RUN_ENCLAVE 2003 -#define SBI_SM_RESUME_ENCLAVE 2005 -#define FID_RANGE_HOST 2999 +#define SBI_SM_CREATE_ENCLAVE 2001 +#define SBI_SM_DESTROY_ENCLAVE 2002 +#define SBI_SM_RUN_ENCLAVE 2003 +#define SBI_SM_RESUME_ENCLAVE 2005 +#define FID_RANGE_HOST 2999 /* 3000-3999 are called by enclave */ -#define SBI_SM_RANDOM 3001 -#define SBI_SM_ATTEST_ENCLAVE 3002 -#define SBI_SM_GET_SEALING_KEY 3003 -#define SBI_SM_STOP_ENCLAVE 3004 -#define SBI_SM_EXIT_ENCLAVE 3006 -#define FID_RANGE_ENCLAVE 3999 +#define SBI_SM_RANDOM 3001 +#define SBI_SM_ATTEST_ENCLAVE 3002 +#define SBI_SM_GET_SEALING_KEY 3003 +#define SBI_SM_STOP_ENCLAVE 3004 +#define SBI_SM_EXIT_ENCLAVE 3006 +#define FID_RANGE_ENCLAVE 3999 /* 4000-4999 are experimental */ -#define SBI_SM_CALL_PLUGIN 4000 -#define FID_RANGE_CUSTOM 4999 +#define SBI_SM_CALL_PLUGIN 4000 +#define FID_RANGE_CUSTOM 4999 /* error codes */ -#define SBI_ERR_SM_ENCLAVE_SUCCESS 0 -#define SBI_ERR_SM_ENCLAVE_UNKNOWN_ERROR 100000 -#define SBI_ERR_SM_ENCLAVE_INVALID_ID 100001 -#define SBI_ERR_SM_ENCLAVE_INTERRUPTED 100002 -#define SBI_ERR_SM_ENCLAVE_PMP_FAILURE 100003 -#define SBI_ERR_SM_ENCLAVE_NOT_RUNNABLE 100004 -#define SBI_ERR_SM_ENCLAVE_NOT_DESTROYABLE 100005 -#define SBI_ERR_SM_ENCLAVE_REGION_OVERLAPS 100006 -#define SBI_ERR_SM_ENCLAVE_NOT_ACCESSIBLE 100007 -#define SBI_ERR_SM_ENCLAVE_ILLEGAL_ARGUMENT 100008 -#define SBI_ERR_SM_ENCLAVE_NOT_RUNNING 100009 -#define SBI_ERR_SM_ENCLAVE_NOT_RESUMABLE 100010 -#define SBI_ERR_SM_ENCLAVE_EDGE_CALL_HOST 100011 -#define SBI_ERR_SM_ENCLAVE_NOT_INITIALIZED 100012 -#define SBI_ERR_SM_ENCLAVE_NO_FREE_RESOURCE 100013 -#define SBI_ERR_SM_ENCLAVE_SBI_PROHIBITED 100014 -#define SBI_ERR_SM_ENCLAVE_ILLEGAL_PTE 100015 -#define SBI_ERR_SM_ENCLAVE_NOT_FRESH 100016 -#define SBI_ERR_SM_DEPRECATED 100099 -#define SBI_ERR_SM_NOT_IMPLEMENTED 100100 +#define SBI_ERR_SM_ENCLAVE_SUCCESS 0 +#define SBI_ERR_SM_ENCLAVE_UNKNOWN_ERROR 100000 +#define SBI_ERR_SM_ENCLAVE_INVALID_ID 100001 +#define SBI_ERR_SM_ENCLAVE_INTERRUPTED 100002 +#define SBI_ERR_SM_ENCLAVE_PMP_FAILURE 100003 +#define SBI_ERR_SM_ENCLAVE_NOT_RUNNABLE 100004 +#define SBI_ERR_SM_ENCLAVE_NOT_DESTROYABLE 100005 +#define SBI_ERR_SM_ENCLAVE_REGION_OVERLAPS 100006 +#define SBI_ERR_SM_ENCLAVE_NOT_ACCESSIBLE 100007 +#define SBI_ERR_SM_ENCLAVE_ILLEGAL_ARGUMENT 100008 +#define SBI_ERR_SM_ENCLAVE_NOT_RUNNING 100009 +#define SBI_ERR_SM_ENCLAVE_NOT_RESUMABLE 100010 +#define SBI_ERR_SM_ENCLAVE_EDGE_CALL_HOST 100011 +#define SBI_ERR_SM_ENCLAVE_NOT_INITIALIZED 100012 +#define SBI_ERR_SM_ENCLAVE_NO_FREE_RESOURCE 100013 +#define SBI_ERR_SM_ENCLAVE_SBI_PROHIBITED 100014 +#define SBI_ERR_SM_ENCLAVE_ILLEGAL_PTE 100015 +#define SBI_ERR_SM_ENCLAVE_NOT_FRESH 100016 +#define SBI_ERR_SM_DEPRECATED 100099 +#define SBI_ERR_SM_NOT_IMPLEMENTED 100100 -#define SBI_ERR_SM_PMP_SUCCESS 0 -#define SBI_ERR_SM_PMP_REGION_SIZE_INVALID 100020 -#define SBI_ERR_SM_PMP_REGION_NOT_PAGE_GRANULARITY 100021 -#define SBI_ERR_SM_PMP_REGION_NOT_ALIGNED 100022 -#define SBI_ERR_SM_PMP_REGION_MAX_REACHED 100023 -#define SBI_ERR_SM_PMP_REGION_INVALID 100024 -#define SBI_ERR_SM_PMP_REGION_OVERLAP 100025 -#define SBI_ERR_SM_PMP_REGION_IMPOSSIBLE_TOR 100026 +#define SBI_ERR_SM_PMP_SUCCESS 0 +#define SBI_ERR_SM_PMP_REGION_SIZE_INVALID 100020 +#define SBI_ERR_SM_PMP_REGION_NOT_PAGE_GRANULARITY 100021 +#define SBI_ERR_SM_PMP_REGION_NOT_ALIGNED 100022 +#define SBI_ERR_SM_PMP_REGION_MAX_REACHED 100023 +#define SBI_ERR_SM_PMP_REGION_INVALID 100024 +#define SBI_ERR_SM_PMP_REGION_OVERLAP 100025 +#define SBI_ERR_SM_PMP_REGION_IMPOSSIBLE_TOR 100026 -void sm_init(bool cold_boot); +void +sm_init(bool cold_boot); /* platform specific functions */ -#define ATTESTATION_KEY_LENGTH 64 -void sm_retrieve_pubkey(void* dest); -void sm_sign(void* sign, const void* data, size_t len); -int sm_derive_sealing_key(unsigned char *key, - const unsigned char *key_ident, - size_t key_ident_size, - const unsigned char *enclave_hash); +#define ATTESTATION_KEY_LENGTH 64 +void +sm_retrieve_pubkey(void* dest); +void +sm_sign(void* sign, const void* data, size_t len); +int +sm_derive_sealing_key( + unsigned char* key, const unsigned char* key_ident, size_t key_ident_size, + const unsigned char* enclave_hash); /* creation parameters */ -struct keystone_sbi_pregion -{ +struct keystone_sbi_pregion { uintptr_t paddr; size_t size; }; -struct runtime_va_params_t -{ +struct runtime_va_params_t { uintptr_t runtime_entry; uintptr_t user_entry; uintptr_t untrusted_ptr; uintptr_t untrusted_size; }; -struct runtime_pa_params -{ +struct runtime_pa_params { uintptr_t dram_base; uintptr_t dram_size; uintptr_t runtime_base; @@ -97,8 +98,7 @@ struct runtime_pa_params uintptr_t free_base; }; -struct keystone_sbi_create -{ +struct keystone_sbi_create { struct keystone_sbi_pregion epm_region; struct keystone_sbi_pregion utm_region; @@ -110,5 +110,6 @@ struct keystone_sbi_create unsigned int* eid_pptr; }; -int osm_pmp_set(uint8_t perm); +int +osm_pmp_set(uint8_t perm); #endif diff --git a/sm/src/thread.c b/sm/src/thread.c index 2df94774d..942c98658 100644 --- a/sm/src/thread.c +++ b/sm/src/thread.c @@ -2,43 +2,50 @@ // Copyright (c) 2018, The Regents of the University of California (Regents). // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ +#include "thread.h" + #include #include -#include "thread.h" -void switch_vector_enclave(){ +void +switch_vector_enclave() { extern void trap_vector_enclave(); csr_write(mtvec, &trap_vector_enclave); } -void switch_vector_host(){ +void +switch_vector_host() { extern void _trap_handler(); csr_write(mtvec, &_trap_handler); } -void swap_prev_mstatus(struct thread_state* thread, struct sbi_trap_regs* regs, uintptr_t current_mstatus) { - //Time interrupts can occur in either user mode or supervisor mode +void +swap_prev_mstatus( + struct thread_state* thread, struct sbi_trap_regs* regs, + uintptr_t current_mstatus) { + // Time interrupts can occur in either user mode or supervisor mode uintptr_t mstatus_mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_SPP | - MSTATUS_MPP | MSTATUS_FS | MSTATUS_SUM | - MSTATUS_MXR; + MSTATUS_MPP | MSTATUS_FS | MSTATUS_SUM | MSTATUS_MXR; uintptr_t tmp = thread->prev_mstatus; - thread->prev_mstatus = (current_mstatus & ~mstatus_mask) | (current_mstatus & mstatus_mask); + thread->prev_mstatus = + (current_mstatus & ~mstatus_mask) | (current_mstatus & mstatus_mask); regs->mstatus = (current_mstatus & ~mstatus_mask) | tmp; } /* Swaps the entire s-mode visible state, general registers and then csrs */ -void swap_prev_state(struct thread_state* thread, struct sbi_trap_regs* regs, int return_on_resume) -{ +void +swap_prev_state( + struct thread_state* thread, struct sbi_trap_regs* regs, + int return_on_resume) { int i; - uintptr_t* prev = (uintptr_t*) &thread->prev_state; - for(i=0; i<32; i++) - { + uintptr_t* prev = (uintptr_t*)&thread->prev_state; + for (i = 0; i < 32; i++) { /* swap state */ - uintptr_t tmp = prev[i]; - prev[i] = ((unsigned long *)regs)[i]; - ((unsigned long *)regs)[i] = tmp; + uintptr_t tmp = prev[i]; + prev[i] = ((unsigned long*)regs)[i]; + ((unsigned long*)regs)[i] = tmp; } prev[0] = !return_on_resume; @@ -52,20 +59,19 @@ void swap_prev_state(struct thread_state* thread, struct sbi_trap_regs* regs, in /* TODO: Right now we are only handling the ones that our test platforms support. Realistically we should have these behind defines for extensions (ex: N extension)*/ -void swap_prev_smode_csrs(struct thread_state* -thread){ - +void +swap_prev_smode_csrs(struct thread_state* thread) { uintptr_t tmp; -#define LOCAL_SWAP_CSR(csrname) \ - tmp = thread->prev_csrs.csrname; \ - thread->prev_csrs.csrname = csr_read(csrname); \ +#define LOCAL_SWAP_CSR(csrname) \ + tmp = thread->prev_csrs.csrname; \ + thread->prev_csrs.csrname = csr_read(csrname); \ csr_write(csrname, tmp); LOCAL_SWAP_CSR(sstatus); // These only exist with N extension. - //LOCAL_SWAP_CSR(sedeleg); - //LOCAL_SWAP_CSR(sideleg); + // LOCAL_SWAP_CSR(sedeleg); + // LOCAL_SWAP_CSR(sideleg); LOCAL_SWAP_CSR(sie); LOCAL_SWAP_CSR(stvec); LOCAL_SWAP_CSR(scounteren); @@ -79,43 +85,43 @@ thread){ #undef LOCAL_SWAP_CSR } -void swap_prev_mepc(struct thread_state* thread, struct sbi_trap_regs* regs, uintptr_t current_mepc) -{ - uintptr_t tmp = thread->prev_mepc; +void +swap_prev_mepc( + struct thread_state* thread, struct sbi_trap_regs* regs, + uintptr_t current_mepc) { + uintptr_t tmp = thread->prev_mepc; thread->prev_mepc = current_mepc; - regs->mepc = tmp; + regs->mepc = tmp; } - -void clean_state(struct thread_state* state){ +void +clean_state(struct thread_state* state) { int i; - uintptr_t* prev = (uintptr_t*) &state->prev_state; - for(i=1; i<32; i++) - { + uintptr_t* prev = (uintptr_t*)&state->prev_state; + for (i = 1; i < 32; i++) { prev[i] = 0; } - state->prev_mpp = -1; // 0x800; + state->prev_mpp = -1; // 0x800; clean_smode_csrs(state); } -void clean_smode_csrs(struct thread_state* state){ - +void +clean_smode_csrs(struct thread_state* state) { state->prev_csrs.sstatus = 0; // We can't read these or set these from M-mode? state->prev_csrs.sedeleg = 0; state->prev_csrs.sideleg = 0; - state->prev_csrs.sie = 0; + state->prev_csrs.sie = 0; state->prev_csrs.stvec = 0; // For now we take whatever the OS was doing state->prev_csrs.scounteren = csr_read(scounteren); - state->prev_csrs.sscratch = 0; - state->prev_csrs.sepc = 0; - state->prev_csrs.scause = 0; - state->prev_csrs.sbadaddr = 0; - state->prev_csrs.sip = 0; - state->prev_csrs.satp = 0; - + state->prev_csrs.sscratch = 0; + state->prev_csrs.sepc = 0; + state->prev_csrs.scause = 0; + state->prev_csrs.sbadaddr = 0; + state->prev_csrs.sip = 0; + state->prev_csrs.satp = 0; } diff --git a/sm/src/thread.h b/sm/src/thread.h index ba6ea5a6d..559ea0e13 100644 --- a/sm/src/thread.h +++ b/sm/src/thread.h @@ -5,10 +5,9 @@ #ifndef __THREAD_H__ #define __THREAD_H__ -#include #include -struct ctx -{ +#include +struct ctx { uintptr_t slot; uintptr_t ra; uintptr_t sp; @@ -43,31 +42,28 @@ struct ctx uintptr_t t6; } __packed; -struct csrs -{ - uintptr_t sstatus; //Supervisor status register. - uintptr_t sedeleg; //Supervisor exception delegation register. - uintptr_t sideleg; //Supervisor interrupt delegation register. - uintptr_t sie; //Supervisor interrupt-enable register. - uintptr_t stvec; //Supervisor trap handler base address. - uintptr_t scounteren; //Supervisor counter enable +struct csrs { + uintptr_t sstatus; // Supervisor status register. + uintptr_t sedeleg; // Supervisor exception delegation register. + uintptr_t sideleg; // Supervisor interrupt delegation register. + uintptr_t sie; // Supervisor interrupt-enable register. + uintptr_t stvec; // Supervisor trap handler base address. + uintptr_t scounteren; // Supervisor counter enable /* Supervisor Trap Handling */ - uintptr_t sscratch; //Scratch register for supervisor trap handlers. - uintptr_t sepc; //Supervisor exception program counter. - uintptr_t scause; //Supervisor trap cause. - //NOTE: This should be stval, toolchain issue? - uintptr_t sbadaddr; //Supervisor bad address. - uintptr_t sip; //Supervisor interrupt pending. + uintptr_t sscratch; // Scratch register for supervisor trap handlers. + uintptr_t sepc; // Supervisor exception program counter. + uintptr_t scause; // Supervisor trap cause. + // NOTE: This should be stval, toolchain issue? + uintptr_t sbadaddr; // Supervisor bad address. + uintptr_t sip; // Supervisor interrupt pending. /* Supervisor Protection and Translation */ - uintptr_t satp; //Page-table base register. - + uintptr_t satp; // Page-table base register. }; /* enclave thread state */ -struct thread_state -{ +struct thread_state { int prev_mpp; uintptr_t prev_mepc; uintptr_t prev_mstatus; @@ -76,17 +72,31 @@ struct thread_state }; /* swap previous and current thread states */ -void swap_prev_state(struct thread_state* state, struct sbi_trap_regs* regs, int return_on_resume); -void swap_prev_mepc(struct thread_state* state, struct sbi_trap_regs* regs, uintptr_t mepc); -void swap_prev_mstatus(struct thread_state* state, struct sbi_trap_regs* regs, uintptr_t mstatus); -void swap_prev_smode_csrs(struct thread_state* thread); +void +swap_prev_state( + struct thread_state* state, struct sbi_trap_regs* regs, + int return_on_resume); +void +swap_prev_mepc( + struct thread_state* state, struct sbi_trap_regs* regs, uintptr_t mepc); +void +swap_prev_mstatus( + struct thread_state* state, struct sbi_trap_regs* regs, uintptr_t mstatus); +void +swap_prev_smode_csrs(struct thread_state* thread); -void switch_vector_enclave(); -void switch_vector_host(); -extern void trap_vector_enclave(); -extern void trap_vector(); +void +switch_vector_enclave(); +void +switch_vector_host(); +extern void +trap_vector_enclave(); +extern void +trap_vector(); /* Clean state generation */ -void clean_state(struct thread_state* state); -void clean_smode_csrs(struct thread_state* state); +void +clean_state(struct thread_state* state); +void +clean_smode_csrs(struct thread_state* state); #endif /* thread */ diff --git a/sm/tools/hash_generator.c b/sm/tools/hash_generator.c index 12a0f9d5f..2c4ff057d 100644 --- a/sm/tools/hash_generator.c +++ b/sm/tools/hash_generator.c @@ -1,13 +1,13 @@ #include -#include #include +#include #include -#define FW_MEMORY_SIZE 0x1ff000 -#define HASH_SIZE 64 +#define FW_MEMORY_SIZE 0x1ff000 +#define HASH_SIZE 64 -int main(int argc, char* argv[]) -{ +int +main(int argc, char* argv[]) { if (argc != 3) { printf("Usage: %s \n", argv[0]); return 0; @@ -15,7 +15,7 @@ int main(int argc, char* argv[]) unsigned char sm_hash[HASH_SIZE]; unsigned char* buf; - FILE* fw = fopen(argv[1],"rb"); + FILE* fw = fopen(argv[1], "rb"); int fwsize; if (!fw) { @@ -26,14 +26,14 @@ int main(int argc, char* argv[]) fwsize = strtol(argv[2], NULL, 16); // copy all file contents - buf = (unsigned char*) malloc(FW_MEMORY_SIZE); + buf = (unsigned char*)malloc(FW_MEMORY_SIZE); memset(buf, 0, FW_MEMORY_SIZE); if (!buf) { printf("Failed to allocate buffer\n"); return -1; } - int result = fread (buf,1,fwsize,fw); + int result = fread(buf, 1, fwsize, fw); if (result != fwsize) { printf("Failed to read file\n"); return -1; @@ -48,8 +48,7 @@ int main(int argc, char* argv[]) printf("unsigned char sm_expected_hash[] = {"); - for (int i=0; i < HASH_SIZE; i++) - { + for (int i = 0; i < HASH_SIZE; i++) { if (i % 8 == 0) { printf("\n"); } From 9abfae24f4d442a8a57f8c0fbe5d52b7dcfe28bc Mon Sep 17 00:00:00 2001 From: red-robby Date: Fri, 17 Feb 2023 14:38:20 -0800 Subject: [PATCH 10/14] Add .clang-format (mistake before) --- .clang-format | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..0cc8944ae --- /dev/null +++ b/.clang-format @@ -0,0 +1,10 @@ +BasedOnStyle: Google +IndentWidth: 2 +TabWidth: 2 +ColumnLimit: 80 +AlignAfterOpenBracket: AlwaysBreak +AlwaysBreakAfterReturnType: TopLevel +DerivePointerAlignment: false +PointerAlignment: Left +AlignConsecutiveAssignments: true +SpacesInAngles: false From 10ce4e44b64ecaa8c5f854b98be0f58dd9697284 Mon Sep 17 00:00:00 2001 From: red-robby Date: Fri, 17 Feb 2023 14:55:57 -0800 Subject: [PATCH 11/14] Apply .clang-format to C files in sdk (only cpp files previously) --- sdk/examples/hello-native/eapp/eapp_native.c | 19 +- sdk/examples/hello/eapp/hello.c | 4 +- sdk/examples/tests/attestation/attestation.c | 6 +- sdk/examples/tests/attestation/edge_wrapper.c | 19 +- .../tests/data-sealing/data-sealing.c | 20 +- .../data-sealing/data-sealing_with_output.c | 57 +++-- sdk/examples/tests/fib-bench/fib-bench.c | 19 +- sdk/examples/tests/fibonacci/fibonacci.c | 10 +- sdk/examples/tests/malloc/malloc.c | 12 +- sdk/examples/tests/untrusted/edge_wrapper.c | 19 +- sdk/examples/tests/untrusted/untrusted.c | 12 +- sdk/src/app/tiny-malloc.c | 2 + sdk/src/edge/edge_call.c | 3 +- sdk/src/edge/edge_syscall.c | 202 +++++++++++------- sdk/src/verifier/ed25519/fe.c | 1 + sdk/src/verifier/ed25519/ge.c | 1 + sdk/src/verifier/ed25519/sc.c | 1 + 17 files changed, 242 insertions(+), 165 deletions(-) diff --git a/sdk/examples/hello-native/eapp/eapp_native.c b/sdk/examples/hello-native/eapp/eapp_native.c index 0e37e5e1e..c76b7735f 100644 --- a/sdk/examples/hello-native/eapp/eapp_native.c +++ b/sdk/examples/hello-native/eapp/eapp_native.c @@ -2,24 +2,29 @@ // Copyright (c) 2018, The Regents of the University of California (Regents). // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ +#include + #include "eapp_utils.h" -#include "string.h" #include "edge_call.h" -#include +#include "string.h" #define OCALL_PRINT_STRING 1 -unsigned long ocall_print_string(char* string); - -int main(){ +unsigned long +ocall_print_string(char* string); +int +main() { ocall_print_string("Hello World"); EAPP_RETURN(0); } -unsigned long ocall_print_string(char* string){ +unsigned long +ocall_print_string(char* string) { unsigned long retval; - ocall(OCALL_PRINT_STRING, string, strlen(string)+1, &retval ,sizeof(unsigned long)); + ocall( + OCALL_PRINT_STRING, string, strlen(string) + 1, &retval, + sizeof(unsigned long)); return retval; } diff --git a/sdk/examples/hello/eapp/hello.c b/sdk/examples/hello/eapp/hello.c index c3102f19c..af631cb1a 100644 --- a/sdk/examples/hello/eapp/hello.c +++ b/sdk/examples/hello/eapp/hello.c @@ -1,7 +1,7 @@ #include -int main() -{ +int +main() { printf("hello, world!\n"); return 0; } diff --git a/sdk/examples/tests/attestation/attestation.c b/sdk/examples/tests/attestation/attestation.c index 010b34546..7b9385f70 100644 --- a/sdk/examples/tests/attestation/attestation.c +++ b/sdk/examples/tests/attestation/attestation.c @@ -5,16 +5,16 @@ #include "app/eapp_utils.h" #include "app/string.h" #include "app/syscall.h" - #include "edge_wrapper.h" -void EAPP_ENTRY eapp_entry(){ +void EAPP_ENTRY +eapp_entry() { edge_init(); char* data = "nonce"; char buffer[2048]; - attest_enclave((void*) buffer, data, 5); + attest_enclave((void*)buffer, data, 5); ocall_copy_report(buffer, 2048); diff --git a/sdk/examples/tests/attestation/edge_wrapper.c b/sdk/examples/tests/attestation/edge_wrapper.c index 4c7b4da07..764de871a 100644 --- a/sdk/examples/tests/attestation/edge_wrapper.c +++ b/sdk/examples/tests/attestation/edge_wrapper.c @@ -2,33 +2,36 @@ // Copyright (c) 2018, The Regents of the University of California (Regents). // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ -#include "edge/edge_call.h" #include "edge_wrapper.h" + #include "app/eapp_utils.h" #include "app/string.h" #include "app/syscall.h" +#include "edge/edge_call.h" -void edge_init(){ +void +edge_init() { /* Nothing for now, will probably register buffers/callsites later */ } -void ocall_print_value(unsigned long val){ - +void +ocall_print_value(unsigned long val) { unsigned long val_ = val; ocall(2, &val_, sizeof(unsigned long), 0, 0); return; } -unsigned long ocall_print_buffer(char* data, size_t data_len){ - +unsigned long +ocall_print_buffer(char* data, size_t data_len) { unsigned long retval; - ocall(1, data, data_len, &retval ,sizeof(unsigned long)); + ocall(1, data, data_len, &retval, sizeof(unsigned long)); return retval; } -void ocall_copy_report(void* report, size_t len) { +void +ocall_copy_report(void* report, size_t len) { ocall(3, report, len, 0, 0); } diff --git a/sdk/examples/tests/data-sealing/data-sealing.c b/sdk/examples/tests/data-sealing/data-sealing.c index 32c663d37..234b0801c 100644 --- a/sdk/examples/tests/data-sealing/data-sealing.c +++ b/sdk/examples/tests/data-sealing/data-sealing.c @@ -13,10 +13,11 @@ * All Rights Reserved. See LICENSE for license details. */ +#include "data-sealing.h" + #include "app/eapp_utils.h" #include "app/string.h" #include "app/syscall.h" -#include "data-sealing.h" /* * Function main: @@ -24,15 +25,16 @@ * Description: * Derives the sealing key */ -int main() -{ - char *key_identifier = "identifier"; +int +main() { + char* key_identifier = "identifier"; struct sealing_key key_buffer; int ret = 0; /* Derive the sealing key */ - ret = get_sealing_key(&key_buffer, sizeof(key_buffer), - (void *)key_identifier, strlen(key_identifier)); + ret = get_sealing_key( + &key_buffer, sizeof(key_buffer), (void*)key_identifier, + strlen(key_identifier)); if (ret) { ocall_print_buffer("Sealing key derivation failed!\n", 32); @@ -49,11 +51,11 @@ int main() * Description: * Prints the buffer to the console */ -unsigned long ocall_print_buffer(char *data, size_t data_len) -{ +unsigned long +ocall_print_buffer(char* data, size_t data_len) { unsigned long retval; - ocall(OCALL_PRINT_BUFFER, data, data_len, &retval ,sizeof(unsigned long)); + ocall(OCALL_PRINT_BUFFER, data, data_len, &retval, sizeof(unsigned long)); return retval; } diff --git a/sdk/examples/tests/data-sealing/data-sealing_with_output.c b/sdk/examples/tests/data-sealing/data-sealing_with_output.c index 7dc51e589..cc131f15e 100644 --- a/sdk/examples/tests/data-sealing/data-sealing_with_output.c +++ b/sdk/examples/tests/data-sealing/data-sealing_with_output.c @@ -18,8 +18,10 @@ #include "app/syscall.h" #include "data-sealing.h" -int hextostring(const unsigned char *hex_in, size_t hex_in_size, - char *str_out, size_t str_out_size); +int +hextostring( + const unsigned char* hex_in, size_t hex_in_size, char* str_out, + size_t str_out_size); /* * Function main: @@ -27,24 +29,29 @@ int hextostring(const unsigned char *hex_in, size_t hex_in_size, * Description: * Derives the sealing key */ -int main() -{ - char *key_identifier = "identifier"; - char *key_identifier_2 = "identifier2"; +int +main() { + char* key_identifier = "identifier"; + char* key_identifier_2 = "identifier2"; struct sealing_key key_buffer; int ret = 0; /* Derive the sealing key */ - ret = get_sealing_key(&key_buffer, sizeof(key_buffer), - (void *)key_identifier, strlen(key_identifier)); + ret = get_sealing_key( + &key_buffer, sizeof(key_buffer), (void*)key_identifier, + strlen(key_identifier)); size_t string_key_size = SEALING_KEY_SIZE * 2 + 1; char string_key[string_key_size]; size_t string_signature_size = SIGNATURE_SIZE * 2 + 1; char string_signature[string_signature_size]; - hextostring((const unsigned char *)&key_buffer.key, SEALING_KEY_SIZE, string_key, string_key_size); - hextostring((const unsigned char *)&key_buffer.signature, SIGNATURE_SIZE, string_signature, string_signature_size); + hextostring( + (const unsigned char*)&key_buffer.key, SEALING_KEY_SIZE, string_key, + string_key_size); + hextostring( + (const unsigned char*)&key_buffer.signature, SIGNATURE_SIZE, + string_signature, string_signature_size); ocall_print_buffer("Key:\n", 6); ocall_print_buffer(string_key, string_key_size); @@ -52,11 +59,16 @@ int main() ocall_print_buffer(string_signature, string_signature_size); ocall_print_buffer("\n", 2); - ret = get_sealing_key(&key_buffer, sizeof(key_buffer), - (void *)key_identifier_2, strlen(key_identifier_2)); + ret = get_sealing_key( + &key_buffer, sizeof(key_buffer), (void*)key_identifier_2, + strlen(key_identifier_2)); - hextostring((const unsigned char *)&key_buffer.key, SEALING_KEY_SIZE, string_key, string_key_size); - hextostring((const unsigned char *)&key_buffer.signature, SIGNATURE_SIZE, string_signature, string_signature_size); + hextostring( + (const unsigned char*)&key_buffer.key, SEALING_KEY_SIZE, string_key, + string_key_size); + hextostring( + (const unsigned char*)&key_buffer.signature, SIGNATURE_SIZE, + string_signature, string_signature_size); ocall_print_buffer("Key:\n", 6); ocall_print_buffer(string_key, string_key_size); @@ -79,11 +91,11 @@ int main() * Description: * Prints the buffer to the console */ -unsigned long ocall_print_buffer(char *data, size_t data_len) -{ +unsigned long +ocall_print_buffer(char* data, size_t data_len) { unsigned long retval; - ocall(OCALL_PRINT_BUFFER, data, data_len, &retval ,sizeof(unsigned long)); + ocall(OCALL_PRINT_BUFFER, data, data_len, &retval, sizeof(unsigned long)); return retval; } @@ -103,10 +115,11 @@ unsigned long ocall_print_buffer(char *data, size_t data_len) * * Return value: 0 if function has performed correctly */ -int hextostring(const unsigned char *hex_in, size_t hex_in_size, - char *str_out, size_t str_out_size) -{ - char *hex = "0123456789ABCDEF"; +int +hextostring( + const unsigned char* hex_in, size_t hex_in_size, char* str_out, + size_t str_out_size) { + char* hex = "0123456789ABCDEF"; int i; if (str_out_size < 2 * hex_in_size + 1) { @@ -114,7 +127,7 @@ int hextostring(const unsigned char *hex_in, size_t hex_in_size, } for (i = 0; i < hex_in_size; i++) { - str_out[2 * i] = hex[hex_in[i] >> 4]; + str_out[2 * i] = hex[hex_in[i] >> 4]; str_out[2 * i + 1] = hex[hex_in[i] & 0x0F]; } diff --git a/sdk/examples/tests/fib-bench/fib-bench.c b/sdk/examples/tests/fib-bench/fib-bench.c index a355a5b33..8e523304c 100644 --- a/sdk/examples/tests/fib-bench/fib-bench.c +++ b/sdk/examples/tests/fib-bench/fib-bench.c @@ -4,29 +4,32 @@ //------------------------------------------------------------------------------ #include "app/eapp_utils.h" -unsigned long read_cycles(void) -{ +unsigned long +read_cycles(void) { unsigned long cycles; - asm volatile ("rdcycle %0" : "=r" (cycles)); + asm volatile("rdcycle %0" : "=r"(cycles)); return cycles; } -unsigned long fibonacci_rec(unsigned long in){ - if( in <= 1) +unsigned long +fibonacci_rec(unsigned long in) { + if (in <= 1) return 1; else - return fibonacci_rec(in-1)+fibonacci_rec(in-2); + return fibonacci_rec(in - 1) + fibonacci_rec(in - 2); } // Returns the number of cycles for a given fibonacci execution -unsigned long fib_eapp(unsigned long in) { +unsigned long +fib_eapp(unsigned long in) { unsigned long start = read_cycles(); fibonacci_rec(in); unsigned long end = read_cycles(); return end - start; } -void EAPP_ENTRY eapp_entry(){ +void EAPP_ENTRY +eapp_entry() { int arg = 35; EAPP_RETURN(fib_eapp(arg)); } diff --git a/sdk/examples/tests/fibonacci/fibonacci.c b/sdk/examples/tests/fibonacci/fibonacci.c index e4bd58ac0..d810497e8 100644 --- a/sdk/examples/tests/fibonacci/fibonacci.c +++ b/sdk/examples/tests/fibonacci/fibonacci.c @@ -4,14 +4,16 @@ //------------------------------------------------------------------------------ #include "app/eapp_utils.h" -unsigned long fibonacci_rec(unsigned long in){ - if( in <= 1) +unsigned long +fibonacci_rec(unsigned long in) { + if (in <= 1) return 1; else - return fibonacci_rec(in-1)+fibonacci_rec(in-2); + return fibonacci_rec(in - 1) + fibonacci_rec(in - 2); } -void EAPP_ENTRY eapp_entry(){ +void EAPP_ENTRY +eapp_entry() { int arg = 35; EAPP_RETURN(fibonacci_rec(arg)); } diff --git a/sdk/examples/tests/malloc/malloc.c b/sdk/examples/tests/malloc/malloc.c index 5c89bd4c9..b0857aa5e 100644 --- a/sdk/examples/tests/malloc/malloc.c +++ b/sdk/examples/tests/malloc/malloc.c @@ -2,14 +2,16 @@ // Copyright (c) 2018, The Regents of the University of California (Regents). // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ -#include "app/eapp_utils.h" #include "malloc.h" -void EAPP_ENTRY eapp_entry(){ +#include "app/eapp_utils.h" + +void EAPP_ENTRY +eapp_entry() { int arg; - int* ptr = (int*) malloc(sizeof(int)); - *ptr = 11411; - arg = *ptr; + int* ptr = (int*)malloc(sizeof(int)); + *ptr = 11411; + arg = *ptr; EAPP_RETURN(arg); } diff --git a/sdk/examples/tests/untrusted/edge_wrapper.c b/sdk/examples/tests/untrusted/edge_wrapper.c index 02213aca4..89c94d39c 100644 --- a/sdk/examples/tests/untrusted/edge_wrapper.c +++ b/sdk/examples/tests/untrusted/edge_wrapper.c @@ -2,12 +2,14 @@ // Copyright (c) 2018, The Regents of the University of California (Regents). // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ +#include "edge_wrapper.h" + #include "app/eapp_utils.h" #include "app/string.h" #include "app/syscall.h" -#include "edge_wrapper.h" -void edge_init(){ +void +edge_init() { /* Nothing for now, will probably register buffers/callsites later */ } @@ -16,23 +18,24 @@ void edge_init(){ #define OCALL_PRINT_VALUE 2 #define OCALL_GET_STRING 4 -void ocall_print_value(unsigned long val){ - +void +ocall_print_value(unsigned long val) { unsigned long val_ = val; ocall(OCALL_PRINT_VALUE, &val_, sizeof(unsigned long), 0, 0); return; } -unsigned long ocall_print_buffer(char* data, size_t data_len){ - +unsigned long +ocall_print_buffer(char* data, size_t data_len) { unsigned long retval; - ocall(OCALL_PRINT_BUFFER, data, data_len, &retval ,sizeof(unsigned long)); + ocall(OCALL_PRINT_BUFFER, data, data_len, &retval, sizeof(unsigned long)); return retval; } -void ocall_get_string(struct edge_data* retdata){ +void +ocall_get_string(struct edge_data* retdata) { ocall(OCALL_GET_STRING, NULL, 0, retdata, sizeof(struct edge_data)); return; } diff --git a/sdk/examples/tests/untrusted/untrusted.c b/sdk/examples/tests/untrusted/untrusted.c index 4b8abd2cb..0b7291430 100644 --- a/sdk/examples/tests/untrusted/untrusted.c +++ b/sdk/examples/tests/untrusted/untrusted.c @@ -3,14 +3,14 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include "app/eapp_utils.h" +#include "app/malloc.h" #include "app/string.h" #include "app/syscall.h" -#include "app/malloc.h" #include "edge_wrapper.h" -void EAPP_ENTRY eapp_entry(){ - - char* msg = "hello world!\n"; +void EAPP_ENTRY +eapp_entry() { + char* msg = "hello world!\n"; char* msg2 = "2nd hello world!\n"; edge_init(); @@ -28,8 +28,8 @@ void EAPP_ENTRY eapp_entry(){ int i; int ct; - for(i = 0; i < pkgstr.size; i++){ - if( ((char*)host_str)[i] == 'l' ){ + for (i = 0; i < pkgstr.size; i++) { + if (((char*)host_str)[i] == 'l') { ct++; } } diff --git a/sdk/src/app/tiny-malloc.c b/sdk/src/app/tiny-malloc.c index e1a3f18d0..51d4b0fbf 100644 --- a/sdk/src/app/tiny-malloc.c +++ b/sdk/src/app/tiny-malloc.c @@ -57,6 +57,7 @@ #endif #include + #include "string.h" void* malloc(size_t); @@ -469,6 +470,7 @@ mallinfo(void) { #ifdef DEFINE_MALLOC_STATS #include + #include "malloc.h" void diff --git a/sdk/src/edge/edge_call.c b/sdk/src/edge/edge_call.c index aeba83943..9dfc7bc4a 100644 --- a/sdk/src/edge/edge_call.c +++ b/sdk/src/edge/edge_call.c @@ -3,10 +3,11 @@ // All Rights Reserved. See LICENSE for license details. //------------------------------------------------------------------------------ #include -#include "string.h" #include #include +#include "string.h" + uintptr_t _shared_start; size_t _shared_len; diff --git a/sdk/src/edge/edge_syscall.c b/sdk/src/edge/edge_syscall.c index 8eeaee0fd..53c3b43c0 100644 --- a/sdk/src/edge/edge_syscall.c +++ b/sdk/src/edge/edge_syscall.c @@ -1,11 +1,12 @@ #include "edge_syscall.h" + #include #include -#include #include -#include #include #include +#include +#include // Special edge-call handler for syscall proxying void incoming_syscall(struct edge_call* edge_call) { @@ -22,7 +23,7 @@ incoming_syscall(struct edge_call* edge_call) { edge_call->return_data.call_status = CALL_STATUS_OK; int64_t ret; - int is_str_ret = 0; + int is_str_ret = 0; char* retbuf; // Right now we only handle some io syscalls. See runtime for how @@ -31,8 +32,8 @@ incoming_syscall(struct edge_call* edge_call) { case (SYS_openat):; sargs_SYS_openat* openat_args = (sargs_SYS_openat*)syscall_info->data; ret = openat( - openat_args->dirfd, openat_args->path, openat_args->flags, - openat_args->mode); + openat_args->dirfd, openat_args->path, openat_args->flags, + openat_args->mode); break; case (SYS_unlinkat):; sargs_SYS_unlinkat* unlinkat_args = @@ -51,17 +52,17 @@ incoming_syscall(struct edge_call* edge_call) { ret = fstatat( fstatat_args->dirfd, fstatat_args->pathname, &fstatat_args->stats, fstatat_args->flags); - break; - case (SYS_fstat):; + break; + case (SYS_fstat):; sargs_SYS_fstat* fstat_args = (sargs_SYS_fstat*)syscall_info->data; // Note the use of the implicit buffer in the stat args object (stats) - ret = fstat(fstat_args->fd, &fstat_args->stats); - break; - case (SYS_getcwd):; // TODO: how to handle string return + ret = fstat(fstat_args->fd, &fstat_args->stats); + break; + case (SYS_getcwd):; // TODO: how to handle string return sargs_SYS_getcwd* getcwd_args = (sargs_SYS_getcwd*)syscall_info->data; - retbuf = getcwd(getcwd_args->buf, getcwd_args->size); + retbuf = getcwd(getcwd_args->buf, getcwd_args->size); is_str_ret = 1; - break; + break; case (SYS_write):; sargs_SYS_write* write_args = (sargs_SYS_write*)syscall_info->data; ret = write(write_args->fd, write_args->buf, write_args->len); @@ -87,112 +88,149 @@ incoming_syscall(struct edge_call* edge_call) { ret = lseek(lseek_args->fd, lseek_args->offset, lseek_args->whence); break; case (SYS_pipe2):; - int *fds = (int *) syscall_info->data; - ret = pipe(fds); + int* fds = (int*)syscall_info->data; + ret = pipe(fds); break; case (SYS_epoll_create1):; - sargs_SYS_epoll_create1 *epoll_args = (sargs_SYS_epoll_create1 *) syscall_info->data; + sargs_SYS_epoll_create1* epoll_args = + (sargs_SYS_epoll_create1*)syscall_info->data; ret = epoll_create(epoll_args->size); break; - case(SYS_chdir):; - sargs_SYS_chdir* chdir_args = (sargs_SYS_chdir*) syscall_info->data; - ret = chdir(chdir_args->path); - break; + case (SYS_chdir):; + sargs_SYS_chdir* chdir_args = (sargs_SYS_chdir*)syscall_info->data; + ret = chdir(chdir_args->path); + break; case (SYS_epoll_ctl):; - sargs_SYS_epoll_ctl *epoll_ctl_args = (sargs_SYS_epoll_ctl *) syscall_info->data; - ret = epoll_ctl(epoll_ctl_args->epfd, epoll_ctl_args->op, epoll_ctl_args->fd, (struct epoll_event * ) &epoll_ctl_args->event); + sargs_SYS_epoll_ctl* epoll_ctl_args = + (sargs_SYS_epoll_ctl*)syscall_info->data; + ret = epoll_ctl( + epoll_ctl_args->epfd, epoll_ctl_args->op, epoll_ctl_args->fd, + (struct epoll_event*)&epoll_ctl_args->event); break; case (SYS_epoll_pwait):; - sargs_SYS_epoll_pwait *epoll_pwait_args = (sargs_SYS_epoll_pwait *) syscall_info->data; - ret = epoll_wait(epoll_pwait_args->epfd, &epoll_pwait_args->events, - epoll_pwait_args->maxevents, epoll_pwait_args->timeout); + sargs_SYS_epoll_pwait* epoll_pwait_args = + (sargs_SYS_epoll_pwait*)syscall_info->data; + ret = epoll_wait( + epoll_pwait_args->epfd, &epoll_pwait_args->events, + epoll_pwait_args->maxevents, epoll_pwait_args->timeout); break; case (SYS_getpeername):; - sargs_SYS_getpeername *getpeername_args = (sargs_SYS_getpeername *) syscall_info->data; - ret = getpeername(getpeername_args->sockfd, (struct sockaddr *) &getpeername_args->addr, - &getpeername_args->addrlen); + sargs_SYS_getpeername* getpeername_args = + (sargs_SYS_getpeername*)syscall_info->data; + ret = getpeername( + getpeername_args->sockfd, (struct sockaddr*)&getpeername_args->addr, + &getpeername_args->addrlen); - break; - case (SYS_getsockname):; - sargs_SYS_getsockname *getsockname_args = (sargs_SYS_getsockname *) syscall_info->data; - ret = getsockname(getsockname_args->sockfd, (struct sockaddr *) &getsockname_args->addr, - &getsockname_args->addrlen); - break; + break; + case (SYS_getsockname):; + sargs_SYS_getsockname* getsockname_args = + (sargs_SYS_getsockname*)syscall_info->data; + ret = getsockname( + getsockname_args->sockfd, (struct sockaddr*)&getsockname_args->addr, + &getsockname_args->addrlen); + break; case (SYS_renameat2):; - sargs_SYS_renameat2 *renameat_args = (sargs_SYS_renameat2 *) syscall_info->data; + sargs_SYS_renameat2* renameat_args = + (sargs_SYS_renameat2*)syscall_info->data; - ret = renameat(renameat_args->olddirfd, renameat_args->oldpath, - renameat_args->newdirfd, renameat_args->newpath); - break; + ret = renameat( + renameat_args->olddirfd, renameat_args->oldpath, + renameat_args->newdirfd, renameat_args->newpath); + break; case (SYS_umask):; - sargs_SYS_umask *umask_args = (sargs_SYS_umask *) syscall_info->data; - ret = umask(umask_args->mask); - break; + sargs_SYS_umask* umask_args = (sargs_SYS_umask*)syscall_info->data; + ret = umask(umask_args->mask); + break; case (SYS_socket):; - sargs_SYS_socket *socket_args = (sargs_SYS_socket *) syscall_info->data; - ret = socket(socket_args->domain, socket_args->type, socket_args->protocol); - break; + sargs_SYS_socket* socket_args = (sargs_SYS_socket*)syscall_info->data; + ret = + socket(socket_args->domain, socket_args->type, socket_args->protocol); + break; case (SYS_setsockopt):; - sargs_SYS_setsockopt *setsockopt_args = (sargs_SYS_setsockopt *) syscall_info->data; - ret = setsockopt(setsockopt_args->socket, setsockopt_args->level, setsockopt_args->option_name, &setsockopt_args->option_value, setsockopt_args->option_len); + sargs_SYS_setsockopt* setsockopt_args = + (sargs_SYS_setsockopt*)syscall_info->data; + ret = setsockopt( + setsockopt_args->socket, setsockopt_args->level, + setsockopt_args->option_name, &setsockopt_args->option_value, + setsockopt_args->option_len); break; case (SYS_bind):; - sargs_SYS_bind *bind_args = (sargs_SYS_bind *) syscall_info->data; - ret = bind(bind_args->sockfd, (struct sockaddr *) &bind_args->addr, bind_args->addrlen); + sargs_SYS_bind* bind_args = (sargs_SYS_bind*)syscall_info->data; + ret = bind( + bind_args->sockfd, (struct sockaddr*)&bind_args->addr, + bind_args->addrlen); break; case (SYS_listen):; - sargs_SYS_listen *listen_args = (sargs_SYS_listen *) syscall_info->data; + sargs_SYS_listen* listen_args = (sargs_SYS_listen*)syscall_info->data; ret = listen(listen_args->sockfd, listen_args->backlog); break; case (SYS_accept):; - sargs_SYS_accept *accept_args = (sargs_SYS_accept *) syscall_info->data; - ret = accept(accept_args->sockfd, (struct sockaddr *) &accept_args->addr, &accept_args->addrlen); - break; - case (SYS_recvfrom):; - sargs_SYS_recvfrom *recvfrom_args = (sargs_SYS_recvfrom *) syscall_info->data; - struct sockaddr *src_addr = recvfrom_args->src_addr_is_null ? NULL : &recvfrom_args->src_addr; - socklen_t *addrlen = recvfrom_args->src_addr_is_null ? NULL : &recvfrom_args->addrlen; - ret = recvfrom(recvfrom_args->sockfd, recvfrom_args->buf, recvfrom_args->len, recvfrom_args->flags, - src_addr, addrlen); - break; - case (SYS_sendto):; - sargs_SYS_sendto *sendto_args = (sargs_SYS_sendto *) syscall_info->data; - struct sockaddr *dest_addr = sendto_args->dest_addr_is_null ? NULL : &sendto_args->dest_addr; - socklen_t dest_addrlen = sendto_args->dest_addr_is_null ? 0 : sendto_args->addrlen; - ret = sendto(sendto_args->sockfd, sendto_args->buf, sendto_args->len, sendto_args->flags, - dest_addr, dest_addrlen); - break; - case (SYS_sendfile):; - sargs_SYS_sendfile *sendfile_args = (sargs_SYS_sendfile *) syscall_info->data; - ret = sendfile(sendfile_args->out_fd, sendfile_args->in_fd, &sendfile_args->offset, sendfile_args->count); + sargs_SYS_accept* accept_args = (sargs_SYS_accept*)syscall_info->data; + ret = accept( + accept_args->sockfd, (struct sockaddr*)&accept_args->addr, + &accept_args->addrlen); + break; + case (SYS_recvfrom):; + sargs_SYS_recvfrom* recvfrom_args = + (sargs_SYS_recvfrom*)syscall_info->data; + struct sockaddr* src_addr = + recvfrom_args->src_addr_is_null ? NULL : &recvfrom_args->src_addr; + socklen_t* addrlen = + recvfrom_args->src_addr_is_null ? NULL : &recvfrom_args->addrlen; + ret = recvfrom( + recvfrom_args->sockfd, recvfrom_args->buf, recvfrom_args->len, + recvfrom_args->flags, src_addr, addrlen); + break; + case (SYS_sendto):; + sargs_SYS_sendto* sendto_args = (sargs_SYS_sendto*)syscall_info->data; + struct sockaddr* dest_addr = + sendto_args->dest_addr_is_null ? NULL : &sendto_args->dest_addr; + socklen_t dest_addrlen = + sendto_args->dest_addr_is_null ? 0 : sendto_args->addrlen; + ret = sendto( + sendto_args->sockfd, sendto_args->buf, sendto_args->len, + sendto_args->flags, dest_addr, dest_addrlen); + break; + case (SYS_sendfile):; + sargs_SYS_sendfile* sendfile_args = + (sargs_SYS_sendfile*)syscall_info->data; + ret = sendfile( + sendfile_args->out_fd, sendfile_args->in_fd, &sendfile_args->offset, + sendfile_args->count); break; case (SYS_fcntl):; - sargs_SYS_fcntl* fcntl_args = (sargs_SYS_fcntl*)syscall_info->data; - if (!fcntl_args->has_struct) + sargs_SYS_fcntl* fcntl_args = (sargs_SYS_fcntl*)syscall_info->data; + if (!fcntl_args->has_struct) ret = fcntl(fcntl_args->fd, fcntl_args->cmd, fcntl_args->arg[0]); - else + else ret = fcntl(fcntl_args->fd, fcntl_args->cmd, fcntl_args->arg); - break; + break; case (SYS_getuid):; - ret = getuid(); + ret = getuid(); break; case (SYS_pselect6):; - sargs_SYS_pselect* pselect_args = (sargs_SYS_pselect*)syscall_info->data; - fd_set *readfds = pselect_args->readfds_is_null ? NULL : &pselect_args->readfds; - fd_set *writefds = pselect_args->writefds_is_null ? NULL : &pselect_args->writefds; - fd_set *exceptfds = pselect_args->exceptfds_is_null ? NULL : &pselect_args->exceptfds; - struct timespec *timeout = pselect_args->timeout_is_null ? NULL : &pselect_args->timeout; - sigset_t *sigmask = pselect_args->sigmask_is_null ? NULL : &pselect_args->sigmask; - ret = pselect(pselect_args->nfds, readfds, writefds, exceptfds, timeout, sigmask); + sargs_SYS_pselect* pselect_args = (sargs_SYS_pselect*)syscall_info->data; + fd_set* readfds = + pselect_args->readfds_is_null ? NULL : &pselect_args->readfds; + fd_set* writefds = + pselect_args->writefds_is_null ? NULL : &pselect_args->writefds; + fd_set* exceptfds = + pselect_args->exceptfds_is_null ? NULL : &pselect_args->exceptfds; + struct timespec* timeout = + pselect_args->timeout_is_null ? NULL : &pselect_args->timeout; + sigset_t* sigmask = + pselect_args->sigmask_is_null ? NULL : &pselect_args->sigmask; + ret = pselect( + pselect_args->nfds, readfds, writefds, exceptfds, timeout, sigmask); break; default: goto syscall_error; } /* Setup return value */ - void* ret_data_ptr = (void*)edge_call_data_ptr(); + void* ret_data_ptr = (void*)edge_call_data_ptr(); if (is_str_ret) { - *(char**) ret_data_ptr = retbuf; // TODO: check ptr stuff + *(char**)ret_data_ptr = retbuf; // TODO: check ptr stuff if (edge_call_setup_ret(edge_call, ret_data_ptr, sizeof(int64_t)) != 0) goto syscall_error; } else { diff --git a/sdk/src/verifier/ed25519/fe.c b/sdk/src/verifier/ed25519/fe.c index 98eaad7d6..a133de531 100644 --- a/sdk/src/verifier/ed25519/fe.c +++ b/sdk/src/verifier/ed25519/fe.c @@ -1,4 +1,5 @@ #include "ed25519/fe.h" + #include "ed25519/fixedint.h" /* diff --git a/sdk/src/verifier/ed25519/ge.c b/sdk/src/verifier/ed25519/ge.c index 02f662877..a329fb0ec 100644 --- a/sdk/src/verifier/ed25519/ge.c +++ b/sdk/src/verifier/ed25519/ge.c @@ -1,4 +1,5 @@ #include "ed25519/ge.h" + #include "ed25519/precomp_data.h" /* diff --git a/sdk/src/verifier/ed25519/sc.c b/sdk/src/verifier/ed25519/sc.c index ee3d1b092..a823898e0 100644 --- a/sdk/src/verifier/ed25519/sc.c +++ b/sdk/src/verifier/ed25519/sc.c @@ -1,4 +1,5 @@ #include "ed25519/sc.h" + #include "ed25519/fixedint.h" static uint64_t From 6cce522733086a2caf7c85a4693110fee7f068fa Mon Sep 17 00:00:00 2001 From: red-robby Date: Fri, 17 Feb 2023 15:12:07 -0800 Subject: [PATCH 12/14] Add .clang-tidy file to SDK, run with --fix-errors --- sdk/.clang-tidy | 2 + .../attestation/host/attestor-runner.cpp | 2 +- sdk/examples/attestation/host/host.cpp | 2 +- sdk/examples/attestation/host/host.h | 2 +- sdk/examples/attestation/host/verifier.cpp | 2 +- .../hello-native/host/host_native.cpp | 2 +- sdk/examples/tests/edge_wrapper.cpp | 12 +++--- sdk/examples/tests/test-runner.cpp | 4 +- sdk/include/host/elf32.h | 2 +- sdk/include/host/elf64.h | 2 +- sdk/src/host/Enclave.cpp | 17 +++++--- sdk/src/host/Memory.cpp | 14 ++++--- sdk/src/verifier/Report.cpp | 4 +- sdk/src/verifier/json11.cpp | 41 ++++++++++++------- 14 files changed, 64 insertions(+), 44 deletions(-) create mode 100644 sdk/.clang-tidy diff --git a/sdk/.clang-tidy b/sdk/.clang-tidy new file mode 100644 index 000000000..364b42b13 --- /dev/null +++ b/sdk/.clang-tidy @@ -0,0 +1,2 @@ +Checks: '-*,google-*,bugbrone-*,clang-analyzer-*' +FormatStyle: none \ No newline at end of file diff --git a/sdk/examples/attestation/host/attestor-runner.cpp b/sdk/examples/attestation/host/attestor-runner.cpp index 4fb129d8c..6d8ae3eec 100644 --- a/sdk/examples/attestation/host/attestor-runner.cpp +++ b/sdk/examples/attestation/host/attestor-runner.cpp @@ -31,7 +31,7 @@ main(int argc, char** argv) { size_t untrusted_size = 2 * 1024 * 1024; size_t freemem_size = 48 * 1024 * 1024; - uintptr_t utm_ptr = (uintptr_t)DEFAULT_UNTRUSTED_PTR; + uintptr_t utm_ptr = static_cast(DEFAULT_UNTRUSTED_PTR); bool retval_exist = false; unsigned long retval = 0; diff --git a/sdk/examples/attestation/host/host.cpp b/sdk/examples/attestation/host/host.cpp index 31122b7a3..4ceafad38 100644 --- a/sdk/examples/attestation/host/host.cpp +++ b/sdk/examples/attestation/host/host.cpp @@ -124,7 +124,7 @@ SharedBuffer::setup_ret_or_bad_ptr(unsigned long ret_val) { // Assuming we are done with the data section for args, use as // return region. // - // TODO safety check? + // TODO(ubuntu): safety check? uintptr_t data_section = data_ptr(); memcpy((void*)data_section, &ret_val, sizeof(unsigned long)); diff --git a/sdk/examples/attestation/host/host.h b/sdk/examples/attestation/host/host.h index eedb8133a..322b0e912 100644 --- a/sdk/examples/attestation/host/host.h +++ b/sdk/examples/attestation/host/host.h @@ -18,7 +18,7 @@ class SharedBuffer { SharedBuffer(void* buffer, size_t buffer_len) /* For now we assume the call struct is at the front of the shared * buffer. This will have to change to allow nested calls. */ - : edge_call_((struct edge_call*)buffer), + : edge_call_(static_cast(buffer)), buffer_((uintptr_t)buffer), buffer_len_(buffer_len) {} diff --git a/sdk/examples/attestation/host/verifier.cpp b/sdk/examples/attestation/host/verifier.cpp index 206f0eaf3..c18510af3 100644 --- a/sdk/examples/attestation/host/verifier.cpp +++ b/sdk/examples/attestation/host/verifier.cpp @@ -69,7 +69,7 @@ Verifier::verify_data(Report& report, const std::string& nonce) { throw std::runtime_error(error); } - if (0 == strcmp(nonce.c_str(), (char*)report.getDataSection())) { + if (0 == strcmp(nonce.c_str(), static_cast(report.getDataSection()))) { printf("Returned data in the report match with the nonce sent.\n"); } else { printf("Returned data in the report do NOT match with the nonce sent.\n"); diff --git a/sdk/examples/hello-native/host/host_native.cpp b/sdk/examples/hello-native/host/host_native.cpp index 5f492f1f2..93c54fe36 100644 --- a/sdk/examples/hello-native/host/host_native.cpp +++ b/sdk/examples/hello-native/host/host_native.cpp @@ -53,7 +53,7 @@ main(int argc, char** argv) { void print_string_wrapper(void* buffer) { /* Parse and validate the incoming call data */ - struct edge_call* edge_call = (struct edge_call*)buffer; + struct edge_call* edge_call = static_cast(buffer); uintptr_t call_args; unsigned long ret_val; size_t arg_len; diff --git a/sdk/examples/tests/edge_wrapper.cpp b/sdk/examples/tests/edge_wrapper.cpp index 6d6f8a01d..4431b5291 100644 --- a/sdk/examples/tests/edge_wrapper.cpp +++ b/sdk/examples/tests/edge_wrapper.cpp @@ -30,7 +30,7 @@ void print_buffer_wrapper(void* buffer) { /* For now we assume the call struct is at the front of the shared * buffer. This will have to change to allow nested calls. */ - struct edge_call* edge_call = (struct edge_call*)buffer; + struct edge_call* edge_call = static_cast(buffer); uintptr_t call_args; unsigned long ret_val; @@ -43,7 +43,7 @@ print_buffer_wrapper(void* buffer) { ret_val = print_buffer((char*)call_args); // We are done with the data section for args, use as return region - // TODO safety check? + // TODO(ubuntu): safety check? uintptr_t data_section = edge_call_data_ptr(); memcpy((void*)data_section, &ret_val, sizeof(unsigned long)); @@ -62,7 +62,7 @@ void print_value_wrapper(void* buffer) { /* For now we assume the call struct is at the front of the shared * buffer. This will have to change to allow nested calls. */ - struct edge_call* edge_call = (struct edge_call*)buffer; + struct edge_call* edge_call = static_cast(buffer); uintptr_t call_args; unsigned long ret_val; @@ -82,11 +82,11 @@ void copy_report_wrapper(void* buffer) { /* For now we assume the call struct is at the front of the shared * buffer. This will have to change to allow nested calls. */ - struct edge_call* edge_call = (struct edge_call*)buffer; + struct edge_call* edge_call = static_cast(buffer); uintptr_t data_section; unsigned long ret_val; - // TODO check the other side of this + // TODO(ubuntu): check the other side of this if (edge_call_get_ptr_from_offset( edge_call->call_arg_offset, sizeof(report_t), &data_section) != 0) { edge_call->return_data.call_status = CALL_STATUS_BAD_OFFSET; @@ -104,7 +104,7 @@ void get_host_string_wrapper(void* buffer) { /* For now we assume the call struct is at the front of the shared * buffer. This will have to change to allow nested calls. */ - struct edge_call* edge_call = (struct edge_call*)buffer; + struct edge_call* edge_call = static_cast(buffer); uintptr_t call_args; unsigned long ret_val; diff --git a/sdk/examples/tests/test-runner.cpp b/sdk/examples/tests/test-runner.cpp index 5cfcacd87..6452da904 100644 --- a/sdk/examples/tests/test-runner.cpp +++ b/sdk/examples/tests/test-runner.cpp @@ -46,7 +46,7 @@ void copy_report(void* buffer) { Report report; - report.fromBytes((unsigned char*)buffer); + report.fromBytes(static_cast(buffer)); if (report.checkSignaturesOnly(_sanctum_dev_public_key)) { printf("Attestation report SIGNATURE is valid\n"); @@ -71,7 +71,7 @@ main(int argc, char** argv) { size_t untrusted_size = 2 * 1024 * 1024; size_t freemem_size = 48 * 1024 * 1024; - uintptr_t utm_ptr = (uintptr_t)DEFAULT_UNTRUSTED_PTR; + uintptr_t utm_ptr = static_cast(DEFAULT_UNTRUSTED_PTR); bool retval_exist = false; unsigned long retval = 0; diff --git a/sdk/include/host/elf32.h b/sdk/include/host/elf32.h index d3dac515b..fac5c1365 100644 --- a/sdk/include/host/elf32.h +++ b/sdk/include/host/elf32.h @@ -26,7 +26,7 @@ elf_isElf32(elf_t* elf) { static inline Elf32_Ehdr elf32_getHeader(elf_t* elf) { - return *(Elf32_Ehdr*)elf->elfFile; + return *static_cast(elf->elfFile); } static inline uintptr_t diff --git a/sdk/include/host/elf64.h b/sdk/include/host/elf64.h index 0aab6f626..dc02aa194 100644 --- a/sdk/include/host/elf64.h +++ b/sdk/include/host/elf64.h @@ -26,7 +26,7 @@ elf_isElf64(elf_t* elf) { static inline Elf64_Ehdr elf64_getHeader(elf_t* elf) { - return *(Elf64_Ehdr*)elf->elfFile; + return *static_cast(elf->elfFile); } static inline uintptr_t diff --git a/sdk/src/host/Enclave.cpp b/sdk/src/host/Enclave.cpp index 39b562b5a..091500be9 100644 --- a/sdk/src/host/Enclave.cpp +++ b/sdk/src/host/Enclave.cpp @@ -73,8 +73,9 @@ Enclave::initStack(std::uintptr_t start, std::size_t size, bool is_rt) { for (int i = 0; i < stk_pages; i++) { if (!pMemory->allocPage( va_start_stk, (std::uintptr_t)nullpage, - (is_rt ? RT_NOEXEC : USER_NOEXEC))) + (is_rt ? RT_NOEXEC : USER_NOEXEC))) { return false; +} va_start_stk += PAGE_SIZE; } @@ -126,16 +127,18 @@ Enclave::loadElf(ElfFile* elf) { char page[PAGE_SIZE]; memset(page, 0, PAGE_SIZE); memcpy(page + offset, (const void*)src, length); - if (!pMemory->allocPage(PAGE_DOWN(va), (std::uintptr_t)page, mode)) + if (!pMemory->allocPage(PAGE_DOWN(va), (std::uintptr_t)page, mode)) { return Error::PageAllocationFailure; +} va += length; src += length; } /* first load all pages that do not include .bss segment */ while (va + PAGE_SIZE <= file_end) { - if (!pMemory->allocPage(va, (std::uintptr_t)src, mode)) + if (!pMemory->allocPage(va, (std::uintptr_t)src, mode)) { return Error::PageAllocationFailure; +} src += PAGE_SIZE; va += PAGE_SIZE; @@ -147,15 +150,17 @@ Enclave::loadElf(ElfFile* elf) { char page[PAGE_SIZE]; memset(page, 0, PAGE_SIZE); memcpy(page, (const void*)src, static_cast(file_end - va)); - if (!pMemory->allocPage(va, (std::uintptr_t)page, mode)) + if (!pMemory->allocPage(va, (std::uintptr_t)page, mode)) { return Error::PageAllocationFailure; +} va += PAGE_SIZE; } /* finally, load the remaining .bss segments */ while (va < memory_end) { - if (!pMemory->allocPage(va, (std::uintptr_t)nullpage, mode)) + if (!pMemory->allocPage(va, (std::uintptr_t)nullpage, mode)) { return Error::PageAllocationFailure; +} va += PAGE_SIZE; } } @@ -259,7 +264,7 @@ Enclave::prepareEnclave(std::uintptr_t alternatePhysAddr) { Error Enclave::init(const char* eapppath, const char* runtimepath, Params _params) { - return this->init(eapppath, runtimepath, _params, (std::uintptr_t)0); + return this->init(eapppath, runtimepath, _params, static_cast(0)); } const char* diff --git a/sdk/src/host/Memory.cpp b/sdk/src/host/Memory.cpp index c585790ef..da36f6313 100644 --- a/sdk/src/host/Memory.cpp +++ b/sdk/src/host/Memory.cpp @@ -79,13 +79,13 @@ Memory::allocPage(std::uintptr_t va, std::uintptr_t src, unsigned int mode) { case RT_FULL: { *pte = pte_create(page_addr, PTE_D | PTE_A | PTE_R | PTE_W | PTE_X | PTE_V); - writeMem(src, (std::uintptr_t)page_addr << PAGE_BITS, PAGE_SIZE); + writeMem(src, page_addr << PAGE_BITS, PAGE_SIZE); break; } case USER_FULL: { *pte = pte_create( page_addr, PTE_D | PTE_A | PTE_R | PTE_W | PTE_X | PTE_U | PTE_V); - writeMem(src, (std::uintptr_t)page_addr << PAGE_BITS, PAGE_SIZE); + writeMem(src, page_addr << PAGE_BITS, PAGE_SIZE); break; } case UTM_FULL: { @@ -141,11 +141,12 @@ Memory::__ept_walk(std::uintptr_t addr) { std::uintptr_t Memory::epm_va_to_pa(std::uintptr_t addr) { pte* pte = __ept_walk(addr); - if (pte) + if (pte) { return pte_ppn(*pte) << RISCV_PGSHIFT; - else + } else { return 0; } +} /* This function pre-allocates the required page tables so that * the virtual addresses are linearly mapped to the physical memory */ @@ -194,10 +195,11 @@ Memory::validateAndHashEpm( } /* propagate the highest bit of the VA */ - if (level == RISCV_PGLEVEL_TOP && i & RISCV_PGTABLE_HIGHEST_BIT) + if (level == RISCV_PGLEVEL_TOP && i & RISCV_PGTABLE_HIGHEST_BIT) { vpn = ((-1UL << RISCV_PGLEVEL_BITS) | (i & RISCV_PGLEVEL_MASK)); - else + } else { vpn = ((vaddr << RISCV_PGLEVEL_BITS) | (i & RISCV_PGLEVEL_MASK)); +} std::uintptr_t va_start = vpn << RISCV_PGSHIFT; diff --git a/sdk/src/verifier/Report.cpp b/sdk/src/verifier/Report.cpp index cb94201d2..ae5595460 100644 --- a/sdk/src/verifier/Report.cpp +++ b/sdk/src/verifier/Report.cpp @@ -18,7 +18,7 @@ Report::BytesToHex(byte* bytes, size_t len) { std::string str; for (i = 0; i < len; i += 1) { std::stringstream ss; - ss << std::setfill('0') << std::setw(2) << std::hex << (uintptr_t)bytes[i]; + ss << std::setfill('0') << std::setw(2) << std::hex << static_cast(bytes[i]); str += ss.str(); } @@ -33,7 +33,7 @@ Report::HexToBytes(byte* bytes, size_t len, std::string hexstr) { std::stringstream ss; ss << hexstr.substr(i * 2, 2); ss >> std::hex >> data; - bytes[i] = (byte)data; + bytes[i] = static_cast(data); } } diff --git a/sdk/src/verifier/json11.cpp b/sdk/src/verifier/json11.cpp index e9003e1ca..52addce90 100644 --- a/sdk/src/verifier/json11.cpp +++ b/sdk/src/verifier/json11.cpp @@ -372,10 +372,11 @@ JsonObject::operator[](const string& key) const { } const Json& JsonArray::operator[](size_t i) const { - if (i >= m_value.size()) + if (i >= m_value.size()) { return static_null(); - else - return m_value[i]; + } else { + r +}eturn m_value[i]; } /* * * * * * * * * * * * * * * * * * * * @@ -455,8 +456,9 @@ struct JsonParser final { * Advance until the current character is non-whitespace. */ void consume_whitespace() { - while (str[i] == ' ' || str[i] == '\r' || str[i] == '\n' || str[i] == '\t') + while (str[i] == ' ' || str[i] == '\r' || str[i] == '\n' || str[i] == '\t') { i++; +} } /* consume_comment() @@ -467,8 +469,9 @@ struct JsonParser final { bool comment_found = false; if (str[i] == '/') { i++; - if (i == str.size()) + if (i == str.size()) { return fail("unexpected end of input after start of comment", false); +} if (str[i] == '/') { // inline comment i++; // advance until next line, or end of input @@ -478,20 +481,23 @@ struct JsonParser final { comment_found = true; } else if (str[i] == '*') { // multiline comment i++; - if (i > str.size() - 2) + if (i > str.size() - 2) { return fail( "unexpected end of input inside multi-line comment", false); +} // advance until closing tokens while (!(str[i] == '*' && str[i + 1] == '/')) { i++; - if (i > str.size() - 2) + if (i > str.size() - 2) { return fail( "unexpected end of input inside multi-line comment", false); +} } i += 2; comment_found = true; - } else + } else { return fail("malformed comment", false); +} } return comment_found; } @@ -519,8 +525,8 @@ struct JsonParser final { */ char get_next_token() { consume_garbage(); - if (failed) return (char)0; - if (i == str.size()) return fail("unexpected end of input", (char)0); + if (failed) return static_cast(0); + if (i == str.size()) return fail("unexpected end of input", static_cast(0)); return str[i++]; } @@ -566,8 +572,9 @@ struct JsonParser final { return out; } - if (in_range(ch, 0, 0x1f)) + if (in_range(ch, 0, 0x1f)) { return fail("unescaped " + esc(ch) + " in string", ""); +} // The usual case: non-escaped characters if (ch != '\\') { @@ -593,8 +600,9 @@ struct JsonParser final { } for (size_t j = 0; j < 4; j++) { if (!in_range(esc[j], 'a', 'f') && !in_range(esc[j], 'A', 'F') && - !in_range(esc[j], '0', '9')) + !in_range(esc[j], '0', '9')) { return fail("bad \\u escape: " + esc, ""); +} } long codepoint = strtol(esc.data(), nullptr, 16); @@ -656,8 +664,9 @@ struct JsonParser final { // Integer part if (str[i] == '0') { i++; - if (in_range(str[i], '0', '9')) + if (in_range(str[i], '0', '9')) { return fail("leading 0s not permitted in numbers"); +} } else if (in_range(str[i], '1', '9')) { i++; while (in_range(str[i], '0', '9')) i++; @@ -674,8 +683,9 @@ struct JsonParser final { // Decimal part if (str[i] == '.') { i++; - if (!in_range(str[i], '0', '9')) + if (!in_range(str[i], '0', '9')) { return fail("at least one digit required in fractional part"); +} while (in_range(str[i], '0', '9')) i++; } @@ -686,8 +696,9 @@ struct JsonParser final { if (str[i] == '+' || str[i] == '-') i++; - if (!in_range(str[i], '0', '9')) + if (!in_range(str[i], '0', '9')) { return fail("at least one digit required in exponent"); +} while (in_range(str[i], '0', '9')) i++; } From 553e10691e0cb503f266702e1b9069aa2e9eeca9 Mon Sep 17 00:00:00 2001 From: red-robby Date: Fri, 17 Feb 2023 17:44:08 -0800 Subject: [PATCH 13/14] Add missing headers in SDK example test files --- sdk/examples/tests/attestation/edge_wrapper.h | 2 ++ sdk/examples/tests/data-sealing/data-sealing.h | 1 + 2 files changed, 3 insertions(+) diff --git a/sdk/examples/tests/attestation/edge_wrapper.h b/sdk/examples/tests/attestation/edge_wrapper.h index 42f82003d..1ae7caa0d 100644 --- a/sdk/examples/tests/attestation/edge_wrapper.h +++ b/sdk/examples/tests/attestation/edge_wrapper.h @@ -5,6 +5,8 @@ #ifndef _EDGE_WRAPPER_H_ #define _EDGE_WRAPPER_H_ +#include + void edge_init(); diff --git a/sdk/examples/tests/data-sealing/data-sealing.h b/sdk/examples/tests/data-sealing/data-sealing.h index 323492971..66f70d1ca 100644 --- a/sdk/examples/tests/data-sealing/data-sealing.h +++ b/sdk/examples/tests/data-sealing/data-sealing.h @@ -10,6 +10,7 @@ */ #include "app/sealing.h" +#include #define OCALL_PRINT_BUFFER 1 From c5d68bf79bdc73113dd2cafc0953cc6d49f3e077 Mon Sep 17 00:00:00 2001 From: red-robby Date: Fri, 17 Feb 2023 18:07:31 -0800 Subject: [PATCH 14/14] Add another missing header --- sdk/examples/tests/data-sealing/data-sealing.h | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/examples/tests/data-sealing/data-sealing.h b/sdk/examples/tests/data-sealing/data-sealing.h index 66f70d1ca..a048ac85b 100644 --- a/sdk/examples/tests/data-sealing/data-sealing.h +++ b/sdk/examples/tests/data-sealing/data-sealing.h @@ -11,6 +11,7 @@ #include "app/sealing.h" #include +#include #define OCALL_PRINT_BUFFER 1