cjson
fuzzing
inputs
test1 test10 test11 test2 test3 test3.bu test3.uf test3.uu test4 test5 test6 test7 test8 test9library_config
cJSONConfig.cmake.in cJSONConfigVersion.cmake.in libcjson.pc.in libcjson_utils.pc.in uninstall.cmaketests
inputs
test1 test1.expected test10 test10.expected test11 test11.expected test2 test2.expected test3 test3.expected test4 test4.expected test5 test5.expected test6 test7 test7.expected test8 test8.expected test9 test9.expectedjson-patch-tests
.editorconfig .gitignore .npmignore README.md cjson-utils-tests.json package.json spec_tests.json tests.jsonunity
auto
colour_prompt.rb colour_reporter.rb generate_config.yml generate_module.rb generate_test_runner.rb parse_output.rb stylize_as_junit.rb test_file_filter.rb type_sanitizer.rb unity_test_summary.py unity_test_summary.rb unity_to_junit.pydocs
ThrowTheSwitchCodingStandard.md UnityAssertionsCheatSheetSuitableforPrintingandPossiblyFraming.pdf UnityAssertionsReference.md UnityConfigurationGuide.md UnityGettingStartedGuide.md UnityHelperScriptsGuide.md license.txtexamples
unity_config.hcurl
.github
scripts
cleancmd.pl cmp-config.pl cmp-pkg-config.sh codespell-ignore.words codespell.sh distfiles.sh pyspelling.words pyspelling.yaml randcurl.pl requirements-docs.txt requirements-proselint.txt requirements.txt shellcheck-ci.sh shellcheck.sh spellcheck.curl trimmarkdownheader.pl typos.sh typos.toml verify-examples.pl verify-synopsis.pl yamlcheck.sh yamlcheck.yamlworkflows
appveyor-status.yml checkdocs.yml checksrc.yml checkurls.yml codeql.yml configure-vs-cmake.yml curl-for-win.yml distcheck.yml fuzz.yml http3-linux.yml label.yml linux-old.yml linux.yml macos.yml non-native.yml windows.ymlCMake
CurlSymbolHiding.cmake CurlTests.c FindBrotli.cmake FindCares.cmake FindGSS.cmake FindGnuTLS.cmake FindLDAP.cmake FindLibbacktrace.cmake FindLibgsasl.cmake FindLibidn2.cmake FindLibpsl.cmake FindLibssh.cmake FindLibssh2.cmake FindLibuv.cmake FindMbedTLS.cmake FindNGHTTP2.cmake FindNGHTTP3.cmake FindNGTCP2.cmake FindNettle.cmake FindQuiche.cmake FindRustls.cmake FindWolfSSL.cmake FindZstd.cmake Macros.cmake OtherTests.cmake PickyWarnings.cmake Utilities.cmake cmake_uninstall.in.cmake curl-config.in.cmake unix-cache.cmake win32-cache.cmakedocs
cmdline-opts
.gitignore CMakeLists.txt MANPAGE.md Makefile.am Makefile.inc _AUTHORS.md _BUGS.md _DESCRIPTION.md _ENVIRONMENT.md _EXITCODES.md _FILES.md _GLOBBING.md _NAME.md _OPTIONS.md _OUTPUT.md _PROGRESS.md _PROTOCOLS.md _PROXYPREFIX.md _SEEALSO.md _SYNOPSIS.md _URL.md _VARIABLES.md _VERSION.md _WWW.md abstract-unix-socket.md alt-svc.md anyauth.md append.md aws-sigv4.md basic.md ca-native.md cacert.md capath.md cert-status.md cert-type.md cert.md ciphers.md compressed-ssh.md compressed.md config.md connect-timeout.md connect-to.md continue-at.md cookie-jar.md cookie.md create-dirs.md create-file-mode.md crlf.md crlfile.md curves.md data-ascii.md data-binary.md data-raw.md data-urlencode.md data.md delegation.md digest.md disable-eprt.md disable-epsv.md disable.md disallow-username-in-url.md dns-interface.md dns-ipv4-addr.md dns-ipv6-addr.md dns-servers.md doh-cert-status.md doh-insecure.md doh-url.md dump-ca-embed.md dump-header.md ech.md egd-file.md engine.md etag-compare.md etag-save.md expect100-timeout.md fail-early.md fail-with-body.md fail.md false-start.md follow.md form-escape.md form-string.md form.md ftp-account.md ftp-alternative-to-user.md ftp-create-dirs.md ftp-method.md ftp-pasv.md ftp-port.md ftp-pret.md ftp-skip-pasv-ip.md ftp-ssl-ccc-mode.md ftp-ssl-ccc.md ftp-ssl-control.md get.md globoff.md happy-eyeballs-timeout-ms.md haproxy-clientip.md haproxy-protocol.md head.md header.md help.md hostpubmd5.md hostpubsha256.md hsts.md http0.9.md http1.0.md http1.1.md http2-prior-knowledge.md http2.md http3-only.md http3.md ignore-content-length.md insecure.md interface.md ip-tos.md ipfs-gateway.md ipv4.md ipv6.md json.md junk-session-cookies.md keepalive-cnt.md keepalive-time.md key-type.md key.md knownhosts.md krb.md libcurl.md limit-rate.md list-only.md local-port.md location-trusted.md location.md login-options.md mail-auth.md mail-from.md mail-rcpt-allowfails.md mail-rcpt.md mainpage.idx manual.md max-filesize.md max-redirs.md max-time.md metalink.md mptcp.md negotiate.md netrc-file.md netrc-optional.md netrc.md next.md no-alpn.md no-buffer.md no-clobber.md no-keepalive.md no-npn.md no-progress-meter.md no-sessionid.md noproxy.md ntlm-wb.md ntlm.md oauth2-bearer.md out-null.md output-dir.md output.md parallel-immediate.md parallel-max-host.md parallel-max.md parallel.md pass.md path-as-is.md pinnedpubkey.md post301.md post302.md post303.md preproxy.md progress-bar.md proto-default.md proto-redir.md proto.md proxy-anyauth.md proxy-basic.md proxy-ca-native.md proxy-cacert.md proxy-capath.md proxy-cert-type.md proxy-cert.md proxy-ciphers.md proxy-crlfile.md proxy-digest.md proxy-header.md proxy-http2.md proxy-insecure.md proxy-key-type.md proxy-key.md proxy-negotiate.md proxy-ntlm.md proxy-pass.md proxy-pinnedpubkey.md proxy-service-name.md proxy-ssl-allow-beast.md proxy-ssl-auto-client-cert.md proxy-tls13-ciphers.md proxy-tlsauthtype.md proxy-tlspassword.md proxy-tlsuser.md proxy-tlsv1.md proxy-user.md proxy.md proxy1.0.md proxytunnel.md pubkey.md quote.md random-file.md range.md rate.md raw.md referer.md remote-header-name.md remote-name-all.md remote-name.md remote-time.md remove-on-error.md request-target.md request.md resolve.md retry-all-errors.md retry-connrefused.md retry-delay.md retry-max-time.md retry.md sasl-authzid.md sasl-ir.md service-name.md show-error.md show-headers.md sigalgs.md silent.md skip-existing.md socks4.md socks4a.md socks5-basic.md socks5-gssapi-nec.md socks5-gssapi-service.md socks5-gssapi.md socks5-hostname.md socks5.md speed-limit.md speed-time.md ssl-allow-beast.md ssl-auto-client-cert.md ssl-no-revoke.md ssl-reqd.md ssl-revoke-best-effort.md ssl-sessions.md ssl.md sslv2.md sslv3.md stderr.md styled-output.md suppress-connect-headers.md tcp-fastopen.md tcp-nodelay.md telnet-option.md tftp-blksize.md tftp-no-options.md time-cond.md tls-earlydata.md tls-max.md tls13-ciphers.md tlsauthtype.md tlspassword.md tlsuser.md tlsv1.0.md tlsv1.1.md tlsv1.2.md tlsv1.3.md tlsv1.md tr-encoding.md trace-ascii.md trace-config.md trace-ids.md trace-time.md trace.md unix-socket.md upload-file.md upload-flags.md url-query.md url.md use-ascii.md user-agent.md user.md variable.md verbose.md version.md vlan-priority.md write-out.md xattr.mdexamples
.checksrc .gitignore 10-at-a-time.c CMakeLists.txt Makefile.am Makefile.example Makefile.inc README.md adddocsref.pl address-scope.c altsvc.c anyauthput.c block_ip.c cacertinmem.c certinfo.c chkspeed.c connect-to.c cookie_interface.c crawler.c debug.c default-scheme.c ephiperfifo.c evhiperfifo.c externalsocket.c fileupload.c ftp-delete.c ftp-wildcard.c ftpget.c ftpgetinfo.c ftpgetresp.c ftpsget.c ftpupload.c ftpuploadfrommem.c ftpuploadresume.c getinfo.c getinmemory.c getredirect.c getreferrer.c ghiper.c headerapi.c hiperfifo.c hsts-preload.c htmltidy.c htmltitle.cpp http-options.c http-post.c http2-download.c http2-pushinmemory.c http2-serverpush.c http2-upload.c http3-present.c http3.c httpcustomheader.c httpput-postfields.c httpput.c https.c imap-append.c imap-authzid.c imap-copy.c imap-create.c imap-delete.c imap-examine.c imap-fetch.c imap-list.c imap-lsub.c imap-multi.c imap-noop.c imap-search.c imap-ssl.c imap-store.c imap-tls.c interface.c ipv6.c keepalive.c localport.c log_failed_transfers.c maxconnects.c multi-app.c multi-debugcallback.c multi-double.c multi-event.c multi-formadd.c multi-legacy.c multi-post.c multi-single.c multi-uv.c netrc.c parseurl.c persistent.c pop3-authzid.c pop3-dele.c pop3-list.c pop3-multi.c pop3-noop.c pop3-retr.c pop3-ssl.c pop3-stat.c pop3-tls.c pop3-top.c pop3-uidl.c post-callback.c postinmemory.c postit2-formadd.c postit2.c progressfunc.c protofeats.c range.c resolve.c rtsp-options.c sendrecv.c sepheaders.c sessioninfo.c sftpget.c sftpuploadresume.c shared-connection-cache.c simple.c simplepost.c simplessl.c smooth-gtk-thread.c smtp-authzid.c smtp-expn.c smtp-mail.c smtp-mime.c smtp-multi.c smtp-ssl.c smtp-tls.c smtp-vrfy.c sslbackend.c synctime.c threaded.c unixsocket.c url2file.c urlapi.c usercertinmem.c version-check.pl websocket-cb.c websocket-updown.c websocket.c xmlstream.cinternals
BUFQ.md BUFREF.md CHECKSRC.md CLIENT-READERS.md CLIENT-WRITERS.md CODE_STYLE.md CONNECTION-FILTERS.md CREDENTIALS.md CURLX.md DYNBUF.md HASH.md LLIST.md MID.md MQTT.md MULTI-EV.md NEW-PROTOCOL.md PEERS.md PORTING.md RATELIMITS.md README.md SCORECARD.md SPLAY.md STRPARSE.md THRDPOOL-AND-QUEUE.md TIME-KEEPING.md TLS-SESSIONS.md UINT_SETS.md WEBSOCKET.mdlibcurl
opts
CMakeLists.txt CURLINFO_ACTIVESOCKET.md CURLINFO_APPCONNECT_TIME.md CURLINFO_APPCONNECT_TIME_T.md CURLINFO_CAINFO.md CURLINFO_CAPATH.md CURLINFO_CERTINFO.md CURLINFO_CONDITION_UNMET.md CURLINFO_CONNECT_TIME.md CURLINFO_CONNECT_TIME_T.md CURLINFO_CONN_ID.md CURLINFO_CONTENT_LENGTH_DOWNLOAD.md CURLINFO_CONTENT_LENGTH_DOWNLOAD_T.md CURLINFO_CONTENT_LENGTH_UPLOAD.md CURLINFO_CONTENT_LENGTH_UPLOAD_T.md CURLINFO_CONTENT_TYPE.md CURLINFO_COOKIELIST.md CURLINFO_EARLYDATA_SENT_T.md CURLINFO_EFFECTIVE_METHOD.md CURLINFO_EFFECTIVE_URL.md CURLINFO_FILETIME.md CURLINFO_FILETIME_T.md CURLINFO_FTP_ENTRY_PATH.md CURLINFO_HEADER_SIZE.md CURLINFO_HTTPAUTH_AVAIL.md CURLINFO_HTTPAUTH_USED.md CURLINFO_HTTP_CONNECTCODE.md CURLINFO_HTTP_VERSION.md CURLINFO_LASTSOCKET.md CURLINFO_LOCAL_IP.md CURLINFO_LOCAL_PORT.md CURLINFO_NAMELOOKUP_TIME.md CURLINFO_NAMELOOKUP_TIME_T.md CURLINFO_NUM_CONNECTS.md CURLINFO_OS_ERRNO.md CURLINFO_POSTTRANSFER_TIME_T.md CURLINFO_PRETRANSFER_TIME.md CURLINFO_PRETRANSFER_TIME_T.md CURLINFO_PRIMARY_IP.md CURLINFO_PRIMARY_PORT.md CURLINFO_PRIVATE.md CURLINFO_PROTOCOL.md CURLINFO_PROXYAUTH_AVAIL.md CURLINFO_PROXYAUTH_USED.md CURLINFO_PROXY_ERROR.md CURLINFO_PROXY_SSL_VERIFYRESULT.md CURLINFO_QUEUE_TIME_T.md CURLINFO_REDIRECT_COUNT.md CURLINFO_REDIRECT_TIME.md CURLINFO_REDIRECT_TIME_T.md CURLINFO_REDIRECT_URL.md CURLINFO_REFERER.md CURLINFO_REQUEST_SIZE.md CURLINFO_RESPONSE_CODE.md CURLINFO_RETRY_AFTER.md CURLINFO_RTSP_CLIENT_CSEQ.md CURLINFO_RTSP_CSEQ_RECV.md CURLINFO_RTSP_SERVER_CSEQ.md CURLINFO_RTSP_SESSION_ID.md CURLINFO_SCHEME.md CURLINFO_SIZE_DELIVERED.md CURLINFO_SIZE_DOWNLOAD.md CURLINFO_SIZE_DOWNLOAD_T.md CURLINFO_SIZE_UPLOAD.md CURLINFO_SIZE_UPLOAD_T.md CURLINFO_SPEED_DOWNLOAD.md CURLINFO_SPEED_DOWNLOAD_T.md CURLINFO_SPEED_UPLOAD.md CURLINFO_SPEED_UPLOAD_T.md CURLINFO_SSL_ENGINES.md CURLINFO_SSL_VERIFYRESULT.md CURLINFO_STARTTRANSFER_TIME.md CURLINFO_STARTTRANSFER_TIME_T.md CURLINFO_TLS_SESSION.md CURLINFO_TLS_SSL_PTR.md CURLINFO_TOTAL_TIME.md CURLINFO_TOTAL_TIME_T.md CURLINFO_USED_PROXY.md CURLINFO_XFER_ID.md CURLMINFO_XFERS_ADDED.md CURLMINFO_XFERS_CURRENT.md CURLMINFO_XFERS_DONE.md CURLMINFO_XFERS_PENDING.md CURLMINFO_XFERS_RUNNING.md CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE.md CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE.md CURLMOPT_MAXCONNECTS.md CURLMOPT_MAX_CONCURRENT_STREAMS.md CURLMOPT_MAX_HOST_CONNECTIONS.md CURLMOPT_MAX_PIPELINE_LENGTH.md CURLMOPT_MAX_TOTAL_CONNECTIONS.md CURLMOPT_NETWORK_CHANGED.md CURLMOPT_NOTIFYDATA.md CURLMOPT_NOTIFYFUNCTION.md CURLMOPT_PIPELINING.md CURLMOPT_PIPELINING_SERVER_BL.md CURLMOPT_PIPELINING_SITE_BL.md CURLMOPT_PUSHDATA.md CURLMOPT_PUSHFUNCTION.md CURLMOPT_QUICK_EXIT.md CURLMOPT_RESOLVE_THREADS_MAX.md CURLMOPT_SOCKETDATA.md CURLMOPT_SOCKETFUNCTION.md CURLMOPT_TIMERDATA.md CURLMOPT_TIMERFUNCTION.md CURLOPT_ABSTRACT_UNIX_SOCKET.md CURLOPT_ACCEPTTIMEOUT_MS.md CURLOPT_ACCEPT_ENCODING.md CURLOPT_ADDRESS_SCOPE.md CURLOPT_ALTSVC.md CURLOPT_ALTSVC_CTRL.md CURLOPT_APPEND.md CURLOPT_AUTOREFERER.md CURLOPT_AWS_SIGV4.md CURLOPT_BUFFERSIZE.md CURLOPT_CAINFO.md CURLOPT_CAINFO_BLOB.md CURLOPT_CAPATH.md CURLOPT_CA_CACHE_TIMEOUT.md CURLOPT_CERTINFO.md CURLOPT_CHUNK_BGN_FUNCTION.md CURLOPT_CHUNK_DATA.md CURLOPT_CHUNK_END_FUNCTION.md CURLOPT_CLOSESOCKETDATA.md CURLOPT_CLOSESOCKETFUNCTION.md CURLOPT_CONNECTTIMEOUT.md CURLOPT_CONNECTTIMEOUT_MS.md CURLOPT_CONNECT_ONLY.md CURLOPT_CONNECT_TO.md CURLOPT_CONV_FROM_NETWORK_FUNCTION.md CURLOPT_CONV_FROM_UTF8_FUNCTION.md CURLOPT_CONV_TO_NETWORK_FUNCTION.md CURLOPT_COOKIE.md CURLOPT_COOKIEFILE.md CURLOPT_COOKIEJAR.md CURLOPT_COOKIELIST.md CURLOPT_COOKIESESSION.md CURLOPT_COPYPOSTFIELDS.md CURLOPT_CRLF.md CURLOPT_CRLFILE.md CURLOPT_CURLU.md CURLOPT_CUSTOMREQUEST.md CURLOPT_DEBUGDATA.md CURLOPT_DEBUGFUNCTION.md CURLOPT_DEFAULT_PROTOCOL.md CURLOPT_DIRLISTONLY.md CURLOPT_DISALLOW_USERNAME_IN_URL.md CURLOPT_DNS_CACHE_TIMEOUT.md CURLOPT_DNS_INTERFACE.md CURLOPT_DNS_LOCAL_IP4.md CURLOPT_DNS_LOCAL_IP6.md CURLOPT_DNS_SERVERS.md CURLOPT_DNS_SHUFFLE_ADDRESSES.md CURLOPT_DNS_USE_GLOBAL_CACHE.md CURLOPT_DOH_SSL_VERIFYHOST.md CURLOPT_DOH_SSL_VERIFYPEER.md CURLOPT_DOH_SSL_VERIFYSTATUS.md CURLOPT_DOH_URL.md CURLOPT_ECH.md CURLOPT_EGDSOCKET.md CURLOPT_ERRORBUFFER.md CURLOPT_EXPECT_100_TIMEOUT_MS.md CURLOPT_FAILONERROR.md CURLOPT_FILETIME.md CURLOPT_FNMATCH_DATA.md CURLOPT_FNMATCH_FUNCTION.md CURLOPT_FOLLOWLOCATION.md CURLOPT_FORBID_REUSE.md CURLOPT_FRESH_CONNECT.md CURLOPT_FTPPORT.md CURLOPT_FTPSSLAUTH.md CURLOPT_FTP_ACCOUNT.md CURLOPT_FTP_ALTERNATIVE_TO_USER.md CURLOPT_FTP_CREATE_MISSING_DIRS.md CURLOPT_FTP_FILEMETHOD.md CURLOPT_FTP_SKIP_PASV_IP.md CURLOPT_FTP_SSL_CCC.md CURLOPT_FTP_USE_EPRT.md CURLOPT_FTP_USE_EPSV.md CURLOPT_FTP_USE_PRET.md CURLOPT_GSSAPI_DELEGATION.md CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS.md CURLOPT_HAPROXYPROTOCOL.md CURLOPT_HAPROXY_CLIENT_IP.md CURLOPT_HEADER.md CURLOPT_HEADERDATA.md CURLOPT_HEADERFUNCTION.md CURLOPT_HEADEROPT.md CURLOPT_HSTS.md CURLOPT_HSTSREADDATA.md CURLOPT_HSTSREADFUNCTION.md CURLOPT_HSTSWRITEDATA.md CURLOPT_HSTSWRITEFUNCTION.md CURLOPT_HSTS_CTRL.md CURLOPT_HTTP09_ALLOWED.md CURLOPT_HTTP200ALIASES.md CURLOPT_HTTPAUTH.md CURLOPT_HTTPGET.md CURLOPT_HTTPHEADER.md CURLOPT_HTTPPOST.md CURLOPT_HTTPPROXYTUNNEL.md CURLOPT_HTTP_CONTENT_DECODING.md CURLOPT_HTTP_TRANSFER_DECODING.md CURLOPT_HTTP_VERSION.md CURLOPT_IGNORE_CONTENT_LENGTH.md CURLOPT_INFILESIZE.md CURLOPT_INFILESIZE_LARGE.md CURLOPT_INTERFACE.md CURLOPT_INTERLEAVEDATA.md CURLOPT_INTERLEAVEFUNCTION.md CURLOPT_IOCTLDATA.md CURLOPT_IOCTLFUNCTION.md CURLOPT_IPRESOLVE.md CURLOPT_ISSUERCERT.md CURLOPT_ISSUERCERT_BLOB.md CURLOPT_KEEP_SENDING_ON_ERROR.md CURLOPT_KEYPASSWD.md CURLOPT_KRBLEVEL.md CURLOPT_LOCALPORT.md CURLOPT_LOCALPORTRANGE.md CURLOPT_LOGIN_OPTIONS.md CURLOPT_LOW_SPEED_LIMIT.md CURLOPT_LOW_SPEED_TIME.md CURLOPT_MAIL_AUTH.md CURLOPT_MAIL_FROM.md CURLOPT_MAIL_RCPT.md CURLOPT_MAIL_RCPT_ALLOWFAILS.md CURLOPT_MAXAGE_CONN.md CURLOPT_MAXCONNECTS.md CURLOPT_MAXFILESIZE.md CURLOPT_MAXFILESIZE_LARGE.md CURLOPT_MAXLIFETIME_CONN.md CURLOPT_MAXREDIRS.md CURLOPT_MAX_RECV_SPEED_LARGE.md CURLOPT_MAX_SEND_SPEED_LARGE.md CURLOPT_MIMEPOST.md CURLOPT_MIME_OPTIONS.md CURLOPT_NETRC.md CURLOPT_NETRC_FILE.md CURLOPT_NEW_DIRECTORY_PERMS.md CURLOPT_NEW_FILE_PERMS.md CURLOPT_NOBODY.md CURLOPT_NOPROGRESS.md CURLOPT_NOPROXY.md CURLOPT_NOSIGNAL.md CURLOPT_OPENSOCKETDATA.md CURLOPT_OPENSOCKETFUNCTION.md CURLOPT_PASSWORD.md CURLOPT_PATH_AS_IS.md CURLOPT_PINNEDPUBLICKEY.md CURLOPT_PIPEWAIT.md CURLOPT_PORT.md CURLOPT_POST.md CURLOPT_POSTFIELDS.md CURLOPT_POSTFIELDSIZE.md CURLOPT_POSTFIELDSIZE_LARGE.md CURLOPT_POSTQUOTE.md CURLOPT_POSTREDIR.md CURLOPT_PREQUOTE.md CURLOPT_PREREQDATA.md CURLOPT_PREREQFUNCTION.md CURLOPT_PRE_PROXY.md CURLOPT_PRIVATE.md CURLOPT_PROGRESSDATA.md CURLOPT_PROGRESSFUNCTION.md CURLOPT_PROTOCOLS.md CURLOPT_PROTOCOLS_STR.md CURLOPT_PROXY.md CURLOPT_PROXYAUTH.md CURLOPT_PROXYHEADER.md CURLOPT_PROXYPASSWORD.md CURLOPT_PROXYPORT.md CURLOPT_PROXYTYPE.md CURLOPT_PROXYUSERNAME.md CURLOPT_PROXYUSERPWD.md CURLOPT_PROXY_CAINFO.md CURLOPT_PROXY_CAINFO_BLOB.md CURLOPT_PROXY_CAPATH.md CURLOPT_PROXY_CRLFILE.md CURLOPT_PROXY_ISSUERCERT.md CURLOPT_PROXY_ISSUERCERT_BLOB.md CURLOPT_PROXY_KEYPASSWD.md CURLOPT_PROXY_PINNEDPUBLICKEY.md CURLOPT_PROXY_SERVICE_NAME.md CURLOPT_PROXY_SSLCERT.md CURLOPT_PROXY_SSLCERTTYPE.md CURLOPT_PROXY_SSLCERT_BLOB.md CURLOPT_PROXY_SSLKEY.md CURLOPT_PROXY_SSLKEYTYPE.md CURLOPT_PROXY_SSLKEY_BLOB.md CURLOPT_PROXY_SSLVERSION.md CURLOPT_PROXY_SSL_CIPHER_LIST.md CURLOPT_PROXY_SSL_OPTIONS.md CURLOPT_PROXY_SSL_VERIFYHOST.md CURLOPT_PROXY_SSL_VERIFYPEER.md CURLOPT_PROXY_TLS13_CIPHERS.md CURLOPT_PROXY_TLSAUTH_PASSWORD.md CURLOPT_PROXY_TLSAUTH_TYPE.md CURLOPT_PROXY_TLSAUTH_USERNAME.md CURLOPT_PROXY_TRANSFER_MODE.md CURLOPT_PUT.md CURLOPT_QUICK_EXIT.md CURLOPT_QUOTE.md CURLOPT_RANDOM_FILE.md CURLOPT_RANGE.md CURLOPT_READDATA.md CURLOPT_READFUNCTION.md CURLOPT_REDIR_PROTOCOLS.md CURLOPT_REDIR_PROTOCOLS_STR.md CURLOPT_REFERER.md CURLOPT_REQUEST_TARGET.md CURLOPT_RESOLVE.md CURLOPT_RESOLVER_START_DATA.md CURLOPT_RESOLVER_START_FUNCTION.md CURLOPT_RESUME_FROM.md CURLOPT_RESUME_FROM_LARGE.md CURLOPT_RTSP_CLIENT_CSEQ.md CURLOPT_RTSP_REQUEST.md CURLOPT_RTSP_SERVER_CSEQ.md CURLOPT_RTSP_SESSION_ID.md CURLOPT_RTSP_STREAM_URI.md CURLOPT_RTSP_TRANSPORT.md CURLOPT_SASL_AUTHZID.md CURLOPT_SASL_IR.md CURLOPT_SEEKDATA.md CURLOPT_SEEKFUNCTION.md CURLOPT_SERVER_RESPONSE_TIMEOUT.md CURLOPT_SERVER_RESPONSE_TIMEOUT_MS.md CURLOPT_SERVICE_NAME.md CURLOPT_SHARE.md CURLOPT_SOCKOPTDATA.md CURLOPT_SOCKOPTFUNCTION.md CURLOPT_SOCKS5_AUTH.md CURLOPT_SOCKS5_GSSAPI_NEC.md CURLOPT_SOCKS5_GSSAPI_SERVICE.md CURLOPT_SSH_AUTH_TYPES.md CURLOPT_SSH_COMPRESSION.md CURLOPT_SSH_HOSTKEYDATA.md CURLOPT_SSH_HOSTKEYFUNCTION.md CURLOPT_SSH_HOST_PUBLIC_KEY_MD5.md CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256.md CURLOPT_SSH_KEYDATA.md CURLOPT_SSH_KEYFUNCTION.md CURLOPT_SSH_KNOWNHOSTS.md CURLOPT_SSH_PRIVATE_KEYFILE.md CURLOPT_SSH_PUBLIC_KEYFILE.md CURLOPT_SSLCERT.md CURLOPT_SSLCERTTYPE.md CURLOPT_SSLCERT_BLOB.md CURLOPT_SSLENGINE.md CURLOPT_SSLENGINE_DEFAULT.md CURLOPT_SSLKEY.md CURLOPT_SSLKEYTYPE.md CURLOPT_SSLKEY_BLOB.md CURLOPT_SSLVERSION.md CURLOPT_SSL_CIPHER_LIST.md CURLOPT_SSL_CTX_DATA.md CURLOPT_SSL_CTX_FUNCTION.md CURLOPT_SSL_EC_CURVES.md CURLOPT_SSL_ENABLE_ALPN.md CURLOPT_SSL_ENABLE_NPN.md CURLOPT_SSL_FALSESTART.md CURLOPT_SSL_OPTIONS.md CURLOPT_SSL_SESSIONID_CACHE.md CURLOPT_SSL_SIGNATURE_ALGORITHMS.md CURLOPT_SSL_VERIFYHOST.md CURLOPT_SSL_VERIFYPEER.md CURLOPT_SSL_VERIFYSTATUS.md CURLOPT_STDERR.md CURLOPT_STREAM_DEPENDS.md CURLOPT_STREAM_DEPENDS_E.md CURLOPT_STREAM_WEIGHT.md CURLOPT_SUPPRESS_CONNECT_HEADERS.md CURLOPT_TCP_FASTOPEN.md CURLOPT_TCP_KEEPALIVE.md CURLOPT_TCP_KEEPCNT.md CURLOPT_TCP_KEEPIDLE.md CURLOPT_TCP_KEEPINTVL.md CURLOPT_TCP_NODELAY.md CURLOPT_TELNETOPTIONS.md CURLOPT_TFTP_BLKSIZE.md CURLOPT_TFTP_NO_OPTIONS.md CURLOPT_TIMECONDITION.md CURLOPT_TIMEOUT.md CURLOPT_TIMEOUT_MS.md CURLOPT_TIMEVALUE.md CURLOPT_TIMEVALUE_LARGE.md CURLOPT_TLS13_CIPHERS.md CURLOPT_TLSAUTH_PASSWORD.md CURLOPT_TLSAUTH_TYPE.md CURLOPT_TLSAUTH_USERNAME.md CURLOPT_TRAILERDATA.md CURLOPT_TRAILERFUNCTION.md CURLOPT_TRANSFERTEXT.md CURLOPT_TRANSFER_ENCODING.md CURLOPT_UNIX_SOCKET_PATH.md CURLOPT_UNRESTRICTED_AUTH.md CURLOPT_UPKEEP_INTERVAL_MS.md CURLOPT_UPLOAD.md CURLOPT_UPLOAD_BUFFERSIZE.md CURLOPT_UPLOAD_FLAGS.md CURLOPT_URL.md CURLOPT_USERAGENT.md CURLOPT_USERNAME.md CURLOPT_USERPWD.md CURLOPT_USE_SSL.md CURLOPT_VERBOSE.md CURLOPT_WILDCARDMATCH.md CURLOPT_WRITEDATA.md CURLOPT_WRITEFUNCTION.md CURLOPT_WS_OPTIONS.md CURLOPT_XFERINFODATA.md CURLOPT_XFERINFOFUNCTION.md CURLOPT_XOAUTH2_BEARER.md CURLSHOPT_LOCKFUNC.md CURLSHOPT_SHARE.md CURLSHOPT_UNLOCKFUNC.md CURLSHOPT_UNSHARE.md CURLSHOPT_USERDATA.md Makefile.am Makefile.incinclude
curl
Makefile.am curl.h curlver.h easy.h header.h mprintf.h multi.h options.h stdcheaders.h system.h typecheck-gcc.h urlapi.h websockets.hlib
curlx
base64.c base64.h basename.c basename.h dynbuf.c dynbuf.h fopen.c fopen.h inet_ntop.c inet_ntop.h inet_pton.c inet_pton.h multibyte.c multibyte.h nonblock.c nonblock.h snprintf.c snprintf.h strcopy.c strcopy.h strdup.c strdup.h strerr.c strerr.h strparse.c strparse.h timediff.c timediff.h timeval.c timeval.h version_win32.c version_win32.h wait.c wait.h warnless.c warnless.h winapi.c winapi.hvauth
cleartext.c cram.c digest.c digest.h digest_sspi.c gsasl.c krb5_gssapi.c krb5_sspi.c ntlm.c ntlm_sspi.c oauth2.c spnego_gssapi.c spnego_sspi.c vauth.c vauth.hvquic
curl_ngtcp2.c curl_ngtcp2.h curl_quiche.c curl_quiche.h vquic-tls.c vquic-tls.h vquic.c vquic.h vquic_int.hvtls
apple.c apple.h cipher_suite.c cipher_suite.h gtls.c gtls.h hostcheck.c hostcheck.h keylog.c keylog.h mbedtls.c mbedtls.h openssl.c openssl.h rustls.c rustls.h schannel.c schannel.h schannel_int.h schannel_verify.c vtls.c vtls.h vtls_int.h vtls_scache.c vtls_scache.h vtls_spack.c vtls_spack.h wolfssl.c wolfssl.h x509asn1.c x509asn1.hm4
.gitignore curl-amissl.m4 curl-apple-sectrust.m4 curl-compilers.m4 curl-confopts.m4 curl-functions.m4 curl-gnutls.m4 curl-mbedtls.m4 curl-openssl.m4 curl-override.m4 curl-reentrant.m4 curl-rustls.m4 curl-schannel.m4 curl-sysconfig.m4 curl-wolfssl.m4 xc-am-iface.m4 xc-cc-check.m4 xc-lt-iface.m4 xc-val-flgs.m4 zz40-xc-ovr.m4 zz50-xc-ovr.m4projects
OS400
.checksrc README.OS400 ccsidcurl.c ccsidcurl.h config400.default curl.cmd curl.inc.in curlcl.c curlmain.c initscript.sh make-docs.sh make-include.sh make-lib.sh make-src.sh make-tests.sh makefile.sh os400sys.c os400sys.hWindows
tmpl
.gitattributes README.txt curl-all.sln curl.sln curl.vcxproj curl.vcxproj.filters libcurl.sln libcurl.vcxproj libcurl.vcxproj.filtersvms
Makefile.am backup_gnv_curl_src.com build_curl-config_script.com build_gnv_curl.com build_gnv_curl_pcsi_desc.com build_gnv_curl_pcsi_text.com build_gnv_curl_release_notes.com build_libcurl_pc.com build_vms.com clean_gnv_curl.com compare_curl_source.com config_h.com curl_crtl_init.c curl_gnv_build_steps.txt curl_release_note_start.txt curl_startup.com curlmsg.h curlmsg.msg curlmsg.sdl curlmsg_vms.h generate_config_vms_h_curl.com generate_vax_transfer.com gnv_conftest.c_first gnv_curl_configure.sh gnv_libcurl_symbols.opt gnv_link_curl.com macro32_exactcase.patch make_gnv_curl_install.sh make_pcsi_curl_kit_name.com pcsi_gnv_curl_file_list.txt pcsi_product_gnv_curl.com readme report_openssl_version.c setup_gnv_curl_build.com stage_curl_install.com vms_eco_level.hscripts
.checksrc CMakeLists.txt Makefile.am badwords badwords-all badwords.txt cd2cd cd2nroff cdall checksrc-all.pl checksrc.pl cmakelint.sh completion.pl contributors.sh contrithanks.sh coverage.sh delta dmaketgz extract-unit-protos firefox-db2pem.sh installcheck.sh maketgz managen mdlinkcheck mk-ca-bundle.pl mk-unity.pl nroff2cd perlcheck.sh pythonlint.sh randdisable release-notes.pl release-tools.sh schemetable.c singleuse.pl spacecheck.pl top-complexity top-length verify-release wcurlsrc
.checksrc .gitignore CMakeLists.txt Makefile.am Makefile.inc config2setopts.c config2setopts.h curl.rc curlinfo.c mk-file-embed.pl mkhelp.pl slist_wc.c slist_wc.h terminal.c terminal.h tool_cb_dbg.c tool_cb_dbg.h tool_cb_hdr.c tool_cb_hdr.h tool_cb_prg.c tool_cb_prg.h tool_cb_rea.c tool_cb_rea.h tool_cb_see.c tool_cb_see.h tool_cb_soc.c tool_cb_soc.h tool_cb_wrt.c tool_cb_wrt.h tool_cfgable.c tool_cfgable.h tool_dirhie.c tool_dirhie.h tool_doswin.c tool_doswin.h tool_easysrc.c tool_easysrc.h tool_filetime.c tool_filetime.h tool_findfile.c tool_findfile.h tool_formparse.c tool_formparse.h tool_getparam.c tool_getparam.h tool_getpass.c tool_getpass.h tool_help.c tool_help.h tool_helpers.c tool_helpers.h tool_hugehelp.h tool_ipfs.c tool_ipfs.h tool_libinfo.c tool_libinfo.h tool_listhelp.c tool_main.c tool_main.h tool_msgs.c tool_msgs.h tool_operate.c tool_operate.h tool_operhlp.c tool_operhlp.h tool_paramhlp.c tool_paramhlp.h tool_parsecfg.c tool_parsecfg.h tool_progress.c tool_progress.h tool_sdecls.h tool_setopt.c tool_setopt.h tool_setup.h tool_ssls.c tool_ssls.h tool_stderr.c tool_stderr.h tool_urlglob.c tool_urlglob.h tool_util.c tool_util.h tool_version.h tool_vms.c tool_vms.h tool_writeout.c tool_writeout.h tool_writeout_json.c tool_writeout_json.h tool_xattr.c tool_xattr.h var.c var.htests
certs
.gitignore CMakeLists.txt Makefile.am Makefile.inc genserv.pl srp-verifier-conf srp-verifier-db test-ca.cnf test-ca.prm test-client-cert.prm test-client-eku-only.prm test-localhost-san-first.prm test-localhost-san-last.prm test-localhost.nn.prm test-localhost.prm test-localhost0h.prmdata
.gitignore DISABLED Makefile.am data-xml1 data1400.c data1401.c data1402.c data1403.c data1404.c data1405.c data1406.c data1407.c data1420.c data1461.txt data1463.txt data1465.c data1481.c data1705-1.md data1705-2.md data1705-3.md data1705-4.md data1705-stdout.1 data1706-1.md data1706-2.md data1706-3.md data1706-4.md data1706-stdout.txt data320.html test1 test10 test100 test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 test1008 test1009 test101 test1010 test1011 test1012 test1013 test1014 test1015 test1016 test1017 test1018 test1019 test102 test1020 test1021 test1022 test1023 test1024 test1025 test1026 test1027 test1028 test1029 test103 test1030 test1031 test1032 test1033 test1034 test1035 test1036 test1037 test1038 test1039 test104 test1040 test1041 test1042 test1043 test1044 test1045 test1046 test1047 test1048 test1049 test105 test1050 test1051 test1052 test1053 test1054 test1055 test1056 test1057 test1058 test1059 test106 test1060 test1061 test1062 test1063 test1064 test1065 test1066 test1067 test1068 test1069 test107 test1070 test1071 test1072 test1073 test1074 test1075 test1076 test1077 test1078 test1079 test108 test1080 test1081 test1082 test1083 test1084 test1085 test1086 test1087 test1088 test1089 test109 test1090 test1091 test1092 test1093 test1094 test1095 test1096 test1097 test1098 test1099 test11 test110 test1100 test1101 test1102 test1103 test1104 test1105 test1106 test1107 test1108 test1109 test111 test1110 test1111 test1112 test1113 test1114 test1115 test1116 test1117 test1118 test1119 test112 test1120 test1121 test1122 test1123 test1124 test1125 test1126 test1127 test1128 test1129 test113 test1130 test1131 test1132 test1133 test1134 test1135 test1136 test1137 test1138 test1139 test114 test1140 test1141 test1142 test1143 test1144 test1145 test1146 test1147 test1148 test1149 test115 test1150 test1151 test1152 test1153 test1154 test1155 test1156 test1157 test1158 test1159 test116 test1160 test1161 test1162 test1163 test1164 test1165 test1166 test1167 test1168 test1169 test117 test1170 test1171 test1172 test1173 test1174 test1175 test1176 test1177 test1178 test1179 test118 test1180 test1181 test1182 test1183 test1184 test1185 test1186 test1187 test1188 test1189 test119 test1190 test1191 test1192 test1193 test1194 test1195 test1196 test1197 test1198 test1199 test12 test120 test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 test1208 test1209 test121 test1210 test1211 test1212 test1213 test1214 test1215 test1216 test1217 test1218 test1219 test122 test1220 test1221 test1222 test1223 test1224 test1225 test1226 test1227 test1228 test1229 test123 test1230 test1231 test1232 test1233 test1234 test1235 test1236 test1237 test1238 test1239 test124 test1240 test1241 test1242 test1243 test1244 test1245 test1246 test1247 test1248 test1249 test125 test1250 test1251 test1252 test1253 test1254 test1255 test1256 test1257 test1258 test1259 test126 test1260 test1261 test1262 test1263 test1264 test1265 test1266 test1267 test1268 test1269 test127 test1270 test1271 test1272 test1273 test1274 test1275 test1276 test1277 test1278 test1279 test128 test1280 test1281 test1282 test1283 test1284 test1285 test1286 test1287 test1288 test1289 test129 test1290 test1291 test1292 test1293 test1294 test1295 test1296 test1297 test1298 test1299 test13 test130 test1300 test1301 test1302 test1303 test1304 test1305 test1306 test1307 test1308 test1309 test131 test1310 test1311 test1312 test1313 test1314 test1315 test1316 test1317 test1318 test1319 test132 test1320 test1321 test1322 test1323 test1324 test1325 test1326 test1327 test1328 test1329 test133 test1330 test1331 test1332 test1333 test1334 test1335 test1336 test1337 test1338 test1339 test134 test1340 test1341 test1342 test1343 test1344 test1345 test1346 test1347 test1348 test1349 test135 test1350 test1351 test1352 test1353 test1354 test1355 test1356 test1357 test1358 test1359 test136 test1360 test1361 test1362 test1363 test1364 test1365 test1366 test1367 test1368 test1369 test137 test1370 test1371 test1372 test1373 test1374 test1375 test1376 test1377 test1378 test1379 test138 test1380 test1381 test1382 test1383 test1384 test1385 test1386 test1387 test1388 test1389 test139 test1390 test1391 test1392 test1393 test1394 test1395 test1396 test1397 test1398 test1399 test14 test140 test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 test1408 test1409 test141 test1410 test1411 test1412 test1413 test1414 test1415 test1416 test1417 test1418 test1419 test142 test1420 test1421 test1422 test1423 test1424 test1425 test1426 test1427 test1428 test1429 test143 test1430 test1431 test1432 test1433 test1434 test1435 test1436 test1437 test1438 test1439 test144 test1440 test1441 test1442 test1443 test1444 test1445 test1446 test1447 test1448 test1449 test145 test1450 test1451 test1452 test1453 test1454 test1455 test1456 test1457 test1458 test1459 test146 test1460 test1461 test1462 test1463 test1464 test1465 test1466 test1467 test1468 test1469 test147 test1470 test1471 test1472 test1473 test1474 test1475 test1476 test1477 test1478 test1479 test148 test1480 test1481 test1482 test1483 test1484 test1485 test1486 test1487 test1488 test1489 test149 test1490 test1491 test1492 test1493 test1494 test1495 test1496 test1497 test1498 test1499 test15 test150 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 test1508 test1509 test151 test1510 test1511 test1512 test1513 test1514 test1515 test1516 test1517 test1518 test1519 test152 test1520 test1521 test1522 test1523 test1524 test1525 test1526 test1527 test1528 test1529 test153 test1530 test1531 test1532 test1533 test1534 test1535 test1536 test1537 test1538 test1539 test154 test1540 test1541 test1542 test1543 test1544 test1545 test1546 test1547 test1548 test1549 test155 test1550 test1551 test1552 test1553 test1554 test1555 test1556 test1557 test1558 test1559 test156 test1560 test1561 test1562 test1563 test1564 test1565 test1566 test1567 test1568 test1569 test157 test1570 test1571 test1572 test1573 test1574 test1575 test1576 test1577 test1578 test1579 test158 test1580 test1581 test1582 test1583 test1584 test1585 test1586 test1587 test1588 test1589 test159 test1590 test1591 test1592 test1593 test1594 test1595 test1596 test1597 test1598 test1599 test16 test160 test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 test1608 test1609 test161 test1610 test1611 test1612 test1613 test1614 test1615 test1616 test1617 test1618 test1619 test162 test1620 test1621 test1622 test1623 test1624 test1625 test1626 test1627 test1628 test1629 test163 test1630 test1631 test1632 test1633 test1634 test1635 test1636 test1637 test1638 test1639 test164 test1640 test1641 test1642 test1643 test1644 test1645 test165 test1650 test1651 test1652 test1653 test1654 test1655 test1656 test1657 test1658 test1659 test166 test1660 test1661 test1662 test1663 test1664 test1665 test1666 test1667 test1668 test1669 test167 test1670 test1671 test1672 test1673 test1674 test1675 test1676 test168 test1680 test1681 test1682 test1683 test1684 test1685 test169 test17 test170 test1700 test1701 test1702 test1703 test1704 test1705 test1706 test1707 test1708 test1709 test171 test1710 test1711 test1712 test1713 test1714 test1715 test172 test1720 test1721 test173 test174 test175 test176 test177 test178 test179 test18 test180 test1800 test1801 test1802 test181 test182 test183 test184 test1847 test1848 test1849 test185 test1850 test1851 test186 test187 test188 test189 test19 test190 test1900 test1901 test1902 test1903 test1904 test1905 test1906 test1907 test1908 test1909 test191 test1910 test1911 test1912 test1913 test1914 test1915 test1916 test1917 test1918 test1919 test192 test1920 test1921 test193 test1933 test1934 test1935 test1936 test1937 test1938 test1939 test194 test1940 test1941 test1942 test1943 test1944 test1945 test1946 test1947 test1948 test195 test1955 test1956 test1957 test1958 test1959 test196 test1960 test1964 test1965 test1966 test197 test1970 test1971 test1972 test1973 test1974 test1975 test1976 test1977 test1978 test1979 test198 test1980 test1981 test1982 test1983 test1984 test199 test2 test20 test200 test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 test2008 test2009 test201 test2010 test2011 test2012 test2013 test2014 test202 test2023 test2024 test2025 test2026 test2027 test2028 test2029 test203 test2030 test2031 test2032 test2033 test2034 test2035 test2037 test2038 test2039 test204 test2040 test2041 test2042 test2043 test2044 test2045 test2046 test2047 test2048 test2049 test205 test2050 test2051 test2052 test2053 test2054 test2055 test2056 test2057 test2058 test2059 test206 test2060 test2061 test2062 test2063 test2064 test2065 test2066 test2067 test2068 test2069 test207 test2070 test2071 test2072 test2073 test2074 test2075 test2076 test2077 test2078 test2079 test208 test2080 test2081 test2082 test2083 test2084 test2085 test2086 test2087 test2088 test2089 test209 test2090 test2091 test2092 test21 test210 test2100 test2101 test2102 test2103 test2104 test211 test212 test213 test214 test215 test216 test217 test218 test219 test22 test220 test2200 test2201 test2202 test2203 test2204 test2205 test2206 test2207 test221 test222 test223 test224 test225 test226 test227 test228 test229 test23 test230 test2300 test2301 test2302 test2303 test2304 test2306 test2307 test2308 test2309 test231 test232 test233 test234 test235 test236 test237 test238 test239 test24 test240 test2400 test2401 test2402 test2403 test2404 test2405 test2406 test2407 test2408 test2409 test241 test2410 test2411 test242 test243 test244 test245 test246 test247 test248 test249 test25 test250 test2500 test2501 test2502 test2503 test2504 test2505 test2506 test251 test252 test253 test254 test255 test256 test257 test258 test259 test26 test260 test2600 test2601 test2602 test2603 test2604 test2605 test261 test262 test263 test264 test265 test266 test267 test268 test269 test27 test270 test2700 test2701 test2702 test2703 test2704 test2705 test2706 test2707 test2708 test2709 test271 test2710 test2711 test2712 test2713 test2714 test2715 test2716 test2717 test2718 test2719 test272 test2720 test2721 test2722 test2723 test273 test274 test275 test276 test277 test278 test279 test28 test280 test281 test282 test283 test284 test285 test286 test287 test288 test289 test29 test290 test291 test292 test293 test294 test295 test296 test297 test298 test299 test3 test30 test300 test3000 test3001 test3002 test3003 test3004 test3005 test3006 test3007 test3008 test3009 test301 test3010 test3011 test3012 test3013 test3014 test3015 test3016 test3017 test3018 test3019 test302 test3020 test3021 test3022 test3023 test3024 test3025 test3026 test3027 test3028 test3029 test303 test3030 test3031 test3032 test3033 test3034 test3035 test3036 test304 test305 test306 test307 test308 test309 test31 test310 test3100 test3101 test3102 test3103 test3104 test3105 test3106 test311 test312 test313 test314 test315 test316 test317 test318 test319 test32 test320 test3200 test3201 test3202 test3203 test3204 test3205 test3206 test3207 test3208 test3209 test321 test3210 test3211 test3212 test3213 test3214 test3215 test3216 test3217 test3218 test3219 test322 test3220 test323 test324 test325 test326 test327 test328 test329 test33 test330 test3300 test3301 test3302 test331 test332 test333 test334 test335 test336 test337 test338 test339 test34 test340 test341 test342 test343 test344 test345 test346 test347 test348 test349 test35 test350 test351 test352 test353 test354 test355 test356 test357 test358 test359 test36 test360 test361 test362 test363 test364 test365 test366 test367 test368 test369 test37 test370 test371 test372 test373 test374 test375 test376 test378 test379 test38 test380 test381 test383 test384 test385 test386 test387 test388 test389 test39 test390 test391 test392 test393 test394 test395 test396 test397 test398 test399 test4 test40 test400 test4000 test4001 test401 test402 test403 test404 test405 test406 test407 test408 test409 test41 test410 test411 test412 test413 test414 test415 test416 test417 test418 test419 test42 test420 test421 test422 test423 test424 test425 test426 test427 test428 test429 test43 test430 test431 test432 test433 test434 test435 test436 test437 test438 test439 test44 test440 test441 test442 test443 test444 test445 test446 test447 test448 test449 test45 test450 test451 test452 test453 test454 test455 test456 test457 test458 test459 test46 test460 test461 test462 test463 test467 test468 test469 test47 test470 test471 test472 test473 test474 test475 test476 test477 test478 test479 test48 test480 test481 test482 test483 test484 test485 test486 test487 test488 test489 test49 test490 test491 test492 test493 test494 test495 test496 test497 test498 test499 test5 test50 test500 test501 test502 test503 test504 test505 test506 test507 test508 test509 test51 test510 test511 test512 test513 test514 test515 test516 test517 test518 test519 test52 test520 test521 test522 test523 test524 test525 test526 test527 test528 test529 test53 test530 test531 test532 test533 test534 test535 test536 test537 test538 test539 test54 test540 test541 test542 test543 test544 test545 test546 test547 test548 test549 test55 test550 test551 test552 test553 test554 test555 test556 test557 test558 test559 test56 test560 test561 test562 test563 test564 test565 test566 test567 test568 test569 test57 test570 test571 test572 test573 test574 test575 test576 test577 test578 test579 test58 test580 test581 test582 test583 test584 test585 test586 test587 test588 test589 test59 test590 test591 test592 test593 test594 test595 test596 test597 test598 test599 test6 test60 test600 test601 test602 test603 test604 test605 test606 test607 test608 test609 test61 test610 test611 test612 test613 test614 test615 test616 test617 test618 test619 test62 test620 test621 test622 test623 test624 test625 test626 test627 test628 test629 test63 test630 test631 test632 test633 test634 test635 test636 test637 test638 test639 test64 test640 test641 test642 test643 test644 test645 test646 test647 test648 test649 test65 test650 test651 test652 test653 test654 test655 test656 test658 test659 test66 test660 test661 test662 test663 test664 test665 test666 test667 test668 test669 test67 test670 test671 test672 test673 test674 test675 test676 test677 test678 test679 test68 test680 test681 test682 test683 test684 test685 test686 test687 test688 test689 test69 test690 test691 test692 test693 test694 test695 test696 test697 test698 test699 test7 test70 test700 test701 test702 test703 test704 test705 test706 test707 test708 test709 test71 test710 test711 test712 test713 test714 test715 test716 test717 test718 test719 test72 test720 test721 test722 test723 test724 test725 test726 test727 test728 test729 test73 test730 test731 test732 test733 test734 test735 test736 test737 test738 test739 test74 test740 test741 test742 test743 test744 test745 test746 test747 test748 test749 test75 test750 test751 test752 test753 test754 test755 test756 test757 test758 test759 test76 test760 test761 test762 test763 test764 test765 test766 test767 test768 test769 test77 test770 test771 test772 test773 test774 test775 test776 test777 test778 test779 test78 test780 test781 test782 test783 test784 test785 test786 test787 test788 test789 test79 test790 test791 test792 test793 test794 test795 test796 test797 test798 test799 test8 test80 test800 test801 test802 test803 test804 test805 test806 test807 test808 test809 test81 test810 test811 test812 test813 test814 test815 test816 test817 test818 test819 test82 test820 test821 test822 test823 test824 test825 test826 test827 test828 test829 test83 test830 test831 test832 test833 test834 test835 test836 test837 test838 test839 test84 test840 test841 test842 test843 test844 test845 test846 test847 test848 test849 test85 test850 test851 test852 test853 test854 test855 test856 test857 test858 test859 test86 test860 test861 test862 test863 test864 test865 test866 test867 test868 test869 test87 test870 test871 test872 test873 test874 test875 test876 test877 test878 test879 test88 test880 test881 test882 test883 test884 test885 test886 test887 test888 test889 test89 test890 test891 test892 test893 test894 test895 test896 test897 test898 test899 test9 test90 test900 test901 test902 test903 test904 test905 test906 test907 test908 test909 test91 test910 test911 test912 test913 test914 test915 test916 test917 test918 test919 test92 test920 test921 test922 test923 test924 test925 test926 test927 test928 test929 test93 test930 test931 test932 test933 test934 test935 test936 test937 test938 test939 test94 test940 test941 test942 test943 test944 test945 test946 test947 test948 test949 test95 test950 test951 test952 test953 test954 test955 test956 test957 test958 test959 test96 test960 test961 test962 test963 test964 test965 test966 test967 test968 test969 test97 test970 test971 test972 test973 test974 test975 test976 test977 test978 test979 test98 test980 test981 test982 test983 test984 test985 test986 test987 test988 test989 test99 test990 test991 test992 test993 test994 test995 test996 test997 test998 test999http
testenv
__init__.py caddy.py certs.py client.py curl.py dante.py dnsd.py env.py httpd.py nghttpx.py ports.py sshd.py vsftpd.py ws_echo_server.pylibtest
.gitignore CMakeLists.txt Makefile.am Makefile.inc cli_ftp_upload.c cli_h2_pausing.c cli_h2_serverpush.c cli_h2_upgrade_extreme.c cli_hx_download.c cli_hx_upload.c cli_tls_session_reuse.c cli_upload_pausing.c cli_ws_data.c cli_ws_pingpong.c first.c first.h lib1156.c lib1301.c lib1308.c lib1485.c lib1500.c lib1501.c lib1502.c lib1506.c lib1507.c lib1508.c lib1509.c lib1510.c lib1511.c lib1512.c lib1513.c lib1514.c lib1515.c lib1517.c lib1518.c lib1520.c lib1522.c lib1523.c lib1525.c lib1526.c lib1527.c lib1528.c lib1529.c lib1530.c lib1531.c lib1532.c lib1533.c lib1534.c lib1535.c lib1536.c lib1537.c lib1538.c lib1540.c lib1541.c lib1542.c lib1545.c lib1549.c lib1550.c lib1551.c lib1552.c lib1553.c lib1554.c lib1555.c lib1556.c lib1557.c lib1558.c lib1559.c lib1560.c lib1564.c lib1565.c lib1567.c lib1568.c lib1569.c lib1571.c lib1576.c lib1582.c lib1587.c lib1588.c lib1589.c lib1591.c lib1592.c lib1593.c lib1594.c lib1597.c lib1598.c lib1599.c lib1662.c lib1900.c lib1901.c lib1902.c lib1903.c lib1905.c lib1906.c lib1907.c lib1908.c lib1910.c lib1911.c lib1912.c lib1913.c lib1915.c lib1916.c lib1918.c lib1919.c lib1920.c lib1921.c lib1933.c lib1934.c lib1935.c lib1936.c lib1937.c lib1938.c lib1939.c lib1940.c lib1945.c lib1947.c lib1948.c lib1955.c lib1956.c lib1957.c lib1958.c lib1959.c lib1960.c lib1964.c lib1965.c lib1970.c lib1971.c lib1972.c lib1973.c lib1974.c lib1975.c lib1977.c lib1978.c lib2023.c lib2032.c lib2082.c lib2301.c lib2302.c lib2304.c lib2306.c lib2308.c lib2309.c lib2402.c lib2404.c lib2405.c lib2502.c lib2504.c lib2505.c lib2506.c lib2700.c lib3010.c lib3025.c lib3026.c lib3027.c lib3033.c lib3034.c lib3100.c lib3101.c lib3102.c lib3103.c lib3104.c lib3105.c lib3207.c lib3208.c lib500.c lib501.c lib502.c lib503.c lib504.c lib505.c lib506.c lib507.c lib508.c lib509.c lib510.c lib511.c lib512.c lib513.c lib514.c lib515.c lib516.c lib517.c lib518.c lib519.c lib520.c lib521.c lib523.c lib524.c lib525.c lib526.c lib530.c lib533.c lib536.c lib537.c lib539.c lib540.c lib541.c lib542.c lib543.c lib544.c lib547.c lib549.c lib552.c lib553.c lib554.c lib555.c lib556.c lib557.c lib558.c lib559.c lib560.c lib562.c lib564.c lib566.c lib567.c lib568.c lib569.c lib570.c lib571.c lib572.c lib573.c lib574.c lib575.c lib576.c lib578.c lib579.c lib582.c lib583.c lib586.c lib589.c lib590.c lib591.c lib597.c lib598.c lib599.c lib643.c lib650.c lib651.c lib652.c lib653.c lib654.c lib655.c lib658.c lib659.c lib661.c lib666.c lib667.c lib668.c lib670.c lib674.c lib676.c lib677.c lib678.c lib694.c lib695.c lib751.c lib753.c lib757.c lib758.c lib766.c memptr.c mk-lib1521.pl test1013.pl test1022.pl test307.pl test610.pl test613.pl testtrace.c testtrace.h testutil.c testutil.h unitcheck.hserver
.checksrc .gitignore CMakeLists.txt Makefile.am Makefile.inc dnsd.c first.c first.h getpart.c mqttd.c resolve.c rtspd.c sockfilt.c socksd.c sws.c tftpd.c util.ctunit
.gitignore CMakeLists.txt Makefile.am Makefile.inc README.md tool1394.c tool1604.c tool1621.c tool1622.c tool1623.c tool1720.cunit
.gitignore CMakeLists.txt Makefile.am Makefile.inc README.md unit1300.c unit1302.c unit1303.c unit1304.c unit1305.c unit1307.c unit1309.c unit1323.c unit1330.c unit1395.c unit1396.c unit1397.c unit1398.c unit1399.c unit1600.c unit1601.c unit1602.c unit1603.c unit1605.c unit1606.c unit1607.c unit1608.c unit1609.c unit1610.c unit1611.c unit1612.c unit1614.c unit1615.c unit1616.c unit1620.c unit1625.c unit1626.c unit1627.c unit1636.c unit1650.c unit1651.c unit1652.c unit1653.c unit1654.c unit1655.c unit1656.c unit1657.c unit1658.c unit1660.c unit1661.c unit1663.c unit1664.c unit1666.c unit1667.c unit1668.c unit1669.c unit1674.c unit1675.c unit1676.c unit1979.c unit1980.c unit2600.c unit2601.c unit2602.c unit2603.c unit2604.c unit2605.c unit3200.c unit3205.c unit3211.c unit3212.c unit3213.c unit3214.c unit3216.c unit3219.c unit3300.c unit3301.c unit3302.cexamples
.env config.ini crypto_test.lua env_test.lua fs_example.lua http_server.lua https_test.lua ini_example.lua json.lua log.lua path_fs_example.lua process_example.lua request_download.lua request_test.lua run_all.lua sqlite_example.lua sqlite_http_template.lua stash_test.lua template_test.lua timer.lua websocket.luainiparser
example
iniexample.c iniwrite.c parse.c twisted-errors.ini twisted-genhuge.py twisted-ofkey.ini twisted-ofval.ini twisted.initest
CMakeLists.txt test_dictionary.c test_iniparser.c unity-config.yml unity_config.hjinjac
libjinjac
src
CMakeLists.txt ast.c ast.h block_statement.c block_statement.h buffer.c buffer.h buildin.c buildin.h common.h convert.c convert.h flex_decl.h jfunction.c jfunction.h jinja_expression.l jinja_expression.y jinjac_parse.c jinjac_parse.h jinjac_stream.c jinjac_stream.h jlist.c jlist.h jobject.c jobject.h parameter.c parameter.h str_obj.c str_obj.h trace.c trace.htest
.gitignore CMakeLists.txt autotest.rb test_01.expected test_01.jinja test_01b.expected test_01b.jinja test_01c.expected test_01c.jinja test_01d.expected test_01d.jinja test_02.expected test_02.jinja test_03.expected test_03.jinja test_04.expected test_04.jinja test_05.expected test_05.jinja test_06.expected test_06.jinja test_07.expected test_07.jinja test_08.expected test_08.jinja test_08b.expected test_08b.jinja test_09.expected test_09.jinja test_10.expected test_10.jinja test_11.expected test_11.jinja test_12.expected test_12.jinja test_13.expected test_13.jinja test_14.expected test_14.jinja test_15.expected test_15.jinja test_16.expected test_16.jinja test_17.expected test_17.jinja test_18.expected test_18.jinja test_18b.expected test_18b.jinja test_18c.expected test_18c.jinja test_19.expected test_19.jinja test_19b.expected test_19b.jinja test_19c.expected test_19c.jinja test_19d.expected test_19d.jinja test_19e.expected test_19e.jinja test_19f.expected test_19f.jinja test_20.expected test_20.jinja test_21.expected test_21.jinja test_22.expected test_22.jinja test_22a.expected test_22a.jinja test_22b.expected test_22b.jinja test_23.expected test_23.jinja test_24.expected test_24.jinjalibev
Changes LICENSE Makefile Makefile.am Makefile.in README Symbols.ev Symbols.event aclocal.m4 autogen.sh compile config.guess config.h config.h.in config.status config.sub configure configure.ac depcomp ev++.h ev.3 ev.c ev.h ev.pod ev_epoll.c ev_kqueue.c ev_poll.c ev_port.c ev_select.c ev_vars.h ev_win32.c ev_wrap.h event.c event.h install-sh libev.m4 libtool ltmain.sh missing mkinstalldirs stamp-h1luajit
doc
bluequad-print.css bluequad.css contact.html ext_buffer.html ext_c_api.html ext_ffi.html ext_ffi_api.html ext_ffi_semantics.html ext_ffi_tutorial.html ext_jit.html ext_profiler.html extensions.html install.html luajit.html running.htmldynasm
dasm_arm.h dasm_arm.lua dasm_arm64.h dasm_arm64.lua dasm_mips.h dasm_mips.lua dasm_mips64.lua dasm_ppc.h dasm_ppc.lua dasm_proto.h dasm_x64.lua dasm_x86.h dasm_x86.lua dynasm.luasrc
host
.gitignore README buildvm.c buildvm.h buildvm_asm.c buildvm_fold.c buildvm_lib.c buildvm_libbc.h buildvm_peobj.c genlibbc.lua genminilua.lua genversion.lua minilua.cjit
.gitignore bc.lua bcsave.lua dis_arm.lua dis_arm64.lua dis_arm64be.lua dis_mips.lua dis_mips64.lua dis_mips64el.lua dis_mips64r6.lua dis_mips64r6el.lua dis_mipsel.lua dis_ppc.lua dis_x64.lua dis_x86.lua dump.lua p.lua v.lua zone.luawolfssl
.github
workflows
ada.yml arduino.yml async-examples.yml async.yml atecc608-sim.yml bind.yml cmake-autoconf.yml cmake.yml codespell.yml coverity-scan-fixes.yml cryptocb-only.yml curl.yml cyrus-sasl.yml disable-pk-algs.yml docker-Espressif.yml docker-OpenWrt.yml emnet-nonblock.yml fil-c.yml freertos-mem-track.yml gencertbuf.yml grpc.yml haproxy.yml hostap-vm.yml intelasm-c-fallback.yml ipmitool.yml jwt-cpp.yml krb5.yml libspdm.yml libssh2.yml libvncserver.yml linuxkm.yml macos-apple-native-cert-validation.yml mbedtls.sh mbedtls.yml membrowse-comment.yml membrowse-onboard.yml membrowse-report.yml memcached.sh memcached.yml mono.yml mosquitto.yml msmtp.yml msys2.yml multi-arch.yml multi-compiler.yml net-snmp.yml nginx.yml no-malloc.yml no-tls.yml nss.sh nss.yml ntp.yml ocsp.yml openldap.yml openssh.yml openssl-ech.yml opensslcoexist.yml openvpn.yml os-check.yml packaging.yml pam-ipmi.yml pq-all.yml pr-commit-check.yml psk.yml puf.yml python.yml rng-tools.yml rust-wrapper.yml se050-sim.yml smallStackSize.yml socat.yml softhsm.yml sssd.yml stm32-sim.yml stsafe-a120-sim.yml stunnel.yml symbol-prefixes.yml threadx.yml tls-anvil.yml trackmemory.yml watcomc.yml win-csharp-test.yml wolfCrypt-Wconversion.yml wolfboot-integration.yml wolfsm.yml xcode.yml zephyr-4.x.yml zephyr.ymlIDE
ARDUINO
Arduino_README_prepend.md README.md include.am keywords.txt library.properties.template wolfssl-arduino.cpp wolfssl-arduino.sh wolfssl.hECLIPSE
Espressif
ESP-IDF
examples
template
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp8266wolfssl_benchmark
VisualGDB
wolfssl_benchmark_IDF_v4.4_ESP32.sln wolfssl_benchmark_IDF_v4.4_ESP32.vgdbproj wolfssl_benchmark_IDF_v5_ESP32.sln wolfssl_benchmark_IDF_v5_ESP32.vgdbproj wolfssl_benchmark_IDF_v5_ESP32C3.sln wolfssl_benchmark_IDF_v5_ESP32C3.vgdbproj wolfssl_benchmark_IDF_v5_ESP32S3.sln wolfssl_benchmark_IDF_v5_ESP32S3.vgdbprojwolfssl_client
CMakeLists.txt Makefile README.md README_server_sm.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32c2 sdkconfig.defaults.esp8266 wolfssl_client_ESP8266.vgdbprojwolfssl_server
CMakeLists.txt Makefile README.md README_server_sm.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32c2 sdkconfig.defaults.esp8266 wolfssl_server_ESP8266.vgdbprojwolfssl_test
VisualGDB
wolfssl_test-IDF_v5_ESP32.sln wolfssl_test-IDF_v5_ESP32.vgdbproj wolfssl_test-IDF_v5_ESP32C3.sln wolfssl_test-IDF_v5_ESP32C3.vgdbproj wolfssl_test-IDF_v5_ESP32C6.sln wolfssl_test-IDF_v5_ESP32C6.vgdbproj wolfssl_test_IDF_v5_ESP32S3.sln wolfssl_test_IDF_v5_ESP32S3.vgdbprojGCC-ARM
Makefile Makefile.bench Makefile.client Makefile.common Makefile.server Makefile.static Makefile.test README.md include.am linker.ld linker_fips.ldIAR-EWARM
embOS
SAMV71_XULT
embOS_SAMV71_XULT_user_settings
user_settings.h user_settings_simple_example.h user_settings_verbose_example.hembOS_wolfcrypt_benchmark_SAMV71_XULT
README_wolfcrypt_benchmark wolfcrypt_benchmark.ewd wolfcrypt_benchmark.ewpINTIME-RTOS
Makefile README.md include.am libwolfssl.c libwolfssl.vcxproj user_settings.h wolfExamples.c wolfExamples.h wolfExamples.sln wolfExamples.vcxproj wolfssl-lib.sln wolfssl-lib.vcxprojMQX
Makefile README-jp.md README.md client-tls.c include.am server-tls.c user_config.h user_settings.hMSVS-2019-AZSPHERE
wolfssl_new_azsphere
.gitignore CMakeLists.txt CMakeSettings.json app_manifest.json applibs_versions.h launch.vs.json main.cNETOS
Makefile.wolfcrypt.inc README.md include.am user_settings.h user_settings.h-cert2425 user_settings.h-cert3389 wolfssl_netos_custom.cPlatformIO
examples
wolfssl_benchmark
CMakeLists.txt README.md platformio.ini sdkconfig.defaults wolfssl_benchmark.code-workspaceROWLEY-CROSSWORKS-ARM
Kinetis_FlashPlacement.xml README.md arm_startup.c benchmark_main.c hw.h include.am kinetis_hw.c retarget.c test_main.c user_settings.h wolfssl.hzp wolfssl_ltc.hzpRenesas
e2studio
RA6M3
README.md README_APRA6M_en.md README_APRA6M_jp.md include.amRX72N
EnvisionKit
Simple
README_EN.md README_JP.mdwolfssl_demo
key_data.c key_data.h user_settings.h wolfssl_demo.c wolfssl_demo.h wolfssl_tsip_unit_test.cSTM32Cube
README.md STM32_Benchmarks.md default_conf.ftl include.am main.c wolfssl_example.c wolfssl_example.hWIN
README.txt include.am test.vcxproj user_settings.h user_settings_dtls.h wolfssl-fips.sln wolfssl-fips.vcxprojWIN-SRTP-KDF-140-3
README.txt include.am resource.h test.vcxproj user_settings.h wolfssl-fips.rc wolfssl-fips.sln wolfssl-fips.vcxprojWIN10
README.txt include.am resource.h test.vcxproj user_settings.h wolfssl-fips.rc wolfssl-fips.sln wolfssl-fips.vcxprojXCODE
Benchmark
include.amXilinxSDK
README.md bench.sh combine.sh eclipse_formatter_profile.xml graph.sh include.am user_settings.h wolfssl_example.capple-universal
wolfssl-multiplatform
iotsafe
Makefile README.md ca-cert.c devices.c devices.h include.am main.c memory-tls.c startup.c target.ld user_settings.hmynewt
README.md apps.wolfcrypttest.pkg.yml crypto.wolfssl.pkg.yml crypto.wolfssl.syscfg.yml include.am setup.shcerts
1024
ca-cert.der ca-cert.pem ca-key.der ca-key.pem client-cert.der client-cert.pem client-key.der client-key.pem client-keyPub.der dh1024.der dh1024.pem dsa-pub-1024.pem dsa1024.der dsa1024.pem include.am rsa1024.der server-cert.der server-cert.pem server-key.der server-key.pemcrl
extra-crls
ca-int-cert-revoked.pem claim-root.pem crl_critical_entry.pem crlnum_57oct.pem crlnum_64oct.pem general-server-crl.pem large_crlnum.pem large_crlnum2.pemdilithium
bench_dilithium_level2_key.der bench_dilithium_level3_key.der bench_dilithium_level5_key.der include.amecc
bp256r1-key.der bp256r1-key.pem ca-secp256k1-cert.pem ca-secp256k1-key.pem client-bp256r1-cert.der client-bp256r1-cert.pem client-secp256k1-cert.der client-secp256k1-cert.pem genecc.sh include.am secp256k1-key.der secp256k1-key.pem secp256k1-param.pem secp256k1-privkey.der secp256k1-privkey.pem server-bp256r1-cert.der server-bp256r1-cert.pem server-secp256k1-cert.der server-secp256k1-cert.pem server2-secp256k1-cert.der server2-secp256k1-cert.pem wolfssl.cnf wolfssl_384.cnfed25519
ca-ed25519-key.der ca-ed25519-key.pem ca-ed25519-priv.der ca-ed25519-priv.pem ca-ed25519.der ca-ed25519.pem client-ed25519-key.der client-ed25519-key.pem client-ed25519-priv.der client-ed25519-priv.pem client-ed25519.der client-ed25519.pem eddsa-ed25519.der eddsa-ed25519.pem gen-ed25519-certs.sh gen-ed25519-keys.sh gen-ed25519.sh include.am root-ed25519-key.der root-ed25519-key.pem root-ed25519-priv.der root-ed25519-priv.pem root-ed25519.der root-ed25519.pem server-ed25519-cert.pem server-ed25519-key.der server-ed25519-key.pem server-ed25519-priv.der server-ed25519-priv.pem server-ed25519.der server-ed25519.pemed448
ca-ed448-key.der ca-ed448-key.pem ca-ed448-priv.der ca-ed448-priv.pem ca-ed448.der ca-ed448.pem client-ed448-key.der client-ed448-key.pem client-ed448-priv.der client-ed448-priv.pem client-ed448.der client-ed448.pem gen-ed448-certs.sh gen-ed448-keys.sh include.am root-ed448-key.der root-ed448-key.pem root-ed448-priv.der root-ed448-priv.pem root-ed448.der root-ed448.pem server-ed448-cert.pem server-ed448-key.der server-ed448-key.pem server-ed448-priv.der server-ed448-priv.pem server-ed448.der server-ed448.pemexternal
DigiCertGlobalRootCA.pem README.txt ca-digicert-ev.pem ca-globalsign-root.pem ca-google-root.pem ca_collection.pem include.amintermediate
ca_false_intermediate
gentestcert.sh int_ca.key server.key test_ca.key test_ca.pem test_int_not_cacert.pem test_sign_bynoca_srv.pem wolfssl_base.conf wolfssl_srv.conflms
bc_hss_L2_H5_W8_root.der bc_hss_L3_H5_W4_root.der bc_lms_chain_ca.der bc_lms_chain_leaf.der bc_lms_native_bc_root.der bc_lms_sha256_h10_w8_root.der bc_lms_sha256_h5_w4_root.der include.ammldsa
README.txt include.am mldsa44-cert.der mldsa44-cert.pem mldsa44-key.pem mldsa44_bare-priv.der mldsa44_bare-seed.der mldsa44_oqskeypair.der mldsa44_priv-only.der mldsa44_pub-spki.der mldsa44_seed-only.der mldsa44_seed-priv.der mldsa65-cert.der mldsa65-cert.pem mldsa65-key.pem mldsa65_bare-priv.der mldsa65_bare-seed.der mldsa65_oqskeypair.der mldsa65_priv-only.der mldsa65_pub-spki.der mldsa65_seed-only.der mldsa65_seed-priv.der mldsa87-cert.der mldsa87-cert.pem mldsa87-key.pem mldsa87_bare-priv.der mldsa87_bare-seed.der mldsa87_oqskeypair.der mldsa87_priv-only.der mldsa87_pub-spki.der mldsa87_seed-only.der mldsa87_seed-priv.derocsp
imposter-root-ca-cert.der imposter-root-ca-cert.pem imposter-root-ca-key.der imposter-root-ca-key.pem include.am index-ca-and-intermediate-cas.txt index-ca-and-intermediate-cas.txt.attr index-intermediate1-ca-issued-certs.txt index-intermediate1-ca-issued-certs.txt.attr index-intermediate2-ca-issued-certs.txt index-intermediate2-ca-issued-certs.txt.attr index-intermediate3-ca-issued-certs.txt index-intermediate3-ca-issued-certs.txt.attr intermediate1-ca-cert.der intermediate1-ca-cert.pem intermediate1-ca-key.der intermediate1-ca-key.pem intermediate2-ca-cert.der intermediate2-ca-cert.pem intermediate2-ca-key.der intermediate2-ca-key.pem intermediate3-ca-cert.der intermediate3-ca-cert.pem intermediate3-ca-key.der intermediate3-ca-key.pem ocsp-responder-cert.der ocsp-responder-cert.pem ocsp-responder-key.der ocsp-responder-key.pem openssl.cnf renewcerts-for-test.sh renewcerts.sh root-ca-cert.der root-ca-cert.pem root-ca-crl.pem root-ca-key.der root-ca-key.pem server1-cert.der server1-cert.pem server1-chain-noroot.pem server1-key.der server1-key.pem server2-cert.der server2-cert.pem server2-key.der server2-key.pem server3-cert.der server3-cert.pem server3-key.der server3-key.pem server4-cert.der server4-cert.pem server4-key.der server4-key.pem server5-cert.der server5-cert.pem server5-key.der server5-key.pem test-leaf-response.der test-multi-response.der test-response-nointern.der test-response-rsapss.der test-response.derp521
ca-p521-key.der ca-p521-key.pem ca-p521-priv.der ca-p521-priv.pem ca-p521.der ca-p521.pem client-p521-key.der client-p521-key.pem client-p521-priv.der client-p521-priv.pem client-p521.der client-p521.pem gen-p521-certs.sh gen-p521-keys.sh include.am root-p521-key.der root-p521-key.pem root-p521-priv.der root-p521-priv.pem root-p521.der root-p521.pem server-p521-cert.pem server-p521-key.der server-p521-key.pem server-p521-priv.der server-p521-priv.pem server-p521.der server-p521.pemrpk
client-cert-rpk.der client-ecc-cert-rpk.der include.am server-cert-rpk.der server-ecc-cert-rpk.derrsapss
ca-3072-rsapss-key.der ca-3072-rsapss-key.pem ca-3072-rsapss-priv.der ca-3072-rsapss-priv.pem ca-3072-rsapss.der ca-3072-rsapss.pem ca-rsapss-key.der ca-rsapss-key.pem ca-rsapss-priv.der ca-rsapss-priv.pem ca-rsapss.der ca-rsapss.pem client-3072-rsapss-key.der client-3072-rsapss-key.pem client-3072-rsapss-priv.der client-3072-rsapss-priv.pem client-3072-rsapss.der client-3072-rsapss.pem client-rsapss-key.der client-rsapss-key.pem client-rsapss-priv.der client-rsapss-priv.pem client-rsapss.der client-rsapss.pem gen-rsapss-keys.sh include.am renew-rsapss-certs.sh root-3072-rsapss-key.der root-3072-rsapss-key.pem root-3072-rsapss-priv.der root-3072-rsapss-priv.pem root-3072-rsapss.der root-3072-rsapss.pem root-rsapss-key.der root-rsapss-key.pem root-rsapss-priv.der root-rsapss-priv.pem root-rsapss.der root-rsapss.pem server-3072-rsapss-cert.pem server-3072-rsapss-key.der server-3072-rsapss-key.pem server-3072-rsapss-priv.der server-3072-rsapss-priv.pem server-3072-rsapss.der server-3072-rsapss.pem server-mix-rsapss-cert.pem server-rsapss-cert.pem server-rsapss-key.der server-rsapss-key.pem server-rsapss-priv.der server-rsapss-priv.pem server-rsapss.der server-rsapss.pemslhdsa
bench_slhdsa_sha2_128f_key.der bench_slhdsa_sha2_128s_key.der bench_slhdsa_sha2_192f_key.der bench_slhdsa_sha2_192s_key.der bench_slhdsa_sha2_256f_key.der bench_slhdsa_sha2_256s_key.der bench_slhdsa_shake128f_key.der bench_slhdsa_shake128s_key.der bench_slhdsa_shake192f_key.der bench_slhdsa_shake192s_key.der bench_slhdsa_shake256f_key.der bench_slhdsa_shake256s_key.der client-mldsa44-priv.pem client-mldsa44-sha2.der client-mldsa44-sha2.pem client-mldsa44-shake.der client-mldsa44-shake.pem gen-slhdsa-mldsa-certs.sh include.am root-slhdsa-sha2-128s-priv.der root-slhdsa-sha2-128s-priv.pem root-slhdsa-sha2-128s.der root-slhdsa-sha2-128s.pem root-slhdsa-shake-128s-priv.der root-slhdsa-shake-128s-priv.pem root-slhdsa-shake-128s.der root-slhdsa-shake-128s.pem server-mldsa44-priv.pem server-mldsa44-sha2.der server-mldsa44-sha2.pem server-mldsa44-shake.der server-mldsa44-shake.pemsm2
ca-sm2-key.der ca-sm2-key.pem ca-sm2-priv.der ca-sm2-priv.pem ca-sm2.der ca-sm2.pem client-sm2-key.der client-sm2-key.pem client-sm2-priv.der client-sm2-priv.pem client-sm2.der client-sm2.pem fix_sm2_spki.py gen-sm2-certs.sh gen-sm2-keys.sh include.am root-sm2-key.der root-sm2-key.pem root-sm2-priv.der root-sm2-priv.pem root-sm2.der root-sm2.pem self-sm2-cert.pem self-sm2-key.pem self-sm2-priv.pem server-sm2-cert.der server-sm2-cert.pem server-sm2-key.der server-sm2-key.pem server-sm2-priv.der server-sm2-priv.pem server-sm2.der server-sm2.pemstatickeys
dh-ffdhe2048-params.pem dh-ffdhe2048-pub.der dh-ffdhe2048-pub.pem dh-ffdhe2048.der dh-ffdhe2048.pem ecc-secp256r1.der ecc-secp256r1.pem gen-static.sh include.am x25519-pub.der x25519-pub.pem x25519.der x25519.pemtest
catalog.txt cert-bad-neg-int.der cert-bad-oid.der cert-bad-utf8.der cert-ext-ia.cfg cert-ext-ia.der cert-ext-ia.pem cert-ext-joi.cfg cert-ext-joi.der cert-ext-joi.pem cert-ext-mnc.der cert-ext-multiple.cfg cert-ext-multiple.der cert-ext-multiple.pem cert-ext-nc-combined.der cert-ext-nc-combined.pem cert-ext-nc.cfg cert-ext-nc.der cert-ext-nc.pem cert-ext-ncdns.der cert-ext-ncdns.pem cert-ext-ncip.der cert-ext-ncip.pem cert-ext-ncmixed.der cert-ext-ncmulti.der cert-ext-ncmulti.pem cert-ext-ncrid.der cert-ext-ncrid.pem cert-ext-nct.cfg cert-ext-nct.der cert-ext-nct.pem cert-ext-ndir-exc.cfg cert-ext-ndir-exc.der cert-ext-ndir-exc.pem cert-ext-ndir.cfg cert-ext-ndir.der cert-ext-ndir.pem cert-ext-ns.der cert-over-max-altnames.cfg cert-over-max-altnames.der cert-over-max-altnames.pem cert-over-max-nc.cfg cert-over-max-nc.der cert-over-max-nc.pem client-ecc-cert-ski.hex cn-ip-literal.der cn-ip-wildcard.der crit-cert.pem crit-key.pem dh1024.der dh1024.pem dh512.der dh512.pem digsigku.pem encrypteddata.msg gen-badsig.sh gen-ext-certs.sh gen-testcerts.sh include.am kari-keyid-cms.msg ktri-keyid-cms.msg ossl-trusted-cert.pem server-badaltname.der server-badaltname.pem server-badaltnull.der server-badaltnull.pem server-badcn.der server-badcn.pem server-badcnnull.der server-badcnnull.pem server-cert-ecc-badsig.der server-cert-ecc-badsig.pem server-cert-rsa-badsig.der server-cert-rsa-badsig.pem server-duplicate-policy.pem server-garbage.der server-garbage.pem server-goodalt.der server-goodalt.pem server-goodaltwild.der server-goodaltwild.pem server-goodcn.der server-goodcn.pem server-goodcnwild.der server-goodcnwild.pem server-localhost.der server-localhost.pem smime-test-canon.p7s smime-test-multipart-badsig.p7s smime-test-multipart.p7s smime-test.p7stest-pathlen
assemble-chains.sh chainA-ICA1-key.pem chainA-ICA1-pathlen0.pem chainA-assembled.pem chainA-entity-key.pem chainA-entity.pem chainB-ICA1-key.pem chainB-ICA1-pathlen0.pem chainB-ICA2-key.pem chainB-ICA2-pathlen1.pem chainB-assembled.pem chainB-entity-key.pem chainB-entity.pem chainC-ICA1-key.pem chainC-ICA1-pathlen1.pem chainC-assembled.pem chainC-entity-key.pem chainC-entity.pem chainD-ICA1-key.pem chainD-ICA1-pathlen127.pem chainD-assembled.pem chainD-entity-key.pem chainD-entity.pem chainE-ICA1-key.pem chainE-ICA1-pathlen128.pem chainE-assembled.pem chainE-entity-key.pem chainE-entity.pem chainF-ICA1-key.pem chainF-ICA1-pathlen1.pem chainF-ICA2-key.pem chainF-ICA2-pathlen0.pem chainF-assembled.pem chainF-entity-key.pem chainF-entity.pem chainG-ICA1-key.pem chainG-ICA1-pathlen0.pem chainG-ICA2-key.pem chainG-ICA2-pathlen1.pem chainG-ICA3-key.pem chainG-ICA3-pathlen99.pem chainG-ICA4-key.pem chainG-ICA4-pathlen5.pem chainG-ICA5-key.pem chainG-ICA5-pathlen20.pem chainG-ICA6-key.pem chainG-ICA6-pathlen10.pem chainG-ICA7-key.pem chainG-ICA7-pathlen100.pem chainG-assembled.pem chainG-entity-key.pem chainG-entity.pem chainH-ICA1-key.pem chainH-ICA1-pathlen0.pem chainH-ICA2-key.pem chainH-ICA2-pathlen2.pem chainH-ICA3-key.pem chainH-ICA3-pathlen2.pem chainH-ICA4-key.pem chainH-ICA4-pathlen2.pem chainH-assembled.pem chainH-entity-key.pem chainH-entity.pem chainI-ICA1-key.pem chainI-ICA1-no_pathlen.pem chainI-ICA2-key.pem chainI-ICA2-no_pathlen.pem chainI-ICA3-key.pem chainI-ICA3-pathlen2.pem chainI-assembled.pem chainI-entity-key.pem chainI-entity.pem chainJ-ICA1-key.pem chainJ-ICA1-no_pathlen.pem chainJ-ICA2-key.pem chainJ-ICA2-no_pathlen.pem chainJ-ICA3-key.pem chainJ-ICA3-no_pathlen.pem chainJ-ICA4-key.pem chainJ-ICA4-pathlen2.pem chainJ-assembled.pem chainJ-entity-key.pem chainJ-entity.pem include.am refreshkeys.shtest-serial0
ee_normal.pem ee_serial0.pem generate_certs.sh include.am intermediate_serial0.pem root_serial0.pem root_serial0_key.pem selfsigned_nonca_serial0.pemxmss
bc_xmss_chain_ca.der bc_xmss_chain_leaf.der bc_xmss_sha2_10_256_root.der bc_xmss_sha2_16_256_root.der bc_xmssmt_sha2_20_2_256_root.der bc_xmssmt_sha2_20_4_256_root.der bc_xmssmt_sha2_40_8_256_root.der include.amcmake
Config.cmake.in README.md config.in functions.cmake include.am options.h.in wolfssl-config-version.cmake.in wolfssl-targets.cmake.indebian
changelog.in control.in copyright include.am libwolfssl-dev.install libwolfssl.install rules.indoc
dox_comments
header_files
aes.h arc4.h ascon.h asn.h asn_public.h blake2.h bn.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cryptocb.h curve25519.h curve448.h des3.h dh.h doxygen_groups.h doxygen_pages.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h evp.h hash.h hmac.h iotsafe.h kdf.h logging.h md2.h md4.h md5.h memory.h ocsp.h pem.h pkcs11.h pkcs7.h poly1305.h psa.h puf.h pwdbased.h quic.h random.h ripemd.h rsa.h sakke.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h srp.h ssl.h tfm.h types.h wc_encrypt.h wc_port.h wc_she.h wc_slhdsa.h wolfio.hheader_files-ja
aes.h arc4.h ascon.h asn.h asn_public.h blake2.h bn.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cryptocb.h curve25519.h curve448.h des3.h dh.h doxygen_groups.h doxygen_pages.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h evp.h hash.h hmac.h iotsafe.h kdf.h logging.h md2.h md4.h md5.h memory.h ocsp.h pem.h pkcs11.h pkcs7.h poly1305.h psa.h pwdbased.h quic.h random.h ripemd.h rsa.h sakke.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h srp.h ssl.h tfm.h types.h wc_encrypt.h wc_port.h wolfio.hexamples
async
Makefile README.md async_client.c async_server.c async_tls.c async_tls.h include.am user_settings.hconfigs
README.md include.am user_settings_EBSnet.h user_settings_all.h user_settings_arduino.h user_settings_baremetal.h user_settings_ca.h user_settings_curve25519nonblock.h user_settings_dtls13.h user_settings_eccnonblock.h user_settings_espressif.h user_settings_fipsv2.h user_settings_fipsv5.h user_settings_min_ecc.h user_settings_openssl_compat.h user_settings_pkcs7.h user_settings_platformio.h user_settings_pq.h user_settings_rsa_only.h user_settings_stm32.h user_settings_template.h user_settings_tls12.h user_settings_tls13.h user_settings_wolfboot_keytools.h user_settings_wolfssh.h user_settings_wolftpm.hechoclient
echoclient.c echoclient.h echoclient.sln echoclient.vcproj echoclient.vcxproj include.am quitlinuxkm
Kbuild Makefile README.md get_thread_size.c include.am linuxkm-fips-hash-wrapper.sh linuxkm-fips-hash.c linuxkm_memory.c linuxkm_memory.h linuxkm_wc_port.h lkcapi_aes_glue.c lkcapi_dh_glue.c lkcapi_ecdh_glue.c lkcapi_ecdsa_glue.c lkcapi_glue.c lkcapi_rsa_glue.c lkcapi_sha_glue.c module_exports.c.template module_hooks.c pie_redirect_table.c wolfcrypt.lds x86_vector_register_glue.cm4
ax_add_am_macro.m4 ax_am_jobserver.m4 ax_am_macros.m4 ax_append_compile_flags.m4 ax_append_flag.m4 ax_append_link_flags.m4 ax_append_to_file.m4 ax_atomic.m4 ax_bsdkm.m4 ax_check_compile_flag.m4 ax_check_link_flag.m4 ax_compiler_version.m4 ax_count_cpus.m4 ax_create_generic_config.m4 ax_debug.m4 ax_file_escapes.m4 ax_harden_compiler_flags.m4 ax_linuxkm.m4 ax_print_to_file.m4 ax_pthread.m4 ax_require_defined.m4 ax_tls.m4 ax_vcs_checkout.m4 hexversion.m4 lib_socket_nsl.m4 visibility.m4mqx
wolfcrypt_benchmark
ReferencedRSESystems.xml wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launchwolfcrypt_test
ReferencedRSESystems.xml wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launchwolfssl_client
ReferencedRSESystems.xml wolfssl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launchscripts
aria-cmake-build-test.sh asn1_oid_sum.pl benchmark.test benchmark_compare.sh cleanup_testfiles.sh crl-gen-openssl.test crl-revoked.test dertoc.pl dtls.test dtlscid.test external.test google.test include.am makedistsmall.sh memtest.sh ocsp-responder-openssl-interop.test ocsp-stapling-with-ca-as-responder.test ocsp-stapling-with-wolfssl-responder.test ocsp-stapling.test ocsp-stapling2.test ocsp-stapling_tls13multi.test ocsp.test openssl.test openssl_srtp.test pem.test ping.test pkcallbacks.test psk.test resume.test rsapss.test sniffer-gen.sh sniffer-ipv6.pcap sniffer-static-rsa.pcap sniffer-testsuite.test sniffer-tls12-keylog.out sniffer-tls12-keylog.pcap sniffer-tls12-keylog.sslkeylog sniffer-tls13-dh-resume.pcap sniffer-tls13-dh.pcap sniffer-tls13-ecc-resume.pcap sniffer-tls13-ecc.pcap sniffer-tls13-hrr.pcap sniffer-tls13-keylog.out sniffer-tls13-keylog.pcap sniffer-tls13-keylog.sslkeylog sniffer-tls13-x25519-resume.pcap sniffer-tls13-x25519.pcap stm32l4-v4_0_1_build.sh tls13.test trusted_peer.test unit.test.in user_settings_asm.shsrc
bio.c conf.c crl.c dtls.c dtls13.c include.am internal.c keys.c ocsp.c pk.c pk_ec.c pk_rsa.c quic.c sniffer.c ssl.c ssl_api_cert.c ssl_api_crl_ocsp.c ssl_api_pk.c ssl_asn1.c ssl_bn.c ssl_certman.c ssl_crypto.c ssl_ech.c ssl_load.c ssl_misc.c ssl_p7p12.c ssl_sess.c ssl_sk.c tls.c tls13.c wolfio.c x509.c x509_str.ctests
api
api.h api_decl.h create_ocsp_test_blobs.py include.am test_aes.c test_aes.h test_arc4.c test_arc4.h test_ascon.c test_ascon.h test_ascon_kats.h test_asn.c test_asn.h test_blake2.c test_blake2.h test_camellia.c test_camellia.h test_certman.c test_certman.h test_chacha.c test_chacha.h test_chacha20_poly1305.c test_chacha20_poly1305.h test_cmac.c test_cmac.h test_curve25519.c test_curve25519.h test_curve448.c test_curve448.h test_des3.c test_des3.h test_dh.c test_dh.h test_digest.h test_dsa.c test_dsa.h test_dtls.c test_dtls.h test_ecc.c test_ecc.h test_ed25519.c test_ed25519.h test_ed448.c test_ed448.h test_evp.c test_evp.h test_evp_cipher.c test_evp_cipher.h test_evp_digest.c test_evp_digest.h test_evp_pkey.c test_evp_pkey.h test_hash.c test_hash.h test_hmac.c test_hmac.h test_md2.c test_md2.h test_md4.c test_md4.h test_md5.c test_md5.h test_mldsa.c test_mldsa.h test_mlkem.c test_mlkem.h test_ocsp.c test_ocsp.h test_ocsp_test_blobs.h test_ossl_asn1.c test_ossl_asn1.h test_ossl_bio.c test_ossl_bio.h test_ossl_bn.c test_ossl_bn.h test_ossl_cipher.c test_ossl_cipher.h test_ossl_dgst.c test_ossl_dgst.h test_ossl_dh.c test_ossl_dh.h test_ossl_dsa.c test_ossl_dsa.h test_ossl_ec.c test_ossl_ec.h test_ossl_ecx.c test_ossl_ecx.h test_ossl_mac.c test_ossl_mac.h test_ossl_obj.c test_ossl_obj.h test_ossl_p7p12.c test_ossl_p7p12.h test_ossl_pem.c test_ossl_pem.h test_ossl_rand.c test_ossl_rand.h test_ossl_rsa.c test_ossl_rsa.h test_ossl_sk.c test_ossl_sk.h test_ossl_x509.c test_ossl_x509.h test_ossl_x509_acert.c test_ossl_x509_acert.h test_ossl_x509_crypto.c test_ossl_x509_crypto.h test_ossl_x509_ext.c test_ossl_x509_ext.h test_ossl_x509_info.c test_ossl_x509_info.h test_ossl_x509_io.c test_ossl_x509_io.h test_ossl_x509_lu.c test_ossl_x509_lu.h test_ossl_x509_name.c test_ossl_x509_name.h test_ossl_x509_pk.c test_ossl_x509_pk.h test_ossl_x509_str.c test_ossl_x509_str.h test_ossl_x509_vp.c test_ossl_x509_vp.h test_pkcs12.c test_pkcs12.h test_pkcs7.c test_pkcs7.h test_poly1305.c test_poly1305.h test_random.c test_random.h test_rc2.c test_rc2.h test_ripemd.c test_ripemd.h test_rsa.c test_rsa.h test_sha.c test_sha.h test_sha256.c test_sha256.h test_sha3.c test_sha3.h test_sha512.c test_sha512.h test_she.c test_she.h test_signature.c test_signature.h test_slhdsa.c test_slhdsa.h test_sm2.c test_sm2.h test_sm3.c test_sm3.h test_sm4.c test_sm4.h test_tls.c test_tls.h test_tls13.c test_tls13.h test_tls_ext.c test_tls_ext.h test_wc_encrypt.c test_wc_encrypt.h test_wolfmath.c test_wolfmath.h test_x509.c test_x509.hwolfcrypt
benchmark
README.md benchmark-VS2022.sln benchmark-VS2022.vcxproj benchmark-VS2022.vcxproj.user benchmark.c benchmark.h benchmark.sln benchmark.vcproj benchmark.vcxproj include.amsrc
port
Espressif
esp_crt_bundle
README.md cacrt_all.pem cacrt_deprecated.pem cacrt_local.pem esp_crt_bundle.c gen_crt_bundle.py pio_install_cryptography.pyRenesas
README.md renesas_common.c renesas_fspsm_aes.c renesas_fspsm_rsa.c renesas_fspsm_sha.c renesas_fspsm_util.c renesas_rx64_hw_sha.c renesas_rx64_hw_util.c renesas_tsip_aes.c renesas_tsip_rsa.c renesas_tsip_sha.c renesas_tsip_util.carm
armv8-32-aes-asm.S armv8-32-aes-asm_c.c armv8-32-chacha-asm.S armv8-32-chacha-asm_c.c armv8-32-curve25519.S armv8-32-curve25519_c.c armv8-32-mlkem-asm.S armv8-32-mlkem-asm_c.c armv8-32-poly1305-asm.S armv8-32-poly1305-asm_c.c armv8-32-sha256-asm.S armv8-32-sha256-asm_c.c armv8-32-sha3-asm.S armv8-32-sha3-asm_c.c armv8-32-sha512-asm.S armv8-32-sha512-asm_c.c armv8-aes-asm.S armv8-aes-asm_c.c armv8-aes.c armv8-chacha-asm.S armv8-chacha-asm_c.c armv8-curve25519.S armv8-curve25519_c.c armv8-mlkem-asm.S armv8-mlkem-asm_c.c armv8-poly1305-asm.S armv8-poly1305-asm_c.c armv8-sha256-asm.S armv8-sha256-asm_c.c armv8-sha256.c armv8-sha3-asm.S armv8-sha3-asm_c.c armv8-sha512-asm.S armv8-sha512-asm_c.c armv8-sha512.c cryptoCell.c cryptoCellHash.c thumb2-aes-asm.S thumb2-aes-asm_c.c thumb2-chacha-asm.S thumb2-chacha-asm_c.c thumb2-curve25519.S thumb2-curve25519_c.c thumb2-mlkem-asm.S thumb2-mlkem-asm_c.c thumb2-poly1305-asm.S thumb2-poly1305-asm_c.c thumb2-sha256-asm.S thumb2-sha256-asm_c.c thumb2-sha3-asm.S thumb2-sha3-asm_c.c thumb2-sha512-asm.S thumb2-sha512-asm_c.ccaam
README.md caam_aes.c caam_doc.pdf caam_driver.c caam_error.c caam_integrity.c caam_qnx.c caam_sha.c wolfcaam_aes.c wolfcaam_cmac.c wolfcaam_ecdsa.c wolfcaam_fsl_nxp.c wolfcaam_hash.c wolfcaam_hmac.c wolfcaam_init.c wolfcaam_qnx.c wolfcaam_rsa.c wolfcaam_seco.c wolfcaam_x25519.cdevcrypto
README.md devcrypto_aes.c devcrypto_ecdsa.c devcrypto_hash.c devcrypto_hmac.c devcrypto_rsa.c devcrypto_x25519.c wc_devcrypto.criscv
riscv-64-aes.c riscv-64-chacha.c riscv-64-poly1305.c riscv-64-sha256.c riscv-64-sha3.c riscv-64-sha512.cwolfssl
openssl
aes.h asn1.h asn1t.h bio.h bn.h buffer.h camellia.h cmac.h cms.h compat_types.h conf.h crypto.h des.h dh.h dsa.h ec.h ec25519.h ec448.h ecdh.h ecdsa.h ed25519.h ed448.h engine.h err.h evp.h fips_rand.h hmac.h include.am kdf.h lhash.h md4.h md5.h modes.h obj_mac.h objects.h ocsp.h opensslconf.h opensslv.h ossl_typ.h pem.h pkcs12.h pkcs7.h rand.h rc4.h ripemd.h rsa.h safestack.h sha.h sha3.h srp.h ssl.h ssl23.h stack.h tls1.h txt_db.h ui.h x509.h x509_vfy.h x509v3.hwolfcrypt
port
Renesas
renesas-fspsm-crypt.h renesas-fspsm-types.h renesas-rx64-hw-crypt.h renesas-tsip-crypt.h renesas_cmn.h renesas_fspsm_internal.h renesas_sync.h renesas_tsip_internal.h renesas_tsip_types.hcaam
caam_driver.h caam_error.h caam_qnx.h wolfcaam.h wolfcaam_aes.h wolfcaam_cmac.h wolfcaam_ecdsa.h wolfcaam_fsl_nxp.h wolfcaam_hash.h wolfcaam_qnx.h wolfcaam_rsa.h wolfcaam_seco.h wolfcaam_sha.h wolfcaam_x25519.hwrapper
Ada
examples
src
aes_verify_main.adb rsa_verify_main.adb sha256_main.adb spark_sockets.adb spark_sockets.ads spark_terminal.adb spark_terminal.ads tls_client.adb tls_client.ads tls_client_main.adb tls_server.adb tls_server.ads tls_server_main.adbtests
src
aes_bindings_tests.adb aes_bindings_tests.ads rsa_verify_bindings_tests.adb rsa_verify_bindings_tests.ads sha256_bindings_tests.adb sha256_bindings_tests.ads tests.adbCSharp
wolfSSL-Example-IOCallbacks
App.config wolfSSL-Example-IOCallbacks.cs wolfSSL-Example-IOCallbacks.csprojwolfSSL-TLS-ServerThreaded
App.config wolfSSL-TLS-ServerThreaded.cs wolfSSL-TLS-ServerThreaded.csprojrust
wolfssl-wolfcrypt
src
aes.rs blake2.rs chacha20_poly1305.rs cmac.rs cmac_mac.rs curve25519.rs dh.rs dilithium.rs ecc.rs ecdsa.rs ed25519.rs ed448.rs fips.rs hkdf.rs hmac.rs hmac_mac.rs kdf.rs lib.rs lms.rs mlkem.rs mlkem_kem.rs pbkdf2_password_hash.rs prf.rs random.rs rsa.rs rsa_pkcs1v15.rs sha.rs sha_digest.rs sys.rstests
test_aes.rs test_blake2.rs test_chacha20_poly1305.rs test_cmac.rs test_cmac_mac.rs test_curve25519.rs test_dh.rs test_dilithium.rs test_ecc.rs test_ecdsa.rs test_ed25519.rs test_ed448.rs test_hkdf.rs test_hmac.rs test_hmac_mac.rs test_kdf.rs test_lms.rs test_mlkem.rs test_mlkem_kem.rs test_pbkdf2_password_hash.rs test_prf.rs test_random.rs test_rsa.rs test_rsa_pkcs1v15.rs test_sha.rs test_sha_digest.rs test_wolfcrypt.rszephyr
samples
wolfssl_benchmark
CMakeLists.txt README install_test.sh prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.confwolfssl_test
CMakeLists.txt README install_test.sh prj-no-malloc.conf prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl/wolfcrypt/benchmark/benchmark.c
raw
1/* benchmark.c
2 *
3 * Copyright (C) 2006-2026 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22
23/* wolfCrypt benchmark */
24
25/* Some common, optional build settings:
26 * these can also be set in wolfssl/options.h or user_settings.h
27 * -------------------------------------------------------------
28 * make the binary always use CSV format:
29 * WOLFSSL_BENCHMARK_FIXED_CSV
30 *
31 * choose to use the same units, regardless of scale. pick 1:
32 * WOLFSSL_BENCHMARK_FIXED_UNITS_GB
33 * WOLFSSL_BENCHMARK_FIXED_UNITS_MB
34 * WOLFSSL_BENCHMARK_FIXED_UNITS_KB
35 * WOLFSSL_BENCHMARK_FIXED_UNITS_B
36 *
37 * when the output should be in machine-parseable format:
38 * GENERATE_MACHINE_PARSEABLE_REPORT
39 *
40 * use microseconds as the unit of time:
41 * BENCH_MICROSECOND
42 *
43 * display mean, max, min and sd of operation durations:
44 * MULTI_VALUE_STATISTICS
45 *
46 * Enable tracking of the stats into an allocated linked list:
47 * (use -print to display results):
48 * WC_BENCH_TRACK_STATS
49 *
50 * set the default devId for cryptocb to the value instead of INVALID_DEVID
51 * WC_USE_DEVID=0x1234
52 *
53 * Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc)
54 * DEBUG_WOLFSSL_BENCHMARK_TIMING
55 *
56 * Turn on timer debugging (used when CPU cycles not available)
57 * WOLFSSL_BENCHMARK_TIMER_DEBUG
58 */
59
60#ifdef HAVE_CONFIG_H
61 #include <config.h>
62#endif
63
64#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
65 #include <wolfssl/options.h>
66#endif
67#include <wolfssl/wolfcrypt/settings.h> /* also picks up user_settings.h */
68
69/* Macro to disable benchmark */
70#ifndef NO_CRYPT_BENCHMARK
71
72#undef WC_ALLOC_DO_ON_FAILURE
73#define WC_ALLOC_DO_ON_FAILURE() do { printf("out of memory at benchmark.c L %d\n", __LINE__); ret = MEMORY_E; goto exit; } while (0)
74
75#include <wolfssl/wolfcrypt/types.h>
76#include <wolfssl/wolfcrypt/wc_port.h>
77#include <wolfssl/wolfcrypt/wolfmath.h>
78#include <wolfssl/wolfcrypt/memory.h>
79#include <wolfssl/wolfcrypt/random.h>
80#include <wolfssl/wolfcrypt/error-crypt.h>
81#include <wolfssl/wolfcrypt/asn.h>
82#include <wolfssl/version.h>
83
84#ifdef WOLFSSL_LINUXKM
85 /* remap current_time() -- collides with a function in kernel linux/fs.h */
86 #define current_time benchmark_current_time
87#endif /* WOLFSSL_LINUXKM */
88
89#ifdef HAVE_CHACHA
90 #include <wolfssl/wolfcrypt/chacha.h>
91#endif
92#ifdef HAVE_POLY1305
93 #include <wolfssl/wolfcrypt/poly1305.h>
94#endif
95#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
96 #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
97#endif
98#ifndef NO_AES
99 #include <wolfssl/wolfcrypt/aes.h>
100#endif
101#ifdef HAVE_CAMELLIA
102 #include <wolfssl/wolfcrypt/camellia.h>
103#endif
104#ifdef WOLFSSL_SM4
105 #include <wolfssl/wolfcrypt/sm4.h>
106#endif
107#ifndef NO_MD5
108 #include <wolfssl/wolfcrypt/md5.h>
109#endif
110#ifndef NO_SHA
111 #include <wolfssl/wolfcrypt/sha.h>
112#endif
113#ifndef NO_SHA256
114 #include <wolfssl/wolfcrypt/sha256.h>
115#endif
116#if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
117 #include <wolfssl/wolfcrypt/sha512.h>
118#endif
119#ifdef WOLFSSL_SHA3
120 #include <wolfssl/wolfcrypt/sha3.h>
121#endif
122#ifdef WOLFSSL_SM3
123 #include <wolfssl/wolfcrypt/sm3.h>
124#endif
125#ifndef NO_RSA
126 #include <wolfssl/wolfcrypt/rsa.h>
127#endif
128#ifdef WOLFSSL_RIPEMD
129 #include <wolfssl/wolfcrypt/ripemd.h>
130#endif
131#ifdef WOLFSSL_CMAC
132 #include <wolfssl/wolfcrypt/cmac.h>
133#endif
134#ifndef NO_DH
135 #include <wolfssl/wolfcrypt/dh.h>
136#endif
137#ifndef NO_DES3
138 #include <wolfssl/wolfcrypt/des3.h>
139#endif
140#ifndef NO_RC4
141 #include <wolfssl/wolfcrypt/arc4.h>
142#endif
143#ifndef NO_HMAC
144 #include <wolfssl/wolfcrypt/hmac.h>
145#endif
146#ifdef WOLFSSL_SIPHASH
147 #include <wolfssl/wolfcrypt/siphash.h>
148#endif
149 #include <wolfssl/wolfcrypt/kdf.h>
150#ifndef NO_PWDBASED
151 #include <wolfssl/wolfcrypt/pwdbased.h>
152#endif
153#ifdef HAVE_ECC
154 #include <wolfssl/wolfcrypt/ecc.h>
155#endif
156#ifdef WOLFSSL_SM2
157 #include <wolfssl/wolfcrypt/sm2.h>
158#endif
159#ifdef HAVE_CURVE25519
160 #include <wolfssl/wolfcrypt/curve25519.h>
161#endif
162#ifdef HAVE_ED25519
163 #include <wolfssl/wolfcrypt/ed25519.h>
164#endif
165#ifdef HAVE_CURVE448
166 #include <wolfssl/wolfcrypt/curve448.h>
167#endif
168#ifdef HAVE_ED448
169 #include <wolfssl/wolfcrypt/ed448.h>
170#endif
171#ifdef WOLFSSL_HAVE_MLKEM
172 #include <wolfssl/wolfcrypt/wc_mlkem.h>
173#endif
174#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
175 #include <wolfssl/wolfcrypt/wc_lms.h>
176#endif
177#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
178 #include <wolfssl/wolfcrypt/wc_xmss.h>
179#endif
180#if defined(WOLFSSL_HAVE_SLHDSA)
181 #include <wolfssl/wolfcrypt/wc_slhdsa.h>
182#endif
183#ifdef WOLFCRYPT_HAVE_ECCSI
184 #include <wolfssl/wolfcrypt/eccsi.h>
185#endif
186#ifdef WOLFCRYPT_HAVE_SAKKE
187 #include <wolfssl/wolfcrypt/sakke.h>
188#endif
189
190#if defined(HAVE_FALCON)
191 #include <wolfssl/wolfcrypt/falcon.h>
192#endif
193#if defined(HAVE_DILITHIUM)
194 #include <wolfssl/wolfcrypt/dilithium.h>
195#endif
196
197#ifdef WOLF_CRYPTO_CB
198 #include <wolfssl/wolfcrypt/cryptocb.h>
199 #ifdef HAVE_INTEL_QA_SYNC
200 #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
201 #endif
202 #ifdef HAVE_CAVIUM_OCTEON_SYNC
203 #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
204 #endif
205 #ifdef HAVE_RENESAS_SYNC
206 #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
207 #endif
208 #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
209 #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
210 #endif
211#endif
212
213#ifdef WOLFSSL_ASYNC_CRYPT
214 #include <wolfssl/wolfcrypt/async.h>
215#endif
216
217#include <wolfssl/wolfcrypt/cpuid.h>
218
219#ifdef USE_FLAT_BENCHMARK_H
220 #include "benchmark.h"
221#else
222 #include "wolfcrypt/benchmark/benchmark.h"
223#endif
224
225/* define the max length for each string of metric reported */
226#ifndef WC_BENCH_MAX_LINE_LEN
227#define WC_BENCH_MAX_LINE_LEN 150
228#endif
229
230/* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
231#define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
232#define MILLION_VALUE 1000000.0
233
234#ifdef BENCH_MICROSECOND
235 #define WOLFSSL_FIXED_TIME_UNIT "ฮผs"
236 #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
237#else
238 #define WOLFSSL_FIXED_TIME_UNIT "s"
239#endif
240
241#if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
242 #define WC_BENCH_HEAP_TRACKING
243#endif
244
245#if defined(HAVE_STACK_SIZE_VERBOSE)
246 #define WC_BENCH_STACK_TRACKING
247#endif
248
249#if (defined(WC_BENCH_HEAP_TRACKING) || defined(WC_BENCH_STACK_TRACKING)) && \
250 (WC_BENCH_MAX_LINE_LEN < 240)
251 #undef WC_BENCH_MAX_LINE_LEN
252 #define WC_BENCH_MAX_LINE_LEN 240
253#endif
254
255#if defined(WC_BENCH_HEAP_TRACKING) || defined(WC_BENCH_STACK_TRACKING)
256 #include <wolfssl/wolfcrypt/mem_track.h>
257#endif
258
259#ifdef WC_BENCH_STACK_TRACKING
260static long bench_last_stack_bytes;
261#define BENCH_LAST_STACK_BYTES bench_last_stack_bytes
262#else
263#define BENCH_LAST_STACK_BYTES 0
264#endif
265
266#ifdef WC_BENCH_HEAP_TRACKING
267static long bench_heap_baseline_allocs;
268static long bench_heap_baseline_bytes;
269
270static WC_INLINE void bench_heap_checkpoint_prepare(void)
271{
272 (void)wolfCrypt_heap_peakAllocs_checkpoint();
273 bench_heap_baseline_allocs = wolfCrypt_heap_peakAllocs_checkpoint();
274 (void)wolfCrypt_heap_peakBytes_checkpoint();
275 bench_heap_baseline_bytes = wolfCrypt_heap_peakBytes_checkpoint();
276}
277
278static WC_INLINE void bench_heap_checkpoint_measure(long* allocs,
279 long* bytes)
280{
281 long peak_allocs = wolfCrypt_heap_peakAllocs_checkpoint();
282 long peak_bytes = wolfCrypt_heap_peakBytes_checkpoint();
283
284 if (allocs != NULL) {
285 long relative = peak_allocs - bench_heap_baseline_allocs;
286 *allocs = (relative > 0) ? relative : 0;
287 }
288 if (bytes != NULL) {
289 long relative = peak_bytes - bench_heap_baseline_bytes;
290 *bytes = (relative > 0) ? relative : 0;
291 }
292
293 bench_heap_baseline_allocs = wolfCrypt_heap_peakAllocs_checkpoint();
294 bench_heap_baseline_bytes = wolfCrypt_heap_peakBytes_checkpoint();
295}
296#else
297static WC_INLINE void bench_heap_checkpoint_prepare(void) {}
298static WC_INLINE void bench_heap_checkpoint_measure(long* allocs,
299 long* bytes)
300{
301 if (allocs != NULL)
302 *allocs = 0;
303 if (bytes != NULL)
304 *bytes = 0;
305}
306#endif
307
308#ifdef WC_BENCH_STACK_TRACKING
309static WC_INLINE void bench_stack_checkpoint_prepare(void)
310{
311 (void)StackSizeHWMReset();
312 bench_last_stack_bytes = (long)StackSizeHWM_OffsetCorrected();
313}
314
315static WC_INLINE long bench_stack_checkpoint_measure(void)
316{
317 long used = (long)StackSizeHWM_OffsetCorrected();
318
319 used -= bench_last_stack_bytes;
320 if (used < 0)
321 used = 0;
322 (void)StackSizeHWMReset();
323 bench_last_stack_bytes = used;
324 return used;
325}
326#else
327static WC_INLINE void bench_stack_checkpoint_prepare(void) {}
328static WC_INLINE long bench_stack_checkpoint_measure(void)
329{
330 return 0;
331}
332#endif
333
334#if defined(WC_BENCH_HEAP_TRACKING) || defined(WC_BENCH_STACK_TRACKING)
335static int bench_stats_resources_prepared;
336#ifdef WC_BENCH_HEAP_TRACKING
337static long bench_stats_heap_setup_allocs;
338static long bench_stats_heap_setup_bytes;
339#endif
340#ifdef WC_BENCH_STACK_TRACKING
341static long bench_stats_stack_setup_bytes;
342#endif
343
344static WC_INLINE void bench_stats_reset_setup_offsets(void)
345{
346#ifdef WC_BENCH_HEAP_TRACKING
347 bench_stats_heap_setup_allocs = 0;
348 bench_stats_heap_setup_bytes = 0;
349#endif
350#ifdef WC_BENCH_STACK_TRACKING
351 bench_stats_stack_setup_bytes = 0;
352#endif
353}
354#endif
355
356static WC_INLINE void bench_stats_prepare(void)
357{
358 bench_heap_checkpoint_prepare();
359 bench_stack_checkpoint_prepare();
360#if defined(WC_BENCH_HEAP_TRACKING) || defined(WC_BENCH_STACK_TRACKING)
361 bench_stats_reset_setup_offsets();
362 bench_stats_resources_prepared = 1;
363#endif
364}
365
366#if defined(WC_BENCH_HEAP_TRACKING) || defined(WC_BENCH_STACK_TRACKING)
367static WC_INLINE void bench_append_memory_info(char* buffer, size_t size,
368 int asCsv, long heapAllocs, long heapBytes, long stackBytes)
369{
370 size_t len;
371
372 if (heapAllocs < 0)
373 heapAllocs = 0;
374 if (heapBytes < 0)
375 heapBytes = 0;
376 if (stackBytes < 0)
377 stackBytes = 0;
378
379 len = XSTRLEN(buffer);
380 if (len == 0)
381 return;
382
383 if (buffer[len - 1] == '\n') {
384 buffer[--len] = '\0';
385 }
386
387 if (asCsv) {
388 if (len > 0 && buffer[len - 1] == '\n') {
389 buffer[--len] = '\0';
390 }
391 if (len > 0 && buffer[len - 1] == ',') {
392 buffer[--len] = '\0';
393 }
394 XSNPRINTF(buffer + len, size - len, ",%ld,%ld,%ld\n",
395 heapBytes, heapAllocs, stackBytes);
396 return;
397 }
398 else {
399 int first = 1;
400 XSNPRINTF(buffer + len, size - len, " [");
401 len = XSTRLEN(buffer);
402 XSNPRINTF(buffer + len, size - len,
403 "%sheap %ld bytes (%ld allocs)",
404 first ? "" : ", ", heapBytes, heapAllocs);
405 first = 0;
406 len = XSTRLEN(buffer);
407 XSNPRINTF(buffer + len, size - len,
408 "%sstack %ld bytes", first ? "" : ", ", stackBytes);
409 len = XSTRLEN(buffer);
410 XSNPRINTF(buffer + len, size - len, "]");
411 len = XSTRLEN(buffer);
412 }
413
414 len = XSTRLEN(buffer);
415 if (len == 0 || buffer[len - 1] != '\n') {
416 if (len + 1 < size) {
417 buffer[len++] = '\n';
418 buffer[len] = '\0';
419 }
420 }
421}
422#else
423static WC_INLINE void bench_append_memory_info(char* buffer, size_t size,
424 int asCsv, long heapAllocs, long heapBytes, long stackBytes)
425{
426 (void)buffer;
427 (void)size;
428 (void)asCsv;
429 (void)heapAllocs;
430 (void)heapBytes;
431 (void)stackBytes;
432}
433#endif
434
435#ifdef MULTI_VALUE_STATISTICS
436 #define STATS_CLAUSE_SEPARATOR ""
437 #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
438 squareSum = 0, prev = 0, delta;\
439 int runs = 0;
440 #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
441 delta = current_time(0) - start;\
442 min = delta;\
443 max = delta;\
444 }\
445 else {\
446 delta = current_time(0) - prev;\
447 }\
448 if (max < delta)\
449 max = delta;\
450 else if (min > delta)\
451 min = delta;\
452 sum += delta;\
453 squareSum += delta * delta;\
454 runs++;\
455 prev = current_time(0)
456 #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
457 runs = 0;\
458 sum = 0;\
459 squareSum = 0
460#else
461 #define STATS_CLAUSE_SEPARATOR "\n"
462 #define DECLARE_MULTI_VALUE_STATS_VARS()
463 #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
464 #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
465#endif
466
467#ifdef WOLFSSL_NO_FLOAT_FMT
468 #define FLT_FMT "%0ld,%09lu"
469 #define FLT_FMT_PREC "%0ld.%0*lu"
470 #define FLT_FMT_PREC2 FLT_FMT_PREC
471 #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
472 (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
473 (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
474 static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
475 10000.0, 100000.0, 1000000.0, \
476 10000000.0, 100000000.0, \
477 1000000000.0 };
478 #define FLT_FMT_PREC_ARGS(p, x) \
479 (long)(x), \
480 p, \
481 (x) >= 0.0 ? \
482 (unsigned long int)((((x) - (double)(long)(x)) * \
483 pow_10_array[(p)+1]) + 0.5) : \
484 (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
485 pow_10_array[(p)+1]) + 0.5)
486 #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
487#else
488 #define FLT_FMT "%f"
489 #define FLT_FMT_PREC "%.*f"
490 #define FLT_FMT_PREC2 "%*.*f"
491 #define FLT_FMT_ARGS(x) x
492 #define FLT_FMT_PREC_ARGS(p, x) p, x
493 #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
494#endif /* WOLFSSL_NO_FLOAT_FMT */
495
496#ifdef WOLFSSL_ESPIDF
497 #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
498
499 /* Benchmark uses 64 bit integer formatting support. When new nanolib is
500 * enabled, all if the values in report are blank. */
501 #ifdef CONFIG_NEWLIB_NANO_FORMAT
502 #if CONFIG_NEWLIB_NANO_FORMAT == 1
503 #error "Nano newlib formatting must not be enabled for benchmark"
504 #endif
505 #endif
506 #if ESP_IDF_VERSION_MAJOR >= 5
507 #define TFMT "%lu"
508 #else
509 #define TFMT "%d"
510 #endif
511
512 #ifdef configTICK_RATE_HZ
513 /* Define CPU clock cycles per tick of FreeRTOS clock
514 * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
515 * configTICK_RATE_HZ is typically 100 or 1000.
516 **/
517 #if defined(CONFIG_IDF_TARGET_ESP8266)
518 #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
519 #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
520 CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
521 #endif
522 #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
523 #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
524 #endif
525 #endif
526 #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
527 /* This section is for pre-v5 ESP-IDF */
528 #if defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
529 #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
530 CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
531 #elif defined(CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ)
532 #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
533 CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
534 #elif defined(CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ)
535 #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
536 CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
537 #elif defined(CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ)
538 #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
539 CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
540 #elif defined(CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ)
541 #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
542 CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
543 #else
544 /* TODO unsupported */
545 #endif /* older CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ */
546 #endif
547 #define CPU_TICK_CYCLES ( \
548 (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
549 / configTICK_RATE_HZ \
550 )
551 #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
552
553 #if defined(CONFIG_IDF_TARGET_ESP32C2)
554 #include "driver/gptimer.h"
555 static gptimer_handle_t esp_gptimer = NULL;
556 static gptimer_config_t esp_timer_config = {
557 .clk_src = GPTIMER_CLK_SRC_DEFAULT,
558 .direction = GPTIMER_COUNT_UP,
559 .resolution_hz = CONFIG_XTAL_FREQ * 100000,
560 };
561 #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
562 defined(CONFIG_IDF_TARGET_ESP32C6)
563 #include <esp_cpu.h>
564 #if ESP_IDF_VERSION_MAJOR >= 5
565 #include <driver/gptimer.h>
566 #endif
567 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
568 #define RESOLUTION_SCALE 100
569 /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
570 static gptimer_handle_t esp_gptimer = NULL;
571 static gptimer_config_t esp_timer_config = {
572 .clk_src = GPTIMER_CLK_SRC_DEFAULT,
573 .direction = GPTIMER_COUNT_UP,
574 /* CONFIG_XTAL_FREQ = 40,
575 * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
576 .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
577 (MILLION_VALUE / RESOLUTION_SCALE),
578 };
579 #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
580
581 #elif defined(CONFIG_IDF_TARGET_ESP32) || \
582 defined(CONFIG_IDF_TARGET_ESP32S2) || \
583 defined(CONFIG_IDF_TARGET_ESP32S3)
584 #include <xtensa/hal.h>
585 #elif defined(CONFIG_IDF_TARGET_ESP8266)
586 /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
587 #include <FreeRTOS.h>
588 #include <esp_system.h>
589 #include <esp_timer.h>
590 #include <xtensa/hal.h>
591 #elif defined(CONFIG_IDF_TARGET_ESP32H2)
592 /* TODO add ESP32-H2 benchmark support */
593 #else
594 /* Other platform */
595 #endif
596 #include <esp_log.h>
597#endif /* WOLFSSL_ESPIDF */
598
599#if defined(HAVE_PTHREAD) || \
600 (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
601 !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
602 !defined(BENCH_EMBEDDED))
603 #include <errno.h>
604 #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
605 #include <unistd.h>
606 #endif
607#endif
608
609#if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
610 /* fflush in Zephyr doesn't work on stdout and stderr. Use
611 * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
612 #undef XFFLUSH
613 #define XFFLUSH(...) WC_DO_NOTHING
614#endif
615
616/* only for stack size check */
617#include <wolfssl/wolfcrypt/mem_track.h>
618
619#if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
620 #define WC_ENABLE_BENCH_THREADING
621#endif
622/* enable tracking of stats for threaded benchmark */
623#if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
624 #define WC_BENCH_TRACK_STATS
625#endif
626
627#ifdef GENERATE_MACHINE_PARSEABLE_REPORT
628 static const char info_prefix[] = "###, ";
629 static const char err_prefix[] = "!!!, ";
630#else
631 static const char info_prefix[] = "";
632 static const char err_prefix[] = "";
633#endif
634
635
636/* printf mappings */
637#ifdef FREESCALE_MQX
638 #include <mqx.h>
639 /* see wc_port.h for fio.h and nio.h includes */
640#elif defined(FREESCALE_KSDK_1_3)
641 #include "fsl_debug_console.h"
642 #include "fsl_os_abstraction.h"
643
644 #undef printf
645 #define printf PRINTF
646#elif defined(WOLFSSL_DEOS)
647 #include <deos.h>
648 #include <printx.h>
649 #undef printf
650 #define printf printx
651#elif defined(MICRIUM)
652 #if (OS_VERSION < 50000)
653 #include <bsp_ser.h>
654 void BSP_Ser_Printf (CPU_CHAR* format, ...);
655 #undef printf
656 #define printf BSP_Ser_Printf
657 #endif
658#elif defined(WOLFSSL_ZEPHYR)
659 #include <stdio.h>
660 #include <stdarg.h>
661 #define BENCH_EMBEDDED
662 #define printf printfk
663 static int printfk(const char *fmt, ...)
664 {
665 int ret;
666 char line[WC_BENCH_MAX_LINE_LEN];
667 va_list ap;
668
669 va_start(ap, fmt);
670
671 ret = vsnprintf(line, sizeof(line), fmt, ap);
672 line[sizeof(line)-1] = '\0';
673 printk("%s", line);
674
675 va_end(ap);
676
677 return ret;
678 }
679
680#elif defined(WOLFSSL_TELIT_M2MB)
681 #include <stdarg.h>
682 #include <stdio.h>
683 #include <string.h>
684 #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
685 /* remap printf */
686 #undef printf
687 #define printf M2M_LOG_INFO
688 /* OS requires occasional sleep() */
689 #ifndef TEST_SLEEP_MS
690 #define TEST_SLEEP_MS 50
691 #endif
692 #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
693 /* don't use file system for these tests, since ./certs dir isn't loaded */
694 #undef NO_FILESYSTEM
695 #define NO_FILESYSTEM
696
697/* ANDROID_V454 (for android studio) displays information in a textview
698 * and redirects printf to the textview output instead of using
699 * __android_log_print() */
700#elif defined(ANDROID) && !defined(ANDROID_V454)
701 #ifdef XMALLOC_USER
702 #include <stdlib.h> /* we're using malloc / free direct here */
703 #endif
704 #ifndef STRING_USER
705 #include <stdio.h>
706 #endif
707 #include <android/log.h>
708
709 #define printf(...) \
710 __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
711 #define fprintf(fp, ...) \
712 __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
713
714#else
715 #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
716 /* MQX classic needs for EXIT_FAILURE */
717 #include <stdlib.h> /* we're using malloc / free direct here */
718 #endif
719
720 #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
721 #include <string.h>
722 #include <stdio.h>
723 #endif
724
725 /* enable way for customer to override test/bench printf */
726 #ifdef XPRINTF
727 #undef printf
728 #define printf XPRINTF
729 #elif defined(NETOS)
730 int dc_log_printf(char* format, ...);
731 #undef printf
732 #define printf dc_log_printf
733 #endif
734#endif
735
736#ifdef HAVE_ASCON
737 #include <wolfssl/wolfcrypt/ascon.h>
738#endif
739
740#ifdef HAVE_FIPS
741 #include <wolfssl/wolfcrypt/fips_test.h>
742
743 static void myFipsCb(int ok, int err, const char* hash)
744 {
745 printf("%sin my Fips callback, ok = %d, err = %d\n",
746 ok ? info_prefix : err_prefix, ok, err);
747 printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
748 wc_GetErrorString(err));
749 printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
750
751 if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
752 printf("%sIn core integrity hash check failure, copy above hash\n",
753 err_prefix);
754 printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
755 err_prefix);
756 }
757 }
758#endif
759
760#ifdef WOLFSSL_STATIC_MEMORY
761 static WOLFSSL_HEAP_HINT* HEAP_HINT;
762#else
763 #define HEAP_HINT NULL
764#endif /* WOLFSSL_STATIC_MEMORY */
765
766#ifndef EXIT_FAILURE
767#define EXIT_FAILURE 1
768#endif
769
770#undef LIBCALL_CHECK_RET
771#if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
772 defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
773#define LIBCALL_CHECK_RET(...) (void)(__VA_ARGS__)
774#else
775#define LIBCALL_CHECK_RET(...) do { \
776 int _libcall_ret = (__VA_ARGS__); \
777 if (_libcall_ret < 0) { \
778 printf("%s%s L%d error %d for \"%s\"\n", \
779 err_prefix, __FILE__, __LINE__, \
780 errno, #__VA_ARGS__); \
781 XFFLUSH(stdout); \
782 _exit(1); \
783 } \
784 } while(0)
785#endif
786
787#undef THREAD_CHECK_RET
788#define THREAD_CHECK_RET(...) do { \
789 int _thread_ret = (__VA_ARGS__); \
790 if (_thread_ret != 0) { \
791 errno = _thread_ret; \
792 printf("%s%s L%d error %d for \"%s\"\n", \
793 err_prefix, __FILE__, __LINE__, \
794 _thread_ret, #__VA_ARGS__); \
795 XFFLUSH(stdout); \
796 _exit(1); \
797 } \
798 } while(0)
799
800/* optional macro to add sleep between tests */
801#ifndef TEST_SLEEP
802 #define TEST_SLEEP() WC_RELAX_LONG_LOOP()
803#endif
804
805#define TEST_STRING "Everyone gets Friday off."
806#define TEST_STRING_SZ 25
807
808/* Bit values for each algorithm that is able to be benchmarked.
809 * Common grouping of algorithms also.
810 * Each algorithm has a unique value for its type e.g. cipher.
811 */
812/* Cipher algorithms. */
813#define BENCH_AES_CBC 0x00000001
814#define BENCH_AES_GCM 0x00000002
815#define BENCH_AES_GMAC 0x00400000
816#define BENCH_AES_ECB 0x00000004
817#define BENCH_AES_XTS 0x00000008
818#define BENCH_AES_CTR 0x00000010
819#define BENCH_AES_CCM 0x00000020
820#define BENCH_CAMELLIA 0x00000100
821#define BENCH_ARC4 0x00000200
822#define BENCH_CHACHA20 0x00001000
823#define BENCH_CHACHA20_POLY1305 0x00002000
824#define BENCH_DES 0x00004000
825#define BENCH_AES_CFB 0x00010000
826#define BENCH_AES_OFB 0x00020000
827#define BENCH_AES_SIV 0x00040000
828#define BENCH_SM4_CBC 0x00080000
829#define BENCH_SM4_GCM 0x00100000
830#define BENCH_SM4_CCM 0x00200000
831#define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
832/* Digest algorithms. */
833#define BENCH_MD5 0x00000001
834#define BENCH_POLY1305 0x00000002
835#define BENCH_SHA 0x00000004
836#define BENCH_SHA224 0x00000010
837#define BENCH_SHA256 0x00000020
838#define BENCH_SHA384 0x00000040
839#define BENCH_SHA512 0x00000080
840#define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
841 BENCH_SHA384 | BENCH_SHA512)
842#define BENCH_SHA3_224 0x00000100
843#define BENCH_SHA3_256 0x00000200
844#define BENCH_SHA3_384 0x00000400
845#define BENCH_SHA3_512 0x00000800
846#define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
847 BENCH_SHA3_384 | BENCH_SHA3_512)
848#define BENCH_SHAKE128 0x00001000
849#define BENCH_SHAKE256 0x00002000
850#define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
851#define BENCH_RIPEMD 0x00004000
852#define BENCH_BLAKE2B 0x00008000
853#define BENCH_BLAKE2S 0x00010000
854#define BENCH_SM3 0x00020000
855#define BENCH_ASCON_HASH256 0x00040000
856#define BENCH_ASCON_AEAD128 0x00080000
857
858/* MAC algorithms. */
859#define BENCH_CMAC 0x00000001
860#define BENCH_HMAC_MD5 0x00000002
861#define BENCH_HMAC_SHA 0x00000004
862#define BENCH_HMAC_SHA224 0x00000010
863#define BENCH_HMAC_SHA256 0x00000020
864#define BENCH_HMAC_SHA384 0x00000040
865#define BENCH_HMAC_SHA512 0x00000080
866#define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
867 BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
868 BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
869#define BENCH_PBKDF2 0x00000100
870#define BENCH_SIPHASH 0x00000200
871
872/* KDF algorithms */
873#define BENCH_SRTP_KDF 0x00000001
874
875/* Asymmetric algorithms. */
876#define BENCH_RSA_KEYGEN 0x00000001
877#define BENCH_RSA 0x00000002
878#define BENCH_RSA_SZ 0x00000004
879#define BENCH_DH 0x00000010
880#define BENCH_ECC_MAKEKEY 0x00001000
881#define BENCH_ECC 0x00002000
882#define BENCH_ECC_ENCRYPT 0x00004000
883#define BENCH_ECC_ALL 0x00008000
884#define BENCH_CURVE25519_KEYGEN 0x00010000
885#define BENCH_CURVE25519_KA 0x00020000
886#define BENCH_ED25519_KEYGEN 0x00040000
887#define BENCH_ED25519_SIGN 0x00080000
888#define BENCH_CURVE448_KEYGEN 0x00100000
889#define BENCH_CURVE448_KA 0x00200000
890#define BENCH_ED448_KEYGEN 0x00400000
891#define BENCH_ED448_SIGN 0x00800000
892#define BENCH_ECC_P256 0x01000000
893#define BENCH_ECC_P384 0x02000000
894#define BENCH_ECC_P521 0x04000000
895#define BENCH_SM2 0x08000000
896#define BENCH_ECCSI_KEYGEN 0x00000020
897#define BENCH_ECCSI_PAIRGEN 0x00000040
898#define BENCH_ECCSI_VALIDATE 0x00000080
899#define BENCH_ECCSI 0x00000400
900#define BENCH_SAKKE_KEYGEN 0x10000000
901#define BENCH_SAKKE_RSKGEN 0x20000000
902#define BENCH_SAKKE_VALIDATE 0x40000000
903#define BENCH_SAKKE 0x80000000
904
905/* Post-Quantum Asymmetric algorithms. */
906#define BENCH_KYBER512 0x00000020
907#define BENCH_KYBER768 0x00000040
908#define BENCH_KYBER1024 0x00000080
909#define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
910 BENCH_KYBER1024)
911#define BENCH_ML_KEM_512 0x00000020
912#define BENCH_ML_KEM_768 0x00000040
913#define BENCH_ML_KEM_1024 0x00000080
914#define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
915 BENCH_ML_KEM_1024)
916#define BENCH_FALCON_LEVEL1_SIGN 0x00000001
917#define BENCH_FALCON_LEVEL5_SIGN 0x00000002
918#define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
919#define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
920#define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
921#define BENCH_ML_DSA_44_SIGN 0x04000000
922#define BENCH_ML_DSA_65_SIGN 0x08000000
923#define BENCH_ML_DSA_87_SIGN 0x10000000
924#define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
925 BENCH_ML_DSA_65_SIGN | \
926 BENCH_ML_DSA_87_SIGN)
927
928
929/* Post-Quantum Stateful Hash-Based sig algorithms. */
930#define BENCH_LMS_HSS 0x00000001
931#define BENCH_XMSS_XMSSMT_SHA256 0x00000002
932#define BENCH_XMSS_XMSSMT_SHA512 0x00000004
933#define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
934#define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
935#ifndef NO_SHA256
936#define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
937#elif defined(WOLFSSL_SHA512)
938#define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
939#elif defined(WOLFSSL_SHAKE128)
940#define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
941#elif defined(WOLFSSL_SHAKE256)
942#define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
943#else
944#define BENCH_XMSS_XMSSMT 0x00000000
945#endif
946#define BENCH_SLHDSA_SHAKE128S 0x00000020
947#define BENCH_SLHDSA_SHAKE128F 0x00000040
948#define BENCH_SLHDSA_SHAKE192S 0x00000080
949#define BENCH_SLHDSA_SHAKE192F 0x00000100
950#define BENCH_SLHDSA_SHAKE256S 0x00000200
951#define BENCH_SLHDSA_SHAKE256F 0x00000400
952#define BENCH_SLHDSA_SHA2_128S 0x00000800
953#define BENCH_SLHDSA_SHA2_128F 0x00001000
954#define BENCH_SLHDSA_SHA2_192S 0x00002000
955#define BENCH_SLHDSA_SHA2_192F 0x00004000
956#define BENCH_SLHDSA_SHA2_256S 0x00008000
957#define BENCH_SLHDSA_SHA2_256F 0x00010000
958#define BENCH_SLHDSA (BENCH_SLHDSA_SHAKE128S | \
959 BENCH_SLHDSA_SHAKE128F | \
960 BENCH_SLHDSA_SHAKE192S | \
961 BENCH_SLHDSA_SHAKE192F | \
962 BENCH_SLHDSA_SHAKE256S | \
963 BENCH_SLHDSA_SHAKE256F | \
964 BENCH_SLHDSA_SHA2_128S | \
965 BENCH_SLHDSA_SHA2_128F | \
966 BENCH_SLHDSA_SHA2_192S | \
967 BENCH_SLHDSA_SHA2_192F | \
968 BENCH_SLHDSA_SHA2_256S | \
969 BENCH_SLHDSA_SHA2_256F)
970
971/* Other */
972#define BENCH_RNG 0x00000001
973#define BENCH_SCRYPT 0x00000002
974#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
975 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
976 #define BENCH_RNG_SHA512 0x00000004
977#endif
978#define BENCH_RNG_INIT 0x00000008
979#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
980 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
981 #define BENCH_RNG_SHA512_INIT 0x00000010
982#endif
983
984#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || \
985 (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
986/* Define AES_AUTH_ADD_SZ already here, since it's used in the
987 * static declaration of `bench_Usage_msg1`. */
988#if !defined(AES_AUTH_ADD_SZ) && \
989 (defined(STM32_CRYPTO) || \
990 defined(WOLFSSL_XILINX_CRYPT_VERSAL))
991 /* For STM32 use multiple of 4 to leverage crypto hardware
992 * Xilinx Versal requires to use multiples of 16 bytes */
993 #define AES_AUTH_ADD_SZ 16
994#endif
995#ifndef AES_AUTH_ADD_SZ
996 #define AES_AUTH_ADD_SZ 13
997#endif
998#endif
999
1000#if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
1001 (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)) || \
1002 defined(WOLFSSL_HAVE_SLHDSA)
1003 #define BENCH_PQ_STATEFUL_HBS
1004#endif
1005
1006/* Benchmark all compiled in algorithms.
1007 * When 1, ignore other benchmark algorithm values.
1008 * 0, only benchmark algorithm values set.
1009 */
1010static int bench_all = 1;
1011/* Cipher algorithms to benchmark. */
1012static word32 bench_cipher_algs = 0;
1013/* Digest algorithms to benchmark. */
1014static word32 bench_digest_algs = 0;
1015/* MAC algorithms to benchmark. */
1016static word32 bench_mac_algs = 0;
1017/* KDF algorithms to benchmark. */
1018static word32 bench_kdf_algs = 0;
1019/* Asymmetric algorithms to benchmark. */
1020static word32 bench_asym_algs = 0;
1021/* Post-Quantum Asymmetric algorithms to benchmark. */
1022static word32 bench_pq_asym_algs = 0;
1023/* Other cryptographic algorithms to benchmark. */
1024static word32 bench_other_algs = 0;
1025/* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
1026static word32 bench_pq_hash_sig_algs = 0;
1027
1028#if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
1029
1030/* The mapping of command line option to bit values. */
1031typedef struct bench_alg {
1032 /* Command line option string. */
1033 const char* str;
1034 /* Bit values to set. */
1035 word32 val;
1036} bench_alg;
1037
1038#ifndef MAIN_NO_ARGS
1039/* All recognized cipher algorithm choosing command line options. */
1040static const bench_alg bench_cipher_opt[] = {
1041 { "-cipher", 0xffffffff },
1042#ifdef HAVE_AES_CBC
1043 { "-aes-cbc", BENCH_AES_CBC },
1044#endif
1045#ifdef HAVE_AESGCM
1046 { "-aes-gcm", BENCH_AES_GCM },
1047#endif
1048#ifdef HAVE_AESGCM
1049 { "-aes-gmac", BENCH_AES_GMAC },
1050#endif
1051#if defined(HAVE_AES_ECB) || (defined(HAVE_FIPS) && defined(WOLFSSL_AES_DIRECT))
1052 { "-aes-ecb", BENCH_AES_ECB },
1053#endif
1054#ifdef WOLFSSL_AES_XTS
1055 { "-aes-xts", BENCH_AES_XTS },
1056#endif
1057#ifdef WOLFSSL_AES_CFB
1058 { "-aes-cfb", BENCH_AES_CFB },
1059#endif
1060#ifdef WOLFSSL_AES_OFB
1061 { "-aes-ofb", BENCH_AES_OFB },
1062#endif
1063#ifdef WOLFSSL_AES_COUNTER
1064 { "-aes-ctr", BENCH_AES_CTR },
1065#endif
1066#ifdef HAVE_AESCCM
1067 { "-aes-ccm", BENCH_AES_CCM },
1068#endif
1069#ifdef WOLFSSL_AES_SIV
1070 { "-aes-siv", BENCH_AES_SIV },
1071#endif
1072#ifdef HAVE_CAMELLIA
1073 { "-camellia", BENCH_CAMELLIA },
1074#endif
1075#ifndef NO_RC4
1076 { "-arc4", BENCH_ARC4 },
1077#endif
1078#ifdef HAVE_CHACHA
1079 { "-chacha20", BENCH_CHACHA20 },
1080#endif
1081#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
1082 { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
1083#endif
1084#ifdef WOLFSSL_SM4_CBC
1085 { "-sm4-cbc", BENCH_SM4_CBC },
1086#endif
1087#ifdef WOLFSSL_SM4_GCM
1088 { "-sm4-gcm", BENCH_SM4_GCM },
1089#endif
1090#ifdef WOLFSSL_SM4_CCM
1091 { "-sm4-ccm", BENCH_SM4_CCM },
1092#endif
1093#ifdef WOLFSSL_SM4
1094 { "-sm4", BENCH_SM4 },
1095#endif
1096#ifndef NO_DES3
1097 { "-des", BENCH_DES },
1098#endif
1099#ifdef HAVE_ASCON
1100 { "-ascon-aead", BENCH_ASCON_AEAD128 },
1101#endif
1102 { NULL, 0 }
1103};
1104
1105/* All recognized digest algorithm choosing command line options. */
1106static const bench_alg bench_digest_opt[] = {
1107 { "-digest", 0xffffffff },
1108#ifndef NO_MD5
1109 { "-md5", BENCH_MD5 },
1110#endif
1111#ifdef HAVE_POLY1305
1112 { "-poly1305", BENCH_POLY1305 },
1113#endif
1114#ifndef NO_SHA
1115 { "-sha", BENCH_SHA },
1116#endif
1117#if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
1118 || defined(WOLFSSL_SHA512)
1119 { "-sha2", BENCH_SHA2 },
1120#endif
1121#ifdef WOLFSSL_SHA224
1122 { "-sha224", BENCH_SHA224 },
1123#endif
1124#ifndef NO_SHA256
1125 { "-sha256", BENCH_SHA256 },
1126#endif
1127#ifdef WOLFSSL_SHA384
1128 { "-sha384", BENCH_SHA384 },
1129#endif
1130#ifdef WOLFSSL_SHA512
1131 { "-sha512", BENCH_SHA512 },
1132#endif
1133#ifdef WOLFSSL_SHA3
1134 { "-sha3", BENCH_SHA3 },
1135 #ifndef WOLFSSL_NOSHA3_224
1136 { "-sha3-224", BENCH_SHA3_224 },
1137 #endif
1138 #ifndef WOLFSSL_NOSHA3_256
1139 { "-sha3-256", BENCH_SHA3_256 },
1140 #endif
1141 #ifndef WOLFSSL_NOSHA3_384
1142 { "-sha3-384", BENCH_SHA3_384 },
1143 #endif
1144 #ifndef WOLFSSL_NOSHA3_512
1145 { "-sha3-512", BENCH_SHA3_512 },
1146 #endif
1147 #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
1148 { "-shake", BENCH_SHAKE },
1149 #endif
1150 #ifdef WOLFSSL_SHAKE128
1151 { "-shake128", BENCH_SHAKE128 },
1152 #endif
1153 #ifdef WOLFSSL_SHAKE256
1154 { "-shake256", BENCH_SHAKE256 },
1155 #endif
1156#endif
1157#ifdef WOLFSSL_SM3
1158 { "-sm3", BENCH_SM3 },
1159#endif
1160#ifdef WOLFSSL_RIPEMD
1161 { "-ripemd", BENCH_RIPEMD },
1162#endif
1163#ifdef HAVE_BLAKE2B
1164 { "-blake2b", BENCH_BLAKE2B },
1165#endif
1166#ifdef HAVE_BLAKE2S
1167 { "-blake2s", BENCH_BLAKE2S },
1168#endif
1169#ifdef HAVE_ASCON
1170 { "-ascon-hash", BENCH_ASCON_HASH256 },
1171#endif
1172 { NULL, 0 }
1173};
1174
1175/* All recognized MAC algorithm choosing command line options. */
1176static const bench_alg bench_mac_opt[] = {
1177 { "-mac", 0xffffffff },
1178#ifdef WOLFSSL_CMAC
1179 { "-cmac", BENCH_CMAC },
1180#endif
1181#ifndef NO_HMAC
1182 { "-hmac", BENCH_HMAC },
1183 #ifndef NO_MD5
1184 { "-hmac-md5", BENCH_HMAC_MD5 },
1185 #endif
1186 #ifndef NO_SHA
1187 { "-hmac-sha", BENCH_HMAC_SHA },
1188 #endif
1189 #ifdef WOLFSSL_SHA224
1190 { "-hmac-sha224", BENCH_HMAC_SHA224 },
1191 #endif
1192 #ifndef NO_SHA256
1193 { "-hmac-sha256", BENCH_HMAC_SHA256 },
1194 #endif
1195 #ifdef WOLFSSL_SHA384
1196 { "-hmac-sha384", BENCH_HMAC_SHA384 },
1197 #endif
1198 #ifdef WOLFSSL_SHA512
1199 { "-hmac-sha512", BENCH_HMAC_SHA512 },
1200 #endif
1201 #ifndef NO_PWDBASED
1202 { "-pbkdf2", BENCH_PBKDF2 },
1203 #endif
1204#endif
1205 #ifdef WOLFSSL_SIPHASH
1206 { "-siphash", BENCH_SIPHASH },
1207 #endif
1208 { NULL, 0 }
1209};
1210
1211/* All recognized KDF algorithm choosing command line options. */
1212static const bench_alg bench_kdf_opt[] = {
1213 { "-kdf", 0xffffffff },
1214#ifdef WC_SRTP_KDF
1215 { "-srtp-kdf", BENCH_SRTP_KDF },
1216#endif
1217 { NULL, 0 }
1218};
1219
1220/* All recognized asymmetric algorithm choosing command line options. */
1221static const bench_alg bench_asym_opt[] = {
1222 { "-asym", 0xffffffff },
1223#ifndef NO_RSA
1224 #ifdef WOLFSSL_KEY_GEN
1225 { "-rsa-kg", BENCH_RSA_KEYGEN },
1226 #endif
1227 { "-rsa", BENCH_RSA },
1228 #ifdef WOLFSSL_KEY_GEN
1229 { "-rsa-sz", BENCH_RSA_SZ },
1230 #endif
1231#endif
1232#ifndef NO_DH
1233 { "-dh", BENCH_DH },
1234#endif
1235#ifdef HAVE_ECC
1236 { "-ecc-kg", BENCH_ECC_MAKEKEY },
1237 { "-ecc", BENCH_ECC },
1238 #ifdef HAVE_ECC_ENCRYPT
1239 { "-ecc-enc", BENCH_ECC_ENCRYPT },
1240 #endif
1241 { "-ecc-all", BENCH_ECC_ALL },
1242#endif
1243#ifdef WOLFSSL_SM2
1244 { "-sm2", BENCH_SM2 },
1245#endif
1246#ifdef HAVE_CURVE25519
1247 { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
1248 #ifdef HAVE_CURVE25519_SHARED_SECRET
1249 { "-x25519", BENCH_CURVE25519_KA },
1250 #endif
1251#endif
1252#ifdef HAVE_ED25519
1253 { "-ed25519-kg", BENCH_ED25519_KEYGEN },
1254 { "-ed25519", BENCH_ED25519_SIGN },
1255#endif
1256#ifdef HAVE_CURVE448
1257 { "-curve448-kg", BENCH_CURVE448_KEYGEN },
1258 #ifdef HAVE_CURVE448_SHARED_SECRET
1259 { "-x448", BENCH_CURVE448_KA },
1260 #endif
1261#endif
1262#ifdef HAVE_ED448
1263 { "-ed448-kg", BENCH_ED448_KEYGEN },
1264 { "-ed448", BENCH_ED448_SIGN },
1265#endif
1266#ifdef WOLFCRYPT_HAVE_ECCSI
1267 { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
1268 { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
1269 { "-eccsi-val", BENCH_ECCSI_VALIDATE },
1270 { "-eccsi", BENCH_ECCSI },
1271#endif
1272#ifdef WOLFCRYPT_HAVE_SAKKE
1273 { "-sakke-kg", BENCH_SAKKE_KEYGEN },
1274 { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
1275 { "-sakke-val", BENCH_SAKKE_VALIDATE },
1276 { "-sakke", BENCH_SAKKE },
1277#endif
1278 { NULL, 0 }
1279};
1280
1281/* All recognized other cryptographic algorithm choosing command line options.
1282 */
1283static const bench_alg bench_other_opt[] = {
1284 { "-other", 0xffffffff },
1285#ifndef WC_NO_RNG
1286 { "-rng", BENCH_RNG },
1287#endif
1288#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
1289 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
1290 { "-rng-sha512", BENCH_RNG_SHA512 },
1291#endif
1292#ifndef WC_NO_RNG
1293 { "-rng-init", BENCH_RNG_INIT },
1294#endif
1295#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
1296 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
1297 { "-rng-sha512-init", BENCH_RNG_SHA512_INIT },
1298#endif
1299#ifdef HAVE_SCRYPT
1300 { "-scrypt", BENCH_SCRYPT },
1301#endif
1302 { NULL, 0}
1303};
1304#endif /* MAIN_NO_ARGS */
1305
1306#endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
1307
1308#if defined(BENCH_PQ_STATEFUL_HBS)
1309typedef struct bench_pq_hash_sig_alg {
1310 /* Command line option string. */
1311 const char* str;
1312 /* Bit values to set. */
1313 word32 val;
1314} bench_pq_hash_sig_alg;
1315
1316static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
1317 { "-pq_hash_sig", 0xffffffff},
1318#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
1319 { "-lms_hss", BENCH_LMS_HSS},
1320#endif
1321#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
1322 { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
1323#ifdef WC_XMSS_SHA256
1324 { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
1325#endif
1326#ifdef WC_XMSS_SHA512
1327#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
1328 { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
1329#endif
1330#endif
1331#ifdef WC_XMSS_SHAKE128
1332#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
1333 { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
1334#endif
1335#endif
1336#ifdef WC_XMSS_SHAKE256
1337 { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
1338#endif
1339#endif
1340#if defined(WOLFSSL_HAVE_SLHDSA)
1341 { "-slhdsa-shake128s", BENCH_SLHDSA_SHAKE128S},
1342 { "-slhdsa-shake128f", BENCH_SLHDSA_SHAKE128F},
1343 { "-slhdsa-shake192s", BENCH_SLHDSA_SHAKE192S},
1344 { "-slhdsa-shake192f", BENCH_SLHDSA_SHAKE192F},
1345 { "-slhdsa-shake256s", BENCH_SLHDSA_SHAKE256S},
1346 { "-slhdsa-shake256f", BENCH_SLHDSA_SHAKE256F},
1347 { "-slhdsa-sha2-128s", BENCH_SLHDSA_SHA2_128S},
1348 { "-slhdsa-sha2-128f", BENCH_SLHDSA_SHA2_128F},
1349 { "-slhdsa-sha2-192s", BENCH_SLHDSA_SHA2_192S},
1350 { "-slhdsa-sha2-192f", BENCH_SLHDSA_SHA2_192F},
1351 { "-slhdsa-sha2-256s", BENCH_SLHDSA_SHA2_256S},
1352 { "-slhdsa-sha2-256f", BENCH_SLHDSA_SHA2_256F},
1353 { "-slhdsa", BENCH_SLHDSA },
1354#endif
1355 { NULL, 0}
1356};
1357#endif /* BENCH_PQ_STATEFUL_HBS */
1358
1359#if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(MAIN_NO_ARGS)
1360#if defined(WOLFSSL_HAVE_MLKEM) || defined(HAVE_FALCON) || \
1361 defined(HAVE_DILITHIUM)
1362/* The post-quantum-specific mapping of command line option to bit values and
1363 * OQS name. */
1364typedef struct bench_pq_alg {
1365 /* Command line option string. */
1366 const char* str;
1367 /* Bit values to set. */
1368 word32 val;
1369} bench_pq_alg;
1370
1371/* All recognized post-quantum asymmetric algorithm choosing command line
1372 * options. */
1373static const bench_pq_alg bench_pq_asym_opt[] = {
1374 { "-pq", 0xffffffff },
1375#ifdef WOLFSSL_HAVE_MLKEM
1376 { "-kyber", BENCH_KYBER },
1377 { "-kyber512", BENCH_KYBER512 },
1378 { "-kyber768", BENCH_KYBER768 },
1379 { "-kyber1024", BENCH_KYBER1024 },
1380 { "-ml-kem", BENCH_ML_KEM },
1381 { "-ml-kem-512", BENCH_ML_KEM_512 },
1382 { "-ml-kem-768", BENCH_ML_KEM_768 },
1383 { "-ml-kem-1024", BENCH_ML_KEM_1024 },
1384#endif
1385#if defined(HAVE_FALCON)
1386 { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
1387 { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
1388#endif
1389#if defined(HAVE_DILITHIUM)
1390 { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
1391 { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
1392 { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
1393 { "-ml-dsa", BENCH_ML_DSA_SIGN },
1394 { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
1395 { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
1396 { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
1397#endif
1398 { NULL, 0 }
1399};
1400#endif
1401
1402#endif
1403
1404#ifdef HAVE_WNR
1405 const char* wnrConfigFile = "wnr-example.conf";
1406#endif
1407
1408#if defined(WOLFSSL_MDK_ARM)
1409 extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
1410 #define fopen wolfSSL_fopen
1411#endif
1412
1413static int lng_index = 0;
1414
1415#ifndef NO_MAIN_DRIVER
1416#ifndef MAIN_NO_ARGS
1417static const char* bench_Usage_msg1[][29] = {
1418 /* 0 English */
1419 { "-? <num> Help, print this usage\n",
1420 " 0: English, 1: Japanese\n",
1421 "-csv Print terminal output in csv format\n",
1422 "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
1423 "-same_buf Use same buffer for out as in (AES-CBC/AES-CTR)\n",
1424 "-no_aad No additional authentication data passed.\n",
1425 "-aad_size <num> With <num> bytes of AAD.\n",
1426 ("-all_aad With AAD length of 0, "
1427 WC_STRINGIFY(AES_AUTH_ADD_SZ)
1428 " and\n"
1429 " (if set via -aad_size) <aad_size> bytes.\n"
1430 ),
1431 "-dgst_full Full digest operation performed.\n",
1432 "-mac_final MAC update and final operation timed.\n",
1433 "-aead_set_key Set the key as part of the timing of AEAD ciphers.\n",
1434 "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
1435 "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
1436 "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
1437 "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
1438 "-p256 Measure ECC using P-256 curve.\n",
1439 "-p384 Measure ECC using P-384 curve.\n",
1440 "-p521 Measure ECC using P-521 curve.\n",
1441 "-ecc-all Bench all enabled ECC curves.\n",
1442 "-<alg> Algorithm to benchmark. Available algorithms include:\n",
1443 ("-lng <num> Display benchmark result by specified language.\n"
1444 " 0: English, 1: Japanese\n"
1445 ),
1446 "<num> Size of block in bytes\n",
1447 ("-blocks <num> Number of blocks. Can be used together with the "
1448 "'Size of block'\n"
1449 " option, but must be used after that one.\n"
1450 ),
1451 "-threads <num> Number of threads to run\n",
1452 "-print Show benchmark stats summary\n",
1453 "-hash_input <file> Input data to use for hash benchmarking\n",
1454 "-cipher_input <file> Input data to use for cipher benchmarking\n",
1455 "-min_runs <num> Specify minimum number of operation runs\n",
1456 "-freq <num> Actual clock frequency\n"
1457 },
1458#ifndef NO_MULTIBYTE_PRINT
1459 /* 1 Japanese */
1460 { "-? <num> ใใซใ, ไฝฟใๆนใ่กจ็คบใใพใใ\n",
1461 " 0: ่ฑ่ชใ 1: ๆฅๆฌ่ช\n",
1462 "-csv csv ๅฝขๅผใง็ซฏๆซใซๅบๅใใพใใ\n",
1463 "-base10 ใใคใใ10ใฎในใไนใง่กจ็คบใใพใใ(ไพ 1 kB = 1000 Bytes)\n",
1464 "-same_buf Use the same buffer for in and out in AES-CBC\n",
1465 "-no_aad ่ฟฝๅ ใฎ่ช่จผใใผใฟใไฝฟ็จใใพใใ.\n",
1466 "-aad_size <num> TBD.\n",
1467 "-all_aad TBD.\n",
1468 "-dgst_full ใใซใฎ digest ๆๅทๆไฝใๅฎๆฝใใพใใ\n",
1469 "-mac_final MAC update and final operation timed.\n",
1470 "-aead_set_key Set the key as part of the timing of AEAD ciphers.\n",
1471 "-rsa_sign ๆๅท/ๅพฉๅทๅใฎไปฃใใใซ RSA ใฎ็ฝฒๅ/ๆค่จผใๆธฌๅฎใใพใใ\n",
1472 "<keySz> -rsa-sz\n RSA <key size> ใฎๆง่ฝใๆธฌๅฎใใพใใ\n",
1473 "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
1474 "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
1475 "-p256 Measure ECC using P-256 curve.\n",
1476 "-p384 Measure ECC using P-384 curve.\n",
1477 "-p521 Measure ECC using P-521 curve.\n",
1478 "-ecc-all Bench all enabled ECC curves.\n",
1479 ("-<alg> ใขใซใดใชใบใ ใฎใใณใใใผใฏใๅฎๆฝใใพใใ\n"
1480 " ๅฉ็จๅฏ่ฝใชใขใซใดใชใบใ ใฏไธ่จใๅซใฟใพใ:\n"
1481 ),
1482 ("-lng <num> ๆๅฎใใใ่จ่ชใงใใณใใใผใฏ็ตๆใ่กจ็คบใใพใใ\n"
1483 " 0: ่ฑ่ชใ 1: ๆฅๆฌ่ช\n"
1484 ),
1485 "<num> ใใญใใฏใตใคใบใใใคใๅไฝใงๆๅฎใใพใใ\n",
1486 "-blocks <num> TBD.\n",
1487 "-threads <num> ๅฎ่กใใในใฌใใๆฐ\n",
1488 "-print ใใณใใใผใฏ็ตฑ่จใฎ่ฆ็ดใ่กจ็คบใใ\n",
1489 /* TODO: translate below */
1490 "-hash_input <file> Input data to use for hash benchmarking\n",
1491 "-cipher_input <file> Input data to use for cipher benchmarking\n",
1492 "-min_runs <num> Specify minimum number of operation runs\n",
1493 "-freq <num> Actual clock frequency\n"
1494 },
1495#endif
1496};
1497#endif /* MAIN_NO_ARGS */
1498#endif
1499
1500static const char* bench_result_words1[][5] = {
1501 { "took",
1502#ifdef BENCH_MICROSECOND
1503 "microseconds"
1504#else
1505 "seconds"
1506#endif
1507 , "Cycles per byte", "Cycles/op",
1508 NULL }, /* 0 English */
1509#ifndef NO_MULTIBYTE_PRINT
1510 { "ใ" , "็งใงๅฆ็", "1ใใคใใใใใฎใตใคใฏใซๆฐ", "Cycles/op",
1511 NULL }, /* 1 Japanese */
1512#endif
1513};
1514
1515#if ((!defined(NO_RSA) || \
1516 defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
1517 defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
1518 defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
1519 defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
1520 defined(HAVE_DILITHIUM)) && !defined(WC_NO_RNG)) || \
1521 defined(WOLFSSL_HAVE_MLKEM)
1522
1523static const char* bench_desc_words[][15] = {
1524 /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
1525 {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
1526#ifndef NO_MULTIBYTE_PRINT
1527 {"ๅ
ฌ้้ต", "็งๅฏ้ต" ,"้ต็ๆ" , "้ตๅ
ฑๆ" , "็ฝฒๅ", "ๆค่จผ" , "ๆๅทๅ" , "ๅพฉๅทๅ" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
1528#endif
1529};
1530
1531#endif
1532
1533#ifdef MULTI_VALUE_STATISTICS
1534static const char* bench_result_words3[][5] = {
1535 /* 0 English */
1536 { "max duration", "min duration" , "mean duration", "sd", NULL },
1537 /* TODO: Add japenese version */
1538 { "max duration", "min duration" , "mean duration", "sd", NULL }
1539};
1540#endif
1541
1542#if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && \
1543 !defined(WOLFSSL_SGX)
1544 #define HAVE_GET_CYCLES
1545 static WC_INLINE word64 get_intel_cycles(void);
1546 static THREAD_LS_T word64 total_cycles;
1547 #define INIT_CYCLE_COUNTER
1548 #define BEGIN_CYCLES total_cycles = get_intel_cycles();
1549 #define END_CYCLES total_cycles = get_intel_cycles() - total_cycles;
1550 /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
1551 #define SHOW_CYCLES(b, n, s) \
1552 (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
1553 " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
1554 bench_result_words1[lng_index][2], \
1555 FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
1556 (double)total_cycles / ((word64)count*(s))))
1557 #define SHOW_CYCLES_OPS(b, n) \
1558 (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
1559 " " FLT_FMT_PREC2 " %s" STATS_CLAUSE_SEPARATOR, \
1560 FLT_FMT_PREC2_ARGS(10, 1, count == 0 ? 0 : \
1561 (double)total_cycles / (word64)count), \
1562 bench_result_words1[lng_index][3])
1563 #define SHOW_CYCLES_CSV(b, n, s) \
1564 (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
1565 STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
1566 (double)total_cycles / ((word64)count*(s))))
1567#elif defined(LINUX_CYCLE_COUNT)
1568 #include <linux/perf_event.h>
1569 #include <sys/syscall.h>
1570 #include <unistd.h>
1571 #include <fcntl.h>
1572 #include <errno.h>
1573
1574 #ifndef PERF_FLAG_FD_CLOEXEC
1575 #define PERF_FLAG_FD_CLOEXEC (1UL << 3)
1576 #endif
1577
1578 static THREAD_LS_T word64 begin_cycles;
1579 static THREAD_LS_T word64 total_cycles;
1580 static THREAD_LS_T int cycles = -1;
1581 static THREAD_LS_T struct perf_event_attr atr;
1582
1583 /* Try with PERF_FLAG_FD_CLOEXEC first; on older kernels (< 3.14) this
1584 * fails with EINVAL, so fall back to flags=0 and set FD_CLOEXEC via
1585 * fcntl() as a best-effort. */
1586 #define INIT_CYCLE_COUNTER do { \
1587 atr.type = PERF_TYPE_HARDWARE; \
1588 atr.config = PERF_COUNT_HW_CPU_CYCLES; \
1589 cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, \
1590 PERF_FLAG_FD_CLOEXEC); \
1591 if (cycles < 0 && errno == EINVAL) { \
1592 cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
1593 wc_set_cloexec(cycles); \
1594 } \
1595 } while (0);
1596
1597 #define BEGIN_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
1598 #define END_CYCLES do { \
1599 read(cycles, &total_cycles, sizeof(total_cycles)); \
1600 total_cycles = total_cycles - begin_cycles; \
1601 } while (0);
1602
1603 /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
1604 #define SHOW_CYCLES(b, n, s) \
1605 (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
1606 " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
1607 bench_result_words1[lng_index][2], \
1608 FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
1609 (count*s)))
1610 #define SHOW_CYCLES_OPS(b, n) \
1611 (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
1612 " " FLT_FMT_PREC2 " %s" STATS_CLAUSE_SEPARATOR, \
1613 FLT_FMT_PREC2_ARGS(10, 1, (double)total_cycles / (count)), \
1614 bench_result_words1[lng_index][3]);
1615 #define SHOW_CYCLES_CSV(b, n, s) \
1616 (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
1617 STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
1618 / (count*s)))
1619
1620#elif defined(SYNERGY_CYCLE_COUNT)
1621 #include "hal_data.h"
1622 static THREAD_LS_T word64 begin_cycles;
1623 static THREAD_LS_T word64 total_cycles;
1624
1625 #define INIT_CYCLE_COUNTER
1626 #define BEGIN_CYCLES begin_cycles = DWT->CYCCNT = 0;
1627 #define END_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
1628
1629 /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
1630 #define SHOW_CYCLES(b, n, s) \
1631 (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
1632 " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
1633 bench_result_words1[lng_index][2], \
1634 FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
1635 #define SHOW_CYCLES_OPS(b, n) \
1636 (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
1637 " " FLT_FMT_PREC2 " %s" STATS_CLAUSE_SEPARATOR, \
1638 FLT_FMT_PREC2_ARGS(10, 1, (double)total_cycles / (count)), \
1639 bench_result_words1[lng_index][3])
1640 #define SHOW_CYCLES_CSV(b, n, s) \
1641 (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
1642 FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
1643#elif defined(WOLFSSL_ESPIDF)
1644 /* TAG for ESP_LOGx() */
1645 static const char* TAG = "wolfssl_benchmark";
1646
1647 static THREAD_LS_T word64 begin_cycles = 0;
1648 static THREAD_LS_T word64 begin_cycles_ticks = 0;
1649 static THREAD_LS_T word64 end_cycles = 0;
1650 static THREAD_LS_T word64 total_cycles = 0;
1651
1652 /* the return value, as a global var */
1653 static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
1654
1655 /* the last value seen, adjusted for an overflow, as a global var */
1656 static THREAD_LS_T word64 _esp_cpu_count_last = 0;
1657
1658 static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
1659
1660 /* esp_get_cpu_benchmark_cycles(void):
1661 *
1662 * Architecture-independant CPU clock counter.
1663 * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
1664 static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
1665
1666 /* Some vars for debugging, compare ticks to cycles */
1667 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
1668 static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
1669 static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
1670 static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
1671 static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
1672 #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
1673
1674 /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
1675 #if ESP_IDF_VERSION_MAJOR >= 5
1676 /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
1677 #define HAVE_GET_CYCLES
1678 #define INIT_CYCLE_COUNTER do { \
1679 ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
1680 esp_cpu_set_cycle_count(0); \
1681 } while (0);
1682 #else
1683 #define HAVE_GET_CYCLES
1684 #define INIT_CYCLE_COUNTER do { \
1685 ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
1686 } while (0);
1687 #endif
1688
1689 #define BEGIN_ESP_CYCLES do { \
1690 ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
1691 begin_cycles = esp_get_cpu_benchmark_cycles(); \
1692 begin_cycles_ticks = xTaskGetTickCount(); \
1693 } while (0);
1694
1695 /* since it rolls over, we have something that will tolerate one */
1696 #define END_ESP_CYCLES \
1697 end_cycles = esp_get_cpu_benchmark_cycles(); \
1698 ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
1699 end_cycles, \
1700 begin_cycles \
1701 ); \
1702 total_cycles = (end_cycles - begin_cycles);
1703
1704 #define SHOW_ESP_CYCLES(b, n, s) \
1705 (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
1706 " %s = " FLT_FMT_PREC2 "\n", \
1707 bench_result_words1[lng_index][2], \
1708 FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
1709 )
1710 #define SHOW_ESP_CYCLES_OPS(b, n) \
1711 (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
1712 " " FLT_FMT_PREC2 " %s\n", \
1713 FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count)), \
1714 bench_result_words1[lng_index][3] \
1715 )
1716
1717 #define SHOW_ESP_CYCLES_CSV(b, n, s) \
1718 (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
1719 FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
1720
1721 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
1722 /* 64 bit, unisgned, absolute difference
1723 * used in CPU cycle counter debug calcs. */
1724 static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
1725 {
1726 uint64_t ret;
1727 ret = (x > y) ? (x - y) : (y - x);
1728 return ret;
1729 }
1730 #endif
1731
1732 /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
1733 ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
1734 ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
1735 ** at least once during full benchmark tests.
1736 **
1737 ** To test timing overflow, add a delay longer than max cycles:
1738 ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
1739 */
1740 uint64_t esp_get_cycle_count_ex()
1741 {
1742 /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
1743 /* unsigned int max = 4,294,967,295 */
1744 uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
1745 uint64_t thisIncrement = 0; /* The adjusted increment amount. */
1746 uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
1747 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
1748 uint64_t tickCount = 0; /* Current rtos tick counter. */
1749 uint64_t tickDiff = 0; /* Tick difference from last check. */
1750 uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
1751 #endif
1752 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
1753 uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
1754 uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
1755 * (current - last) */
1756 #endif
1757 #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
1758 defined(CONFIG_IDF_TARGET_ESP32C3) || \
1759 defined(CONFIG_IDF_TARGET_ESP32C6)
1760
1761 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
1762 ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
1763 thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
1764 #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
1765
1766 #if ESP_IDF_VERSION_MAJOR >= 5
1767 thisVal = esp_cpu_get_cycle_count();
1768 #else
1769 thisVal = cpu_hal_get_cycle_count();
1770 #endif
1771
1772 #elif defined(CONFIG_IDF_TARGET_ESP32H2)
1773 thisVal = esp_cpu_get_cycle_count();
1774 #elif defined(CONFIG_IDF_TARGET_ESP8266)
1775 thisVal = esp_timer_get_time();
1776 #else
1777 /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
1778 * Calling current_time(1) to reset time causes thisVal overflow,
1779 * on Xtensa, but not on RISC-V architecture. See also, below */
1780 #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
1781 #ifndef configCPU_CLOCK_HZ
1782 /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
1783 #define configCPU_CLOCK_HZ \
1784 (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
1785 #endif
1786 /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
1787 thisVal = (uint64_t)xTaskGetTickCount() *
1788 (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
1789 #elif defined(__XTENSA__)
1790 thisVal = esp_cpu_get_cycle_count();
1791 #else
1792 /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
1793 thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
1794 #endif
1795 #endif
1796
1797 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
1798 {
1799 tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
1800 tickDiff = tickCount - last_tickCount; /* ticks since bench start */
1801 expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
1802 ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
1803 ESP_LOGV(TAG, "tickCount = %llu", tickCount);
1804 ESP_LOGV(TAG, "last_tickCount = " TFMT, last_tickCount);
1805 ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
1806 ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
1807 }
1808 #endif
1809
1810 /* If either thisVal is smaller than last (overflow), and/or the
1811 * expected value calculated from FreeRTOS tick difference that would
1812 * have never fit into an unsigned 32 bit integer anyhow... then we
1813 * need to adjust thisVal to save. */
1814 if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
1815 {
1816 /* Warning: we assume the return type of esp_cpu_get_cycle_count()
1817 ** will always be unsigned int (or uint32_t) to add UINT_MAX.
1818 **
1819 ** NOTE for long duration between calls with multiple overflows:
1820 **
1821 ** WILL NOT BE DETECTED - the return value will be INCORRECT.
1822 **
1823 ** At this time no single test overflows. This is currently only a
1824 ** concern for cumulative counts over multiple tests. As long
1825 ** as well call xthal_get_ccount_ex() with no more than one
1826 ** overflow CPU tick count, all will be well.
1827 */
1828 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
1829 ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
1830 "(%llu < %llu) adding UINT_MAX = %llu.",
1831 thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
1832 #endif
1833 #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
1834 !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
1835 #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
1836 #endif
1837
1838 /* double check expected diff calc */
1839 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
1840 #if defined(CONFIG_IDF_TARGET_ESP8266)
1841 expected_diff = (CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
1842 * MILLION_VALUE)
1843 * tickDiff / configTICK_RATE_HZ;
1844 #else
1845 expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
1846 * tickDiff / configTICK_RATE_HZ;
1847
1848 #endif
1849 ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
1850 #endif
1851 if (expected_diff > UINT_MAX) {
1852 /* The number of cycles expected from FreeRTOS ticks is
1853 * greater than the maximum size of an unsigned 32-bit
1854 * integer, meaning multiple overflows occurred. */
1855 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
1856 ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
1857 #endif
1858 thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
1859 }
1860 else {
1861 thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
1862 }
1863
1864 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
1865 {
1866 tickBeginDiff = tickCount - begin_cycles_ticks;
1867
1868 ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
1869 ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
1870 ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
1871 ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
1872
1873 ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
1874 }
1875 #endif
1876 }
1877 else {
1878 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
1879 ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
1880 #endif
1881 } /* if thisVal adjustment check */
1882
1883 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
1884 if (thisTimerVal < _esp_cpu_timer_last)
1885 {
1886 ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
1887 "adding %ull", UINT_MAX);
1888 thisTimerVal += (word64)UINT_MAX;
1889 }
1890 /* Check an alternate counter using a timer */
1891
1892 _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
1893 #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
1894
1895 /* Adjust our actual returned value that takes into account overflow,
1896 * increment 64 bit extended total by this 32 bit differential: */
1897 thisIncrement = (thisVal - _esp_cpu_count_last);
1898
1899 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
1900 ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
1901 #endif
1902
1903 /* Add our adjustment, taking into account overflows (see above) */
1904 _esp_get_cycle_count_ex += thisIncrement;
1905
1906 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
1907 _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
1908 _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
1909 diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
1910 #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
1911
1912 /* all of this took some time, so reset the "last seen" value
1913 * for the next measurement. */
1914 #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
1915 defined(CONFIG_IDF_TARGET_ESP32C3) || \
1916 defined(CONFIG_IDF_TARGET_ESP32C6)
1917 {
1918 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
1919 ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
1920 &_esp_cpu_timer_last));
1921 ESP_LOGI(TAG, "thisVal = %llu", thisVal);
1922 ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
1923 ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
1924 ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
1925 #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
1926
1927 #if ESP_IDF_VERSION_MAJOR >= 5
1928 _esp_cpu_count_last = esp_cpu_get_cycle_count();
1929 #else
1930 _esp_cpu_count_last = cpu_hal_get_cycle_count();
1931 #endif
1932
1933 ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
1934 }
1935 #elif defined(CONFIG_IDF_TARGET_ESP32H2)
1936 _esp_cpu_count_last = esp_cpu_get_cycle_count();
1937 #else
1938 /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
1939 * when resetting CPU cycle counter? FreeRTOS tick collision?
1940 * thisVal = esp_cpu_get_cycle_count(); See also, above
1941 * or thisVal = xthal_get_ccount(); */
1942 #if defined(CONFIG_IDF_TARGET_ESP8266)
1943 /* There's no CPU counter on the ESP8266, so we'll estimate
1944 * cycles based on defined CPU frequency from sdkconfig and
1945 * the RTOS tick frequency */
1946 _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
1947 (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
1948 #elif ESP_IDF_VERSION_MAJOR < 5
1949 _esp_cpu_count_last = xthal_get_ccount();
1950 #else
1951 _esp_cpu_count_last = esp_cpu_get_cycle_count();
1952 #endif
1953 #endif
1954
1955 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
1956 ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
1957 #endif
1958
1959 /* Return the 64 bit extended total from 32 bit counter. */
1960 return _esp_get_cycle_count_ex;
1961 } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
1962
1963#elif defined(__aarch64__)
1964 #define HAVE_GET_CYCLES
1965 static WC_INLINE word64 get_aarch64_cycles(void);
1966 static THREAD_LS_T word64 total_cycles;
1967 #define INIT_CYCLE_COUNTER
1968 #define BEGIN_CYCLES \
1969 total_cycles = get_aarch64_cycles();
1970 #define END_CYCLES \
1971 total_cycles = get_aarch64_cycles() - total_cycles;
1972 /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
1973 #define SHOW_CYCLES(b, n, s) \
1974 (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
1975 " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
1976 bench_result_words1[lng_index][2], \
1977 FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
1978 (double)total_cycles / ((word64)count*(s))))
1979 #define SHOW_CYCLES_OPS(b, n) \
1980 (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
1981 " " FLT_FMT_PREC2 " %s" STATS_CLAUSE_SEPARATOR, \
1982 FLT_FMT_PREC2_ARGS(10, 1, count == 0 ? 0 : \
1983 (double)total_cycles / (word64)count), \
1984 bench_result_words1[lng_index][3])
1985 #define SHOW_CYCLES_CSV(b, n, s) \
1986 (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
1987 STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
1988 (double)total_cycles / ((word64)count*(s))))
1989 word64 tick_freq = 0;
1990 word64 actual_freq = 0;
1991
1992/* implement other architecture cycle counters here */
1993
1994#else
1995 /* if we don't know the platform, it is unlikely we can count CPU cycles */
1996 #undef HAVE_GET_CYCLES
1997
1998 #define INIT_CYCLE_COUNTER
1999 #define BEGIN_CYCLES
2000 #define END_CYCLES
2001 #ifdef MULTI_VALUE_STATISTICS
2002 #define SHOW_CYCLES(b, n, s) WC_DO_NOTHING
2003 #define SHOW_CYCLES_OPS(b, n) WC_DO_NOTHING
2004 #define SHOW_CYCLES_CSV(b, n, s) WC_DO_NOTHING
2005 #else
2006 #define SHOW_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
2007 #define SHOW_CYCLES_OPS(b, n) b[XSTRLEN(b)] = '\n'
2008 #define SHOW_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
2009 #endif
2010#endif
2011
2012/* determine benchmark buffer to use (if NO_FILESYSTEM) */
2013#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
2014 !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
2015 #define USE_CERT_BUFFERS_2048 /* default to 2048 */
2016#endif
2017
2018#if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
2019 defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
2020 !defined(NO_DH)
2021 /* include test cert and key buffers for use with NO_FILESYSTEM */
2022 #include <wolfssl/certs_test.h>
2023#endif
2024
2025#if defined(HAVE_BLAKE2B) || defined(HAVE_BLAKE2S)
2026 #include <wolfssl/wolfcrypt/blake2.h>
2027#endif
2028
2029#ifdef _MSC_VER
2030 /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
2031 #pragma warning(disable: 4996)
2032#endif
2033
2034#ifdef WOLFSSL_CURRTIME_REMAP
2035 #define current_time WOLFSSL_CURRTIME_REMAP
2036#else
2037 double current_time(int reset);
2038#endif
2039
2040#ifdef LINUX_RUSAGE_UTIME
2041 static void check_for_excessive_stime(const char *algo,
2042 int strength,
2043 const char *desc,
2044 const char *desc_extra);
2045#endif
2046
2047#if !defined(WC_NO_RNG) && \
2048 ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
2049 || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
2050 || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
2051 || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
2052 || defined(WOLFSSL_HAVE_MLKEM))
2053 #define HAVE_LOCAL_RNG
2054 static THREAD_LS_T WC_RNG gRng;
2055 #define GLOBAL_RNG &gRng
2056#else
2057 #define GLOBAL_RNG NULL
2058#endif
2059
2060#if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
2061 defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
2062 defined(HAVE_ECC) || !defined(NO_DH) || \
2063 !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
2064 defined(WOLFSSL_HAVE_MLKEM) || defined(HAVE_DILITHIUM) || \
2065 defined(WOLFSSL_HAVE_LMS)
2066 #define BENCH_ASYM
2067#endif
2068
2069#if !defined(WC_NO_RNG) || defined(WOLFSSL_HAVE_MLKEM)
2070static const char* bench_result_words2[][6] = {
2071#ifdef BENCH_MICROSECOND
2072 { "ops took", "ฮผsec" , "avg" , "ops/ฮผsec", "cycles/op",
2073 NULL }, /* 0 English for ฮผsec */
2074#else
2075 { "ops took", "sec" , "avg" , "ops/sec", "cycles/op",
2076 NULL }, /* 0 English */
2077#endif
2078#ifndef NO_MULTIBYTE_PRINT
2079 { "ๅๅฆ็ใ", "็งใงๅฎๆฝ", "ๅนณๅ", "ๅฆ็/็ง", "cycles/op",
2080 NULL }, /* 1 Japanese */
2081#endif
2082};
2083#endif /* !WC_NO_RNG || WOLFSSL_HAVE_MLKEM */
2084#if defined(WOLFSSL_MICROCHIP_TA100)
2085 #include <wolfssl/wolfcrypt/port/atmel/atmel.h>
2086#endif
2087
2088#ifdef WOLFSSL_CAAM
2089 #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
2090 #ifdef WOLFSSL_SECO_CAAM
2091 #define SECO_MAX_UPDATES 10000
2092 #define SECO_BENCHMARK_NONCE 0x7777
2093 #define SECO_KEY_STORE_ID 1
2094 #endif
2095
2096 static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
2097#else
2098 #ifdef WC_USE_DEVID
2099 static THREAD_LS_T int devId = WC_USE_DEVID;
2100 #else
2101 static THREAD_LS_T int devId = INVALID_DEVID;
2102 #endif
2103#endif
2104
2105/* Asynchronous helper macros */
2106#ifdef WC_ENABLE_BENCH_THREADING
2107 typedef struct ThreadData {
2108 pthread_t thread_id;
2109 } ThreadData;
2110 static ThreadData* g_threadData;
2111 static volatile int g_threadCount;
2112#endif
2113
2114#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || \
2115 defined(WC_USE_DEVID) || \
2116 defined(WOLFSSL_MICROCHIP_TA100)
2117 #ifndef NO_HW_BENCH
2118 #define BENCH_DEVID
2119 #endif
2120 #if !defined(BENCH_DEVID_GET_NAME)
2121 #ifndef HAVE_RENESAS_SYNC
2122 #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
2123 #else
2124 #define BENCH_DEVID_GET_NAME(useDeviceID) ""
2125 #endif
2126 #endif
2127#else
2128 #define BENCH_DEVID_GET_NAME(useDeviceID) ""
2129#endif
2130
2131#ifdef WOLFSSL_ASYNC_CRYPT
2132 static WOLF_EVENT_QUEUE eventQueue;
2133
2134 #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
2135 #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
2136
2137
2138 static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
2139 int callAgain, int* times, int limit, int* pending)
2140 {
2141 int allowNext = 0;
2142
2143 /* this state can be set from a different thread */
2144 WOLF_EVENT_STATE state = asyncDev->event.state;
2145
2146 /* if algo doesn't require calling again then use this flow */
2147 if (state == WOLF_EVENT_STATE_DONE) {
2148 if (callAgain) {
2149 /* needs called again, so allow it and handle completion in
2150 * bench_async_handle */
2151 allowNext = 1;
2152 }
2153 else {
2154 *ret = asyncDev->event.ret;
2155 asyncDev->event.state = WOLF_EVENT_STATE_READY;
2156 (*times)++;
2157 if (*pending > 0) /* to support case where async blocks */
2158 (*pending)--;
2159
2160 if ((*times + *pending) < limit)
2161 allowNext = 1;
2162 }
2163 }
2164
2165 /* if slot is available and we haven't reached limit, start another */
2166 else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
2167 allowNext = 1;
2168 }
2169
2170 return allowNext;
2171 }
2172
2173 static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
2174 int callAgain, int* times, int* pending)
2175 {
2176 WOLF_EVENT_STATE state = asyncDev->event.state;
2177
2178 if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
2179 if (state == WOLF_EVENT_STATE_DONE) {
2180 *ret = asyncDev->event.ret;
2181 asyncDev->event.state = WOLF_EVENT_STATE_READY;
2182 (*times)++;
2183 (*pending)--;
2184 }
2185 else {
2186 (*pending)++;
2187 *ret = wc_AsyncHandle(asyncDev, &eventQueue,
2188 callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
2189 }
2190 }
2191 else if (*ret >= 0) {
2192 *ret = asyncDev->event.ret;
2193 asyncDev->event.state = WOLF_EVENT_STATE_READY;
2194 (*times)++;
2195 if (*pending > 0) /* to support case where async blocks */
2196 (*pending)--;
2197 }
2198
2199 return (*ret >= 0) ? 1 : 0;
2200 }
2201
2202 static WC_INLINE int bench_async_poll(int* pending)
2203 {
2204 int ret, asyncDone = 0;
2205
2206 ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
2207 WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
2208 if (ret != 0) {
2209 printf("%sAsync poll failed %d\n", err_prefix, ret);
2210 return ret;
2211 }
2212
2213 if (asyncDone == 0) {
2214 #ifndef WC_NO_ASYNC_THREADING
2215 /* give time to other threads */
2216 wc_AsyncThreadYield();
2217 #endif
2218 }
2219
2220 (void)pending;
2221
2222 return asyncDone;
2223 }
2224
2225#else
2226 #define BENCH_MAX_PENDING 1
2227 #define BENCH_ASYNC_GET_DEV(obj) NULL
2228
2229 static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
2230 int callAgain, int* times, int limit, int* pending)
2231 {
2232 (void)ret;
2233 (void)asyncDev;
2234 (void)callAgain;
2235 (void)times;
2236 (void)limit;
2237 (void)pending;
2238
2239 return 1;
2240 }
2241
2242 static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
2243 int callAgain, int* times, int* pending)
2244 {
2245 (void)asyncDev;
2246 (void)callAgain;
2247 (void)pending;
2248
2249 if (*ret >= 0) {
2250 /* operation completed */
2251 (*times)++;
2252 return 1;
2253 }
2254 return 0;
2255 }
2256 #define bench_async_poll(p) WC_DO_NOTHING
2257#endif /* WOLFSSL_ASYNC_CRYPT */
2258
2259
2260
2261/* maximum runtime for each benchmark */
2262#ifndef BENCH_MIN_RUNTIME_SEC
2263 #define BENCH_MIN_RUNTIME_SEC (double)1.0F
2264#endif
2265
2266#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) || \
2267 (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
2268 static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
2269#endif
2270#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
2271 #define AES_AUTH_TAG_SZ 16
2272 #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
2273 #if !defined(AES_AAD_OPTIONS_DEFAULT)
2274 #if !defined(NO_MAIN_DRIVER)
2275 #define AES_AAD_OPTIONS_DEFAULT 0x1U
2276 #else
2277 #define AES_AAD_OPTIONS_DEFAULT 0x3U
2278 #endif
2279 #endif
2280 #define AES_AAD_STRING(s) \
2281 (aesAuthAddSz == 0 ? (s "-no_AAD") : \
2282 (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
2283 enum en_aad_options {
2284 AAD_SIZE_DEFAULT = 0x1U,
2285 AAD_SIZE_ZERO = 0x2U,
2286 AAD_SIZE_CUSTOM = 0x4U,
2287 };
2288 static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
2289 static word32 aes_aad_size = 0;
2290 static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
2291 {
2292 word32 aesAuthAddSz_orig = aesAuthAddSz;
2293 word32 options = aes_aad_options;
2294 while(options) {
2295 if (options & AAD_SIZE_DEFAULT) {
2296 aesAuthAddSz = AES_AUTH_ADD_SZ;
2297 options &= ~(word32)AAD_SIZE_DEFAULT;
2298 }
2299 else if (options & AAD_SIZE_ZERO) {
2300 aesAuthAddSz = 0;
2301 options &= ~(word32)AAD_SIZE_ZERO;
2302 }
2303 else if (options & AAD_SIZE_CUSTOM) {
2304 aesAuthAddSz = aes_aad_size;
2305 options &= ~(word32)AAD_SIZE_CUSTOM;
2306 }
2307 fn(i);
2308 aesAuthAddSz = aesAuthAddSz_orig;
2309 }
2310 }
2311#endif
2312
2313#ifndef BENCH_CIPHER_ADD
2314 #define BENCH_CIPHER_ADD 0
2315#endif
2316
2317
2318
2319#if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
2320 #warning Large/Unalligned AuthSz could result in errors with /dev/crypto
2321#endif
2322
2323/* use kB instead of MB for embedded benchmarking */
2324#ifdef BENCH_EMBEDDED
2325 #ifndef BENCH_NTIMES
2326 #define BENCH_NTIMES 2
2327 #endif
2328 #ifndef BENCH_AGREETIMES
2329 #define BENCH_AGREETIMES 2
2330 #endif
2331 enum BenchmarkBounds {
2332 scryptCnt = 1,
2333 ntimes = BENCH_NTIMES,
2334 genTimes = BENCH_MAX_PENDING,
2335 agreeTimes = BENCH_AGREETIMES
2336 };
2337 /* how many kB to test (en/de)cryption */
2338 #define NUM_BLOCKS 25
2339 #define BENCH_SIZE (1024uL)
2340#else
2341 #ifndef BENCH_NTIMES
2342 #define BENCH_NTIMES 100
2343 #endif
2344 #ifndef BENCH_AGREETIMES
2345 #define BENCH_AGREETIMES 100
2346 #endif
2347 enum BenchmarkBounds {
2348 scryptCnt = 10,
2349 ntimes = BENCH_NTIMES,
2350 genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
2351 agreeTimes = BENCH_AGREETIMES
2352 };
2353 /* how many megs to test (en/de)cryption */
2354 #define NUM_BLOCKS 5
2355 #define BENCH_SIZE (1024*1024uL)
2356#endif
2357
2358static int numBlocks = NUM_BLOCKS;
2359static word32 bench_size = BENCH_SIZE;
2360static int base2 = 1;
2361static int digest_stream = 1;
2362#ifndef NO_HMAC
2363static int mac_stream = 1;
2364#endif
2365#ifdef HAVE_AESGCM
2366static int aead_set_key = 0;
2367#endif
2368#ifdef HAVE_CHACHA
2369static int encrypt_only = 0;
2370#endif
2371#if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || \
2372 defined(HAVE_AESGCM)
2373static int cipher_same_buffer = 0;
2374#endif
2375
2376#ifdef MULTI_VALUE_STATISTICS
2377static int minimum_runs = 0;
2378#endif
2379
2380#ifndef NO_RSA
2381 /* Don't measure RSA sign/verify by default */
2382 static int rsa_sign_verify = 0;
2383#endif
2384
2385#ifndef NO_DH
2386 /* Use the FFDHE parameters */
2387 static int use_ffdhe = 0;
2388#endif
2389
2390/* Don't print out in CSV format by default */
2391static int csv_format = 0;
2392
2393#ifdef WOLFSSL_XILINX_CRYPT_VERSAL
2394 /* Versal PLM maybe prints an error message to the same console.
2395 * In order to not mix those outputs up, sleep a little while
2396 * before erroring out.
2397 */
2398 #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
2399#else
2400 #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
2401#endif
2402
2403/* globals for cipher tests */
2404static THREAD_LS_T byte* bench_plain = NULL;
2405static THREAD_LS_T byte* bench_cipher = NULL;
2406#ifndef NO_FILESYSTEM
2407static THREAD_LS_T char* hash_input = NULL;
2408static THREAD_LS_T char* cipher_input = NULL;
2409#endif
2410
2411static const XGEN_ALIGN byte bench_key_buf[] =
2412{
2413 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
2414 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
2415 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
2416 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
2417 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
2418 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
2419 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
2420 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
2421};
2422
2423static const XGEN_ALIGN byte bench_iv_buf[] =
2424{
2425 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
2426 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
2427 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
2428};
2429static THREAD_LS_T byte* bench_key = NULL;
2430static THREAD_LS_T byte* bench_iv = NULL;
2431#ifdef HAVE_RENESAS_SYNC
2432static THREAD_LS_T byte* bench_key1 = NULL;
2433static THREAD_LS_T byte* bench_key2 = NULL;
2434#endif
2435#ifdef WOLFSSL_STATIC_MEMORY
2436 #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
2437 static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
2438 #elif defined(BENCH_EMBEDDED)
2439 static byte gBenchMemory[50000];
2440 #else
2441 static byte gBenchMemory[400000];
2442 #endif
2443#endif
2444
2445
2446/* This code handles cases with systems where static (non cost) ram variables
2447 aren't properly initialized with data */
2448static void benchmark_static_init(int force)
2449{
2450 static int gBenchStaticInit = 0;
2451 if (gBenchStaticInit == 0 || force) {
2452 gBenchStaticInit = 1;
2453
2454 /* Init static variables */
2455 numBlocks = NUM_BLOCKS;
2456 bench_size = BENCH_SIZE;
2457 #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
2458 aesAuthAddSz = AES_AUTH_ADD_SZ;
2459 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
2460 aes_aad_size = 0;
2461 #endif
2462 base2 = 1;
2463 digest_stream = 1;
2464 #ifdef MULTI_VALUE_STATISTICS
2465 minimum_runs = 0;
2466 #endif
2467
2468 bench_all = 1;
2469 bench_cipher_algs = 0;
2470 bench_digest_algs = 0;
2471 bench_mac_algs = 0;
2472 bench_kdf_algs = 0;
2473 bench_asym_algs = 0;
2474 bench_pq_asym_algs = 0;
2475 bench_other_algs = 0;
2476 bench_pq_hash_sig_algs = 0;
2477 csv_format = 0;
2478 }
2479}
2480
2481
2482
2483/*****************************************************************************/
2484/* Begin Stats Functions */
2485/*****************************************************************************/
2486typedef enum bench_stat_type {
2487 BENCH_STAT_ASYM,
2488 BENCH_STAT_SYM,
2489 BENCH_STAT_IGNORE,
2490} bench_stat_type_t;
2491
2492#ifdef WC_BENCH_TRACK_STATS
2493 static int gPrintStats = 0;
2494 #ifdef WC_ENABLE_BENCH_THREADING
2495 static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
2496 #endif
2497 #ifndef BENCH_MAX_NAME_SZ
2498 #define BENCH_MAX_NAME_SZ 24
2499 #endif
2500 typedef struct bench_stats {
2501 struct bench_stats* next;
2502 struct bench_stats* prev;
2503 char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
2504 const char* desc;
2505 double perfsec;
2506 int strength;
2507 int useDeviceID;
2508 int finishCount;
2509 bench_stat_type_t type;
2510 int lastRet;
2511 const char* perftype;
2512#ifdef WC_BENCH_HEAP_TRACKING
2513 long heapPeakBytes;
2514 long heapPeakAllocs;
2515#endif
2516#ifdef WC_BENCH_STACK_TRACKING
2517 long stackPeakBytes;
2518#endif
2519 } bench_stats_t;
2520 static bench_stats_t* bench_stats_head;
2521 static bench_stats_t* bench_stats_tail;
2522
2523 static bench_stats_t* bench_stats_add(bench_stat_type_t type,
2524 const char* algo, int strength, const char* desc, int useDeviceID,
2525 double perfsec, const char* perftype, int ret,
2526 long heapAllocs, long heapBytes, long stackBytes)
2527 {
2528 bench_stats_t* bstat = NULL;
2529
2530#ifndef WC_BENCH_HEAP_TRACKING
2531 (void)heapAllocs;
2532 (void)heapBytes;
2533#endif
2534#ifndef WC_BENCH_STACK_TRACKING
2535 (void)stackBytes;
2536#endif
2537
2538 #ifdef WC_ENABLE_BENCH_THREADING
2539 /* protect bench_stats_head and bench_stats_tail access */
2540 THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
2541 #endif
2542
2543 if (algo != NULL) {
2544 /* locate existing in list */
2545 for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
2546 /* match based on algo, strength and desc */
2547 if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
2548 bstat->strength == strength &&
2549 bstat->desc == desc &&
2550 bstat->useDeviceID == useDeviceID) {
2551 break;
2552 }
2553 }
2554 }
2555
2556 if (bstat == NULL) {
2557 /* allocate new and put on list */
2558 bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), HEAP_HINT,
2559 DYNAMIC_TYPE_INFO);
2560 if (bstat) {
2561 XMEMSET(bstat, 0, sizeof(bench_stats_t));
2562
2563 /* add to list */
2564 bstat->next = NULL;
2565 if (bench_stats_tail == NULL) {
2566 bench_stats_head = bstat;
2567 }
2568 else {
2569 bench_stats_tail->next = bstat;
2570 bstat->prev = bench_stats_tail;
2571 }
2572 bench_stats_tail = bstat; /* add to the end either way */
2573 }
2574 }
2575 if (bstat) {
2576 bstat->type = type;
2577 if (algo != NULL)
2578 XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
2579 bstat->strength = strength;
2580 bstat->desc = desc;
2581 bstat->useDeviceID = useDeviceID;
2582 bstat->perfsec += perfsec;
2583 bstat->finishCount++;
2584 bstat->perftype = perftype;
2585 if (bstat->lastRet > ret)
2586 bstat->lastRet = ret; /* track last error */
2587#ifdef WC_BENCH_HEAP_TRACKING
2588 if (heapBytes > bstat->heapPeakBytes)
2589 bstat->heapPeakBytes = heapBytes;
2590 if (heapAllocs > bstat->heapPeakAllocs)
2591 bstat->heapPeakAllocs = heapAllocs;
2592#endif
2593#ifdef WC_BENCH_STACK_TRACKING
2594 if (stackBytes > bstat->stackPeakBytes)
2595 bstat->stackPeakBytes = stackBytes;
2596#endif
2597 }
2598 #ifdef WC_ENABLE_BENCH_THREADING
2599 THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
2600 #endif
2601 return bstat;
2602 }
2603
2604 void bench_stats_print(void)
2605 {
2606 bench_stats_t* bstat;
2607 int digits;
2608
2609 #ifdef WC_ENABLE_BENCH_THREADING
2610 /* protect bench_stats_head and bench_stats_tail access */
2611 THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
2612 #endif
2613
2614 #ifdef BENCH_MICROSECOND
2615 digits = 5;
2616 #else
2617 digits = 3;
2618 #endif
2619
2620 for (bstat = bench_stats_head; bstat != NULL; ) {
2621 char line[WC_BENCH_MAX_LINE_LEN];
2622
2623 line[0] = '\0';
2624 if (bstat->type == BENCH_STAT_SYM) {
2625 (void)XSNPRINTF(line, sizeof(line),
2626 "%-16s%s " FLT_FMT_PREC2 " %s/"
2627 WOLFSSL_FIXED_TIME_UNIT "\n",
2628 bstat->desc,
2629 BENCH_DEVID_GET_NAME(bstat->useDeviceID),
2630 FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
2631 base2 ? "MB" : "mB");
2632 }
2633 else {
2634 (void)XSNPRINTF(line, sizeof(line),
2635 "%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
2636 WOLFSSL_FIXED_TIME_UNIT "ec\n",
2637 bstat->algo, bstat->strength, bstat->desc,
2638 BENCH_DEVID_GET_NAME(bstat->useDeviceID),
2639 FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
2640 }
2641
2642 bench_append_memory_info(line, sizeof(line), 0,
2643#ifdef WC_BENCH_HEAP_TRACKING
2644 bstat->heapPeakAllocs, bstat->heapPeakBytes,
2645#else
2646 0, 0,
2647#endif
2648#ifdef WC_BENCH_STACK_TRACKING
2649 bstat->stackPeakBytes
2650#else
2651 0
2652#endif
2653 );
2654
2655 printf("%s", line);
2656 bstat = bstat->next;
2657 }
2658
2659 #ifdef WC_ENABLE_BENCH_THREADING
2660 THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
2661 #endif
2662 }
2663#endif /* WC_BENCH_TRACK_STATS */
2664
2665static WC_INLINE void bench_stats_init(void)
2666{
2667#ifdef WC_BENCH_TRACK_STATS
2668 bench_stats_head = NULL;
2669 bench_stats_tail = NULL;
2670#endif
2671#if defined(WC_BENCH_HEAP_TRACKING) || defined(WC_BENCH_STACK_TRACKING)
2672 bench_stats_reset_setup_offsets();
2673 bench_stats_resources_prepared = 0;
2674#endif
2675 INIT_CYCLE_COUNTER
2676}
2677
2678static WC_INLINE void bench_stats_start(int* count, double* start)
2679{
2680 *count = 0;
2681 *start = current_time(1);
2682
2683#if defined(WC_BENCH_HEAP_TRACKING) || defined(WC_BENCH_STACK_TRACKING)
2684 if (bench_stats_resources_prepared) {
2685#ifdef WC_BENCH_HEAP_TRACKING
2686 long prepAllocs = 0;
2687 long prepBytes = 0;
2688 bench_heap_checkpoint_measure(&prepAllocs, &prepBytes);
2689 bench_stats_heap_setup_allocs += prepAllocs;
2690 bench_stats_heap_setup_bytes += prepBytes;
2691#else
2692 (void)bench_heap_checkpoint_measure(NULL, NULL);
2693#endif
2694#ifdef WC_BENCH_STACK_TRACKING
2695 bench_stats_stack_setup_bytes += bench_stack_checkpoint_measure();
2696#else
2697 (void)bench_stack_checkpoint_measure();
2698#endif
2699 bench_heap_checkpoint_prepare();
2700 bench_stack_checkpoint_prepare();
2701 }
2702 else {
2703 bench_heap_checkpoint_prepare();
2704 bench_stack_checkpoint_prepare();
2705 bench_stats_reset_setup_offsets();
2706 }
2707 bench_stats_resources_prepared = 0;
2708#else
2709 bench_heap_checkpoint_prepare();
2710 bench_stack_checkpoint_prepare();
2711#endif
2712
2713#ifdef WOLFSSL_ESPIDF
2714 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
2715 ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu"
2716 ", start=" FLT_FMT,
2717 total_cycles, FLT_FMT_ARGS(*start) );
2718 #endif
2719 BEGIN_ESP_CYCLES
2720#else
2721 BEGIN_CYCLES
2722#endif
2723}
2724
2725#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
2726 #define bench_stats_start(count, start) do { \
2727 SAVE_VECTOR_REGISTERS(WOLFSSL_DEBUG_PRINTF( \
2728 "ERROR: SAVE_VECTOR_REGISTERS failed for benchmark run."); \
2729 return; ); \
2730 bench_stats_start(count, start); \
2731 } while (0)
2732#elif defined(WOLFSSL_LINUXKM)
2733 /* we're using floating point to figure the statistics, so we need to
2734 * FPU save+lock even without SIMD.
2735 */
2736 #define bench_stats_start(count, start) do { \
2737 kernel_fpu_begin(); \
2738 bench_stats_start(count, start); \
2739 } while (0)
2740#endif
2741
2742static WC_INLINE int bench_stats_check(double start)
2743{
2744 int ret = 0;
2745 double this_current_time = 0.0;
2746 this_current_time = current_time(0); /* get the timestamp, no reset */
2747
2748#if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
2749 #if defined(WOLFSSL_ESPIDF)
2750 ESP_LOGI(TAG, "bench_stats_check Current time = %f, start = %f",
2751 this_current_time, start );
2752 #endif
2753#endif
2754
2755 ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
2756#ifdef BENCH_MICROSECOND
2757 * 1000000
2758#endif
2759 );
2760
2761 return ret;
2762}
2763
2764/* return text for units and scale the value of blocks as needed */
2765static const char* get_blocktype(double* blocks)
2766{
2767 const char* rt;
2768
2769#if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
2770 defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
2771 #undef WOLFSSL_FIXED_UNIT
2772 #define WOLFSSL_FIXED_UNIT "GB"
2773 *blocks /= (1024UL * 1024UL * 1024UL);
2774 rt = "GiB";
2775#elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
2776 defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
2777 #undef WOLFSSL_FIXED_UNIT
2778 #define WOLFSSL_FIXED_UNIT "MB"
2779 *blocks /= (1024UL * 1024UL);
2780 rt = "MiB";
2781#elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
2782 defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
2783 #undef WOLFSSL_FIXED_UNIT
2784 #define WOLFSSL_FIXED_UNIT "KB"
2785 *blocks /= 1024;
2786 rt = "KiB";
2787#elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
2788 #undef WOLFSSL_FIXED_UNIT
2789 #define WOLFSSL_FIXED_UNIT "bytes"
2790 (void)(*blocks); /* no adjustment, just appease compiler for not used */
2791 rt = "bytes";
2792#else
2793 /* If no user-specified, auto-scale each metric (results vary).
2794 * Determine if we should show as KB or MB or bytes. No GiB here. */
2795 if (*blocks > (1024UL * 1024UL)) {
2796 *blocks /= (1024UL * 1024UL);
2797 rt = "MiB";
2798 }
2799 else if (*blocks > 1024) {
2800 *blocks /= 1024;
2801 rt = "KiB";
2802 }
2803 else {
2804 rt = "bytes";
2805 }
2806#endif
2807
2808 return rt;
2809}
2810
2811/* return text for units and scale the value of blocks as needed for base2 */
2812static const char* get_blocktype_base10(double* blocks)
2813{
2814 const char* rt;
2815
2816#if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
2817 defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
2818 *blocks /= (1000UL * 1000UL * 1000UL);
2819 rt = "GB";
2820#elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
2821 defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
2822 *blocks /= (1000UL * 1000UL);
2823 rt = "MB";
2824#elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
2825 defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
2826 *blocks /= (1000UL);
2827 rt = "KB";
2828#elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
2829 (void)(*blocks); /* no adjustment, just appease compiler */
2830 rt = "bytes";
2831#else
2832 /* If not user-specified, auto-scale each metric (results vary).
2833 * Determine if we should show as KB or MB or bytes */
2834 if (*blocks > (1000UL * 1000UL)) {
2835 *blocks /= (1000UL * 1000UL);
2836 rt = "MB";
2837 }
2838 else if (*blocks > 1000) {
2839 *blocks /= 1000; /* make KB */
2840 rt = "KB";
2841 }
2842 else {
2843 rt = "bytes";
2844 }
2845#endif
2846
2847 return rt;
2848}
2849
2850#ifdef MULTI_VALUE_STATISTICS
2851static double wc_sqroot(double in)
2852{
2853 /* do 32 iterations for the sqroot */
2854 int iter = 32;
2855 double root = in/3.0;
2856
2857 if (in < 0.0)
2858 return -1;
2859
2860 for (int i=0; i < iter; i++)
2861 root = (root + in / root) / 2.0;
2862
2863 return root;
2864}
2865
2866static void bench_multi_value_stats(double max, double min, double sum,
2867 double squareSum, int runs)
2868{
2869 double mean = 0;
2870 double sd = 0;
2871 char msg[WC_BENCH_MAX_LINE_LEN];
2872 const char** word = bench_result_words3[lng_index];
2873
2874 XMEMSET(msg, 0, sizeof(msg));
2875
2876 mean = sum / runs;
2877
2878 /* Calculating standard deviation */
2879 sd = (squareSum / runs) - (mean * mean);
2880 sd = wc_sqroot(sd);
2881
2882 if (csv_format == 1) {
2883 (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
2884 FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
2885 FLT_FMT_PREC2_ARGS(3, 3, max),
2886 FLT_FMT_PREC2_ARGS(3, 3, min),
2887 FLT_FMT_PREC2_ARGS(3, 3, mean),
2888 FLT_FMT_PREC2_ARGS(3, 3, sd));
2889 }
2890 else{
2891 (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
2892 WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
2893 WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
2894 WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
2895 WOLFSSL_FIXED_TIME_UNIT "\n",
2896 word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
2897 word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
2898 word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
2899 word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
2900 }
2901 printf("%s", msg);
2902
2903#ifndef WOLFSSL_SGX
2904 XFFLUSH(stdout);
2905#endif
2906
2907}
2908#endif
2909
2910/* countSz is number of bytes that 1 count represents. Normally bench_size,
2911 * except for AES direct that operates on WC_AES_BLOCK_SIZE blocks */
2912static void bench_stats_sym_finish(const char* desc, int useDeviceID,
2913 int count, word32 countSz,
2914 double start, int ret)
2915{
2916 double total, persec = 0, blocks = (double)count;
2917 const char* blockType;
2918#ifdef WC_BENCH_HEAP_TRACKING
2919 long heapAllocs = 0;
2920 long heapBytes = 0;
2921#endif
2922 char msg[WC_BENCH_MAX_LINE_LEN];
2923 const char** word = bench_result_words1[lng_index];
2924 static int sym_header_printed = 0;
2925
2926 XMEMSET(msg, 0, sizeof(msg));
2927
2928#ifdef WOLFSSL_ESPIDF
2929 END_ESP_CYCLES
2930#else
2931 END_CYCLES
2932#endif
2933
2934 total = current_time(0) - start;
2935
2936#if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
2937 ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
2938#endif
2939
2940#ifdef LINUX_RUSAGE_UTIME
2941 check_for_excessive_stime(desc, 0, "", "");
2942#endif
2943
2944 /* calculate actual bytes */
2945 blocks *= countSz;
2946 if (csv_format == 1) {
2947 /* only print out header once */
2948 if (sym_header_printed == 0) {
2949
2950#ifdef GENERATE_MACHINE_PARSEABLE_REPORT
2951 /* machine parseable CSV */
2952 #ifdef HAVE_GET_CYCLES
2953 printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
2954 WOLFSSL_FIXED_TIME_UNIT "econds_total,"
2955 WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
2956 ",cycles_total,Cycles per byte,"
2957#ifdef WC_BENCH_HEAP_TRACKING
2958 "heap_bytes,heap_allocs,"
2959#endif
2960#ifdef WC_BENCH_STACK_TRACKING
2961 "stack_bytes,"
2962#endif
2963 );
2964 #else
2965 printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
2966 WOLFSSL_FIXED_TIME_UNIT "econds_total,"
2967 WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
2968 ",cycles_total,"
2969#ifdef WC_BENCH_HEAP_TRACKING
2970 "heap_bytes,heap_allocs,"
2971#endif
2972#ifdef WC_BENCH_STACK_TRACKING
2973 "stack_bytes,"
2974#endif
2975 );
2976 #endif
2977#else
2978 /* normal CSV */
2979 #ifdef BENCH_DEVID
2980 #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
2981 #else
2982 #define BENCH_DEVID_COLUMN_HEADER
2983 #endif
2984 #ifdef HAVE_GET_CYCLES
2985 printf("\n\nSymmetric Ciphers:\n\n");
2986 printf("Algorithm,"
2987 BENCH_DEVID_COLUMN_HEADER
2988 WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
2989 ",Cycles per byte"
2990#ifdef WC_BENCH_HEAP_TRACKING
2991 ",heap_bytes,heap_allocs"
2992#endif
2993#ifdef WC_BENCH_STACK_TRACKING
2994 ",stack_bytes"
2995#endif
2996 ",");
2997 #else
2998 printf("\n\nSymmetric Ciphers:\n\n");
2999 printf("Algorithm,"
3000 BENCH_DEVID_COLUMN_HEADER
3001 WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
3002#ifdef WC_BENCH_HEAP_TRACKING
3003 ",heap_bytes,heap_allocs"
3004#endif
3005#ifdef WC_BENCH_STACK_TRACKING
3006 ",stack_bytes"
3007#endif
3008 ",");
3009 #endif
3010#endif
3011 #ifdef MULTI_VALUE_STATISTICS
3012 printf("max duration,min duration,mean duration,sd,\n");
3013 #else
3014 printf("\n");
3015 #endif
3016 sym_header_printed = 1;
3017 }
3018 }
3019
3020 /* determine if we have fixed units, or auto-scale bits or bytes for units.
3021 * note that the blockType text is assigned AND the blocks param is scaled.
3022 */
3023 if (base2) {
3024 blockType = get_blocktype(&blocks);
3025 }
3026 else {
3027 blockType = get_blocktype_base10(&blocks);
3028 }
3029
3030 /* calculate blocks per second */
3031 if (total > 0) {
3032 persec = (1 / total) * blocks;
3033 }
3034
3035 bench_heap_checkpoint_measure(
3036#ifdef WC_BENCH_HEAP_TRACKING
3037 &heapAllocs,
3038 &heapBytes
3039#else
3040 NULL,
3041 NULL
3042#endif
3043 );
3044#ifdef WC_BENCH_HEAP_TRACKING
3045 heapAllocs += bench_stats_heap_setup_allocs;
3046 heapBytes += bench_stats_heap_setup_bytes;
3047 bench_stats_heap_setup_allocs = 0;
3048 bench_stats_heap_setup_bytes = 0;
3049#endif
3050#ifdef WC_BENCH_STACK_TRACKING
3051 {
3052 long stackUsed = bench_stack_checkpoint_measure();
3053 bench_last_stack_bytes = MAX(stackUsed, bench_stats_stack_setup_bytes);
3054 }
3055 bench_stats_stack_setup_bytes = 0;
3056#else
3057 (void)bench_stack_checkpoint_measure();
3058#endif
3059
3060 SLEEP_ON_ERROR(ret);
3061 /* format and print to terminal */
3062 if (csv_format == 1) {
3063
3064#ifdef GENERATE_MACHINE_PARSEABLE_REPORT
3065 #ifdef WOLFSSL_ESPIDF
3066 unsigned long bytes_processed =
3067 (unsigned long)count * (unsigned long)countSz;
3068 #else
3069 word64 bytes_processed = (word64)count * (word64)countSz;
3070 #endif
3071
3072 /* note this codepath brings in all the fields from the non-CSV case. */
3073 #ifdef WOLFSSL_ESPIDF
3074 #ifdef HAVE_GET_CYCLES
3075 (void)XSNPRINTF(msg, sizeof(msg),
3076 "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
3077 BENCH_DEVID_GET_NAME(useDeviceID),
3078 bytes_processed, FLT_FMT_ARGS(total),
3079 FLT_FMT_ARGS(persec),
3080 (long unsigned int) total_cycles);
3081 #else
3082 #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
3083 #endif
3084
3085 /* implement other architectures here */
3086
3087 #else
3088 #ifdef HAVE_GET_CYCLES
3089 (void)XSNPRINTF(msg, sizeof(msg),
3090 "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
3091 BENCH_DEVID_GET_NAME(useDeviceID),
3092 bytes_processed, FLT_FMT_ARGS(total),
3093 FLT_FMT_ARGS(persec), total_cycles);
3094 #else
3095 (void)XSNPRINTF(msg, sizeof(msg),
3096 "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
3097 BENCH_DEVID_GET_NAME(useDeviceID),
3098 bytes_processed, FLT_FMT_ARGS(total),
3099 FLT_FMT_ARGS(persec));
3100 #endif
3101 #endif
3102#elif defined(BENCH_DEVID)
3103 (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
3104 BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
3105#else
3106 (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
3107 FLT_FMT_ARGS(persec));
3108#endif
3109
3110 #ifdef WOLFSSL_ESPIDF
3111 SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
3112 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
3113 ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
3114 total_cycles);
3115 #endif
3116
3117 /* implement other cycle counters here */
3118
3119 #else
3120 /* the default cycle counter is Intel */
3121 SHOW_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
3122 #endif
3123 } /* if (csv_format == 1) */
3124
3125 else {
3126#ifdef GENERATE_MACHINE_PARSEABLE_REPORT
3127 #ifdef HAVE_GET_CYCLES
3128 (void)XSNPRINTF(msg, sizeof(msg),
3129 "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
3130 FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
3131 desc, BENCH_DEVID_GET_NAME(useDeviceID),
3132 FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
3133 word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
3134 FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
3135 (unsigned long) total_cycles);
3136 #else
3137 (void)XSNPRINTF(msg, sizeof(msg),
3138 "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
3139 FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
3140 desc, BENCH_DEVID_GET_NAME(useDeviceID),
3141 FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
3142 word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
3143 FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
3144 #endif /* HAVE_GET_CYCLES */
3145#else
3146 (void)XSNPRINTF(msg, sizeof(msg),
3147 "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
3148 FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
3149 desc, BENCH_DEVID_GET_NAME(useDeviceID),
3150 FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
3151 word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
3152 FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
3153#endif
3154
3155#ifdef WOLFSSL_ESPIDF
3156 SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
3157
3158/* implement other architecture cycle counters here */
3159
3160#else
3161 SHOW_CYCLES(msg, sizeof(msg), (unsigned)countSz);
3162#endif
3163 } /* not CSV format */
3164
3165 bench_append_memory_info(msg, sizeof(msg), csv_format == 1,
3166#ifdef WC_BENCH_HEAP_TRACKING
3167 heapAllocs,
3168 heapBytes,
3169#else
3170 0,
3171 0,
3172#endif
3173 BENCH_LAST_STACK_BYTES
3174 );
3175 printf("%s", msg);
3176
3177 /* show errors */
3178 if (ret < 0) {
3179 printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
3180 }
3181
3182#ifndef WOLFSSL_SGX
3183 XFFLUSH(stdout);
3184#endif
3185
3186#ifdef WC_BENCH_TRACK_STATS
3187 /* Add to thread stats */
3188 bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
3189 blockType, ret,
3190#ifdef WC_BENCH_HEAP_TRACKING
3191 heapAllocs, heapBytes,
3192#else
3193 0, 0,
3194#endif
3195 BENCH_LAST_STACK_BYTES
3196 );
3197#endif
3198
3199 (void)useDeviceID;
3200 (void)ret;
3201
3202#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
3203 RESTORE_VECTOR_REGISTERS();
3204#elif defined(WOLFSSL_LINUXKM)
3205 kernel_fpu_end();
3206#endif
3207
3208 bench_stats_prepare();
3209 TEST_SLEEP();
3210} /* bench_stats_sym_finish */
3211
3212#ifndef WC_NO_RNG
3213/* Report ops/sec in the same format as bench_stats_asym_finish, but without
3214 * requiring BENCH_ASYM to be defined. Used for benchmarks like RNG init/free
3215 * that measure operation counts rather than byte throughput. */
3216static void bench_stats_ops_finish(const char* algo, int strength,
3217 const char* desc, int count, double start, int ret)
3218{
3219 double total, each = 0, opsSec, milliEach;
3220 const char **word = bench_result_words2[lng_index];
3221 char msg[256];
3222#ifdef BENCH_MICROSECOND
3223 const int digits = 5;
3224#else
3225 const int digits = 3;
3226#endif
3227
3228 XMEMSET(msg, 0, sizeof(msg));
3229
3230 total = current_time(0) - start;
3231
3232#ifdef WOLFSSL_ESPIDF
3233 END_ESP_CYCLES
3234#else
3235 END_CYCLES
3236#endif
3237
3238 if (count > 0)
3239 each = total / count;
3240 if (total > 0)
3241 opsSec = count / total;
3242 else
3243 opsSec = 0;
3244
3245#ifdef BENCH_MICROSECOND
3246 milliEach = each / 1000;
3247#else
3248 milliEach = each * 1000;
3249#endif
3250
3251 SLEEP_ON_ERROR(ret);
3252
3253 if (csv_format == 1) {
3254 (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s," FLT_FMT_PREC ","
3255 FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
3256 algo, strength, desc,
3257 FLT_FMT_PREC_ARGS(3, milliEach),
3258 FLT_FMT_PREC_ARGS(digits, opsSec));
3259 }
3260 else {
3261#ifdef HAVE_GET_CYCLES
3262 (void)XSNPRINTF(msg, sizeof(msg),
3263 "%-6s %5d %8s %6d %s " FLT_FMT_PREC2 " %s, %s "
3264 FLT_FMT_PREC2 " ms, " FLT_FMT_PREC2 " %s, %lu cycles",
3265 algo, strength, desc,
3266 count, word[0],
3267 FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
3268 FLT_FMT_PREC2_ARGS(5, 3, milliEach),
3269 FLT_FMT_PREC2_ARGS(digits + 6, digits, opsSec),
3270 word[3], (unsigned long)total_cycles);
3271#else
3272 (void)XSNPRINTF(msg, sizeof(msg),
3273 "%-6s %5d %8s %6d %s " FLT_FMT_PREC2 " %s, %s "
3274 FLT_FMT_PREC2 " ms, " FLT_FMT_PREC2 " %s",
3275 algo, strength, desc,
3276 count, word[0],
3277 FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
3278 FLT_FMT_PREC2_ARGS(5, 3, milliEach),
3279 FLT_FMT_PREC2_ARGS(digits + 6, digits, opsSec),
3280 word[3]);
3281#endif
3282
3283#ifdef WOLFSSL_ESPIDF
3284 SHOW_ESP_CYCLES_OPS(msg, sizeof(msg));
3285#else
3286 SHOW_CYCLES_OPS(msg, sizeof(msg));
3287#endif
3288 }
3289
3290 printf("%s", msg);
3291
3292 if (ret < 0) {
3293 printf("%sBenchmark %s %s %d failed: %d\n",
3294 err_prefix, algo, desc, strength, ret);
3295 }
3296
3297#ifndef WOLFSSL_SGX
3298 XFFLUSH(stdout);
3299#endif
3300
3301 (void)ret;
3302
3303#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
3304 RESTORE_VECTOR_REGISTERS();
3305#elif defined(WOLFSSL_LINUXKM)
3306 kernel_fpu_end();
3307#endif
3308
3309 bench_stats_prepare();
3310 TEST_SLEEP();
3311} /* bench_stats_ops_finish */
3312#endif /* !WC_NO_RNG */
3313
3314#ifdef BENCH_ASYM
3315#if ((defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
3316 defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
3317 defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
3318 defined(HAVE_DILITHIUM) || defined(WOLFSSL_HAVE_LMS)) && \
3319 !defined(WC_NO_RNG)) || defined(WOLFSSL_HAVE_MLKEM)
3320static void bench_stats_asym_finish_ex(const char* algo, int strength,
3321 const char* desc, const char* desc_extra, int useDeviceID, int count,
3322 double start, int ret)
3323{
3324 double total, each = 0, opsSec, milliEach;
3325 const char **word = bench_result_words2[lng_index];
3326#ifdef WC_BENCH_TRACK_STATS
3327 const char* kOpsSec = "Ops/Sec";
3328#endif
3329 char msg[256];
3330 static int asym_header_printed = 0;
3331#ifdef BENCH_MICROSECOND
3332 const int digits = 5;
3333#else
3334 const int digits = 3;
3335#endif
3336#ifdef WC_BENCH_HEAP_TRACKING
3337 long heapAllocs = 0;
3338 long heapBytes = 0;
3339#endif
3340 XMEMSET(msg, 0, sizeof(msg));
3341
3342 total = current_time(0) - start;
3343
3344#ifdef LINUX_RUSAGE_UTIME
3345 check_for_excessive_stime(algo, strength, desc, desc_extra);
3346#endif
3347
3348#ifdef WOLFSSL_ESPIDF
3349 END_ESP_CYCLES
3350#else
3351 END_CYCLES
3352#endif
3353
3354 /* some sanity checks on the final numbers */
3355 if (count > 0) {
3356 each = total / count; /* per second */
3357 }
3358 else {
3359 count = 0;
3360 each = 0;
3361 }
3362
3363 if (total > 0) {
3364 opsSec = count / total; /* ops second */
3365 }
3366 else {
3367 opsSec = 0;
3368 }
3369
3370#ifdef BENCH_MICROSECOND
3371 milliEach = each / 1000; /* milliseconds */
3372#else
3373 milliEach = each * 1000; /* milliseconds */
3374#endif
3375
3376 bench_heap_checkpoint_measure(
3377#ifdef WC_BENCH_HEAP_TRACKING
3378 &heapAllocs,
3379 &heapBytes
3380#else
3381 NULL,
3382 NULL
3383#endif
3384 );
3385#ifdef WC_BENCH_HEAP_TRACKING
3386 heapAllocs += bench_stats_heap_setup_allocs;
3387 heapBytes += bench_stats_heap_setup_bytes;
3388 bench_stats_heap_setup_allocs = 0;
3389 bench_stats_heap_setup_bytes = 0;
3390#endif
3391#ifdef WC_BENCH_STACK_TRACKING
3392 {
3393 long stackUsed = bench_stack_checkpoint_measure();
3394 bench_last_stack_bytes = MAX(stackUsed, bench_stats_stack_setup_bytes);
3395 }
3396 bench_stats_stack_setup_bytes = 0;
3397#else
3398 (void)bench_stack_checkpoint_measure();
3399#endif
3400
3401 SLEEP_ON_ERROR(ret);
3402
3403#ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
3404 (void)milliEach;
3405
3406 /* format and print to terminal */
3407 if (csv_format == 1) {
3408 /* only print out header once */
3409 if (asym_header_printed == 0) {
3410#ifdef GENERATE_MACHINE_PARSEABLE_REPORT
3411 #ifdef HAVE_GET_CYCLES
3412 printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
3413 WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
3414 "ecs,cycles,cycles/op,"
3415#ifdef WC_BENCH_HEAP_TRACKING
3416 "heap_bytes,heap_allocs,"
3417#endif
3418#ifdef WC_BENCH_STACK_TRACKING
3419 "stack_bytes,"
3420#endif
3421 );
3422 #else
3423 printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
3424 WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
3425 "ecs,"
3426#ifdef WC_BENCH_HEAP_TRACKING
3427 "heap_bytes,heap_allocs,"
3428#endif
3429#ifdef WC_BENCH_STACK_TRACKING
3430 "stack_bytes,"
3431#endif
3432 );
3433 #endif
3434#else
3435 printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
3436 #ifdef HAVE_GET_CYCLES
3437 printf("%sAlgorithm,key size,operation,ops/"
3438 WOLFSSL_FIXED_TIME_UNIT "ec,cycles/op,", info_prefix);
3439 #else
3440 printf("%sAlgorithm,key size,operation,ops/"
3441 WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
3442 #endif
3443 printf("%s",
3444#ifdef WC_BENCH_HEAP_TRACKING
3445 "heap_bytes,heap_allocs,"
3446#endif
3447#ifdef WC_BENCH_STACK_TRACKING
3448 "stack_bytes,"
3449#endif
3450 "");
3451#endif
3452 printf("max duration,min duration,mean duration,sd,\n");
3453 asym_header_printed = 1;
3454 }
3455#ifdef GENERATE_MACHINE_PARSEABLE_REPORT
3456 #ifdef HAVE_GET_CYCLES
3457 (void)XSNPRINTF(msg, sizeof(msg),
3458 "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
3459 FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
3460 algo, strength, desc, desc_extra,
3461 FLT_FMT_PREC_ARGS(digits, opsSec),
3462 count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
3463 FLT_FMT_PREC_ARGS(6,
3464 (double)total_cycles / (double)count));
3465 #else
3466 (void)XSNPRINTF(msg, sizeof(msg),
3467 "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
3468 FLT_FMT STATS_CLAUSE_SEPARATOR,
3469 algo, strength, desc, desc_extra,
3470 FLT_FMT_PREC_ARGS(digits, opsSec),
3471 count, FLT_FMT_ARGS(total));
3472 #endif
3473#else
3474 #ifdef HAVE_GET_CYCLES
3475 (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
3476 FLT_FMT_PREC "," FLT_FMT_PREC ","
3477 STATS_CLAUSE_SEPARATOR,
3478 algo, strength, desc, desc_extra,
3479 FLT_FMT_PREC_ARGS(digits, opsSec),
3480 FLT_FMT_PREC_ARGS(2, (double)total_cycles /
3481 (double)count));
3482 #else
3483 (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
3484 FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
3485 algo, strength, desc, desc_extra,
3486 FLT_FMT_PREC_ARGS(digits, opsSec));
3487 #endif
3488#endif
3489 } /* if (csv_format == 1) */
3490
3491 else {
3492#ifdef GENERATE_MACHINE_PARSEABLE_REPORT
3493 #ifdef HAVE_GET_CYCLES
3494 (void)XSNPRINTF(msg, sizeof(msg),
3495 "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
3496 FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
3497 algo, strength, desc, desc_extra,
3498 BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
3499 FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
3500 FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
3501 (unsigned long)total_cycles);
3502 #else
3503 (void)XSNPRINTF(msg, sizeof(msg),
3504 "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
3505 FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
3506 algo, strength, desc, desc_extra,
3507 BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
3508 FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
3509 FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
3510 #endif /* HAVE_GET_CYCLES */
3511#else
3512 #ifdef HAVE_GET_CYCLES
3513 (void)XSNPRINTF(msg, sizeof(msg),
3514 "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
3515 FLT_FMT_PREC " %s, " FLT_FMT_PREC2 " %s"
3516 STATS_CLAUSE_SEPARATOR,
3517 algo, strength, desc, desc_extra,
3518 BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
3519 FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
3520 FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
3521 FLT_FMT_PREC2_ARGS(10, 1, (double)total_cycles /
3522 (word64)count), word[4]);
3523 #else
3524 (void)XSNPRINTF(msg, sizeof(msg),
3525 "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
3526 FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
3527 algo, strength, desc, desc_extra,
3528 BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
3529 FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
3530 FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
3531 #endif
3532#endif
3533 }
3534#else /* MULTI_VALUE_STATISTICS. Print with avg ms */
3535 /* format and print to terminal */
3536 if (csv_format == 1) {
3537 /* only print out header once */
3538 if (asym_header_printed == 0) {
3539#ifdef GENERATE_MACHINE_PARSEABLE_REPORT
3540 #ifdef HAVE_GET_CYCLES
3541 printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
3542 WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
3543 "ecs,cycles,cycles/op,"
3544#ifdef WC_BENCH_HEAP_TRACKING
3545 "heap_bytes,heap_allocs,"
3546#endif
3547#ifdef WC_BENCH_STACK_TRACKING
3548 "stack_bytes,"
3549#endif
3550 );
3551 #else
3552 printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
3553 WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
3554 "ecs,"
3555#ifdef WC_BENCH_HEAP_TRACKING
3556 "heap_bytes,heap_allocs,"
3557#endif
3558#ifdef WC_BENCH_STACK_TRACKING
3559 "stack_bytes,"
3560#endif
3561 );
3562 #endif
3563#else
3564 printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
3565 printf("%sAlgorithm,key size,operation,avg ms,ops/"
3566 WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
3567 printf("%s",
3568#ifdef WC_BENCH_HEAP_TRACKING
3569 "heap_bytes,heap_allocs,"
3570#endif
3571#ifdef WC_BENCH_STACK_TRACKING
3572 "stack_bytes,"
3573#endif
3574 "");
3575#endif
3576 printf("\n");
3577 asym_header_printed = 1;
3578 }
3579#ifdef GENERATE_MACHINE_PARSEABLE_REPORT
3580 #ifdef HAVE_GET_CYCLES
3581 (void)XSNPRINTF(msg, sizeof(msg),
3582 "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
3583 FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
3584 algo, strength, desc, desc_extra,
3585 FLT_FMT_PREC_ARGS(3, milliEach),
3586 FLT_FMT_PREC_ARGS(digits, opsSec),
3587 count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
3588 FLT_FMT_PREC_ARGS(6,
3589 (double)total_cycles / (double)count));
3590 #else
3591 (void)XSNPRINTF(msg, sizeof(msg),
3592 "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
3593 FLT_FMT STATS_CLAUSE_SEPARATOR,
3594 algo, strength, desc, desc_extra,
3595 FLT_FMT_PREC_ARGS(3, milliEach),
3596 FLT_FMT_PREC_ARGS(digits, opsSec),
3597 count, FLT_FMT_ARGS(total));
3598 #endif
3599#else
3600 (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
3601 FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
3602 algo, strength, desc, desc_extra,
3603 FLT_FMT_PREC_ARGS(3, milliEach),
3604 FLT_FMT_PREC_ARGS(digits, opsSec));
3605#endif
3606 } /* if (csv_format == 1) */
3607
3608 else {
3609#ifdef GENERATE_MACHINE_PARSEABLE_REPORT
3610 #ifdef HAVE_GET_CYCLES
3611 (void)XSNPRINTF(msg, sizeof(msg),
3612 "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
3613 FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles",
3614 algo, strength, desc, desc_extra,
3615 BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
3616 FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
3617 FLT_FMT_PREC2_ARGS(5, 3, milliEach),
3618 FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
3619 (unsigned long)total_cycles);
3620 #else
3621 (void)XSNPRINTF(msg, sizeof(msg),
3622 "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
3623 FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s",
3624 algo, strength, desc, desc_extra,
3625 BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
3626 FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
3627 FLT_FMT_PREC2_ARGS(5, 3, milliEach),
3628 FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
3629 #endif /* HAVE_GET_CYCLES */
3630#else
3631 #ifdef HAVE_GET_CYCLES
3632 (void)XSNPRINTF(msg, sizeof(msg),
3633 "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
3634 FLT_FMT_PREC2 " ms, " FLT_FMT_PREC2 " %s, %lu cycles",
3635 algo, strength, desc, desc_extra,
3636 BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
3637 FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
3638 FLT_FMT_PREC2_ARGS(5, 3, milliEach),
3639 FLT_FMT_PREC2_ARGS(digits + 6, digits, opsSec),
3640 word[3], (unsigned long)total_cycles);
3641 #else
3642 (void)XSNPRINTF(msg, sizeof(msg),
3643 "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
3644 FLT_FMT_PREC2 " ms, " FLT_FMT_PREC2 " %s",
3645 algo, strength, desc, desc_extra,
3646 BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
3647 FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
3648 FLT_FMT_PREC2_ARGS(5, 3, milliEach),
3649 FLT_FMT_PREC2_ARGS(digits + 6, digits, opsSec),
3650 word[3]);
3651 #endif /* HAVE_GET_CYCLES */
3652#endif
3653#ifdef WOLFSSL_ESPIDF
3654 SHOW_ESP_CYCLES_OPS(msg, sizeof(msg));
3655
3656/* implement other architecture cycle counters here */
3657
3658#else
3659 SHOW_CYCLES_OPS(msg, sizeof(msg));
3660#endif
3661 }
3662#endif /* MULTI_VALUE_STATISTICS */
3663 bench_append_memory_info(msg, sizeof(msg), csv_format == 1,
3664#ifdef WC_BENCH_HEAP_TRACKING
3665 heapAllocs,
3666 heapBytes,
3667#else
3668 0,
3669 0,
3670#endif
3671 BENCH_LAST_STACK_BYTES
3672 );
3673 printf("%s", msg);
3674
3675 /* show errors */
3676 if (ret < 0) {
3677 printf("%sBenchmark %s %s %d failed: %d\n",
3678 err_prefix, algo, desc, strength, ret);
3679 }
3680
3681#ifndef WOLFSSL_SGX
3682 XFFLUSH(stdout);
3683#endif
3684
3685#ifdef WC_BENCH_TRACK_STATS
3686 /* Add to thread stats */
3687 bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
3688 kOpsSec, ret,
3689#ifdef WC_BENCH_HEAP_TRACKING
3690 heapAllocs, heapBytes,
3691#else
3692 0, 0,
3693#endif
3694 BENCH_LAST_STACK_BYTES
3695 );
3696#endif
3697
3698 (void)useDeviceID;
3699 (void)ret;
3700
3701#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
3702 RESTORE_VECTOR_REGISTERS();
3703#elif defined(WOLFSSL_LINUXKM)
3704 kernel_fpu_end();
3705#endif
3706
3707 bench_stats_prepare();
3708 TEST_SLEEP();
3709} /* bench_stats_asym_finish_ex */
3710
3711static void bench_stats_asym_finish(const char* algo, int strength,
3712 const char* desc, int useDeviceID, int count, double start, int ret)
3713{
3714 bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
3715 start, ret);
3716}
3717#endif
3718#endif /* BENCH_ASYM */
3719
3720static WC_INLINE void bench_stats_free(void)
3721{
3722#ifdef WC_BENCH_TRACK_STATS
3723 bench_stats_t* bstat;
3724 for (bstat = bench_stats_head; bstat != NULL; ) {
3725 bench_stats_t* next = bstat->next;
3726 XFREE(bstat, HEAP_HINT, DYNAMIC_TYPE_INFO);
3727 bstat = next;
3728 }
3729 bench_stats_head = NULL;
3730 bench_stats_tail = NULL;
3731#endif
3732}
3733
3734/*****************************************************************************/
3735/* End Stats Functions */
3736/*****************************************************************************/
3737
3738
3739static void* benchmarks_do(void* args)
3740{
3741 long bench_buf_size;
3742
3743#ifdef WOLFSSL_ASYNC_CRYPT
3744#ifndef WC_NO_ASYNC_THREADING
3745 ThreadData* threadData = (ThreadData*)args;
3746
3747 if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
3748#else
3749 if (wolfAsync_DevOpen(&devId) < 0)
3750#endif
3751 {
3752 printf("%sAsync device open failed\n%sRunning without async\n",
3753 err_prefix, err_prefix);
3754 }
3755#endif /* WOLFSSL_ASYNC_CRYPT */
3756
3757 (void)args;
3758
3759#ifdef WOLFSSL_ASYNC_CRYPT
3760 if (wolfEventQueue_Init(&eventQueue) != 0) {
3761 printf("%sAsync event queue init failure!\n", err_prefix);
3762 }
3763#endif
3764
3765#ifdef WOLF_CRYPTO_CB
3766#ifdef HAVE_INTEL_QA_SYNC
3767 devId = wc_CryptoCb_InitIntelQa();
3768 if (devId == INVALID_DEVID) {
3769 printf("%sCouldn't init the Intel QA\n", err_prefix);
3770 }
3771#endif
3772#ifdef HAVE_CAVIUM_OCTEON_SYNC
3773 devId = wc_CryptoCb_InitOcteon();
3774 if (devId == INVALID_DEVID) {
3775 printf("%sCouldn't get the Octeon device ID\n", err_prefix);
3776 }
3777#endif
3778#ifdef HAVE_RENESAS_SYNC
3779 devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
3780 if (devId == INVALID_DEVID) {
3781 printf("%sCouldn't get the Renesas device ID\n", err_prefix);
3782 }
3783#endif
3784#endif
3785
3786#if defined(HAVE_LOCAL_RNG)
3787 {
3788 int rngRet;
3789
3790#ifndef HAVE_FIPS
3791 rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
3792#else
3793 rngRet = wc_InitRng(&gRng);
3794#endif
3795 if (rngRet < 0) {
3796 printf("%sInitRNG failed\n", err_prefix);
3797 return NULL;
3798 }
3799 }
3800#endif
3801
3802 /* setup bench plain, cipher, key and iv globals */
3803 /* make sure bench buffer is multiple of 16 (AES block size) */
3804 bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
3805 if (bench_buf_size % 16)
3806 bench_buf_size += 16 - (bench_buf_size % 16);
3807
3808#ifdef WOLFSSL_AFALG_XILINX_AES
3809 bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
3810 bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
3811#else
3812 bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
3813 HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3814 bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
3815 HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3816#endif
3817 if (bench_plain == NULL || bench_cipher == NULL) {
3818 XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3819 XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3820 bench_plain = bench_cipher = NULL;
3821
3822 printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
3823 goto exit;
3824 }
3825
3826#ifndef NO_FILESYSTEM
3827 if (hash_input) {
3828 size_t rawSz;
3829 XFILE file;
3830 file = XFOPEN(hash_input, "rb");
3831 if (file == XBADFILE)
3832 goto exit;
3833
3834 if (XFSEEK(file, 0, XSEEK_END) != 0) {
3835 XFCLOSE(file);
3836 goto exit;
3837 }
3838
3839 bench_buf_size = XFTELL(file);
3840 if(bench_buf_size < 0 || XFSEEK(file, 0, XSEEK_SET) != 0) {
3841 XFCLOSE(file);
3842 goto exit;
3843 }
3844
3845 XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3846
3847 rawSz = (size_t)bench_buf_size;
3848 if (bench_buf_size % 16)
3849 bench_buf_size += 16 - (bench_buf_size % 16);
3850
3851 bench_size = (word32)bench_buf_size;
3852
3853 bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
3854 HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3855
3856 if (bench_plain == NULL) {
3857 XFCLOSE(file);
3858 goto exit;
3859 }
3860
3861 if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
3862 != rawSz) {
3863 XFCLOSE(file);
3864 goto exit;
3865 }
3866
3867 XFCLOSE(file);
3868 }
3869 else {
3870 XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
3871 }
3872
3873 if (cipher_input) {
3874 size_t rawSz;
3875 XFILE file;
3876 file = XFOPEN(cipher_input, "rb");
3877 if (file == XBADFILE)
3878 goto exit;
3879
3880 if (XFSEEK(file, 0, XSEEK_END) != 0) {
3881 XFCLOSE(file);
3882 goto exit;
3883 }
3884
3885 bench_buf_size = XFTELL(file);
3886 if (bench_buf_size < 0 || XFSEEK(file, 0, XSEEK_SET) != 0) {
3887 XFCLOSE(file);
3888 goto exit;
3889 }
3890
3891 XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3892
3893 rawSz = (size_t)bench_buf_size;
3894 if (bench_buf_size % 16)
3895 bench_buf_size += 16 - (bench_buf_size % 16);
3896
3897 if (bench_size > (word32)bench_buf_size)
3898 bench_size = (word32)bench_buf_size;
3899
3900 bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
3901 HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3902
3903 if (bench_cipher == NULL) {
3904 XFCLOSE(file);
3905 goto exit;
3906 }
3907
3908 if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
3909 != rawSz) {
3910 XFCLOSE(file);
3911 goto exit;
3912 }
3913
3914 XFCLOSE(file);
3915 }
3916 else {
3917 XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
3918 }
3919#endif
3920
3921#if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
3922 bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
3923 HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3924 bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
3925 HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3926
3927 if (bench_key == NULL || bench_iv == NULL) {
3928 XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3929 XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
3930 bench_key = bench_iv = NULL;
3931
3932 printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
3933 goto exit;
3934 }
3935 XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
3936 XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
3937#elif defined(HAVE_RENESAS_SYNC)
3938 bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
3939 bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
3940 bench_key = (byte*)bench_key_buf;
3941 bench_iv = (byte*)bench_iv_buf;
3942#else
3943 bench_key = (byte*)bench_key_buf;
3944 bench_iv = (byte*)bench_iv_buf;
3945#endif
3946
3947#ifndef WC_NO_RNG
3948 if (bench_all || (bench_other_algs & BENCH_RNG))
3949 bench_rng();
3950#endif /* WC_NO_RNG */
3951#if defined(WOLFSSL_DRBG_SHA512) && !defined(WC_NO_RNG) && \
3952 !defined(HAVE_SELFTEST) && \
3953 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
3954 if (bench_all || (bench_other_algs & BENCH_RNG_SHA512))
3955 bench_rng_sha512();
3956#endif
3957#ifndef NO_AES
3958#ifdef HAVE_AES_CBC
3959 if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
3960 #ifndef NO_SW_BENCH
3961 bench_aescbc(0);
3962 #endif
3963 #if defined(BENCH_DEVID)
3964 bench_aescbc(1);
3965 #endif
3966 }
3967#endif
3968#ifdef HAVE_AESGCM
3969 if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
3970 #ifndef NO_SW_BENCH
3971 bench_aes_aad_options_wrap(bench_aesgcm, 0);
3972 #endif
3973 #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
3974 defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
3975 defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM) || \
3976 defined(BENCH_DEVID)) || \
3977 ((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
3978 defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
3979 bench_aes_aad_options_wrap(bench_aesgcm, 1);
3980 #endif
3981 }
3982 if (bench_all || (bench_cipher_algs & BENCH_AES_GCM) ||
3983 (bench_cipher_algs & BENCH_AES_GMAC)) {
3984 #ifndef NO_SW_BENCH
3985 bench_gmac(0);
3986 #endif
3987 #if defined(BENCH_DEVID)
3988 bench_gmac(1);
3989 #endif
3990 }
3991#endif
3992#if defined(HAVE_AES_ECB) || (defined(HAVE_FIPS) && defined(WOLFSSL_AES_DIRECT))
3993 if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
3994 #ifndef NO_SW_BENCH
3995 bench_aesecb(0);
3996 #endif
3997 #ifdef BENCH_DEVID
3998 bench_aesecb(1);
3999 #endif
4000 }
4001#endif
4002#ifdef WOLFSSL_AES_XTS
4003 if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
4004 bench_aesxts();
4005#endif
4006#ifdef WOLFSSL_AES_CFB
4007 if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
4008 bench_aescfb();
4009#endif
4010#ifdef WOLFSSL_AES_OFB
4011 if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
4012 bench_aesofb();
4013#endif
4014#ifdef WOLFSSL_AES_COUNTER
4015 if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
4016 #ifndef NO_SW_BENCH
4017 bench_aesctr(0);
4018 #endif
4019 #ifdef BENCH_DEVID
4020 bench_aesctr(1);
4021 #endif
4022 }
4023#endif
4024#ifdef HAVE_AESCCM
4025 if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
4026 bench_aes_aad_options_wrap(bench_aesccm, 0);
4027 #ifdef BENCH_DEVID
4028 bench_aes_aad_options_wrap(bench_aesccm, 1);
4029 #endif
4030 }
4031#endif
4032#ifdef WOLFSSL_AES_SIV
4033 if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
4034 bench_aessiv();
4035#endif
4036#endif /* !NO_AES */
4037
4038#ifdef HAVE_CAMELLIA
4039 if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
4040 bench_camellia();
4041#endif
4042#ifdef WOLFSSL_SM4_CBC
4043 if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
4044 bench_sm4_cbc();
4045#endif
4046#ifdef WOLFSSL_SM4_GCM
4047 if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
4048 bench_sm4_gcm();
4049#endif
4050#ifdef WOLFSSL_SM4_CCM
4051 if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
4052 bench_sm4_ccm();
4053#endif
4054#ifndef NO_RC4
4055 if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
4056 #ifndef NO_SW_BENCH
4057 bench_arc4(0);
4058 #endif
4059 #ifdef BENCH_DEVID
4060 bench_arc4(1);
4061 #endif
4062 }
4063#endif
4064#ifdef HAVE_CHACHA
4065 if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
4066 bench_chacha();
4067#endif
4068#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
4069 if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
4070 bench_chacha20_poly1305_aead();
4071#endif
4072#ifndef NO_DES3
4073 if (bench_all || (bench_cipher_algs & BENCH_DES)) {
4074 #ifndef NO_SW_BENCH
4075 bench_des(0);
4076 #endif
4077 #ifdef BENCH_DEVID
4078 bench_des(1);
4079 #endif
4080 }
4081#endif
4082#ifdef HAVE_ASCON
4083 if (bench_all || (bench_cipher_algs & BENCH_ASCON_AEAD128))
4084 bench_ascon_aead();
4085#endif
4086#ifndef NO_MD5
4087 if (bench_all || (bench_digest_algs & BENCH_MD5)) {
4088 #ifndef NO_SW_BENCH
4089 bench_md5(0);
4090 #endif
4091 #ifdef BENCH_DEVID
4092 bench_md5(1);
4093 #endif
4094 }
4095#endif
4096#ifdef HAVE_POLY1305
4097 if (bench_all || (bench_digest_algs & BENCH_POLY1305))
4098 bench_poly1305();
4099#endif
4100#ifndef NO_SHA
4101 if (bench_all || (bench_digest_algs & BENCH_SHA)) {
4102 #ifndef NO_SW_BENCH
4103 bench_sha(0);
4104 #endif
4105 #ifdef BENCH_DEVID
4106 bench_sha(1);
4107 #endif
4108 }
4109#endif
4110#ifdef WOLFSSL_SHA224
4111 if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
4112 #ifndef NO_SW_BENCH
4113 bench_sha224(0);
4114 #endif
4115 #ifdef BENCH_DEVID
4116 bench_sha224(1);
4117 #endif
4118 }
4119#endif
4120#ifndef NO_SHA256
4121 if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
4122 #ifndef NO_SW_BENCH
4123 bench_sha256(0);
4124 #endif
4125 #ifdef BENCH_DEVID
4126 bench_sha256(1);
4127 #endif
4128 }
4129#endif
4130#ifdef WOLFSSL_SHA384
4131 if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
4132 #ifndef NO_SW_BENCH
4133 bench_sha384(0);
4134 #endif
4135 #ifdef BENCH_DEVID
4136 bench_sha384(1);
4137 #endif
4138 }
4139#endif
4140#ifdef WOLFSSL_SHA512
4141 if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
4142 #ifndef NO_SW_BENCH
4143 bench_sha512(0);
4144 #endif
4145 #ifdef BENCH_DEVID
4146 bench_sha512(1);
4147 #endif
4148 }
4149
4150#if !defined(WOLFSSL_NOSHA512_224) && \
4151 (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
4152 if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
4153 #ifndef NO_SW_BENCH
4154 bench_sha512_224(0);
4155 #endif
4156 #ifdef BENCH_DEVID
4157 bench_sha512_224(1);
4158 #endif
4159 }
4160#endif /* WOLFSSL_NOSHA512_224 */
4161
4162#if !defined(WOLFSSL_NOSHA512_256) && \
4163 (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
4164 if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
4165 #ifndef NO_SW_BENCH
4166 bench_sha512_256(0);
4167 #endif
4168 #ifdef BENCH_DEVID
4169 bench_sha512_256(1);
4170 #endif
4171 }
4172#endif /* WOLFSSL_NOSHA512_256 */
4173#endif /* WOLFSSL_SHA512 */
4174
4175#ifdef WOLFSSL_SHA3
4176 #ifndef WOLFSSL_NOSHA3_224
4177 if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
4178 #ifndef NO_SW_BENCH
4179 bench_sha3_224(0);
4180 #endif
4181 #ifdef BENCH_DEVID
4182 bench_sha3_224(1);
4183 #endif
4184 }
4185 #endif /* WOLFSSL_NOSHA3_224 */
4186 #ifndef WOLFSSL_NOSHA3_256
4187 if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
4188 #ifndef NO_SW_BENCH
4189 bench_sha3_256(0);
4190 #endif
4191 #ifdef BENCH_DEVID
4192 bench_sha3_256(1);
4193 #endif
4194 }
4195 #endif /* WOLFSSL_NOSHA3_256 */
4196 #ifndef WOLFSSL_NOSHA3_384
4197 if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
4198 #ifndef NO_SW_BENCH
4199 bench_sha3_384(0);
4200 #endif
4201 #ifdef BENCH_DEVID
4202 bench_sha3_384(1);
4203 #endif
4204 }
4205 #endif /* WOLFSSL_NOSHA3_384 */
4206 #ifndef WOLFSSL_NOSHA3_512
4207 if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
4208 #ifndef NO_SW_BENCH
4209 bench_sha3_512(0);
4210 #endif
4211 #ifdef BENCH_DEVID
4212 bench_sha3_512(1);
4213 #endif
4214 }
4215 #endif /* WOLFSSL_NOSHA3_512 */
4216 #ifdef WOLFSSL_SHAKE128
4217 if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
4218 #ifndef NO_SW_BENCH
4219 bench_shake128(0);
4220 #endif
4221 #ifdef BENCH_DEVID
4222 bench_shake128(1);
4223 #endif
4224 }
4225 #endif /* WOLFSSL_SHAKE128 */
4226 #ifdef WOLFSSL_SHAKE256
4227 if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
4228 #ifndef NO_SW_BENCH
4229 bench_shake256(0);
4230 #endif
4231 #ifdef BENCH_DEVID
4232 bench_shake256(1);
4233 #endif
4234 }
4235 #endif /* WOLFSSL_SHAKE256 */
4236#endif
4237#ifdef WOLFSSL_SM3
4238 if (bench_all || (bench_digest_algs & BENCH_SM3)) {
4239 #ifndef NO_SW_BENCH
4240 bench_sm3(0);
4241 #endif
4242 #ifdef BENCH_DEVID
4243 bench_sm3(1);
4244 #endif
4245 }
4246#endif
4247#ifdef WOLFSSL_RIPEMD
4248 if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
4249 bench_ripemd();
4250#endif
4251#ifdef HAVE_BLAKE2B
4252 if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
4253 bench_blake2b();
4254#endif
4255#ifdef HAVE_BLAKE2S
4256 if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
4257 bench_blake2s();
4258#endif
4259#ifdef HAVE_ASCON
4260 if (bench_all || (bench_digest_algs & BENCH_ASCON_HASH256))
4261 bench_ascon_hash();
4262#endif
4263#ifdef WOLFSSL_CMAC
4264 if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
4265 bench_cmac(0);
4266 #ifdef BENCH_DEVID
4267 bench_cmac(1);
4268 #endif
4269 }
4270#endif
4271
4272#ifndef NO_HMAC
4273 #ifndef NO_MD5
4274 if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
4275 #ifndef NO_SW_BENCH
4276 bench_hmac_md5(0);
4277 #endif
4278 #ifdef BENCH_DEVID
4279 bench_hmac_md5(1);
4280 #endif
4281 }
4282 #endif
4283 #ifndef NO_SHA
4284 if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
4285 #ifndef NO_SW_BENCH
4286 bench_hmac_sha(0);
4287 #endif
4288 #ifdef BENCH_DEVID
4289 bench_hmac_sha(1);
4290 #endif
4291 }
4292 #endif
4293 #ifdef WOLFSSL_SHA224
4294 if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
4295 #ifndef NO_SW_BENCH
4296 bench_hmac_sha224(0);
4297 #endif
4298 #ifdef BENCH_DEVID
4299 bench_hmac_sha224(1);
4300 #endif
4301 }
4302 #endif
4303 #ifndef NO_SHA256
4304 if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
4305 #ifndef NO_SW_BENCH
4306 bench_hmac_sha256(0);
4307 #endif
4308 #ifdef BENCH_DEVID
4309 bench_hmac_sha256(1);
4310 #endif
4311 }
4312 #endif
4313 #ifdef WOLFSSL_SHA384
4314 if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
4315 #ifndef NO_SW_BENCH
4316 bench_hmac_sha384(0);
4317 #endif
4318 #ifdef BENCH_DEVID
4319 bench_hmac_sha384(1);
4320 #endif
4321 }
4322 #endif
4323 #ifdef WOLFSSL_SHA512
4324 if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
4325 #ifndef NO_SW_BENCH
4326 bench_hmac_sha512(0);
4327 #endif
4328 #ifdef BENCH_DEVID
4329 bench_hmac_sha512(1);
4330 #endif
4331 }
4332 #endif
4333 #ifndef NO_PWDBASED
4334 if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
4335 bench_pbkdf2();
4336 }
4337 #endif
4338#endif /* NO_HMAC */
4339#ifdef WOLFSSL_SIPHASH
4340 if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
4341 bench_siphash();
4342 }
4343#endif
4344
4345#ifdef WC_SRTP_KDF
4346 if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
4347 bench_srtpkdf();
4348 }
4349#else
4350 (void)bench_kdf_algs;
4351#endif
4352
4353#ifdef HAVE_SCRYPT
4354 if (bench_all || (bench_other_algs & BENCH_SCRYPT))
4355 bench_scrypt();
4356#endif
4357
4358#if !defined(NO_RSA) && !defined(WC_NO_RNG)
4359#ifndef HAVE_RENESAS_SYNC
4360 #if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
4361 if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
4362 #ifndef NO_SW_BENCH
4363 if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
4364 (bench_asym_algs & BENCH_RSA_SZ) == 0) {
4365 bench_rsaKeyGen(0);
4366 }
4367 else {
4368 bench_rsaKeyGen_size(0, bench_size);
4369 }
4370 #endif
4371 #ifdef BENCH_DEVID
4372 if (bench_asym_algs & BENCH_RSA_SZ) {
4373 bench_rsaKeyGen_size(1, bench_size);
4374 }
4375 else {
4376 bench_rsaKeyGen(1);
4377 }
4378 #endif
4379 }
4380 #endif /* WOLFSSL_KEY_GEN */
4381 if (bench_all || (bench_asym_algs & BENCH_RSA)) {
4382 #ifndef NO_SW_BENCH
4383 bench_rsa(0);
4384 #endif
4385 #ifdef BENCH_DEVID
4386 bench_rsa(1);
4387 #endif
4388 }
4389
4390 #if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
4391 if (bench_asym_algs & BENCH_RSA_SZ) {
4392 #ifndef NO_SW_BENCH
4393 bench_rsa_key(0, bench_size);
4394 #endif
4395 #ifdef BENCH_DEVID
4396 bench_rsa_key(1, bench_size);
4397 #endif
4398 }
4399 #endif
4400#endif
4401#endif /* !NO_RSA && !WC_NO_RNG */
4402
4403#if !defined(NO_DH) && !defined(WC_NO_RNG)
4404 if (bench_all || (bench_asym_algs & BENCH_DH)) {
4405 #ifndef NO_SW_BENCH
4406 bench_dh(0);
4407 #endif
4408 #ifdef BENCH_DEVID
4409 bench_dh(1);
4410 #endif
4411 }
4412#endif
4413
4414#ifdef WOLFSSL_HAVE_MLKEM
4415 if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
4416#ifndef WOLFSSL_NO_ML_KEM
4417 #ifdef WOLFSSL_WC_ML_KEM_512
4418 if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
4419 bench_mlkem(WC_ML_KEM_512);
4420 }
4421 #endif
4422 #ifdef WOLFSSL_WC_ML_KEM_768
4423 if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
4424 bench_mlkem(WC_ML_KEM_768);
4425 }
4426 #endif
4427 #ifdef WOLFSSL_WC_ML_KEM_1024
4428 if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
4429 bench_mlkem(WC_ML_KEM_1024);
4430 }
4431 #endif
4432#endif
4433#ifdef WOLFSSL_MLKEM_KYBER
4434 #ifdef WOLFSSL_KYBER512
4435 if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
4436 bench_mlkem(KYBER512);
4437 }
4438 #endif
4439 #ifdef WOLFSSL_KYBER768
4440 if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
4441 bench_mlkem(KYBER768);
4442 }
4443 #endif
4444 #ifdef WOLFSSL_KYBER1024
4445 if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
4446 bench_mlkem(KYBER1024);
4447 }
4448 #endif
4449#endif
4450 }
4451#endif
4452
4453#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
4454 if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
4455 bench_lms();
4456 }
4457#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
4458
4459#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
4460 if (bench_all) {
4461 bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
4462 }
4463#ifndef NO_SHA256
4464 if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
4465 bench_xmss(WC_HASH_TYPE_SHA256);
4466 }
4467#endif
4468#ifdef WOLFSSL_SHA512
4469 if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
4470 bench_xmss(WC_HASH_TYPE_SHA512);
4471 }
4472#endif
4473#ifdef WOLFSSL_SHAKE128
4474 if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
4475 bench_xmss(WC_HASH_TYPE_SHAKE128);
4476 }
4477#endif
4478#ifdef WOLFSSL_SHAKE256
4479 if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
4480 bench_xmss(WC_HASH_TYPE_SHAKE256);
4481 }
4482#endif
4483#endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
4484
4485#if defined(WOLFSSL_HAVE_SLHDSA) && !defined(WOLFSSL_SLHDSA_VERIFY_ONLY)
4486 if (bench_all) {
4487 bench_pq_hash_sig_algs |= BENCH_SLHDSA;
4488 }
4489#ifdef WOLFSSL_SLHDSA_PARAM_128S
4490 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHAKE128S) {
4491 bench_slhdsa(SLHDSA_SHAKE128S);
4492 }
4493#endif
4494#ifdef WOLFSSL_SLHDSA_PARAM_128F
4495 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHAKE128F) {
4496 bench_slhdsa(SLHDSA_SHAKE128F);
4497 }
4498#endif
4499#ifdef WOLFSSL_SLHDSA_PARAM_192S
4500 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHAKE192S) {
4501 bench_slhdsa(SLHDSA_SHAKE192S);
4502 }
4503#endif
4504#ifdef WOLFSSL_SLHDSA_PARAM_192F
4505 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHAKE192F) {
4506 bench_slhdsa(SLHDSA_SHAKE192F);
4507 }
4508#endif
4509#ifdef WOLFSSL_SLHDSA_PARAM_256S
4510 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHAKE256S) {
4511 bench_slhdsa(SLHDSA_SHAKE256S);
4512 }
4513#endif
4514#ifdef WOLFSSL_SLHDSA_PARAM_256F
4515 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHAKE256F) {
4516 bench_slhdsa(SLHDSA_SHAKE256F);
4517 }
4518#endif
4519#ifdef WOLFSSL_SLHDSA_PARAM_SHA2_128S
4520 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHA2_128S) {
4521 bench_slhdsa(SLHDSA_SHA2_128S);
4522 }
4523#endif
4524#ifdef WOLFSSL_SLHDSA_PARAM_SHA2_128F
4525 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHA2_128F) {
4526 bench_slhdsa(SLHDSA_SHA2_128F);
4527 }
4528#endif
4529#ifdef WOLFSSL_SLHDSA_PARAM_SHA2_192S
4530 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHA2_192S) {
4531 bench_slhdsa(SLHDSA_SHA2_192S);
4532 }
4533#endif
4534#ifdef WOLFSSL_SLHDSA_PARAM_SHA2_192F
4535 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHA2_192F) {
4536 bench_slhdsa(SLHDSA_SHA2_192F);
4537 }
4538#endif
4539#ifdef WOLFSSL_SLHDSA_PARAM_SHA2_256S
4540 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHA2_256S) {
4541 bench_slhdsa(SLHDSA_SHA2_256S);
4542 }
4543#endif
4544#ifdef WOLFSSL_SLHDSA_PARAM_SHA2_256F
4545 if (bench_pq_hash_sig_algs & BENCH_SLHDSA_SHA2_256F) {
4546 bench_slhdsa(SLHDSA_SHA2_256F);
4547 }
4548#endif
4549#endif
4550 (void)bench_pq_hash_sig_algs;
4551
4552#if defined(HAVE_ECC) && !defined(WC_NO_RNG)
4553 if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
4554 (bench_asym_algs & BENCH_ECC) ||
4555 (bench_asym_algs & BENCH_ECC_ALL) ||
4556 (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
4557
4558 if (bench_asym_algs & BENCH_ECC_ALL) {
4559 #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
4560 printf("%snot supported in FIPS mode (no ending enum value)\n",
4561 err_prefix);
4562 #else
4563 int curveId = (int)ECC_SECP192R1;
4564
4565 /* set make key and encrypt */
4566 bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
4567 BENCH_ECC_ENCRYPT;
4568 if (csv_format != 1) {
4569 printf("\n%sECC Benchmarks:\n", info_prefix);
4570 }
4571
4572 do {
4573 #ifdef WOLFCRYPT_HAVE_SAKKE
4574 /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
4575 if (curveId == ECC_SAKKE_1) {
4576 curveId++;
4577 continue;
4578 }
4579 #endif
4580
4581 if (wc_ecc_get_curve_size_from_id(curveId) !=
4582 WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
4583 bench_ecc_curve(curveId);
4584 if (csv_format != 1) {
4585 printf("\n");
4586 }
4587 }
4588 curveId++;
4589 } while (curveId != (int)ECC_CURVE_MAX);
4590 #endif
4591 }
4592 else if (bench_asym_algs & BENCH_ECC_P256) {
4593 bench_ecc_curve((int)ECC_SECP256R1);
4594 }
4595 else if (bench_asym_algs & BENCH_ECC_P384) {
4596 bench_ecc_curve((int)ECC_SECP384R1);
4597 }
4598 else if (bench_asym_algs & BENCH_ECC_P521) {
4599 bench_ecc_curve((int)ECC_SECP521R1);
4600 }
4601 else {
4602 #ifndef NO_ECC256
4603 bench_ecc_curve((int)ECC_SECP256R1);
4604 #elif defined(HAVE_ECC384)
4605 bench_ecc_curve((int)ECC_SECP384R1);
4606 #elif defined(HAVE_ECC521)
4607 bench_ecc_curve((int)ECC_SECP521R1);
4608 #endif
4609 #ifdef HAVE_ECC_BRAINPOOL
4610 bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
4611 #endif
4612 }
4613 }
4614#endif
4615#ifdef WOLFSSL_SM2
4616 if (bench_all || (bench_asym_algs & BENCH_SM2)) {
4617 bench_sm2(0);
4618 }
4619#endif
4620
4621#ifdef HAVE_CURVE25519
4622 if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
4623 #ifndef NO_SW_BENCH
4624 bench_curve25519KeyGen(0);
4625 #endif
4626 #ifdef BENCH_DEVID
4627 bench_curve25519KeyGen(1);
4628 #endif
4629 }
4630
4631 #ifdef HAVE_CURVE25519_SHARED_SECRET
4632 if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
4633 bench_curve25519KeyAgree(0);
4634 #ifdef BENCH_DEVID
4635 bench_curve25519KeyAgree(1);
4636 #endif
4637 }
4638 #endif
4639#endif
4640
4641#ifdef HAVE_ED25519
4642 if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN)) {
4643 #ifndef NO_SW_BENCH
4644 bench_ed25519KeyGen(0);
4645 #endif
4646 #ifdef BENCH_DEVID
4647 bench_ed25519KeyGen(1);
4648 #endif
4649 }
4650 if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN)) {
4651 #ifndef NO_SW_BENCH
4652 bench_ed25519KeySign(0);
4653 #endif
4654 #ifdef BENCH_DEVID
4655 bench_ed25519KeySign(1);
4656 #endif
4657 }
4658#endif
4659
4660#ifdef HAVE_CURVE448
4661 if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
4662 bench_curve448KeyGen();
4663 #ifdef HAVE_CURVE448_SHARED_SECRET
4664 if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
4665 bench_curve448KeyAgree();
4666 #endif
4667#endif
4668
4669#ifdef HAVE_ED448
4670 if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
4671 bench_ed448KeyGen();
4672 if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
4673 bench_ed448KeySign();
4674#endif
4675
4676#ifdef WOLFCRYPT_HAVE_ECCSI
4677 #ifdef WOLFCRYPT_ECCSI_KMS
4678 if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
4679 bench_eccsiKeyGen();
4680 }
4681 if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
4682 bench_eccsiPairGen();
4683 }
4684 #endif
4685 #ifdef WOLFCRYPT_ECCSI_CLIENT
4686 if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
4687 bench_eccsiValidate();
4688 }
4689 if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
4690 bench_eccsi();
4691 }
4692 #endif
4693#endif
4694
4695#ifdef WOLFCRYPT_HAVE_SAKKE
4696 #ifdef WOLFCRYPT_SAKKE_KMS
4697 if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
4698 bench_sakkeKeyGen();
4699 }
4700 if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
4701 bench_sakkeRskGen();
4702 }
4703 #endif
4704 #ifdef WOLFCRYPT_SAKKE_CLIENT
4705 if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
4706 bench_sakkeValidate();
4707 }
4708 if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
4709 bench_sakke();
4710 }
4711 #endif
4712#endif
4713
4714#ifdef HAVE_FALCON
4715 if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
4716 bench_falconKeySign(1);
4717 if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
4718 bench_falconKeySign(5);
4719#endif
4720#if defined(HAVE_DILITHIUM) && !defined(WC_NO_RNG)
4721#ifndef WOLFSSL_NO_ML_DSA_44
4722 if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
4723 bench_dilithiumKeySign(2);
4724#endif
4725#ifndef WOLFSSL_NO_ML_DSA_65
4726 if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
4727 bench_dilithiumKeySign(3);
4728#endif
4729#ifndef WOLFSSL_NO_ML_DSA_87
4730 if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
4731 bench_dilithiumKeySign(5);
4732#endif
4733#endif
4734
4735#ifndef WC_NO_RNG
4736 if (bench_all || (bench_other_algs & BENCH_RNG_INIT))
4737 bench_rng_init();
4738#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
4739 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
4740 if (bench_all || (bench_other_algs & BENCH_RNG_SHA512_INIT))
4741 bench_rng_sha512_init();
4742#endif
4743#endif
4744
4745exit:
4746 /* free benchmark buffers */
4747 XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
4748 XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
4749#ifdef WOLFSSL_ASYNC_CRYPT
4750 XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
4751 XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
4752#endif
4753
4754#if defined(HAVE_LOCAL_RNG)
4755 wc_FreeRng(&gRng);
4756#endif
4757
4758/* cleanup the thread if fixed point cache is enabled and have thread local */
4759#if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
4760 wc_ecc_fp_free();
4761#endif
4762
4763 (void)bench_cipher_algs;
4764 (void)bench_digest_algs;
4765 (void)bench_mac_algs;
4766 (void)bench_asym_algs;
4767 (void)bench_other_algs;
4768 (void)bench_pq_asym_algs;
4769
4770 return NULL;
4771}
4772
4773#if defined(HAVE_CPUID) && defined(WOLFSSL_TEST_STATIC_BUILD)
4774static void print_cpu_features(void)
4775{
4776 word32 cpuid_flags = cpuid_get_flags();
4777
4778 printf("CPU: ");
4779#ifdef HAVE_CPUID_INTEL
4780 printf("Intel");
4781#ifdef WOLFSSL_X86_64_BUILD
4782 printf(" x86_64");
4783#else
4784 printf(" x86");
4785#endif
4786 printf(" -");
4787 if (IS_INTEL_AVX1(cpuid_flags)) printf(" avx1");
4788 if (IS_INTEL_AVX2(cpuid_flags)) printf(" avx2");
4789 if (IS_INTEL_RDRAND(cpuid_flags)) printf(" rdrand");
4790 if (IS_INTEL_RDSEED(cpuid_flags)) printf(" rdseed");
4791 if (IS_INTEL_BMI2(cpuid_flags)) printf(" bmi2");
4792 if (IS_INTEL_AESNI(cpuid_flags)) printf(" aesni");
4793 if (IS_INTEL_ADX(cpuid_flags)) printf(" adx");
4794 if (IS_INTEL_MOVBE(cpuid_flags)) printf(" movbe");
4795 if (IS_INTEL_BMI1(cpuid_flags)) printf(" bmi1");
4796 if (IS_INTEL_SHA(cpuid_flags)) printf(" sha");
4797#endif
4798#ifdef __aarch64__
4799 printf("Aarch64 -");
4800 if (IS_AARCH64_AES(cpuid_flags)) printf(" aes");
4801 if (IS_AARCH64_PMULL(cpuid_flags)) printf(" pmull");
4802 if (IS_AARCH64_SHA256(cpuid_flags)) printf(" sha256");
4803 if (IS_AARCH64_SHA512(cpuid_flags)) printf(" sha512");
4804 if (IS_AARCH64_RDM(cpuid_flags)) printf(" rdm");
4805 if (IS_AARCH64_SHA3(cpuid_flags)) printf(" sha3");
4806 if (IS_AARCH64_SM3(cpuid_flags)) printf(" sm3");
4807 if (IS_AARCH64_SM4(cpuid_flags)) printf(" sm4");
4808#endif
4809 printf("\n");
4810}
4811#endif
4812
4813static void print_clock_freq(void)
4814{
4815#ifdef __aarch64__
4816 __asm__ __volatile__ (
4817 "isb\n\t"
4818 "mrs %[freq], cntfrq_el0\n\t"
4819 : [freq] "=r" (tick_freq)
4820 :
4821 :
4822 );
4823 if (tick_freq != 0 && actual_freq != 0) {
4824 printf("Tick frequency: %ld Hz, Clock frequency: %ld Hz\n", tick_freq,
4825 actual_freq);
4826 }
4827 else {
4828 printf("Clock frequency: %ld Hz\n", tick_freq);
4829 }
4830#endif
4831}
4832
4833int benchmark_init(void)
4834{
4835 int ret = 0;
4836
4837 benchmark_static_init(0);
4838
4839#ifdef WOLFSSL_STATIC_MEMORY
4840 ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
4841 sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
4842
4843 if (ret != 0) {
4844 printf("%sunable to load static memory %d\n", err_prefix, ret);
4845 }
4846#endif /* WOLFSSL_STATIC_MEMORY */
4847
4848 if ((ret = wolfCrypt_Init()) != 0) {
4849 printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
4850 return EXIT_FAILURE;
4851 }
4852
4853#if defined(HAVE_CPUID) && defined(WOLFSSL_TEST_STATIC_BUILD)
4854 print_cpu_features();
4855#endif
4856 print_clock_freq();
4857
4858#ifdef HAVE_WC_INTROSPECTION
4859 printf("Math: %s\n", wc_GetMathInfo());
4860#endif
4861
4862#ifdef WOLFSSL_SECO_CAAM
4863 if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
4864 SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
4865 != 0) {
4866 printf("%sunable to open HSM\n", err_prefix);
4867 wolfCrypt_Cleanup();
4868 return EXIT_FAILURE;
4869 }
4870#endif
4871
4872#ifdef WC_RNG_SEED_CB
4873 wc_SetSeed_Cb(WC_GENERATE_SEED_DEFAULT);
4874#endif
4875
4876#if defined(HAVE_FIPS) && FIPS_VERSION3_GE(7,0,0)
4877 /* Pre-run all CASTs so their overhead is not captured in benchmark
4878 * metrics. Without this, the first use of each algorithm triggers
4879 * its CAST on-demand, inflating that algorithm's benchmark numbers. */
4880 {
4881 int castRet = wc_RunAllCast_fips();
4882 if (castRet != 0) {
4883 printf("%swc_RunAllCast_fips: %d CAST(s) failed, module in "
4884 "DEGRADED mode\n", err_prefix, castRet);
4885 }
4886 }
4887#endif
4888
4889 bench_stats_init();
4890
4891#if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
4892 wolfSSL_Debugging_ON();
4893#endif
4894
4895 printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
4896 info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
4897
4898#ifndef GENERATE_MACHINE_PARSEABLE_REPORT
4899 if (csv_format == 1) {
4900 printf("This format allows you to easily copy "
4901 "the output to a csv file.");
4902 }
4903#endif
4904
4905#ifdef HAVE_WNR
4906 ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
4907 if (ret != 0) {
4908 printf("%sWhitewood netRandom config init failed %d\n",
4909 err_prefix, ret);
4910 }
4911#endif /* HAVE_WNR */
4912
4913 return ret;
4914}
4915
4916int benchmark_free(void)
4917{
4918 int ret;
4919
4920#ifdef WC_BENCH_TRACK_STATS
4921 if (gPrintStats || devId != INVALID_DEVID) {
4922 bench_stats_print();
4923 }
4924#endif
4925
4926 bench_stats_free();
4927
4928#ifdef WOLF_CRYPTO_CB
4929#ifdef HAVE_INTEL_QA_SYNC
4930 wc_CryptoCb_CleanupIntelQa(&devId);
4931#endif
4932#ifdef HAVE_CAVIUM_OCTEON_SYNC
4933 wc_CryptoCb_CleanupOcteon(&devId);
4934#endif
4935#ifdef HAVE_RENESAS_SYNC
4936 wc_CryptoCb_CleanupRenesasCmn(&devId);
4937#endif
4938#endif
4939
4940#ifdef WOLFSSL_ASYNC_CRYPT
4941 /* free event queue */
4942 wolfEventQueue_Free(&eventQueue);
4943
4944 /* close device */
4945 wolfAsync_DevClose(&devId);
4946#endif
4947
4948#ifdef HAVE_WNR
4949 ret = wc_FreeNetRandom();
4950 if (ret < 0) {
4951 printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
4952 }
4953#endif
4954
4955#ifdef WOLFSSL_SECO_CAAM
4956 if (wc_SECO_CloseHSM() != 0) {
4957 printf("%sError closing down the key store\n", err_prefix);
4958 }
4959#endif
4960
4961 if ((ret = wolfCrypt_Cleanup()) != 0) {
4962 printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
4963 }
4964
4965 return ret;
4966}
4967
4968
4969#if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
4970static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
4971{
4972 benchmark_test(args);
4973
4974 EXIT_TEST(0);
4975}
4976
4977static int benchmark_test_threaded(void* args)
4978{
4979 int i;
4980
4981 printf("%sThreads: %d\n", info_prefix, g_threadCount);
4982
4983 g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
4984 HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
4985 if (g_threadData == NULL) {
4986 printf("%sThread data alloc failed!\n", err_prefix);
4987 return EXIT_FAILURE;
4988 }
4989
4990 for (i = 0; i < g_threadCount; i++) {
4991 THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
4992 NULL, run_bench, args));
4993 }
4994
4995 for (i = 0; i < g_threadCount; i++) {
4996 THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
4997 }
4998
4999 printf("\n");
5000 bench_stats_print();
5001
5002 return 0;
5003}
5004#endif
5005
5006/* so embedded projects can pull in tests on their own */
5007#ifdef HAVE_STACK_SIZE
5008THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
5009#else
5010int benchmark_test(void *args)
5011#endif
5012{
5013 int ret;
5014
5015 (void)args;
5016
5017#ifdef HAVE_STACK_SIZE_VERBOSE
5018 STACK_SIZE_INIT();
5019#endif
5020
5021#ifdef HAVE_FIPS
5022 wolfCrypt_SetCb_fips(myFipsCb);
5023#endif
5024
5025 ret = benchmark_init();
5026 if (ret != 0)
5027 EXIT_TEST(ret);
5028
5029#if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
5030{
5031 /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
5032 **
5033 ** Chapter Two, Build Options:
5034 **
5035 ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
5036 **
5037 ** asynchronous cryptography using hardware based adapters such as
5038 ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
5039 */
5040 int i;
5041
5042 if (g_threadCount == 0) {
5043 #ifdef WC_ASYNC_BENCH_THREAD_COUNT
5044 g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
5045 #else
5046 g_threadCount = wc_AsyncGetNumberOfCpus();
5047 if (g_threadCount > 0) {
5048 g_threadCount /= 2; /* use physical core count */
5049 }
5050 #endif
5051 }
5052 if (g_threadCount <= 0) {
5053 g_threadCount = 1;
5054 }
5055
5056 printf("%sCPUs: %d\n", info_prefix, g_threadCount);
5057
5058 g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
5059 HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
5060 if (g_threadData == NULL) {
5061 printf("%sThread data alloc failed!\n", err_prefix);
5062 EXIT_TEST(EXIT_FAILURE);
5063 }
5064
5065 /* Create threads */
5066 for (i = 0; i < g_threadCount; i++) {
5067 ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
5068 benchmarks_do, &g_threadData[i]);
5069 if (ret != 0) {
5070 printf("%sError creating benchmark thread %d\n", err_prefix, ret);
5071 EXIT_TEST(EXIT_FAILURE);
5072 }
5073 }
5074
5075 /* Start threads */
5076 for (i = 0; i < g_threadCount; i++) {
5077 wc_AsyncThreadJoin(&g_threadData[i].thread_id);
5078 }
5079
5080 XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
5081}
5082#else
5083 benchmarks_do(NULL);
5084#endif
5085 SLEEP_ON_ERROR(1);
5086 printf("%sBenchmark complete\n", info_prefix);
5087
5088 ret = benchmark_free();
5089
5090 EXIT_TEST(ret);
5091}
5092
5093
5094#ifndef WC_NO_RNG
5095void bench_rng(void)
5096{
5097 int ret, i, count;
5098 double start;
5099 long pos, len, remain;
5100 WC_RNG myrng;
5101 DECLARE_MULTI_VALUE_STATS_VARS()
5102
5103 /* Force SHA-256 DRBG by temporarily disabling SHA-512 DRBG */
5104#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
5105 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
5106 #if !defined(NO_SHA256)
5107 ret = wc_Sha512Drbg_Disable();
5108 if (ret != 0) {
5109 printf("wc_Sha512Drbg_Disable failed %d\n", ret);
5110 return;
5111 }
5112 #else
5113 printf("RNG SHA-256 DRBG (Skipped: Disabled)\n");
5114 return;
5115 #endif
5116#endif
5117
5118 bench_stats_prepare();
5119
5120#ifndef HAVE_FIPS
5121 ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
5122#else
5123 ret = wc_InitRng(&myrng);
5124#endif
5125 if (ret < 0) {
5126 printf("InitRNG (SHA-256) failed %d\n", ret);
5127#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
5128 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
5129 wc_Sha512Drbg_Enable();
5130#endif
5131 return;
5132 }
5133
5134 bench_stats_start(&count, &start);
5135 do {
5136 for (i = 0; i < numBlocks; i++) {
5137 /* Split request to handle large RNG request */
5138 pos = 0;
5139 remain = (int)bench_size;
5140 while (remain > 0) {
5141 len = remain;
5142 if (len > RNG_MAX_BLOCK_LEN)
5143 len = RNG_MAX_BLOCK_LEN;
5144 ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
5145 (word32)len);
5146 if (ret < 0)
5147 goto exit_rng;
5148
5149 remain -= len;
5150 pos += len;
5151 }
5152 RECORD_MULTI_VALUE_STATS();
5153 }
5154 count += i;
5155 } while (bench_stats_check(start)
5156#ifdef MULTI_VALUE_STATISTICS
5157 || runs < minimum_runs
5158#endif
5159 );
5160exit_rng:
5161 bench_stats_sym_finish("RNG SHA-256 DRBG", 0, count, bench_size, start,
5162 ret);
5163#ifdef MULTI_VALUE_STATISTICS
5164 bench_multi_value_stats(max, min, sum, squareSum, runs);
5165#endif
5166
5167 wc_FreeRng(&myrng);
5168
5169 /* Restore SHA-512 DRBG */
5170#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
5171 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
5172 wc_Sha512Drbg_Enable();
5173#endif
5174}
5175#endif /* WC_NO_RNG */
5176
5177#if defined(WOLFSSL_DRBG_SHA512) && !defined(WC_NO_RNG) && \
5178 !defined(HAVE_SELFTEST) && \
5179 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
5180void bench_rng_sha512(void)
5181{
5182 int ret, i, count;
5183 double start;
5184 long pos, len, remain;
5185 WC_RNG myrng;
5186 DECLARE_MULTI_VALUE_STATS_VARS()
5187
5188 /* Force SHA-512 DRBG by temporarily disabling SHA-256 DRBG */
5189#ifndef NO_SHA256
5190 ret = wc_Sha256Drbg_Disable();
5191 if (ret != 0) {
5192 printf("wc_Sha256Drbg_Disable failed %d\n", ret);
5193 return;
5194 }
5195#endif
5196
5197 bench_stats_prepare();
5198
5199#ifndef HAVE_FIPS
5200 ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
5201#else
5202 ret = wc_InitRng(&myrng);
5203#endif
5204 if (ret < 0) {
5205 printf("InitRNG (SHA-512) failed %d\n", ret);
5206#ifndef NO_SHA256
5207 wc_Sha256Drbg_Enable();
5208#endif
5209 return;
5210 }
5211
5212 bench_stats_start(&count, &start);
5213 do {
5214 for (i = 0; i < numBlocks; i++) {
5215 /* Split request to handle large RNG request */
5216 pos = 0;
5217 remain = (int)bench_size;
5218 while (remain > 0) {
5219 len = remain;
5220 if (len > RNG_MAX_BLOCK_LEN)
5221 len = RNG_MAX_BLOCK_LEN;
5222 ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
5223 (word32)len);
5224 if (ret < 0)
5225 goto exit_rng_sha512;
5226
5227 remain -= len;
5228 pos += len;
5229 }
5230 RECORD_MULTI_VALUE_STATS();
5231 }
5232 count += i;
5233 } while (bench_stats_check(start)
5234#ifdef MULTI_VALUE_STATISTICS
5235 || runs < minimum_runs
5236#endif
5237 );
5238exit_rng_sha512:
5239 bench_stats_sym_finish("RNG SHA-512 DRBG", 0, count, bench_size, start,
5240 ret);
5241#ifdef MULTI_VALUE_STATISTICS
5242 bench_multi_value_stats(max, min, sum, squareSum, runs);
5243#endif
5244
5245 wc_FreeRng(&myrng);
5246
5247 /* Restore SHA-256 DRBG */
5248#ifndef NO_SHA256
5249 wc_Sha256Drbg_Enable();
5250#endif
5251}
5252#endif /* WOLFSSL_DRBG_SHA512 && !WC_NO_RNG && !HAVE_SELFTEST && FIPS v7+ */
5253
5254#ifndef WC_NO_RNG
5255void bench_rng_init(void)
5256{
5257 int ret, count;
5258 double start;
5259 WC_RNG myrng;
5260 DECLARE_MULTI_VALUE_STATS_VARS()
5261
5262 /* Force SHA-256 DRBG by temporarily disabling SHA-512 DRBG */
5263#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
5264 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
5265 #if !defined(NO_SHA256)
5266 ret = wc_Sha512Drbg_Disable();
5267 if (ret != 0) {
5268 printf("wc_Sha512Drbg_Disable failed %d\n", ret);
5269 return;
5270 }
5271 #else
5272 printf("RNG SHA-256 Init/Free (Skipped: Disabled)\n");
5273 return;
5274 #endif
5275#endif
5276
5277 bench_stats_start(&count, &start);
5278 do {
5279 #ifndef HAVE_FIPS
5280 ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
5281 #else
5282 ret = wc_InitRng(&myrng);
5283 #endif
5284 if (ret < 0) {
5285 printf("InitRNG (SHA-256 init bench) failed %d\n", ret);
5286 goto exit_rng_init;
5287 }
5288 wc_FreeRng(&myrng);
5289 count++;
5290 RECORD_MULTI_VALUE_STATS();
5291 } while (bench_stats_check(start)
5292#ifdef MULTI_VALUE_STATISTICS
5293 || runs < minimum_runs
5294#endif
5295 );
5296exit_rng_init:
5297 bench_stats_ops_finish("RNG", 256, "SHA256 Init/Free", count, start, ret);
5298#ifdef MULTI_VALUE_STATISTICS
5299 bench_multi_value_stats(max, min, sum, squareSum, runs);
5300#endif
5301
5302 /* Restore SHA-512 DRBG */
5303#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
5304 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
5305 wc_Sha512Drbg_Enable();
5306#endif
5307}
5308
5309#if defined(WOLFSSL_DRBG_SHA512) && !defined(HAVE_SELFTEST) && \
5310 (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
5311void bench_rng_sha512_init(void)
5312{
5313 int ret, count;
5314 double start;
5315 WC_RNG myrng;
5316 DECLARE_MULTI_VALUE_STATS_VARS()
5317
5318 /* Force SHA-512 DRBG by temporarily disabling SHA-256 DRBG */
5319#ifndef NO_SHA256
5320 ret = wc_Sha256Drbg_Disable();
5321 if (ret != 0) {
5322 printf("wc_Sha256Drbg_Disable failed %d\n", ret);
5323 return;
5324 }
5325#endif
5326
5327 bench_stats_start(&count, &start);
5328 do {
5329 #ifndef HAVE_FIPS
5330 ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
5331 #else
5332 ret = wc_InitRng(&myrng);
5333 #endif
5334 if (ret < 0) {
5335 printf("InitRNG (SHA-512 init bench) failed %d\n", ret);
5336 goto exit_rng_sha512_init;
5337 }
5338 wc_FreeRng(&myrng);
5339 count++;
5340 RECORD_MULTI_VALUE_STATS();
5341 } while (bench_stats_check(start)
5342#ifdef MULTI_VALUE_STATISTICS
5343 || runs < minimum_runs
5344#endif
5345 );
5346exit_rng_sha512_init:
5347 bench_stats_ops_finish("RNG", 512, "SHA512 Init/Free", count, start, ret);
5348#ifdef MULTI_VALUE_STATISTICS
5349 bench_multi_value_stats(max, min, sum, squareSum, runs);
5350#endif
5351
5352 /* Restore SHA-256 DRBG */
5353#ifndef NO_SHA256
5354 wc_Sha256Drbg_Enable();
5355#endif
5356}
5357#endif /* WOLFSSL_DRBG_SHA512 && !HAVE_SELFTEST && FIPS v7+ */
5358#endif /* !WC_NO_RNG */
5359
5360/* ============================================================================
5361 * Benchmark init helpers -- use id[] when WC_TEST_*_ID is defined and
5362 * useDeviceID is true, else plain init.
5363 * ========================================================================= */
5364
5365/* --- AES CBC --- */
5366#if !defined(NO_AES) && defined(HAVE_AES_CBC)
5367#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_CBC_ID)
5368static unsigned char benchAesCbcId[] = WC_TEST_AES_CBC_ID;
5369static int benchAesCbcIdLen = (int)sizeof(benchAesCbcId);
5370#endif
5371
5372static WC_MAYBE_UNUSED int bench_AesCbcInit(Aes* aes, void* heap,
5373 int declaredDevId)
5374{
5375#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_CBC_ID)
5376 return wc_AesInit_Id(aes, benchAesCbcId, benchAesCbcIdLen, heap,
5377 declaredDevId);
5378#else
5379 return wc_AesInit(aes, heap, declaredDevId);
5380#endif
5381}
5382#endif /* !NO_AES && HAVE_AES_CBC */
5383
5384/* --- AES GCM --- */
5385#if !defined(NO_AES) && defined(HAVE_AESGCM)
5386#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_GCM_ID)
5387static unsigned char benchAesGcmId[] = WC_TEST_AES_GCM_ID;
5388static int benchAesGcmIdLen = (int)sizeof(benchAesGcmId);
5389#endif
5390
5391static WC_MAYBE_UNUSED int bench_AesGcmInit(Aes* aes, void* heap,
5392 int declaredDevId)
5393{
5394#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_GCM_ID)
5395 return wc_AesInit_Id(aes, benchAesGcmId, benchAesGcmIdLen, heap,
5396 declaredDevId);
5397#else
5398 return wc_AesInit(aes, heap, declaredDevId);
5399#endif
5400}
5401#endif /* !NO_AES && HAVE_AESGCM */
5402
5403/* --- RSA --- */
5404#if !defined(NO_RSA)
5405#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_RSA_PRIV_ID)
5406static unsigned char benchRsaPrivId[] = WC_TEST_RSA_PRIV_ID;
5407static int benchRsaPrivIdLen = (int)sizeof(benchRsaPrivId);
5408#endif
5409
5410static WC_MAYBE_UNUSED int bench_RsaInit(RsaKey* key, void* heap,
5411 int declaredDevId)
5412{
5413#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_RSA_PRIV_ID)
5414 return wc_InitRsaKey_Id(key, benchRsaPrivId, benchRsaPrivIdLen, heap,
5415 declaredDevId);
5416#else
5417 return wc_InitRsaKey_ex(key, heap, declaredDevId);
5418#endif
5419}
5420#endif /* !NO_RSA */
5421
5422/* --- CMAC --- */
5423#ifdef WOLFSSL_CMAC
5424#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_CMAC_ID)
5425static unsigned char benchCmacId[] = WC_TEST_CMAC_ID;
5426static int benchCmacIdLen = (int)sizeof(benchCmacId);
5427#endif
5428
5429static WC_MAYBE_UNUSED int bench_CmacInit(Cmac* cmac, const byte* key,
5430 word32 keySz, int type,
5431 void* unused, void* heap,
5432 int declaredDevId)
5433{
5434#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_CMAC_ID)
5435 return wc_InitCmac_Id(cmac, key, keySz, type, unused,
5436 benchCmacId, benchCmacIdLen, heap, declaredDevId);
5437#elif !defined(HAVE_FIPS)
5438 return wc_InitCmac_ex(cmac, key, keySz, type, unused, heap, declaredDevId);
5439#else
5440 (void)heap;
5441 (void)declaredDevId;
5442 return wc_InitCmac(cmac, key, keySz, type, unused);
5443#endif
5444}
5445#endif /* WOLFSSL_CMAC */
5446
5447/* --- AES ECB --- */
5448#if defined(HAVE_AES_ECB) || \
5449 (defined(HAVE_FIPS) && defined(WOLFSSL_AES_DIRECT))
5450#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
5451static unsigned char benchAesEcbId[] = WC_TEST_AES_ECB_ID;
5452static int benchAesEcbIdLen = (int)sizeof(benchAesEcbId);
5453#endif
5454
5455static WC_MAYBE_UNUSED int bench_AesEcbInit(Aes* aes, void* heap,
5456 int declaredDevId)
5457{
5458#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
5459 return wc_AesInit_Id(aes, benchAesEcbId, benchAesEcbIdLen, heap,
5460 declaredDevId);
5461#else
5462 return wc_AesInit(aes, heap, declaredDevId);
5463#endif
5464}
5465#endif /* HAVE_AES_ECB || (HAVE_FIPS && WOLFSSL_AES_DIRECT) */
5466
5467/* --- ECC --- */
5468#ifdef HAVE_ECC
5469#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_ECC_PAIR_P256_ID)
5470static unsigned char benchEccPairP256Id[] = WC_TEST_ECC_PAIR_P256_ID;
5471static int benchEccPairP256IdLen = (int)sizeof(benchEccPairP256Id);
5472#endif
5473#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_ECC_PAIR_P521_ID)
5474static unsigned char benchEccPairP521Id[] = WC_TEST_ECC_PAIR_P521_ID;
5475static int benchEccPairP521IdLen = (int)sizeof(benchEccPairP521Id);
5476#endif
5477
5478static WC_MAYBE_UNUSED int bench_EccInit_Pair(ecc_key* key, int keySize,
5479 void* heap, int declaredDevId)
5480{
5481#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_ECC_PAIR_P256_ID)
5482 if (keySize == 32) {
5483 return wc_ecc_init_id(key, benchEccPairP256Id,
5484 benchEccPairP256IdLen, heap, declaredDevId);
5485 }
5486#endif
5487#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_ECC_PAIR_P521_ID)
5488 if (keySize == 66) {
5489 return wc_ecc_init_id(key, benchEccPairP521Id,
5490 benchEccPairP521IdLen, heap, declaredDevId);
5491 }
5492#endif
5493 (void)keySize;
5494 return wc_ecc_init_ex(key, heap, declaredDevId);
5495}
5496#endif /* HAVE_ECC */
5497
5498
5499#ifndef NO_AES
5500
5501#ifdef HAVE_AES_CBC
5502static void bench_aescbc_internal(int useDeviceID,
5503 const byte* key, word32 keySz,
5504 const byte* iv, const char* encLabel,
5505 const char* decLabel)
5506{
5507 const byte* in = bench_cipher;
5508 byte* out = bench_plain;
5509 int ret = 0, i, count = 0, times, pending = 0;
5510 WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
5511 sizeof(Aes), HEAP_HINT);
5512 double start;
5513 DECLARE_MULTI_VALUE_STATS_VARS()
5514
5515 bench_stats_prepare();
5516
5517 WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
5518 sizeof(Aes), HEAP_HINT);
5519
5520 /* init keys */
5521 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5522 ret = bench_AesCbcInit(enc[i], HEAP_HINT,
5523 useDeviceID ? devId : INVALID_DEVID);
5524 if (ret != 0) {
5525 printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
5526 goto exit;
5527 }
5528
5529 ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
5530 if (ret != 0) {
5531 printf("AesSetKey failed, ret = %d\n", ret);
5532 goto exit;
5533 }
5534 }
5535
5536 if (cipher_same_buffer) {
5537 in = bench_plain;
5538 }
5539
5540 bench_stats_start(&count, &start);
5541 do {
5542 for (times = 0; times < numBlocks || pending > 0; ) {
5543 bench_async_poll(&pending);
5544
5545 /* while free pending slots in queue, submit ops */
5546 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5547 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
5548 ×, numBlocks, &pending)) {
5549 ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
5550
5551 if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
5552 0, ×, &pending)) {
5553 goto exit_aes_enc;
5554 }
5555 }
5556 } /* for i */
5557 RECORD_MULTI_VALUE_STATS();
5558 } /* for times */
5559 count += times;
5560 } while (bench_stats_check(start)
5561#ifdef MULTI_VALUE_STATISTICS
5562 || runs < minimum_runs
5563#endif
5564 );
5565
5566exit_aes_enc:
5567 bench_stats_sym_finish(encLabel, useDeviceID, count,
5568 bench_size, start, ret);
5569#ifdef MULTI_VALUE_STATISTICS
5570 bench_multi_value_stats(max, min, sum, squareSum, runs);
5571#endif
5572
5573 if (ret < 0) {
5574 goto exit;
5575 }
5576
5577#ifdef HAVE_AES_DECRYPT
5578
5579 if (WC_ARRAY_OK(enc)) {
5580 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5581 wc_AesFree(enc[i]);
5582 }
5583 WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
5584 }
5585
5586 bench_stats_prepare();
5587 WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
5588 sizeof(Aes), HEAP_HINT);
5589
5590 /* init keys */
5591 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5592 ret = bench_AesCbcInit(enc[i], HEAP_HINT,
5593 useDeviceID ? devId : INVALID_DEVID);
5594 if (ret != 0) {
5595 printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
5596 goto exit;
5597 }
5598
5599 ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
5600 if (ret != 0) {
5601 printf("AesSetKey failed, ret = %d\n", ret);
5602 goto exit;
5603 }
5604 }
5605
5606 RESET_MULTI_VALUE_STATS_VARS();
5607
5608 bench_stats_start(&count, &start);
5609 do {
5610 for (times = 0; times < numBlocks || pending > 0; ) {
5611 bench_async_poll(&pending);
5612
5613 /* while free pending slots in queue, submit ops */
5614 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5615 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
5616 ×, numBlocks, &pending)) {
5617 ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
5618
5619 if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
5620 0, ×, &pending)) {
5621 goto exit_aes_dec;
5622 }
5623 }
5624 } /* for i */
5625 RECORD_MULTI_VALUE_STATS();
5626 } /* for times */
5627 count += times;
5628 } while (bench_stats_check(start)
5629#ifdef MULTI_VALUE_STATISTICS
5630 || runs < minimum_runs
5631#endif
5632 );
5633
5634exit_aes_dec:
5635 bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
5636 start, ret);
5637#ifdef MULTI_VALUE_STATISTICS
5638 bench_multi_value_stats(max, min, sum, squareSum, runs);
5639#endif
5640
5641#endif /* HAVE_AES_DECRYPT */
5642
5643 (void)decLabel;
5644exit:
5645
5646 if (WC_ARRAY_OK(enc)) {
5647 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5648 wc_AesFree(enc[i]);
5649 }
5650 WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
5651 }
5652}
5653
5654void bench_aescbc(int useDeviceID)
5655{
5656#ifdef WOLFSSL_AES_128
5657#ifdef HAVE_RENESAS_SYNC
5658 bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
5659 "AES-128-CBC-enc", "AES-128-CBC-dec");
5660#else
5661 bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
5662 "AES-128-CBC-enc", "AES-128-CBC-dec");
5663#endif
5664#endif
5665#ifdef WOLFSSL_AES_192
5666 bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
5667 "AES-192-CBC-enc", "AES-192-CBC-dec");
5668#endif
5669#ifdef WOLFSSL_AES_256
5670#ifdef HAVE_RENESAS_SYNC
5671 bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
5672 "AES-256-CBC-enc", "AES-256-CBC-dec");
5673#else
5674 bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
5675 "AES-256-CBC-enc", "AES-256-CBC-dec");
5676#endif
5677#endif
5678}
5679
5680#endif /* HAVE_AES_CBC */
5681
5682#ifdef HAVE_AESGCM
5683static void bench_aesgcm_internal(int useDeviceID,
5684 const byte* key, word32 keySz,
5685 const byte* iv, word32 ivSz,
5686 const char* encLabel, const char* decLabel)
5687{
5688 int ret = 0, i, count = 0, times, pending = 0;
5689 WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
5690 sizeof(Aes), HEAP_HINT);
5691#ifdef HAVE_AES_DECRYPT
5692 WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
5693 sizeof(Aes), HEAP_HINT);
5694#endif
5695 const byte* in = bench_plain;
5696 byte* out = bench_cipher;
5697 double start;
5698 DECLARE_MULTI_VALUE_STATS_VARS()
5699 WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
5700 WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
5701
5702 bench_stats_prepare();
5703
5704 WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
5705 WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
5706 WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
5707 sizeof(Aes), HEAP_HINT);
5708
5709 XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
5710 XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
5711
5712 /* init keys */
5713 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5714 ret = bench_AesGcmInit(enc[i], HEAP_HINT,
5715 useDeviceID ? devId : INVALID_DEVID);
5716 if (ret != 0) {
5717 printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
5718 goto exit;
5719 }
5720
5721 if (!aead_set_key) {
5722 ret = wc_AesGcmSetKey(enc[i], key, keySz);
5723 if (ret != 0) {
5724 printf("AesGcmSetKey failed, ret = %d\n", ret);
5725 goto exit;
5726 }
5727 }
5728 }
5729
5730 if (cipher_same_buffer) {
5731 out = bench_plain;
5732 }
5733
5734 /* GCM uses same routine in backend for both encrypt and decrypt */
5735 bench_stats_start(&count, &start);
5736 do {
5737 for (times = 0; times < numBlocks || pending > 0; ) {
5738 bench_async_poll(&pending);
5739
5740 /* while free pending slots in queue, submit ops */
5741 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5742 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
5743 ×, numBlocks, &pending)) {
5744 if (aead_set_key) {
5745 ret = wc_AesGcmSetKey(enc[i], key, keySz);
5746 if (!bench_async_handle(&ret,
5747 BENCH_ASYNC_GET_DEV(enc[i]), 0,
5748 ×, &pending)) {
5749 goto exit_aes_gcm;
5750 }
5751 }
5752 ret = wc_AesGcmEncrypt(enc[i], out, in, bench_size,
5753 iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
5754 bench_additional, aesAuthAddSz);
5755 if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
5756 0, ×, &pending)) {
5757 goto exit_aes_gcm;
5758 }
5759 }
5760 } /* for i */
5761 RECORD_MULTI_VALUE_STATS();
5762 } /* for times */
5763 count += times;
5764 } while (bench_stats_check(start)
5765#ifdef MULTI_VALUE_STATISTICS
5766 || runs < minimum_runs
5767#endif
5768 );
5769
5770exit_aes_gcm:
5771 bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
5772 start, ret);
5773#ifdef MULTI_VALUE_STATISTICS
5774 bench_multi_value_stats(max, min, sum, squareSum, runs);
5775#endif
5776
5777#ifdef HAVE_AES_DECRYPT
5778
5779 if (cipher_same_buffer) {
5780 ret = wc_AesGcmSetKey(enc[0], key, keySz);
5781 if (ret != 0) {
5782 goto exit_aes_gcm;
5783 }
5784 ret = wc_AesGcmEncrypt(enc[0], bench_cipher, bench_plain, bench_size,
5785 iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
5786 bench_additional, aesAuthAddSz);
5787 if (ret != 0) {
5788 goto exit_aes_gcm;
5789 }
5790 }
5791
5792 RESET_MULTI_VALUE_STATS_VARS();
5793
5794 bench_stats_prepare();
5795 WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
5796 sizeof(Aes), HEAP_HINT);
5797
5798 /* init keys */
5799 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5800 ret = bench_AesGcmInit(dec[i], HEAP_HINT,
5801 useDeviceID ? devId : INVALID_DEVID);
5802 if (ret != 0) {
5803 printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
5804 goto exit;
5805 }
5806
5807 if (!aead_set_key) {
5808 ret = wc_AesGcmSetKey(dec[i], key, keySz);
5809 if (ret != 0) {
5810 printf("AesGcmSetKey failed, ret = %d\n", ret);
5811 goto exit;
5812 }
5813 }
5814 }
5815
5816 bench_stats_start(&count, &start);
5817 do {
5818 for (times = 0; times < numBlocks || pending > 0; ) {
5819 bench_async_poll(&pending);
5820
5821 /* while free pending slots in queue, submit ops */
5822 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5823 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
5824 ×, numBlocks, &pending)) {
5825 if (aead_set_key) {
5826 ret = wc_AesGcmSetKey(dec[i], key, keySz);
5827 if (!bench_async_handle(&ret,
5828 BENCH_ASYNC_GET_DEV(dec[i]), 0,
5829 ×, &pending)) {
5830 goto exit_aes_gcm_dec;
5831 }
5832 }
5833 ret = wc_AesGcmDecrypt(dec[i], bench_plain,
5834 bench_cipher, bench_size,
5835 iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
5836 bench_additional, aesAuthAddSz);
5837 if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
5838 0, ×, &pending)) {
5839 goto exit_aes_gcm_dec;
5840 }
5841 }
5842 } /* for i */
5843 RECORD_MULTI_VALUE_STATS();
5844 } /* for times */
5845 count += times;
5846 } while (bench_stats_check(start)
5847#ifdef MULTI_VALUE_STATISTICS
5848 || runs < minimum_runs
5849#endif
5850 );
5851
5852exit_aes_gcm_dec:
5853 bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
5854 start, ret);
5855#ifdef MULTI_VALUE_STATISTICS
5856 bench_multi_value_stats(max, min, sum, squareSum, runs);
5857#endif
5858#endif /* HAVE_AES_DECRYPT */
5859
5860 (void)decLabel;
5861
5862exit:
5863
5864 if (ret < 0) {
5865 printf("bench_aesgcm failed: %d\n", ret);
5866 }
5867#ifdef HAVE_AES_DECRYPT
5868 if (WC_ARRAY_OK(dec)) {
5869 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5870 wc_AesFree(dec[i]);
5871 }
5872 WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
5873 }
5874#endif
5875 if (WC_ARRAY_OK(enc)) {
5876 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5877 wc_AesFree(enc[i]);
5878 }
5879 WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
5880 }
5881
5882 WC_FREE_VAR(bench_additional, HEAP_HINT);
5883 WC_FREE_VAR(bench_tag, HEAP_HINT);
5884}
5885
5886#ifdef WOLFSSL_AESGCM_STREAM
5887static void bench_aesgcm_stream_internal(int useDeviceID,
5888 const byte* key, word32 keySz, const byte* iv, word32 ivSz,
5889 const char* encLabel, const char* decLabel)
5890{
5891 int ret = 0, i, count = 0, times, pending = 0;
5892 WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
5893 sizeof(Aes), HEAP_HINT);
5894#ifdef HAVE_AES_DECRYPT
5895 WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
5896 sizeof(Aes), HEAP_HINT);
5897#endif
5898 double start;
5899 DECLARE_MULTI_VALUE_STATS_VARS()
5900
5901 WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
5902 WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
5903
5904 bench_stats_prepare();
5905
5906 WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
5907 WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
5908
5909 WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
5910 sizeof(Aes), HEAP_HINT);
5911#ifdef HAVE_AES_DECRYPT
5912 WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
5913 sizeof(Aes), HEAP_HINT);
5914#endif
5915
5916 XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
5917 XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
5918
5919 /* init keys */
5920 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5921 if ((ret = wc_AesInit(enc[i], HEAP_HINT,
5922 useDeviceID ? devId: INVALID_DEVID)) != 0) {
5923 printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
5924 goto exit;
5925 }
5926
5927 ret = wc_AesGcmSetKey(enc[i], key, keySz);
5928 if (ret != 0) {
5929 printf("AesGcmSetKey failed, ret = %d\n", ret);
5930 goto exit;
5931 }
5932 }
5933
5934 /* GCM uses same routine in backend for both encrypt and decrypt */
5935 bench_stats_start(&count, &start);
5936 do {
5937 for (times = 0; times < numBlocks || pending > 0; ) {
5938 bench_async_poll(&pending);
5939
5940 /* while free pending slots in queue, submit ops */
5941 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5942 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
5943 ×, numBlocks, &pending)) {
5944 ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
5945 if (ret == 0) {
5946 ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
5947 bench_plain, bench_size, bench_additional,
5948 aesAuthAddSz);
5949 }
5950 if (ret == 0) {
5951 ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
5952 AES_AUTH_TAG_SZ);
5953 }
5954 if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
5955 0, ×, &pending)) {
5956 goto exit_aes_gcm;
5957 }
5958 }
5959 } /* for i */
5960 RECORD_MULTI_VALUE_STATS();
5961 } /* for times */
5962 count += times;
5963 } while (bench_stats_check(start)
5964#ifdef MULTI_VALUE_STATISTICS
5965 || runs < minimum_runs
5966#endif
5967 );
5968
5969exit_aes_gcm:
5970 bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
5971 start, ret);
5972#ifdef MULTI_VALUE_STATISTICS
5973 bench_multi_value_stats(max, min, sum, squareSum, runs);
5974#endif
5975
5976#ifdef HAVE_AES_DECRYPT
5977 /* init keys */
5978 for (i = 0; i < BENCH_MAX_PENDING; i++) {
5979 if ((ret = wc_AesInit(dec[i], HEAP_HINT,
5980 useDeviceID ? devId: INVALID_DEVID)) != 0) {
5981 printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
5982 goto exit;
5983 }
5984
5985 ret = wc_AesGcmSetKey(dec[i], key, keySz);
5986 if (ret != 0) {
5987 printf("AesGcmSetKey failed, ret = %d\n", ret);
5988 goto exit;
5989 }
5990 }
5991
5992 RESET_MULTI_VALUE_STATS_VARS();
5993
5994 bench_stats_start(&count, &start);
5995 do {
5996 for (times = 0; times < numBlocks || pending > 0; ) {
5997 bench_async_poll(&pending);
5998
5999 /* while free pending slots in queue, submit ops */
6000 for (i = 0; i < BENCH_MAX_PENDING; i++) {
6001 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
6002 ×, numBlocks, &pending)) {
6003 ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
6004 if (ret == 0) {
6005 ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
6006 bench_cipher, bench_size, bench_additional,
6007 aesAuthAddSz);
6008 }
6009 if (ret == 0) {
6010 ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
6011 AES_AUTH_TAG_SZ);
6012 }
6013 if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
6014 0, ×, &pending)) {
6015 goto exit_aes_gcm_dec;
6016 }
6017 }
6018 } /* for i */
6019 RECORD_MULTI_VALUE_STATS();
6020 } /* for times */
6021 count += times;
6022 } while (bench_stats_check(start)
6023#ifdef MULTI_VALUE_STATISTICS
6024 || runs < minimum_runs
6025#endif
6026 );
6027
6028exit_aes_gcm_dec:
6029 bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
6030 start, ret);
6031#ifdef MULTI_VALUE_STATISTICS
6032 bench_multi_value_stats(max, min, sum, squareSum, runs);
6033#endif
6034#endif /* HAVE_AES_DECRYPT */
6035
6036 (void)decLabel;
6037
6038exit:
6039
6040 if (ret < 0) {
6041 printf("bench_aesgcm failed: %d\n", ret);
6042 }
6043#ifdef HAVE_AES_DECRYPT
6044 if (WC_ARRAY_OK(dec)) {
6045 for (i = 0; i < BENCH_MAX_PENDING; i++) {
6046 wc_AesFree(dec[i]);
6047 }
6048 WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
6049 }
6050#endif
6051 if (WC_ARRAY_OK(enc)) {
6052 for (i = 0; i < BENCH_MAX_PENDING; i++) {
6053 wc_AesFree(enc[i]);
6054 }
6055 WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
6056 }
6057
6058 WC_FREE_VAR(bench_additional, HEAP_HINT);
6059 WC_FREE_VAR(bench_tag, HEAP_HINT);
6060}
6061#endif
6062
6063void bench_aesgcm(int useDeviceID)
6064{
6065#define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
6066#if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
6067 && !defined(WOLFSSL_XILINX_CRYPT) \
6068 || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
6069#ifdef HAVE_RENESAS_SYNC
6070 bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
6071 AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
6072#else
6073 bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
6074 AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
6075#endif
6076#endif
6077#if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
6078 && !defined(WOLFSSL_XILINX_CRYPT)
6079 bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
6080 AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
6081#endif
6082#ifdef WOLFSSL_AES_256
6083#ifdef HAVE_RENESAS_SYNC
6084 bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
6085 AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
6086#else
6087 bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
6088 AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
6089#endif
6090#endif
6091#ifdef WOLFSSL_AESGCM_STREAM
6092#undef AES_GCM_STRING
6093#define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
6094#if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
6095 && !defined(WOLFSSL_XILINX_CRYPT) \
6096 || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
6097 bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
6098 AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
6099#endif
6100#if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
6101 && !defined(WOLFSSL_XILINX_CRYPT)
6102 bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
6103 AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
6104#endif
6105#ifdef WOLFSSL_AES_256
6106 bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
6107 AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
6108#endif
6109#endif /* WOLFSSL_AESGCM_STREAM */
6110#undef AES_GCM_STRING
6111}
6112
6113/* GMAC */
6114void bench_gmac(int useDeviceID)
6115{
6116 int ret = 0, times, count = 0;
6117 Gmac gmac;
6118 double start;
6119 byte tag[AES_AUTH_TAG_SZ];
6120 DECLARE_MULTI_VALUE_STATS_VARS()
6121
6122 /* determine GCM GHASH method */
6123#if defined(WOLFSSL_ARMASM)
6124 const char* gmacStr = "GMAC ARM ASM";
6125#elif defined(GCM_SMALL)
6126 const char* gmacStr = "GMAC Small";
6127#elif defined(GCM_TABLE)
6128 const char* gmacStr = "GMAC Table";
6129#elif defined(GCM_TABLE_4BIT)
6130 const char* gmacStr = "GMAC Table 4-bit";
6131#elif defined(GCM_WORD32)
6132 const char* gmacStr = "GMAC Word32";
6133#else
6134 const char* gmacStr = "GMAC Default";
6135#endif
6136
6137 bench_stats_prepare();
6138
6139/* Implementations of /Dev/Crypto will error out if the size of Auth in is */
6140/* greater than the system's page size */
6141#if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
6142 bench_size = WOLFSSL_AUTHSZ_BENCH;
6143#elif defined(WOLFSSL_DEVCRYPTO)
6144 bench_size = sysconf(_SC_PAGESIZE);
6145#endif
6146
6147 /* init keys */
6148 XMEMSET(bench_plain, 0, bench_size);
6149 XMEMSET(tag, 0, sizeof(tag));
6150 XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
6151 (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
6152 useDeviceID ? devId: INVALID_DEVID);
6153#ifdef HAVE_RENESAS_SYNC
6154 wc_GmacSetKey(&gmac, bench_key1, 16);
6155#else
6156 wc_GmacSetKey(&gmac, bench_key, 16);
6157#endif
6158 bench_stats_start(&count, &start);
6159 do {
6160 for (times = 0; times < numBlocks; times++) {
6161 ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
6162 tag, sizeof(tag));
6163
6164 } /* for times */
6165 count += times;
6166 RECORD_MULTI_VALUE_STATS();
6167 } while (bench_stats_check(start)
6168#ifdef MULTI_VALUE_STATISTICS
6169 || runs < minimum_runs
6170#endif
6171 );
6172
6173 wc_AesFree((Aes*)&gmac);
6174
6175 bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
6176#ifdef MULTI_VALUE_STATISTICS
6177 bench_multi_value_stats(max, min, sum, squareSum, runs);
6178#endif
6179#if defined(WOLFSSL_DEVCRYPTO)
6180 if (ret != 0 && (bench_size > sysconf(_SC_PAGESIZE))) {
6181 printf("authIn Buffer Size[%d] greater than System Page Size[%ld]\n",
6182 bench_size, sysconf(_SC_PAGESIZE));
6183 }
6184 bench_size = BENCH_SIZE;
6185#endif
6186}
6187
6188#endif /* HAVE_AESGCM */
6189
6190
6191#if defined(HAVE_AES_ECB) || (defined(HAVE_FIPS) && defined(WOLFSSL_AES_DIRECT))
6192static void bench_aesecb_internal(int useDeviceID,
6193 const byte* key, word32 keySz,
6194 const char* encLabel, const char* decLabel)
6195{
6196 int ret = 0, i, count = 0, times, pending = 0;
6197 WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
6198 sizeof(Aes), HEAP_HINT);
6199 double start;
6200 DECLARE_MULTI_VALUE_STATS_VARS()
6201#ifdef HAVE_FIPS
6202 const word32 benchSz = WC_AES_BLOCK_SIZE;
6203#else
6204 const word32 benchSz = bench_size;
6205#endif
6206
6207 bench_stats_prepare();
6208
6209 WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
6210 sizeof(Aes), HEAP_HINT);
6211
6212 /* init keys */
6213 for (i = 0; i < BENCH_MAX_PENDING; i++) {
6214 if ((ret = bench_AesEcbInit(enc[i], HEAP_HINT,
6215 useDeviceID ? devId: INVALID_DEVID)) != 0) {
6216 printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
6217 goto exit;
6218 }
6219
6220 ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
6221 if (ret != 0) {
6222 printf("AesSetKey failed, ret = %d\n", ret);
6223 goto exit;
6224 }
6225 }
6226
6227 bench_stats_start(&count, &start);
6228 do {
6229 int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
6230 for (times = 0;
6231 times < outer_loop_limit /* numBlocks */ || pending > 0;
6232 ) {
6233 bench_async_poll(&pending);
6234
6235 /* while free pending slots in queue, submit ops */
6236 for (i = 0; i < BENCH_MAX_PENDING; i++) {
6237 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
6238 ×, outer_loop_limit, &pending)) {
6239 #ifdef HAVE_FIPS
6240 #if defined(WOLFSSL_KERNEL_MODE) || FIPS_VERSION_GE(6, 0)
6241 ret = wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
6242 if (ret != 0)
6243 goto exit_aes_enc;
6244 #else
6245 wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
6246 #endif
6247 #else
6248 wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
6249 benchSz);
6250 #endif
6251 ret = 0;
6252 if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
6253 0, ×, &pending)) {
6254 goto exit_aes_enc;
6255 }
6256 }
6257 } /* for i */
6258 RECORD_MULTI_VALUE_STATS();
6259 } /* for times */
6260 count += times;
6261 } while (bench_stats_check(start)
6262#ifdef MULTI_VALUE_STATISTICS
6263 || runs < minimum_runs
6264#endif
6265 );
6266
6267exit_aes_enc:
6268 bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
6269 start, ret);
6270#ifdef MULTI_VALUE_STATISTICS
6271 bench_multi_value_stats(max, min, sum, squareSum, runs);
6272#endif
6273
6274#ifdef HAVE_AES_DECRYPT
6275 /* init keys */
6276 for (i = 0; i < BENCH_MAX_PENDING; i++) {
6277 ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
6278 if (ret != 0) {
6279 printf("AesSetKey failed, ret = %d\n", ret);
6280 goto exit;
6281 }
6282 }
6283
6284 RESET_MULTI_VALUE_STATS_VARS();
6285
6286 bench_stats_start(&count, &start);
6287 do {
6288 int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
6289 for (times = 0; times < outer_loop_limit || pending > 0; ) {
6290 bench_async_poll(&pending);
6291
6292 /* while free pending slots in queue, submit ops */
6293 for (i = 0; i < BENCH_MAX_PENDING; i++) {
6294 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
6295 ×, outer_loop_limit, &pending)) {
6296 #ifdef HAVE_FIPS
6297 #if defined(WOLFSSL_KERNEL_MODE) || FIPS_VERSION_GE(6, 0)
6298 ret = wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
6299 if (ret != 0)
6300 goto exit_aes_dec;
6301 #else
6302 wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
6303 #endif
6304 #else
6305 wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
6306 benchSz);
6307 #endif
6308 ret = 0;
6309 if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
6310 0, ×, &pending)) {
6311 goto exit_aes_dec;
6312 }
6313 }
6314 } /* for i */
6315 RECORD_MULTI_VALUE_STATS();
6316 } /* for times */
6317 count += times;
6318 } while (bench_stats_check(start)
6319#ifdef MULTI_VALUE_STATISTICS
6320 || runs < minimum_runs
6321#endif
6322 );
6323
6324exit_aes_dec:
6325 bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
6326 start, ret);
6327#ifdef MULTI_VALUE_STATISTICS
6328 bench_multi_value_stats(max, min, sum, squareSum, runs);
6329#endif
6330
6331#endif /* HAVE_AES_DECRYPT */
6332
6333 (void)decLabel;
6334
6335exit:
6336
6337 if (WC_ARRAY_OK(enc)) {
6338 for (i = 0; i < BENCH_MAX_PENDING; i++) {
6339 wc_AesFree(enc[i]);
6340 }
6341 WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
6342 }
6343}
6344
6345void bench_aesecb(int useDeviceID)
6346{
6347#ifdef WOLFSSL_AES_128
6348 bench_aesecb_internal(useDeviceID, bench_key, 16,
6349 "AES-128-ECB-enc", "AES-128-ECB-dec");
6350#endif
6351#ifdef WOLFSSL_AES_192
6352 bench_aesecb_internal(useDeviceID, bench_key, 24,
6353 "AES-192-ECB-enc", "AES-192-ECB-dec");
6354#endif
6355#ifdef WOLFSSL_AES_256
6356 bench_aesecb_internal(useDeviceID, bench_key, 32,
6357 "AES-256-ECB-enc", "AES-256-ECB-dec");
6358#endif
6359}
6360#endif /* HAVE_AES_ECB || (HAVE_FIPS && WOLFSSL_AES_DIRECT) */
6361
6362#ifdef WOLFSSL_AES_CFB
6363static void bench_aescfb_internal(const byte* key,
6364 word32 keySz, const byte* iv,
6365 const char* label_enc, const char* label_dec)
6366{
6367 Aes enc;
6368 double start;
6369 int i, ret, count;
6370 DECLARE_MULTI_VALUE_STATS_VARS()
6371
6372 bench_stats_prepare();
6373
6374 ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
6375 if (ret != 0) {
6376 printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
6377 return;
6378 }
6379
6380 ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
6381 if (ret != 0) {
6382 printf("AesSetKey failed, ret = %d\n", ret);
6383 goto out;
6384 }
6385
6386 bench_stats_start(&count, &start);
6387 do {
6388 for (i = 0; i < numBlocks; i++) {
6389 if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
6390 bench_size)) != 0) {
6391 printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
6392 goto out;
6393 }
6394 RECORD_MULTI_VALUE_STATS();
6395 }
6396 count += i;
6397 } while (bench_stats_check(start)
6398#ifdef MULTI_VALUE_STATISTICS
6399 || runs < minimum_runs
6400#endif
6401 );
6402
6403 bench_stats_sym_finish(label_enc, 0, count, bench_size, start, ret);
6404#ifdef MULTI_VALUE_STATISTICS
6405 bench_multi_value_stats(max, min, sum, squareSum, runs);
6406#endif
6407
6408 ret = wc_AesSetKey(&enc, key, keySz, iv, AES_DECRYPTION);
6409 if (ret != 0) {
6410 printf("AesSetKey failed, ret = %d\n", ret);
6411 goto out;
6412 }
6413
6414#ifdef HAVE_AES_DECRYPT
6415 RESET_MULTI_VALUE_STATS_VARS();
6416
6417 bench_stats_start(&count, &start);
6418 do {
6419 for (i = 0; i < numBlocks; i++) {
6420 if((ret = wc_AesCfbDecrypt(&enc, bench_cipher, bench_plain,
6421 bench_size)) != 0) {
6422 printf("wc_AesCfbDecrypt failed, ret = %d\n", ret);
6423 goto out;
6424 }
6425 RECORD_MULTI_VALUE_STATS();
6426 }
6427 count += i;
6428 } while (bench_stats_check(start)
6429#ifdef MULTI_VALUE_STATISTICS
6430 || runs < minimum_runs
6431#endif
6432 );
6433
6434 bench_stats_sym_finish(label_dec, 0, count, bench_size, start, ret);
6435#ifdef MULTI_VALUE_STATISTICS
6436 bench_multi_value_stats(max, min, sum, squareSum, runs);
6437#endif
6438#endif
6439
6440 (void)label_dec;
6441out:
6442
6443 wc_AesFree(&enc);
6444 return;
6445}
6446
6447void bench_aescfb(void)
6448{
6449#ifdef WOLFSSL_AES_128
6450 bench_aescfb_internal(bench_key, 16, bench_iv,
6451 "AES-128-CFB-enc", "AES-128-CFB-dec");
6452#endif
6453#ifdef WOLFSSL_AES_192
6454 bench_aescfb_internal(bench_key, 24, bench_iv,
6455 "AES-192-CFB-enc", "AES-192-CFB-dec");
6456#endif
6457#ifdef WOLFSSL_AES_256
6458 bench_aescfb_internal(bench_key, 32, bench_iv,
6459 "AES-256-CFB-enc", "AES-256-CFB-dec");
6460#endif
6461}
6462#endif /* WOLFSSL_AES_CFB */
6463
6464
6465#ifdef WOLFSSL_AES_OFB
6466static void bench_aesofb_internal(const byte* key,
6467 word32 keySz, const byte* iv,
6468 const char* label_enc, const char* label_dec)
6469{
6470 Aes enc;
6471 double start;
6472 int i, ret, count;
6473 DECLARE_MULTI_VALUE_STATS_VARS()
6474
6475 bench_stats_prepare();
6476
6477 ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
6478 if (ret != 0) {
6479 printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
6480 return;
6481 }
6482
6483 ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
6484 if (ret != 0) {
6485 printf("AesSetKey failed, ret = %d\n", ret);
6486 return;
6487 }
6488
6489 bench_stats_start(&count, &start);
6490 do {
6491 for (i = 0; i < numBlocks; i++) {
6492 if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
6493 bench_size)) != 0) {
6494 printf("wc_AesOfbEncrypt failed, ret = %d\n", ret);
6495 return;
6496 }
6497 RECORD_MULTI_VALUE_STATS();
6498 }
6499 count += i;
6500 } while (bench_stats_check(start)
6501#ifdef MULTI_VALUE_STATISTICS
6502 || runs < minimum_runs
6503#endif
6504 );
6505
6506 bench_stats_sym_finish(label_enc, 0, count, bench_size, start, ret);
6507#ifdef MULTI_VALUE_STATISTICS
6508 bench_multi_value_stats(max, min, sum, squareSum, runs);
6509#endif
6510
6511 ret = wc_AesSetKey(&enc, key, keySz, iv, AES_DECRYPTION);
6512 if (ret != 0) {
6513 printf("AesSetKey failed, ret = %d\n", ret);
6514 return;
6515 }
6516
6517#ifdef HAVE_AES_DECRYPT
6518 RESET_MULTI_VALUE_STATS_VARS();
6519
6520 bench_stats_start(&count, &start);
6521 do {
6522 for (i = 0; i < numBlocks; i++) {
6523 if((ret = wc_AesOfbDecrypt(&enc, bench_cipher, bench_plain,
6524 bench_size)) != 0) {
6525 printf("wc_AesOfbDecrypt failed, ret = %d\n", ret);
6526 return;
6527 }
6528 RECORD_MULTI_VALUE_STATS();
6529 }
6530 count += i;
6531 } while (bench_stats_check(start)
6532#ifdef MULTI_VALUE_STATISTICS
6533 || runs < minimum_runs
6534#endif
6535 );
6536
6537 bench_stats_sym_finish(label_dec, 0, count, bench_size, start, ret);
6538#ifdef MULTI_VALUE_STATISTICS
6539 bench_multi_value_stats(max, min, sum, squareSum, runs);
6540#endif
6541#endif
6542
6543 (void)label_dec;
6544
6545 wc_AesFree(&enc);
6546}
6547
6548void bench_aesofb(void)
6549{
6550#ifdef WOLFSSL_AES_128
6551 bench_aesofb_internal(bench_key, 16, bench_iv,
6552 "AES-128-OFB-enc", "AES-128-OFB-dec");
6553#endif
6554#ifdef WOLFSSL_AES_192
6555 bench_aesofb_internal(bench_key, 24, bench_iv,
6556 "AES-192-OFB-enc", "AES-192-OFB-dec");
6557#endif
6558#ifdef WOLFSSL_AES_256
6559 bench_aesofb_internal(bench_key, 32, bench_iv,
6560 "AES-256-OFB-enc", "AES-256-OFB-dec");
6561#endif
6562}
6563#endif /* WOLFSSL_AES_CFB */
6564
6565
6566#ifdef WOLFSSL_AES_XTS
6567void bench_aesxts(void)
6568{
6569#ifdef WOLFSSL_AES_128
6570 WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
6571 double start;
6572 int i, count, ret;
6573 DECLARE_MULTI_VALUE_STATS_VARS()
6574
6575 static const unsigned char k1[] = {
6576 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
6577 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
6578 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
6579 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
6580 };
6581
6582 static const unsigned char i1[] = {
6583 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
6584 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
6585 };
6586
6587 bench_stats_prepare();
6588
6589 WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
6590
6591
6592 ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
6593 HEAP_HINT, devId);
6594 if (ret != 0) {
6595 printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
6596 goto exit;
6597 }
6598
6599 bench_stats_start(&count, &start);
6600 do {
6601 for (i = 0; i < numBlocks; i++) {
6602 if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
6603 bench_size, i1, sizeof(i1))) != 0) {
6604 printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
6605 goto exit;
6606 }
6607 RECORD_MULTI_VALUE_STATS();
6608 }
6609 count += i;
6610 } while (bench_stats_check(start)
6611#ifdef MULTI_VALUE_STATISTICS
6612 || runs < minimum_runs
6613#endif
6614 );
6615
6616 bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
6617#ifdef MULTI_VALUE_STATISTICS
6618 bench_multi_value_stats(max, min, sum, squareSum, runs);
6619#endif
6620 wc_AesXtsFree(aes);
6621
6622 /* decryption benchmark */
6623 ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
6624 HEAP_HINT, devId);
6625 if (ret != 0) {
6626 printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
6627 goto exit;
6628 }
6629
6630#ifdef HAVE_AES_DECRYPT
6631 RESET_MULTI_VALUE_STATS_VARS();
6632
6633 bench_stats_start(&count, &start);
6634 do {
6635 for (i = 0; i < numBlocks; i++) {
6636 if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
6637 bench_size, i1, sizeof(i1))) != 0) {
6638 printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
6639 goto exit;
6640 }
6641 RECORD_MULTI_VALUE_STATS();
6642 }
6643 count += i;
6644 } while (bench_stats_check(start)
6645#ifdef MULTI_VALUE_STATISTICS
6646 || runs < minimum_runs
6647#endif
6648 );
6649
6650 bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
6651#ifdef MULTI_VALUE_STATISTICS
6652 bench_multi_value_stats(max, min, sum, squareSum, runs);
6653#endif
6654#endif
6655
6656exit:
6657
6658 wc_AesXtsFree(aes);
6659 WC_FREE_VAR(aes, HEAP_HINT);
6660#else
6661 printf("AES-XTS benchmark is with 128-bit keys only\n");
6662#endif
6663}
6664#endif /* WOLFSSL_AES_XTS */
6665
6666
6667#ifdef WOLFSSL_AES_COUNTER
6668static void bench_aesctr_internal(const byte* key, word32 keySz,
6669 const byte* iv, const char* label,
6670 int useDeviceID)
6671{
6672 Aes enc;
6673 double start;
6674 int i, count, ret = 0;
6675 DECLARE_MULTI_VALUE_STATS_VARS()
6676 const byte* in = bench_cipher;
6677 byte* out = bench_plain;
6678
6679 bench_stats_prepare();
6680
6681 if ((ret = wc_AesInit(&enc, HEAP_HINT,
6682 useDeviceID ? devId : INVALID_DEVID)) != 0) {
6683 printf("wc_AesInit failed, ret = %d\n", ret);
6684 }
6685
6686 if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
6687 printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
6688 return;
6689 }
6690
6691 if (cipher_same_buffer) {
6692 in = bench_plain;
6693 }
6694
6695 bench_stats_start(&count, &start);
6696 do {
6697 for (i = 0; i < numBlocks; i++) {
6698 if((ret = wc_AesCtrEncrypt(&enc, out, in, bench_size)) != 0) {
6699 printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
6700 return;
6701 }
6702 RECORD_MULTI_VALUE_STATS();
6703 }
6704 count += i;
6705 } while (bench_stats_check(start)
6706#ifdef MULTI_VALUE_STATISTICS
6707 || runs < minimum_runs
6708#endif
6709 );
6710
6711 bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
6712#ifdef MULTI_VALUE_STATISTICS
6713 bench_multi_value_stats(max, min, sum, squareSum, runs);
6714#endif
6715
6716 wc_AesFree(&enc);
6717}
6718
6719void bench_aesctr(int useDeviceID)
6720{
6721#ifdef WOLFSSL_AES_128
6722 bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
6723#endif
6724#ifdef WOLFSSL_AES_192
6725 bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
6726#endif
6727#ifdef WOLFSSL_AES_256
6728 bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
6729#endif
6730}
6731#endif /* WOLFSSL_AES_COUNTER */
6732
6733
6734#ifdef HAVE_AESCCM
6735void bench_aesccm(int useDeviceID)
6736{
6737 Aes enc;
6738 int enc_inited = 0;
6739 double start;
6740 int ret, i, count;
6741 DECLARE_MULTI_VALUE_STATS_VARS()
6742
6743 WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
6744 WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
6745
6746 bench_stats_prepare();
6747
6748 WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
6749 WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
6750
6751 XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
6752 XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
6753
6754 if ((ret = wc_AesInit(&enc, HEAP_HINT,
6755 useDeviceID ? devId : INVALID_DEVID)) != 0)
6756 {
6757 printf("wc_AesInit failed, ret = %d\n", ret);
6758 goto exit;
6759 }
6760
6761 if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
6762 printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
6763 goto exit;
6764 }
6765 enc_inited = 1;
6766
6767 bench_stats_start(&count, &start);
6768 do {
6769 for (i = 0; i < numBlocks; i++) {
6770 ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
6771 bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
6772 bench_additional, 0);
6773 RECORD_MULTI_VALUE_STATS();
6774 }
6775 count += i;
6776 } while (bench_stats_check(start)
6777#ifdef MULTI_VALUE_STATISTICS
6778 || runs < minimum_runs
6779#endif
6780 );
6781
6782 bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
6783 bench_size, start, ret);
6784#ifdef MULTI_VALUE_STATISTICS
6785 bench_multi_value_stats(max, min, sum, squareSum, runs);
6786#endif
6787 if (ret != 0) {
6788 printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
6789 goto exit;
6790 }
6791
6792#ifdef HAVE_AES_DECRYPT
6793 RESET_MULTI_VALUE_STATS_VARS();
6794
6795 bench_stats_start(&count, &start);
6796 do {
6797 for (i = 0; i < numBlocks; i++) {
6798 ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
6799 bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
6800 bench_additional, 0);
6801 RECORD_MULTI_VALUE_STATS();
6802 }
6803 count += i;
6804 } while (bench_stats_check(start)
6805#ifdef MULTI_VALUE_STATISTICS
6806 || runs < minimum_runs
6807#endif
6808 );
6809
6810 bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
6811 bench_size, start, ret);
6812#ifdef MULTI_VALUE_STATISTICS
6813 bench_multi_value_stats(max, min, sum, squareSum, runs);
6814#endif
6815 if (ret != 0) {
6816 printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
6817 goto exit;
6818 }
6819#endif
6820
6821 exit:
6822
6823 if (enc_inited)
6824 wc_AesFree(&enc);
6825
6826 WC_FREE_VAR(bench_additional, HEAP_HINT);
6827 WC_FREE_VAR(bench_tag, HEAP_HINT);
6828}
6829#endif /* HAVE_AESCCM */
6830
6831
6832#ifdef WOLFSSL_AES_SIV
6833static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
6834 encLabel, const char* decLabel)
6835{
6836 int i;
6837 int ret = 0;
6838 byte assoc[WC_AES_BLOCK_SIZE];
6839 byte nonce[WC_AES_BLOCK_SIZE];
6840 byte siv[WC_AES_BLOCK_SIZE];
6841 int count = 0;
6842 double start;
6843 DECLARE_MULTI_VALUE_STATS_VARS()
6844
6845 bench_stats_prepare();
6846
6847 bench_stats_start(&count, &start);
6848 do {
6849 for (i = 0; i < numBlocks; i++) {
6850 ret = wc_AesSivEncrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
6851 WC_AES_BLOCK_SIZE, bench_plain, bench_size,
6852 siv, bench_cipher);
6853 if (ret != 0) {
6854 printf("wc_AesSivEncrypt failed (%d)\n", ret);
6855 return;
6856 }
6857 RECORD_MULTI_VALUE_STATS();
6858 }
6859 count += i;
6860 } while (bench_stats_check(start)
6861#ifdef MULTI_VALUE_STATISTICS
6862 || runs < minimum_runs
6863#endif
6864 );
6865
6866 bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
6867#ifdef MULTI_VALUE_STATISTICS
6868 bench_multi_value_stats(max, min, sum, squareSum, runs);
6869#endif
6870
6871 RESET_MULTI_VALUE_STATS_VARS();
6872
6873 bench_stats_start(&count, &start);
6874 do {
6875 for (i = 0; i < numBlocks; i++) {
6876 ret = wc_AesSivDecrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
6877 WC_AES_BLOCK_SIZE, bench_cipher, bench_size,
6878 siv, bench_plain);
6879 if (ret != 0) {
6880 printf("wc_AesSivDecrypt failed (%d)\n", ret);
6881 return;
6882 }
6883 RECORD_MULTI_VALUE_STATS();
6884 }
6885 count += i;
6886 } while (bench_stats_check(start)
6887#ifdef MULTI_VALUE_STATISTICS
6888 || runs < minimum_runs
6889#endif
6890 );
6891
6892 bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
6893#ifdef MULTI_VALUE_STATISTICS
6894 bench_multi_value_stats(max, min, sum, squareSum, runs);
6895#endif
6896}
6897
6898void bench_aessiv(void)
6899{
6900 bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
6901 bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
6902 bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
6903}
6904#endif /* WOLFSSL_AES_SIV */
6905#endif /* !NO_AES */
6906
6907
6908#ifdef HAVE_POLY1305
6909void bench_poly1305(void)
6910{
6911 Poly1305 enc;
6912 byte mac[16];
6913 double start;
6914 int ret = 0, i, count;
6915 DECLARE_MULTI_VALUE_STATS_VARS()
6916
6917 bench_stats_prepare();
6918
6919 if (digest_stream) {
6920 ret = wc_Poly1305SetKey(&enc, bench_key, 32);
6921 if (ret != 0) {
6922 printf("Poly1305SetKey failed, ret = %d\n", ret);
6923 return;
6924 }
6925
6926 bench_stats_start(&count, &start);
6927 do {
6928 for (i = 0; i < numBlocks; i++) {
6929 ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
6930 if (ret != 0) {
6931 printf("Poly1305Update failed: %d\n", ret);
6932 break;
6933 }
6934 RECORD_MULTI_VALUE_STATS();
6935 }
6936 wc_Poly1305Final(&enc, mac);
6937 count += i;
6938 } while (bench_stats_check(start)
6939 #ifdef MULTI_VALUE_STATISTICS
6940 || runs < minimum_runs
6941 #endif
6942 );
6943 }
6944 else {
6945 bench_stats_start(&count, &start);
6946 do {
6947 for (i = 0; i < numBlocks; i++) {
6948 ret = wc_Poly1305SetKey(&enc, bench_key, 32);
6949 if (ret != 0) {
6950 printf("Poly1305SetKey failed, ret = %d\n", ret);
6951 return;
6952 }
6953 ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
6954 if (ret != 0) {
6955 printf("Poly1305Update failed: %d\n", ret);
6956 break;
6957 }
6958 wc_Poly1305Final(&enc, mac);
6959 RECORD_MULTI_VALUE_STATS();
6960 }
6961 count += i;
6962 } while (bench_stats_check(start)
6963 #ifdef MULTI_VALUE_STATISTICS
6964 || runs < minimum_runs
6965 #endif
6966 );
6967 }
6968 bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
6969#ifdef MULTI_VALUE_STATISTICS
6970 bench_multi_value_stats(max, min, sum, squareSum, runs);
6971#endif
6972}
6973#endif /* HAVE_POLY1305 */
6974
6975
6976#ifdef HAVE_CAMELLIA
6977void bench_camellia(void)
6978{
6979 wc_Camellia cam;
6980 double start;
6981 int ret, i, count;
6982 DECLARE_MULTI_VALUE_STATS_VARS()
6983
6984 bench_stats_prepare();
6985
6986 ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
6987 if (ret != 0) {
6988 printf("CamelliaSetKey failed, ret = %d\n", ret);
6989 return;
6990 }
6991
6992 bench_stats_start(&count, &start);
6993 do {
6994 for (i = 0; i < numBlocks; i++) {
6995 ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
6996 bench_size);
6997 if (ret < 0) {
6998 printf("CamelliaCbcEncrypt failed: %d\n", ret);
6999 return;
7000 }
7001 RECORD_MULTI_VALUE_STATS();
7002 }
7003 count += i;
7004 } while (bench_stats_check(start)
7005#ifdef MULTI_VALUE_STATISTICS
7006 || runs < minimum_runs
7007#endif
7008 );
7009
7010 bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
7011#ifdef MULTI_VALUE_STATISTICS
7012 bench_multi_value_stats(max, min, sum, squareSum, runs);
7013#endif
7014}
7015#endif
7016
7017#ifdef WOLFSSL_SM4_CBC
7018void bench_sm4_cbc(void)
7019{
7020 wc_Sm4 sm4;
7021 double start;
7022 int ret;
7023 int i;
7024 int count;
7025 DECLARE_MULTI_VALUE_STATS_VARS()
7026
7027 bench_stats_prepare();
7028
7029 ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
7030 if (ret != 0) {
7031 printf("Sm4SetKey failed, ret = %d\n", ret);
7032 return;
7033 }
7034 ret = wc_Sm4SetIV(&sm4, bench_iv);
7035 if (ret != 0) {
7036 printf("Sm4SetIV failed, ret = %d\n", ret);
7037 return;
7038 }
7039
7040 bench_stats_start(&count, &start);
7041 do {
7042 for (i = 0; i < numBlocks; i++) {
7043 ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
7044 if (ret < 0) {
7045 printf("Sm4CbcEncrypt failed: %d\n", ret);
7046 return;
7047 }
7048 RECORD_MULTI_VALUE_STATS();
7049 }
7050 count += i;
7051 } while (bench_stats_check(start)
7052#ifdef MULTI_VALUE_STATISTICS
7053 || runs < minimum_runs
7054#endif
7055 );
7056
7057 bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
7058#ifdef MULTI_VALUE_STATISTICS
7059 bench_multi_value_stats(max, min, sum, squareSum, runs);
7060#endif
7061
7062 RESET_MULTI_VALUE_STATS_VARS();
7063
7064 bench_stats_start(&count, &start);
7065 do {
7066 for (i = 0; i < numBlocks; i++) {
7067 ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
7068 if (ret < 0) {
7069 printf("Sm4CbcDecrypt failed: %d\n", ret);
7070 return;
7071 }
7072 RECORD_MULTI_VALUE_STATS();
7073 }
7074 count += i;
7075 } while (bench_stats_check(start)
7076#ifdef MULTI_VALUE_STATISTICS
7077 || runs < minimum_runs
7078#endif
7079 );
7080
7081 bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
7082#ifdef MULTI_VALUE_STATISTICS
7083 bench_multi_value_stats(max, min, sum, squareSum, runs);
7084#endif
7085}
7086#endif
7087
7088#ifdef WOLFSSL_SM4_GCM
7089void bench_sm4_gcm(void)
7090{
7091 wc_Sm4 sm4;
7092 double start;
7093 int ret;
7094 int i;
7095 int count;
7096 DECLARE_MULTI_VALUE_STATS_VARS()
7097
7098 WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
7099 WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
7100
7101 bench_stats_prepare();
7102
7103 WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
7104 WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
7105
7106 ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
7107 if (ret != 0) {
7108 printf("Sm4GcmSetKey failed, ret = %d\n", ret);
7109 goto exit;
7110 }
7111
7112 bench_stats_start(&count, &start);
7113 do {
7114 for (i = 0; i < numBlocks; i++) {
7115 ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
7116 bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
7117 bench_additional, aesAuthAddSz);
7118 if (ret < 0) {
7119 printf("Sm4GcmEncrypt failed: %d\n", ret);
7120 goto exit;
7121 }
7122 RECORD_MULTI_VALUE_STATS();
7123 }
7124 count += i;
7125 } while (bench_stats_check(start)
7126#ifdef MULTI_VALUE_STATISTICS
7127 || runs < minimum_runs
7128#endif
7129 );
7130
7131 bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
7132#ifdef MULTI_VALUE_STATISTICS
7133 bench_multi_value_stats(max, min, sum, squareSum, runs);
7134#endif
7135
7136 RESET_MULTI_VALUE_STATS_VARS();
7137
7138 bench_stats_start(&count, &start);
7139 do {
7140 for (i = 0; i < numBlocks; i++) {
7141 ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
7142 bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
7143 bench_additional, aesAuthAddSz);
7144 if (ret < 0) {
7145 printf("Sm4GcmDecrypt failed: %d\n", ret);
7146 goto exit;
7147 }
7148 RECORD_MULTI_VALUE_STATS();
7149 }
7150 count += i;
7151 } while (bench_stats_check(start)
7152#ifdef MULTI_VALUE_STATISTICS
7153 || runs < minimum_runs
7154#endif
7155 );
7156
7157 bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
7158#ifdef MULTI_VALUE_STATISTICS
7159 bench_multi_value_stats(max, min, sum, squareSum, runs);
7160#endif
7161
7162exit:
7163
7164 WC_FREE_VAR(bench_additional, HEAP_HINT);
7165 WC_FREE_VAR(bench_tag, HEAP_HINT);
7166}
7167#endif
7168
7169#ifdef WOLFSSL_SM4_CCM
7170void bench_sm4_ccm(void)
7171{
7172 wc_Sm4 enc;
7173 double start;
7174 int ret, i, count;
7175 DECLARE_MULTI_VALUE_STATS_VARS()
7176
7177 WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
7178 WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
7179
7180 bench_stats_prepare();
7181
7182 WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
7183 WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
7184
7185 XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
7186 XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
7187
7188 if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
7189 printf("wc_Sm4SetKey failed, ret = %d\n", ret);
7190 goto exit;
7191 }
7192
7193 bench_stats_start(&count, &start);
7194 do {
7195 for (i = 0; i < numBlocks; i++) {
7196 ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
7197 bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
7198 bench_additional, 0);
7199 RECORD_MULTI_VALUE_STATS();
7200 }
7201 count += i;
7202 } while (bench_stats_check(start)
7203#ifdef MULTI_VALUE_STATISTICS
7204 || runs < minimum_runs
7205#endif
7206 );
7207
7208 bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
7209#ifdef MULTI_VALUE_STATISTICS
7210 bench_multi_value_stats(max, min, sum, squareSum, runs);
7211#endif
7212 if (ret != 0) {
7213 printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
7214 goto exit;
7215 }
7216
7217 RESET_MULTI_VALUE_STATS_VARS();
7218
7219 bench_stats_start(&count, &start);
7220 do {
7221 for (i = 0; i < numBlocks; i++) {
7222 ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
7223 bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
7224 bench_additional, 0);
7225 RECORD_MULTI_VALUE_STATS();
7226 }
7227 count += i;
7228 } while (bench_stats_check(start)
7229#ifdef MULTI_VALUE_STATISTICS
7230 || runs < minimum_runs
7231#endif
7232 );
7233
7234 bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
7235#ifdef MULTI_VALUE_STATISTICS
7236 bench_multi_value_stats(max, min, sum, squareSum, runs);
7237#endif
7238 if (ret != 0) {
7239 printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
7240 goto exit;
7241 }
7242
7243 exit:
7244
7245 WC_FREE_VAR(bench_additional, HEAP_HINT);
7246 WC_FREE_VAR(bench_tag, HEAP_HINT);
7247}
7248#endif /* HAVE_AESCCM */
7249#ifndef NO_DES3
7250void bench_des(int useDeviceID)
7251{
7252 int ret = 0, i, count = 0, times, pending = 0;
7253 WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
7254 sizeof(Des3), HEAP_HINT);
7255 double start;
7256 DECLARE_MULTI_VALUE_STATS_VARS()
7257
7258 bench_stats_prepare();
7259
7260 WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
7261 sizeof(Des3), HEAP_HINT);
7262
7263 /* init keys */
7264 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7265 if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
7266 useDeviceID ? devId : INVALID_DEVID)) != 0) {
7267 printf("Des3Init failed, ret = %d\n", ret);
7268 goto exit;
7269 }
7270
7271 ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
7272 if (ret != 0) {
7273 printf("Des3_SetKey failed, ret = %d\n", ret);
7274 goto exit;
7275 }
7276 }
7277
7278 bench_stats_start(&count, &start);
7279 do {
7280 for (times = 0; times < numBlocks || pending > 0; ) {
7281 bench_async_poll(&pending);
7282
7283 /* while free pending slots in queue, submit ops */
7284 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7285 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
7286 ×, numBlocks, &pending)) {
7287 ret = wc_Des3_CbcEncrypt(enc[i],
7288 bench_cipher,
7289 bench_plain, bench_size);
7290 if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
7291 0, ×, &pending)) {
7292 goto exit_3des;
7293 }
7294 }
7295 } /* for i */
7296 RECORD_MULTI_VALUE_STATS();
7297 } /* for times */
7298 count += times;
7299 } while (bench_stats_check(start)
7300#ifdef MULTI_VALUE_STATISTICS
7301 || runs < minimum_runs
7302#endif
7303 );
7304
7305exit_3des:
7306 bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
7307#ifdef MULTI_VALUE_STATISTICS
7308 bench_multi_value_stats(max, min, sum, squareSum, runs);
7309#endif
7310
7311exit:
7312
7313 if (WC_ARRAY_OK(enc)) {
7314 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7315 wc_Des3Free(enc[i]);
7316 }
7317 WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
7318 }
7319}
7320#endif /* !NO_DES3 */
7321
7322
7323#ifndef NO_RC4
7324void bench_arc4(int useDeviceID)
7325{
7326 int ret = 0, i, count = 0, times, pending = 0;
7327 WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
7328 sizeof(Arc4), HEAP_HINT);
7329 double start;
7330 DECLARE_MULTI_VALUE_STATS_VARS()
7331
7332 bench_stats_prepare();
7333
7334 WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
7335 sizeof(Arc4), HEAP_HINT);
7336
7337 /* init keys */
7338 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7339 if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
7340 useDeviceID ? devId : INVALID_DEVID)) != 0) {
7341 printf("Arc4Init failed, ret = %d\n", ret);
7342 goto exit;
7343 }
7344
7345 ret = wc_Arc4SetKey(enc[i], bench_key, 16);
7346 if (ret != 0) {
7347 printf("Arc4SetKey failed, ret = %d\n", ret);
7348 goto exit;
7349 }
7350 }
7351
7352 bench_stats_start(&count, &start);
7353 do {
7354 for (times = 0; times < numBlocks || pending > 0; ) {
7355 bench_async_poll(&pending);
7356
7357 /* while free pending slots in queue, submit ops */
7358 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7359 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
7360 ×, numBlocks, &pending)) {
7361 ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
7362 bench_size);
7363 if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
7364 0, ×, &pending)) {
7365 goto exit_arc4;
7366 }
7367 }
7368 } /* for i */
7369 RECORD_MULTI_VALUE_STATS();
7370 } /* for times */
7371 count += times;
7372 } while (bench_stats_check(start)
7373#ifdef MULTI_VALUE_STATISTICS
7374 || runs < minimum_runs
7375#endif
7376 );
7377
7378exit_arc4:
7379 bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
7380#ifdef MULTI_VALUE_STATISTICS
7381 bench_multi_value_stats(max, min, sum, squareSum, runs);
7382#endif
7383
7384exit:
7385
7386 if (WC_ARRAY_OK(enc)) {
7387 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7388 wc_Arc4Free(enc[i]);
7389 }
7390 WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
7391 }
7392}
7393#endif /* !NO_RC4 */
7394
7395
7396#ifdef HAVE_CHACHA
7397void bench_chacha(void)
7398{
7399 WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
7400 double start;
7401 int ret, i, count;
7402 DECLARE_MULTI_VALUE_STATS_VARS()
7403
7404 bench_stats_prepare();
7405
7406 WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
7407
7408 XMEMSET(enc, 0, sizeof(ChaCha));
7409 wc_Chacha_SetKey(enc, bench_key, 16);
7410
7411 if (encrypt_only) {
7412 ret = wc_Chacha_SetIV(enc, bench_iv, 0);
7413 if (ret < 0) {
7414 printf("wc_Chacha_SetIV error: %d\n", ret);
7415 goto exit;
7416 }
7417 bench_stats_start(&count, &start);
7418 do {
7419 for (i = 0; i < numBlocks; i++) {
7420 ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
7421 bench_size);
7422 if (ret < 0) {
7423 printf("wc_Chacha_Process error: %d\n", ret);
7424 goto exit;
7425 }
7426 RECORD_MULTI_VALUE_STATS();
7427 }
7428 count += i;
7429 } while (bench_stats_check(start)
7430 #ifdef MULTI_VALUE_STATISTICS
7431 || runs < minimum_runs
7432 #endif
7433 );
7434 }
7435 else {
7436 bench_stats_start(&count, &start);
7437 do {
7438 for (i = 0; i < numBlocks; i++) {
7439 ret = wc_Chacha_SetIV(enc, bench_iv, 0);
7440 if (ret < 0) {
7441 printf("wc_Chacha_SetIV error: %d\n", ret);
7442 goto exit;
7443 }
7444 ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
7445 bench_size);
7446 if (ret < 0) {
7447 printf("wc_Chacha_Process error: %d\n", ret);
7448 goto exit;
7449 }
7450 RECORD_MULTI_VALUE_STATS();
7451 }
7452 count += i;
7453 } while (bench_stats_check(start)
7454 #ifdef MULTI_VALUE_STATISTICS
7455 || runs < minimum_runs
7456 #endif
7457 );
7458 }
7459
7460 bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
7461#ifdef MULTI_VALUE_STATISTICS
7462 bench_multi_value_stats(max, min, sum, squareSum, runs);
7463#endif
7464
7465exit:
7466 WC_FREE_VAR(enc, HEAP_HINT);
7467}
7468#endif /* HAVE_CHACHA*/
7469
7470#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
7471void bench_chacha20_poly1305_aead(void)
7472{
7473 double start;
7474 int ret = 0, i, count;
7475 DECLARE_MULTI_VALUE_STATS_VARS()
7476
7477 WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
7478 WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
7479
7480 bench_stats_prepare();
7481
7482 WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
7483 WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
7484 XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
7485 XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
7486
7487 bench_stats_start(&count, &start);
7488 do {
7489 for (i = 0; i < numBlocks; i++) {
7490 ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv,
7491 bench_additional, aesAuthAddSz, bench_plain, bench_size,
7492 bench_cipher, authTag);
7493 if (ret < 0) {
7494 printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
7495 goto exit;
7496 }
7497 RECORD_MULTI_VALUE_STATS();
7498 }
7499 count += i;
7500 } while (bench_stats_check(start)
7501#ifdef MULTI_VALUE_STATISTICS
7502 || runs < minimum_runs
7503#endif
7504 );
7505
7506 bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
7507#ifdef MULTI_VALUE_STATISTICS
7508 bench_multi_value_stats(max, min, sum, squareSum, runs);
7509#endif
7510
7511exit:
7512
7513 WC_FREE_VAR(authTag, HEAP_HINT);
7514 WC_FREE_VAR(bench_additional, HEAP_HINT);
7515}
7516#endif /* HAVE_CHACHA && HAVE_POLY1305 */
7517
7518#ifdef HAVE_ASCON
7519
7520void bench_ascon_aead(void)
7521{
7522#define ASCON_AD (byte*)"ADADADADAD"
7523#define ASCON_AD_SZ XSTR_SIZEOF(ASCON_AD)
7524 double start;
7525 int ret = 0, i, count;
7526 WC_DECLARE_VAR(authTag, byte, ASCON_AEAD128_TAG_SZ, HEAP_HINT);
7527 WC_DECLARE_VAR(enc, wc_AsconAEAD128, 1, HEAP_HINT);
7528 DECLARE_MULTI_VALUE_STATS_VARS()
7529
7530 bench_stats_prepare();
7531
7532 WC_ALLOC_VAR(authTag, byte, ASCON_AEAD128_TAG_SZ, HEAP_HINT);
7533 XMEMSET(authTag, 0, ASCON_AEAD128_TAG_SZ);
7534
7535 WC_ALLOC_VAR(enc, wc_AsconAEAD128, 1, HEAP_HINT);
7536 XMEMSET(enc, 0, sizeof(wc_AsconAEAD128));
7537
7538 bench_stats_start(&count, &start);
7539 do {
7540 for (i = 0; i < numBlocks; i++) {
7541 ret = wc_AsconAEAD128_Init(enc);
7542 if (ret == 0)
7543 ret = wc_AsconAEAD128_SetKey(enc, bench_key);
7544 if (ret == 0)
7545 ret = wc_AsconAEAD128_SetNonce(enc, bench_iv);
7546 if (ret == 0)
7547 ret = wc_AsconAEAD128_SetAD(enc, ASCON_AD, ASCON_AD_SZ);
7548 if (ret == 0) {
7549 ret = wc_AsconAEAD128_EncryptUpdate(enc, bench_cipher,
7550 bench_plain, bench_size);
7551 }
7552 if (ret == 0)
7553 ret = wc_AsconAEAD128_EncryptFinal(enc, authTag);
7554 wc_AsconAEAD128_Clear(enc);
7555
7556 if (ret != 0) {
7557 printf("ASCON-AEAD error: %d\n", ret);
7558 goto exit;
7559 }
7560 RECORD_MULTI_VALUE_STATS();
7561 }
7562 count += i;
7563 } while (bench_stats_check(start)
7564#ifdef MULTI_VALUE_STATISTICS
7565 || runs < minimum_runs
7566#endif
7567 );
7568
7569 bench_stats_sym_finish("ASCON-AEAD", 0, count, bench_size, start, ret);
7570#ifdef MULTI_VALUE_STATISTICS
7571 bench_multi_value_stats(max, min, sum, squareSum, runs);
7572#endif
7573
7574exit:
7575
7576 WC_FREE_VAR(authTag, HEAP_HINT);
7577 WC_FREE_VAR(enc, HEAP_HINT);
7578}
7579
7580#endif /* HAVE_ASCON */
7581
7582#ifndef NO_MD5
7583void bench_md5(int useDeviceID)
7584{
7585 WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
7586 sizeof(wc_Md5), HEAP_HINT);
7587 double start = 0;
7588 int ret = 0, i, count = 0, times, pending = 0;
7589 DECLARE_MULTI_VALUE_STATS_VARS()
7590 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
7591 WC_MD5_DIGEST_SIZE, HEAP_HINT);
7592
7593 bench_stats_prepare();
7594
7595 WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
7596 sizeof(wc_Md5), HEAP_HINT);
7597 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
7598 WC_MD5_DIGEST_SIZE, HEAP_HINT);
7599
7600 if (digest_stream) {
7601 /* init keys */
7602 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7603 ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
7604 useDeviceID ? devId : INVALID_DEVID);
7605 if (ret != 0) {
7606 printf("InitMd5_ex failed, ret = %d\n", ret);
7607 goto exit;
7608 }
7609 #ifdef WOLFSSL_PIC32MZ_HASH
7610 wc_Md5SizeSet(hash[i], numBlocks * bench_size);
7611 #endif
7612 }
7613
7614 bench_stats_start(&count, &start);
7615 do {
7616 for (times = 0; times < numBlocks || pending > 0; ) {
7617 bench_async_poll(&pending);
7618
7619 /* while free pending slots in queue, submit ops */
7620 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7621 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
7622 0, ×, numBlocks, &pending)) {
7623 ret = wc_Md5Update(hash[i], bench_plain,
7624 bench_size);
7625 if (!bench_async_handle(&ret,
7626 BENCH_ASYNC_GET_DEV(hash[i]),
7627 0, ×, &pending)) {
7628 goto exit_md5;
7629 }
7630 }
7631 } /* for i */
7632 RECORD_MULTI_VALUE_STATS();
7633 } /* for times */
7634 count += times;
7635
7636 times = 0;
7637 do {
7638 bench_async_poll(&pending);
7639
7640 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7641 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
7642 0, ×, numBlocks, &pending)) {
7643 ret = wc_Md5Final(hash[i], digest[i]);
7644 if (!bench_async_handle(&ret,
7645 BENCH_ASYNC_GET_DEV(hash[i]), 0,
7646 ×, &pending)) {
7647 goto exit_md5;
7648 }
7649 }
7650 } /* for i */
7651 } while (pending > 0);
7652 } while (bench_stats_check(start)
7653 #ifdef MULTI_VALUE_STATISTICS
7654 || runs < minimum_runs
7655 #endif
7656 );
7657 }
7658 else {
7659 bench_stats_start(&count, &start);
7660 do {
7661 for (times = 0; times < numBlocks; times++) {
7662 ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
7663 if (ret == 0)
7664 ret = wc_Md5Update(hash[0], bench_plain, bench_size);
7665 if (ret == 0)
7666 ret = wc_Md5Final(hash[0], digest[0]);
7667 if (ret != 0)
7668 goto exit_md5;
7669 RECORD_MULTI_VALUE_STATS();
7670 } /* for times */
7671 count += times;
7672 } while (bench_stats_check(start)
7673 #ifdef MULTI_VALUE_STATISTICS
7674 || runs < minimum_runs
7675 #endif
7676 );
7677 }
7678exit_md5:
7679 bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
7680#ifdef MULTI_VALUE_STATISTICS
7681 bench_multi_value_stats(max, min, sum, squareSum, runs);
7682#endif
7683
7684exit:
7685
7686#ifdef WOLFSSL_ASYNC_CRYPT
7687 if (WC_ARRAY_OK(hash)) {
7688 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7689 wc_Md5Free(hash[i]);
7690 }
7691 }
7692#endif
7693
7694 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
7695 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
7696}
7697#endif /* !NO_MD5 */
7698
7699
7700#ifndef NO_SHA
7701void bench_sha(int useDeviceID)
7702{
7703 WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
7704 sizeof(wc_Sha), HEAP_HINT);
7705 double start;
7706 int ret = 0, i, count = 0, times, pending = 0;
7707 DECLARE_MULTI_VALUE_STATS_VARS()
7708 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
7709 WC_SHA_DIGEST_SIZE, HEAP_HINT);
7710
7711 bench_stats_prepare();
7712
7713 WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
7714 sizeof(wc_Sha), HEAP_HINT);
7715 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
7716 WC_SHA_DIGEST_SIZE, HEAP_HINT);
7717
7718 if (digest_stream) {
7719 /* init keys */
7720 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7721 ret = wc_InitSha_ex(hash[i], HEAP_HINT,
7722 useDeviceID ? devId : INVALID_DEVID);
7723 if (ret != 0) {
7724 printf("InitSha failed, ret = %d\n", ret);
7725 goto exit;
7726 }
7727 #ifdef WOLFSSL_PIC32MZ_HASH
7728 wc_ShaSizeSet(hash[i], numBlocks * bench_size);
7729 #endif
7730 }
7731
7732 bench_stats_start(&count, &start);
7733 do {
7734 for (times = 0; times < numBlocks || pending > 0; ) {
7735 bench_async_poll(&pending);
7736
7737 /* while free pending slots in queue, submit ops */
7738 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7739 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
7740 0, ×, numBlocks, &pending)) {
7741 ret = wc_ShaUpdate(hash[i], bench_plain,
7742 bench_size);
7743 if (!bench_async_handle(&ret,
7744 BENCH_ASYNC_GET_DEV(hash[i]), 0,
7745 ×, &pending)) {
7746 goto exit_sha;
7747 }
7748 }
7749 } /* for i */
7750 RECORD_MULTI_VALUE_STATS();
7751 } /* for times */
7752 count += times;
7753
7754 times = 0;
7755 do {
7756 bench_async_poll(&pending);
7757
7758 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7759 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
7760 0, ×, numBlocks, &pending)) {
7761 ret = wc_ShaFinal(hash[i], digest[i]);
7762 if (!bench_async_handle(&ret,
7763 BENCH_ASYNC_GET_DEV(hash[i]), 0,
7764 ×, &pending)) {
7765 goto exit_sha;
7766 }
7767 }
7768 } /* for i */
7769 } while (pending > 0);
7770 } while (bench_stats_check(start)
7771 #ifdef MULTI_VALUE_STATISTICS
7772 || runs < minimum_runs
7773 #endif
7774 );
7775 }
7776 else {
7777 bench_stats_start(&count, &start);
7778 do {
7779 for (times = 0; times < numBlocks; times++) {
7780 ret = wc_InitSha_ex(hash[0], HEAP_HINT,
7781 useDeviceID ? devId : INVALID_DEVID);
7782 if (ret == 0)
7783 ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
7784 if (ret == 0)
7785 ret = wc_ShaFinal(hash[0], digest[0]);
7786 if (ret != 0)
7787 goto exit_sha;
7788 RECORD_MULTI_VALUE_STATS();
7789 } /* for times */
7790 count += times;
7791 } while (bench_stats_check(start)
7792 #ifdef MULTI_VALUE_STATISTICS
7793 || runs < minimum_runs
7794 #endif
7795 );
7796 }
7797exit_sha:
7798 bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
7799#ifdef MULTI_VALUE_STATISTICS
7800 bench_multi_value_stats(max, min, sum, squareSum, runs);
7801#endif
7802
7803exit:
7804
7805 if (WC_ARRAY_OK(hash)) {
7806 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7807 wc_ShaFree(hash[i]);
7808 }
7809 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
7810 }
7811 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
7812}
7813#endif /* NO_SHA */
7814
7815
7816#ifdef WOLFSSL_SHA224
7817void bench_sha224(int useDeviceID)
7818{
7819 WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
7820 sizeof(wc_Sha224), HEAP_HINT);
7821 double start;
7822 int ret = 0, i, count = 0, times, pending = 0;
7823 DECLARE_MULTI_VALUE_STATS_VARS()
7824 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
7825 WC_SHA224_DIGEST_SIZE, HEAP_HINT);
7826
7827 bench_stats_prepare();
7828
7829 WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
7830 sizeof(wc_Sha224), HEAP_HINT);
7831 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
7832 WC_SHA224_DIGEST_SIZE, HEAP_HINT);
7833
7834 if (digest_stream) {
7835 /* init keys */
7836 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7837 ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
7838 useDeviceID ? devId : INVALID_DEVID);
7839 if (ret != 0) {
7840 printf("InitSha224_ex failed, ret = %d\n", ret);
7841 goto exit;
7842 }
7843 }
7844
7845 bench_stats_start(&count, &start);
7846 do {
7847 for (times = 0; times < numBlocks || pending > 0; ) {
7848 bench_async_poll(&pending);
7849
7850 /* while free pending slots in queue, submit ops */
7851 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7852 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
7853 0, ×, numBlocks, &pending)) {
7854 ret = wc_Sha224Update(hash[i], bench_plain,
7855 bench_size);
7856 if (!bench_async_handle(&ret,
7857 BENCH_ASYNC_GET_DEV(hash[i]), 0,
7858 ×, &pending)) {
7859 goto exit_sha224;
7860 }
7861 }
7862 } /* for i */
7863 RECORD_MULTI_VALUE_STATS();
7864 } /* for times */
7865 count += times;
7866
7867 times = 0;
7868 do {
7869 bench_async_poll(&pending);
7870 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7871 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
7872 0, ×, numBlocks, &pending)) {
7873 ret = wc_Sha224Final(hash[i], digest[i]);
7874 if (!bench_async_handle(&ret,
7875 BENCH_ASYNC_GET_DEV(hash[i]), 0,
7876 ×, &pending)) {
7877 goto exit_sha224;
7878 }
7879 }
7880 } /* for i */
7881 } while (pending > 0);
7882 } while (bench_stats_check(start)
7883 #ifdef MULTI_VALUE_STATISTICS
7884 || runs < minimum_runs
7885 #endif
7886 );
7887 }
7888 else {
7889 bench_stats_start(&count, &start);
7890 do {
7891 for (times = 0; times < numBlocks; times++) {
7892 ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
7893 useDeviceID ? devId : INVALID_DEVID);
7894 if (ret == 0)
7895 ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
7896 if (ret == 0)
7897 ret = wc_Sha224Final(hash[0], digest[0]);
7898 if (ret != 0)
7899 goto exit_sha224;
7900 } /* for times */
7901 count += times;
7902 } while (bench_stats_check(start)
7903 #ifdef MULTI_VALUE_STATISTICS
7904 || runs < minimum_runs
7905 #endif
7906 );
7907 }
7908exit_sha224:
7909 bench_stats_sym_finish("SHA-224", useDeviceID, count,
7910 bench_size, start, ret);
7911#ifdef MULTI_VALUE_STATISTICS
7912 bench_multi_value_stats(max, min, sum, squareSum, runs);
7913#endif
7914
7915exit:
7916
7917 if (WC_ARRAY_OK(hash)) {
7918 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7919 wc_Sha224Free(hash[i]);
7920 }
7921 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
7922 }
7923 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
7924}
7925#endif
7926
7927
7928#ifndef NO_SHA256
7929void bench_sha256(int useDeviceID)
7930{
7931 WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
7932 sizeof(wc_Sha256), HEAP_HINT);
7933 double start;
7934 int ret = 0, i, count = 0, times, pending = 0;
7935 DECLARE_MULTI_VALUE_STATS_VARS()
7936 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
7937 WC_SHA256_DIGEST_SIZE, HEAP_HINT);
7938
7939 bench_stats_prepare();
7940
7941 WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
7942 sizeof(wc_Sha256), HEAP_HINT);
7943 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
7944 WC_SHA256_DIGEST_SIZE, HEAP_HINT);
7945
7946 if (digest_stream) {
7947 /* init keys */
7948 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7949 ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
7950 useDeviceID ? devId: INVALID_DEVID);
7951 if (ret != 0) {
7952 printf("InitSha256_ex failed, ret = %d\n", ret);
7953 goto exit;
7954 }
7955 #ifdef WOLFSSL_PIC32MZ_HASH
7956 wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
7957 #endif
7958 }
7959
7960 bench_stats_start(&count, &start);
7961 do {
7962 for (times = 0; times < numBlocks || pending > 0; ) {
7963 bench_async_poll(&pending);
7964
7965 /* while free pending slots in queue, submit ops */
7966 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7967 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
7968 0, ×, numBlocks, &pending)) {
7969 ret = wc_Sha256Update(hash[i], bench_plain,
7970 bench_size);
7971 if (!bench_async_handle(&ret,
7972 BENCH_ASYNC_GET_DEV(hash[i]), 0,
7973 ×, &pending)) {
7974 goto exit_sha256;
7975 }
7976 }
7977 } /* for i */
7978 RECORD_MULTI_VALUE_STATS();
7979 } /* for times */
7980 count += times;
7981
7982 times = 0;
7983 do {
7984 bench_async_poll(&pending);
7985 for (i = 0; i < BENCH_MAX_PENDING; i++) {
7986 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
7987 0, ×, numBlocks, &pending)) {
7988 ret = wc_Sha256Final(hash[i], digest[i]);
7989 if (!bench_async_handle(&ret,
7990 BENCH_ASYNC_GET_DEV(hash[i]), 0,
7991 ×, &pending)) {
7992 goto exit_sha256;
7993 }
7994 }
7995 } /* for i */
7996 } while (pending > 0);
7997 } while (bench_stats_check(start)
7998 #ifdef MULTI_VALUE_STATISTICS
7999 || runs < minimum_runs
8000 #endif
8001 );
8002 }
8003 else {
8004 bench_stats_start(&count, &start);
8005 do {
8006 for (times = 0; times < numBlocks; times++) {
8007 ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
8008 useDeviceID ? devId: INVALID_DEVID);
8009 if (ret == 0)
8010 ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
8011 if (ret == 0)
8012 ret = wc_Sha256Final(hash[0], digest[0]);
8013 if (ret != 0)
8014 goto exit_sha256;
8015 RECORD_MULTI_VALUE_STATS();
8016 } /* for times */
8017 count += times;
8018 } while (bench_stats_check(start)
8019 #ifdef MULTI_VALUE_STATISTICS
8020 || runs < minimum_runs
8021 #endif
8022 );
8023 }
8024exit_sha256:
8025 bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
8026 start, ret);
8027#ifdef MULTI_VALUE_STATISTICS
8028 bench_multi_value_stats(max, min, sum, squareSum, runs);
8029#endif
8030exit:
8031 if (WC_ARRAY_OK(hash)) {
8032 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8033 wc_Sha256Free(hash[i]);
8034 }
8035 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
8036 }
8037 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
8038}
8039#endif
8040
8041#ifdef WOLFSSL_SHA384
8042void bench_sha384(int useDeviceID)
8043{
8044 WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
8045 sizeof(wc_Sha384), HEAP_HINT);
8046 double start;
8047 int ret = 0, i, count = 0, times, pending = 0;
8048 DECLARE_MULTI_VALUE_STATS_VARS()
8049 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
8050 WC_SHA384_DIGEST_SIZE, HEAP_HINT);
8051
8052 bench_stats_prepare();
8053
8054 WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
8055 sizeof(wc_Sha384), HEAP_HINT);
8056 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
8057 WC_SHA384_DIGEST_SIZE, HEAP_HINT);
8058
8059 if (digest_stream) {
8060 /* init keys */
8061 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8062 ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
8063 useDeviceID ? devId : INVALID_DEVID);
8064 if (ret != 0) {
8065 printf("InitSha384_ex failed, ret = %d\n", ret);
8066 goto exit;
8067 }
8068 }
8069
8070 bench_stats_start(&count, &start);
8071 do {
8072 for (times = 0; times < numBlocks || pending > 0; ) {
8073 bench_async_poll(&pending);
8074
8075 /* while free pending slots in queue, submit ops */
8076 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8077 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8078 0, ×, numBlocks, &pending)) {
8079 ret = wc_Sha384Update(hash[i], bench_plain,
8080 bench_size);
8081 if (!bench_async_handle(&ret,
8082 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8083 ×, &pending)) {
8084 goto exit_sha384;
8085 }
8086 }
8087 } /* for i */
8088 RECORD_MULTI_VALUE_STATS();
8089 } /* for times */
8090 count += times;
8091
8092 times = 0;
8093 do {
8094 bench_async_poll(&pending);
8095 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8096 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8097 0, ×, numBlocks, &pending)) {
8098 ret = wc_Sha384Final(hash[i], digest[i]);
8099 if (!bench_async_handle(&ret,
8100 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8101 ×, &pending)) {
8102 goto exit_sha384;
8103 }
8104 }
8105 } /* for i */
8106 } while (pending > 0);
8107 } while (bench_stats_check(start)
8108 #ifdef MULTI_VALUE_STATISTICS
8109 || runs < minimum_runs
8110 #endif
8111 );
8112 }
8113 else {
8114 bench_stats_start(&count, &start);
8115 do {
8116 for (times = 0; times < numBlocks; times++) {
8117 ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
8118 useDeviceID ? devId : INVALID_DEVID);
8119 if (ret == 0)
8120 ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
8121 if (ret == 0)
8122 ret = wc_Sha384Final(hash[0], digest[0]);
8123 if (ret != 0)
8124 goto exit_sha384;
8125 RECORD_MULTI_VALUE_STATS();
8126 } /* for times */
8127 count += times;
8128 } while (bench_stats_check(start)
8129 #ifdef MULTI_VALUE_STATISTICS
8130 || runs < minimum_runs
8131 #endif
8132 );
8133 }
8134exit_sha384:
8135 bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
8136 start, ret);
8137#ifdef MULTI_VALUE_STATISTICS
8138 bench_multi_value_stats(max, min, sum, squareSum, runs);
8139#endif
8140
8141exit:
8142
8143 if (WC_ARRAY_OK(hash)) {
8144 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8145 wc_Sha384Free(hash[i]);
8146 }
8147 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
8148 }
8149 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
8150}
8151#endif
8152
8153#ifdef WOLFSSL_SHA512
8154void bench_sha512(int useDeviceID)
8155{
8156 WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
8157 sizeof(wc_Sha512), HEAP_HINT);
8158 double start;
8159 int ret = 0, i, count = 0, times, pending = 0;
8160 DECLARE_MULTI_VALUE_STATS_VARS()
8161 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
8162 WC_SHA512_DIGEST_SIZE, HEAP_HINT);
8163
8164 bench_stats_prepare();
8165
8166 WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
8167 sizeof(wc_Sha512), HEAP_HINT);
8168 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
8169 WC_SHA512_DIGEST_SIZE, HEAP_HINT);
8170
8171 if (digest_stream) {
8172 /* init keys */
8173 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8174 ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
8175 useDeviceID ? devId : INVALID_DEVID);
8176 if (ret != 0) {
8177 printf("InitSha512_ex failed, ret = %d\n", ret);
8178 goto exit;
8179 }
8180 }
8181
8182 bench_stats_start(&count, &start);
8183 do {
8184 for (times = 0; times < numBlocks || pending > 0; ) {
8185 bench_async_poll(&pending);
8186
8187 /* while free pending slots in queue, submit ops */
8188 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8189 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8190 0, ×, numBlocks, &pending)) {
8191 ret = wc_Sha512Update(hash[i], bench_plain,
8192 bench_size);
8193 if (!bench_async_handle(&ret,
8194 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8195 ×, &pending)) {
8196 goto exit_sha512;
8197 }
8198 }
8199 } /* for i */
8200 RECORD_MULTI_VALUE_STATS();
8201 } /* for times */
8202 count += times;
8203
8204 times = 0;
8205 do {
8206 bench_async_poll(&pending);
8207 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8208 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8209 0, ×, numBlocks, &pending)) {
8210 ret = wc_Sha512Final(hash[i], digest[i]);
8211 if (!bench_async_handle(&ret,
8212 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8213 ×, &pending)) {
8214 goto exit_sha512;
8215 }
8216 }
8217 } /* for i */
8218 } while (pending > 0);
8219 } while (bench_stats_check(start)
8220 #ifdef MULTI_VALUE_STATISTICS
8221 || runs < minimum_runs
8222 #endif
8223 );
8224 }
8225 else {
8226 bench_stats_start(&count, &start);
8227 do {
8228 for (times = 0; times < numBlocks; times++) {
8229 ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
8230 useDeviceID ? devId : INVALID_DEVID);
8231 if (ret == 0)
8232 ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
8233 if (ret == 0)
8234 ret = wc_Sha512Final(hash[0], digest[0]);
8235 if (ret != 0)
8236 goto exit_sha512;
8237 RECORD_MULTI_VALUE_STATS();
8238 } /* for times */
8239 count += times;
8240 } while (bench_stats_check(start)
8241 #ifdef MULTI_VALUE_STATISTICS
8242 || runs < minimum_runs
8243 #endif
8244 );
8245 }
8246exit_sha512:
8247 bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
8248 start, ret);
8249#ifdef MULTI_VALUE_STATISTICS
8250 bench_multi_value_stats(max, min, sum, squareSum, runs);
8251#endif
8252
8253exit:
8254
8255 if (WC_ARRAY_OK(hash)) {
8256 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8257 wc_Sha512Free(hash[i]);
8258 }
8259 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
8260 }
8261 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
8262}
8263
8264#if !defined(WOLFSSL_NOSHA512_224) && \
8265 (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
8266void bench_sha512_224(int useDeviceID)
8267{
8268 WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
8269 sizeof(wc_Sha512_224), HEAP_HINT);
8270 double start;
8271 int ret = 0, i, count = 0, times, pending = 0;
8272 DECLARE_MULTI_VALUE_STATS_VARS()
8273 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
8274 WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
8275
8276 bench_stats_prepare();
8277
8278 WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
8279 sizeof(wc_Sha512_224), HEAP_HINT);
8280 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
8281 WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
8282
8283 if (digest_stream) {
8284 /* init keys */
8285 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8286 ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
8287 useDeviceID ? devId : INVALID_DEVID);
8288 if (ret != 0) {
8289 printf("InitSha512_224_ex failed, ret = %d\n", ret);
8290 goto exit;
8291 }
8292 }
8293
8294 bench_stats_start(&count, &start);
8295 do {
8296 for (times = 0; times < numBlocks || pending > 0; ) {
8297 bench_async_poll(&pending);
8298
8299 /* while free pending slots in queue, submit ops */
8300 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8301 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8302 0, ×, numBlocks, &pending)) {
8303 ret = wc_Sha512_224Update(hash[i], bench_plain,
8304 bench_size);
8305 if (!bench_async_handle(&ret,
8306 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8307 ×, &pending)) {
8308 goto exit_sha512_224;
8309 }
8310 }
8311 } /* for i */
8312 RECORD_MULTI_VALUE_STATS();
8313 } /* for times */
8314 count += times;
8315
8316 times = 0;
8317 do {
8318 bench_async_poll(&pending);
8319 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8320 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8321 0, ×, numBlocks, &pending)) {
8322 ret = wc_Sha512_224Final(hash[i], digest[i]);
8323 if (!bench_async_handle(&ret,
8324 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8325 ×, &pending)) {
8326 goto exit_sha512_224;
8327 }
8328 }
8329 } /* for i */
8330 } while (pending > 0);
8331 } while (bench_stats_check(start)
8332 #ifdef MULTI_VALUE_STATISTICS
8333 || runs < minimum_runs
8334 #endif
8335 );
8336 }
8337 else {
8338 bench_stats_start(&count, &start);
8339 do {
8340 for (times = 0; times < numBlocks; times++) {
8341 ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
8342 useDeviceID ? devId : INVALID_DEVID);
8343 if (ret == 0)
8344 ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
8345 if (ret == 0)
8346 ret = wc_Sha512_224Final(hash[0], digest[0]);
8347 if (ret != 0)
8348 goto exit_sha512_224;
8349 RECORD_MULTI_VALUE_STATS();
8350 } /* for times */
8351 count += times;
8352 } while (bench_stats_check(start)
8353 #ifdef MULTI_VALUE_STATISTICS
8354 || runs < minimum_runs
8355 #endif
8356 );
8357 }
8358exit_sha512_224:
8359 bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
8360 start, ret);
8361#ifdef MULTI_VALUE_STATISTICS
8362 bench_multi_value_stats(max, min, sum, squareSum, runs);
8363#endif
8364
8365exit:
8366
8367 if (WC_ARRAY_OK(hash)) {
8368 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8369 wc_Sha512_224Free(hash[i]);
8370 }
8371 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
8372 }
8373 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
8374}
8375#endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
8376
8377#if !defined(WOLFSSL_NOSHA512_256) && \
8378 (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
8379void bench_sha512_256(int useDeviceID)
8380{
8381 WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
8382 sizeof(wc_Sha512_256), HEAP_HINT);
8383 double start;
8384 int ret = 0, i, count = 0, times, pending = 0;
8385 DECLARE_MULTI_VALUE_STATS_VARS()
8386 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
8387 WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
8388
8389 bench_stats_prepare();
8390
8391 WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
8392 sizeof(wc_Sha512_256), HEAP_HINT);
8393 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
8394 WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
8395
8396 if (digest_stream) {
8397 /* init keys */
8398 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8399 ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
8400 useDeviceID ? devId : INVALID_DEVID);
8401 if (ret != 0) {
8402 printf("InitSha512_256_ex failed, ret = %d\n", ret);
8403 goto exit;
8404 }
8405 }
8406
8407 bench_stats_start(&count, &start);
8408 do {
8409 for (times = 0; times < numBlocks || pending > 0; ) {
8410 bench_async_poll(&pending);
8411
8412 /* while free pending slots in queue, submit ops */
8413 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8414 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8415 0, ×, numBlocks, &pending)) {
8416 ret = wc_Sha512_256Update(hash[i], bench_plain,
8417 bench_size);
8418 if (!bench_async_handle(&ret,
8419 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8420 ×, &pending)) {
8421 goto exit_sha512_256;
8422 }
8423 }
8424 } /* for i */
8425 RECORD_MULTI_VALUE_STATS();
8426 } /* for times */
8427 count += times;
8428
8429 times = 0;
8430 do {
8431 bench_async_poll(&pending);
8432 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8433 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8434 0, ×, numBlocks, &pending)) {
8435 ret = wc_Sha512_256Final(hash[i], digest[i]);
8436 if (!bench_async_handle(&ret,
8437 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8438 ×, &pending)) {
8439 goto exit_sha512_256;
8440 }
8441 }
8442 } /* for i */
8443 } while (pending > 0);
8444 } while (bench_stats_check(start)
8445 #ifdef MULTI_VALUE_STATISTICS
8446 || runs < minimum_runs
8447 #endif
8448 );
8449 }
8450 else {
8451 bench_stats_start(&count, &start);
8452 do {
8453 for (times = 0; times < numBlocks; times++) {
8454 ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
8455 useDeviceID ? devId : INVALID_DEVID);
8456 if (ret == 0)
8457 ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
8458 if (ret == 0)
8459 ret = wc_Sha512_256Final(hash[0], digest[0]);
8460 if (ret != 0)
8461 goto exit_sha512_256;
8462 RECORD_MULTI_VALUE_STATS();
8463 } /* for times */
8464 count += times;
8465 } while (bench_stats_check(start)
8466 #ifdef MULTI_VALUE_STATISTICS
8467 || runs < minimum_runs
8468 #endif
8469 );
8470 }
8471exit_sha512_256:
8472 bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
8473 start, ret);
8474#ifdef MULTI_VALUE_STATISTICS
8475 bench_multi_value_stats(max, min, sum, squareSum, runs);
8476#endif
8477
8478exit:
8479
8480 if (WC_ARRAY_OK(hash)) {
8481 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8482 wc_Sha512_256Free(hash[i]);
8483 }
8484 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
8485 }
8486 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
8487}
8488#endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
8489
8490#endif /* WOLFSSL_SHA512 */
8491
8492
8493#ifdef WOLFSSL_SHA3
8494#ifndef WOLFSSL_NOSHA3_224
8495void bench_sha3_224(int useDeviceID)
8496{
8497 WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
8498 sizeof(wc_Sha3), HEAP_HINT);
8499 double start;
8500 int ret = 0, i, count = 0, times, pending = 0;
8501 DECLARE_MULTI_VALUE_STATS_VARS()
8502 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
8503 WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
8504
8505 bench_stats_prepare();
8506
8507 WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
8508 sizeof(wc_Sha3), HEAP_HINT);
8509 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
8510 WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
8511
8512 if (digest_stream) {
8513 /* init keys */
8514 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8515 ret = wc_InitSha3_224(hash[i], HEAP_HINT,
8516 useDeviceID ? devId : INVALID_DEVID);
8517 if (ret != 0) {
8518 printf("InitSha3_224 failed, ret = %d\n", ret);
8519 goto exit;
8520 }
8521 }
8522
8523 bench_stats_start(&count, &start);
8524 do {
8525 for (times = 0; times < numBlocks || pending > 0; ) {
8526 bench_async_poll(&pending);
8527
8528 /* while free pending slots in queue, submit ops */
8529 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8530 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8531 0, ×, numBlocks, &pending)) {
8532 ret = wc_Sha3_224_Update(hash[i], bench_plain,
8533 bench_size);
8534 if (!bench_async_handle(&ret,
8535 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8536 ×, &pending)) {
8537 goto exit_sha3_224;
8538 }
8539 }
8540 } /* for i */
8541 RECORD_MULTI_VALUE_STATS();
8542 } /* for times */
8543 count += times;
8544
8545 times = 0;
8546 do {
8547 bench_async_poll(&pending);
8548 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8549 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8550 0, ×, numBlocks, &pending)) {
8551 ret = wc_Sha3_224_Final(hash[i], digest[i]);
8552 if (!bench_async_handle(&ret,
8553 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8554 ×, &pending)) {
8555 goto exit_sha3_224;
8556 }
8557 }
8558 } /* for i */
8559 } while (pending > 0);
8560 } while (bench_stats_check(start)
8561 #ifdef MULTI_VALUE_STATISTICS
8562 || runs < minimum_runs
8563 #endif
8564 );
8565 }
8566 else {
8567 bench_stats_start(&count, &start);
8568 do {
8569 for (times = 0; times < numBlocks; times++) {
8570 ret = wc_InitSha3_224(hash[0], HEAP_HINT,
8571 useDeviceID ? devId : INVALID_DEVID);
8572 if (ret == 0)
8573 ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
8574 if (ret == 0)
8575 ret = wc_Sha3_224_Final(hash[0], digest[0]);
8576 if (ret != 0)
8577 goto exit_sha3_224;
8578 RECORD_MULTI_VALUE_STATS();
8579 } /* for times */
8580 count += times;
8581 } while (bench_stats_check(start)
8582 #ifdef MULTI_VALUE_STATISTICS
8583 || runs < minimum_runs
8584 #endif
8585 );
8586 }
8587exit_sha3_224:
8588 bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
8589 start, ret);
8590#ifdef MULTI_VALUE_STATISTICS
8591 bench_multi_value_stats(max, min, sum, squareSum, runs);
8592#endif
8593
8594exit:
8595
8596 if (WC_ARRAY_OK(hash)) {
8597 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8598 wc_Sha3_224_Free(hash[i]);
8599 }
8600 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
8601 }
8602 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
8603}
8604#endif /* WOLFSSL_NOSHA3_224 */
8605
8606#ifndef WOLFSSL_NOSHA3_256
8607void bench_sha3_256(int useDeviceID)
8608{
8609 WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
8610 sizeof(wc_Sha3), HEAP_HINT);
8611 double start;
8612 DECLARE_MULTI_VALUE_STATS_VARS()
8613 int ret = 0, i, count = 0, times, pending = 0;
8614 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
8615 WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
8616
8617 bench_stats_prepare();
8618
8619 WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
8620 sizeof(wc_Sha3), HEAP_HINT);
8621 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
8622 WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
8623
8624 if (digest_stream) {
8625 /* init keys */
8626 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8627 ret = wc_InitSha3_256(hash[i], HEAP_HINT,
8628 useDeviceID ? devId : INVALID_DEVID);
8629 if (ret != 0) {
8630 printf("InitSha3_256 failed, ret = %d\n", ret);
8631 goto exit;
8632 }
8633 }
8634
8635 bench_stats_start(&count, &start);
8636 do {
8637 for (times = 0; times < numBlocks || pending > 0; ) {
8638 bench_async_poll(&pending);
8639
8640 /* while free pending slots in queue, submit ops */
8641 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8642 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8643 0, ×, numBlocks, &pending)) {
8644 ret = wc_Sha3_256_Update(hash[i], bench_plain,
8645 bench_size);
8646 if (!bench_async_handle(&ret,
8647 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8648 ×, &pending)) {
8649 goto exit_sha3_256;
8650 }
8651 }
8652 } /* for i */
8653 RECORD_MULTI_VALUE_STATS();
8654 } /* for times */
8655 count += times;
8656
8657 times = 0;
8658 do {
8659 bench_async_poll(&pending);
8660 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8661 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8662 0, ×, numBlocks, &pending)) {
8663 ret = wc_Sha3_256_Final(hash[i], digest[i]);
8664 if (!bench_async_handle(&ret,
8665 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8666 ×, &pending)) {
8667 goto exit_sha3_256;
8668 }
8669 }
8670 } /* for i */
8671 } while (pending > 0);
8672 } while (bench_stats_check(start)
8673 #ifdef MULTI_VALUE_STATISTICS
8674 || runs < minimum_runs
8675 #endif
8676 );
8677 }
8678 else {
8679 bench_stats_start(&count, &start);
8680 do {
8681 for (times = 0; times < numBlocks; times++) {
8682 ret = wc_InitSha3_256(hash[0], HEAP_HINT,
8683 useDeviceID ? devId : INVALID_DEVID);
8684 if (ret == 0)
8685 ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
8686 if (ret == 0)
8687 ret = wc_Sha3_256_Final(hash[0], digest[0]);
8688 if (ret != 0)
8689 goto exit_sha3_256;
8690 RECORD_MULTI_VALUE_STATS();
8691 } /* for times */
8692 count += times;
8693 } while (bench_stats_check(start)
8694 #ifdef MULTI_VALUE_STATISTICS
8695 || runs < minimum_runs
8696 #endif
8697 );
8698 }
8699exit_sha3_256:
8700 bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
8701 start, ret);
8702#ifdef MULTI_VALUE_STATISTICS
8703 bench_multi_value_stats(max, min, sum, squareSum, runs);
8704#endif
8705
8706exit:
8707
8708 if (WC_ARRAY_OK(hash)) {
8709 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8710 wc_Sha3_256_Free(hash[i]);
8711 }
8712 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
8713 }
8714 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
8715}
8716#endif /* WOLFSSL_NOSHA3_256 */
8717
8718#ifndef WOLFSSL_NOSHA3_384
8719void bench_sha3_384(int useDeviceID)
8720{
8721 WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
8722 sizeof(wc_Sha3), HEAP_HINT);
8723 double start;
8724 int ret = 0, i, count = 0, times, pending = 0;
8725 DECLARE_MULTI_VALUE_STATS_VARS()
8726 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
8727 WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
8728
8729 bench_stats_prepare();
8730
8731 WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
8732 sizeof(wc_Sha3), HEAP_HINT);
8733 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
8734 WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
8735
8736 if (digest_stream) {
8737 /* init keys */
8738 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8739 ret = wc_InitSha3_384(hash[i], HEAP_HINT,
8740 useDeviceID ? devId : INVALID_DEVID);
8741 if (ret != 0) {
8742 printf("InitSha3_384 failed, ret = %d\n", ret);
8743 goto exit;
8744 }
8745 }
8746
8747 bench_stats_start(&count, &start);
8748 do {
8749 for (times = 0; times < numBlocks || pending > 0; ) {
8750 bench_async_poll(&pending);
8751
8752 /* while free pending slots in queue, submit ops */
8753 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8754 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8755 0, ×, numBlocks, &pending)) {
8756 ret = wc_Sha3_384_Update(hash[i], bench_plain,
8757 bench_size);
8758 if (!bench_async_handle(&ret,
8759 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8760 ×, &pending)) {
8761 goto exit_sha3_384;
8762 }
8763 }
8764 } /* for i */
8765 RECORD_MULTI_VALUE_STATS();
8766 } /* for times */
8767 count += times;
8768
8769 times = 0;
8770 do {
8771 bench_async_poll(&pending);
8772 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8773 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8774 0, ×, numBlocks, &pending)) {
8775 ret = wc_Sha3_384_Final(hash[i], digest[i]);
8776 if (!bench_async_handle(&ret,
8777 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8778 ×, &pending)) {
8779 goto exit_sha3_384;
8780 }
8781 }
8782 } /* for i */
8783 } while (pending > 0);
8784 } while (bench_stats_check(start)
8785 #ifdef MULTI_VALUE_STATISTICS
8786 || runs < minimum_runs
8787 #endif
8788 );
8789 }
8790 else {
8791 bench_stats_start(&count, &start);
8792 do {
8793 for (times = 0; times < numBlocks; times++) {
8794 ret = wc_InitSha3_384(hash[0], HEAP_HINT,
8795 useDeviceID ? devId : INVALID_DEVID);
8796 if (ret == 0)
8797 ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
8798 if (ret == 0)
8799 ret = wc_Sha3_384_Final(hash[0], digest[0]);
8800 if (ret != 0)
8801 goto exit_sha3_384;
8802 RECORD_MULTI_VALUE_STATS();
8803 } /* for times */
8804 count += times;
8805 } while (bench_stats_check(start)
8806 #ifdef MULTI_VALUE_STATISTICS
8807 || runs < minimum_runs
8808 #endif
8809 );
8810 }
8811exit_sha3_384:
8812 bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
8813 start, ret);
8814#ifdef MULTI_VALUE_STATISTICS
8815 bench_multi_value_stats(max, min, sum, squareSum, runs);
8816#endif
8817
8818exit:
8819
8820 if (WC_ARRAY_OK(hash)) {
8821 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8822 wc_Sha3_384_Free(hash[i]);
8823 }
8824 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
8825 }
8826 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
8827}
8828#endif /* WOLFSSL_NOSHA3_384 */
8829
8830#ifndef WOLFSSL_NOSHA3_512
8831void bench_sha3_512(int useDeviceID)
8832{
8833 WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
8834 sizeof(wc_Sha3), HEAP_HINT);
8835 double start;
8836 int ret = 0, i, count = 0, times, pending = 0;
8837 DECLARE_MULTI_VALUE_STATS_VARS()
8838 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
8839 WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
8840
8841 bench_stats_prepare();
8842
8843 WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
8844 sizeof(wc_Sha3), HEAP_HINT);
8845 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
8846 WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
8847
8848 if (digest_stream) {
8849 /* init keys */
8850 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8851 ret = wc_InitSha3_512(hash[i], HEAP_HINT,
8852 useDeviceID ? devId : INVALID_DEVID);
8853 if (ret != 0) {
8854 printf("InitSha3_512 failed, ret = %d\n", ret);
8855 goto exit;
8856 }
8857 }
8858
8859 bench_stats_start(&count, &start);
8860 do {
8861 for (times = 0; times < numBlocks || pending > 0; ) {
8862 bench_async_poll(&pending);
8863
8864 /* while free pending slots in queue, submit ops */
8865 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8866 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8867 0, ×, numBlocks, &pending)) {
8868 ret = wc_Sha3_512_Update(hash[i], bench_plain,
8869 bench_size);
8870 if (!bench_async_handle(&ret,
8871 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8872 ×, &pending)) {
8873 goto exit_sha3_512;
8874 }
8875 }
8876 } /* for i */
8877 RECORD_MULTI_VALUE_STATS();
8878 } /* for times */
8879 count += times;
8880
8881 times = 0;
8882 do {
8883 bench_async_poll(&pending);
8884 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8885 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8886 0, ×, numBlocks, &pending)) {
8887 ret = wc_Sha3_512_Final(hash[i], digest[i]);
8888 if (!bench_async_handle(&ret,
8889 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8890 ×, &pending)) {
8891 goto exit_sha3_512;
8892 }
8893 }
8894 } /* for i */
8895 } while (pending > 0);
8896 } while (bench_stats_check(start)
8897 #ifdef MULTI_VALUE_STATISTICS
8898 || runs < minimum_runs
8899 #endif
8900 );
8901 }
8902 else {
8903 bench_stats_start(&count, &start);
8904 do {
8905 for (times = 0; times < numBlocks; times++) {
8906 ret = wc_InitSha3_512(hash[0], HEAP_HINT,
8907 useDeviceID ? devId : INVALID_DEVID);
8908 if (ret == 0)
8909 ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
8910 if (ret == 0)
8911 ret = wc_Sha3_512_Final(hash[0], digest[0]);
8912 if (ret != 0)
8913 goto exit_sha3_512;
8914 RECORD_MULTI_VALUE_STATS();
8915 } /* for times */
8916 count += times;
8917 } while (bench_stats_check(start)
8918 #ifdef MULTI_VALUE_STATISTICS
8919 || runs < minimum_runs
8920 #endif
8921 );
8922 }
8923exit_sha3_512:
8924 bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
8925 start, ret);
8926#ifdef MULTI_VALUE_STATISTICS
8927 bench_multi_value_stats(max, min, sum, squareSum, runs);
8928#endif
8929
8930exit:
8931
8932 if (WC_ARRAY_OK(hash)) {
8933 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8934 wc_Sha3_512_Free(hash[i]);
8935 }
8936 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
8937 }
8938 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
8939}
8940#endif /* WOLFSSL_NOSHA3_512 */
8941
8942#ifdef WOLFSSL_SHAKE128
8943void bench_shake128(int useDeviceID)
8944{
8945 WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
8946 sizeof(wc_Shake), HEAP_HINT);
8947 double start;
8948 int ret = 0, i, count = 0, times, pending = 0;
8949 DECLARE_MULTI_VALUE_STATS_VARS()
8950 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
8951 WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
8952
8953 bench_stats_prepare();
8954
8955 WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
8956 sizeof(wc_Shake), HEAP_HINT);
8957 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
8958 WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
8959
8960 if (digest_stream) {
8961 /* init keys */
8962 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8963 ret = wc_InitShake128(hash[i], HEAP_HINT,
8964 useDeviceID ? devId : INVALID_DEVID);
8965 if (ret != 0) {
8966 printf("InitShake128 failed, ret = %d\n", ret);
8967 goto exit;
8968 }
8969 }
8970
8971 bench_stats_start(&count, &start);
8972 do {
8973 for (times = 0; times < numBlocks || pending > 0; ) {
8974 bench_async_poll(&pending);
8975
8976 /* while free pending slots in queue, submit ops */
8977 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8978 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8979 0, ×, numBlocks, &pending)) {
8980 ret = wc_Shake128_Update(hash[i], bench_plain,
8981 bench_size);
8982 if (!bench_async_handle(&ret,
8983 BENCH_ASYNC_GET_DEV(hash[i]), 0,
8984 ×, &pending)) {
8985 goto exit_shake128;
8986 }
8987 }
8988 } /* for i */
8989 RECORD_MULTI_VALUE_STATS();
8990 } /* for times */
8991 count += times;
8992
8993 times = 0;
8994 do {
8995 bench_async_poll(&pending);
8996 for (i = 0; i < BENCH_MAX_PENDING; i++) {
8997 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
8998 0, ×, numBlocks, &pending)) {
8999 ret = wc_Shake128_Final(hash[i], digest[i],
9000 WC_SHA3_128_BLOCK_SIZE);
9001 if (!bench_async_handle(&ret,
9002 BENCH_ASYNC_GET_DEV(hash[i]), 0,
9003 ×, &pending)) {
9004 goto exit_shake128;
9005 }
9006 }
9007 } /* for i */
9008 } while (pending > 0);
9009 } while (bench_stats_check(start)
9010 #ifdef MULTI_VALUE_STATISTICS
9011 || runs < minimum_runs
9012 #endif
9013 );
9014 }
9015 else {
9016 bench_stats_start(&count, &start);
9017 do {
9018 for (times = 0; times < numBlocks; times++) {
9019 ret = wc_InitShake128(hash[0], HEAP_HINT,
9020 useDeviceID ? devId : INVALID_DEVID);
9021 if (ret == 0)
9022 ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
9023 if (ret == 0)
9024 ret = wc_Shake128_Final(hash[0], digest[0],
9025 WC_SHA3_128_BLOCK_SIZE);
9026 if (ret != 0)
9027 goto exit_shake128;
9028 RECORD_MULTI_VALUE_STATS();
9029 } /* for times */
9030 count += times;
9031 } while (bench_stats_check(start)
9032 #ifdef MULTI_VALUE_STATISTICS
9033 || runs < minimum_runs
9034 #endif
9035 );
9036 }
9037exit_shake128:
9038 bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
9039 start, ret);
9040#ifdef MULTI_VALUE_STATISTICS
9041 bench_multi_value_stats(max, min, sum, squareSum, runs);
9042#endif
9043
9044exit:
9045
9046 if (WC_ARRAY_OK(hash)) {
9047 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9048 wc_Shake128_Free(hash[i]);
9049 }
9050 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
9051 }
9052 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
9053}
9054#endif /* WOLFSSL_SHAKE128 */
9055
9056#ifdef WOLFSSL_SHAKE256
9057void bench_shake256(int useDeviceID)
9058{
9059 WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
9060 sizeof(wc_Shake), HEAP_HINT);
9061 double start;
9062 int ret = 0, i, count = 0, times, pending = 0;
9063 DECLARE_MULTI_VALUE_STATS_VARS()
9064 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
9065 WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
9066
9067 bench_stats_prepare();
9068
9069 WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
9070 sizeof(wc_Shake), HEAP_HINT);
9071 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
9072 WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
9073
9074 if (digest_stream) {
9075 /* init keys */
9076 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9077 ret = wc_InitShake256(hash[i], HEAP_HINT,
9078 useDeviceID ? devId : INVALID_DEVID);
9079 if (ret != 0) {
9080 printf("InitShake256 failed, ret = %d\n", ret);
9081 goto exit;
9082 }
9083 }
9084
9085 bench_stats_start(&count, &start);
9086 do {
9087 for (times = 0; times < numBlocks || pending > 0; ) {
9088 bench_async_poll(&pending);
9089
9090 /* while free pending slots in queue, submit ops */
9091 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9092 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
9093 0, ×, numBlocks, &pending)) {
9094 ret = wc_Shake256_Update(hash[i], bench_plain,
9095 bench_size);
9096 if (!bench_async_handle(&ret,
9097 BENCH_ASYNC_GET_DEV(hash[i]), 0,
9098 ×, &pending)) {
9099 goto exit_shake256;
9100 }
9101 }
9102 } /* for i */
9103 RECORD_MULTI_VALUE_STATS();
9104 } /* for times */
9105 count += times;
9106
9107 times = 0;
9108 do {
9109 bench_async_poll(&pending);
9110 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9111 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
9112 0, ×, numBlocks, &pending)) {
9113 ret = wc_Shake256_Final(hash[i], digest[i],
9114 WC_SHA3_256_BLOCK_SIZE);
9115 if (!bench_async_handle(&ret,
9116 BENCH_ASYNC_GET_DEV(hash[i]), 0,
9117 ×, &pending)) {
9118 goto exit_shake256;
9119 }
9120 }
9121 } /* for i */
9122 } while (pending > 0);
9123 } while (bench_stats_check(start)
9124 #ifdef MULTI_VALUE_STATISTICS
9125 || runs < minimum_runs
9126 #endif
9127 );
9128 }
9129 else {
9130 bench_stats_start(&count, &start);
9131 do {
9132 for (times = 0; times < numBlocks; times++) {
9133 ret = wc_InitShake256(hash[0], HEAP_HINT,
9134 useDeviceID ? devId : INVALID_DEVID);
9135 if (ret == 0)
9136 ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
9137 if (ret == 0)
9138 ret = wc_Shake256_Final(hash[0], digest[0],
9139 WC_SHA3_256_BLOCK_SIZE);
9140 if (ret != 0)
9141 goto exit_shake256;
9142 RECORD_MULTI_VALUE_STATS();
9143 } /* for times */
9144 count += times;
9145 } while (bench_stats_check(start)
9146 #ifdef MULTI_VALUE_STATISTICS
9147 || runs < minimum_runs
9148 #endif
9149 );
9150 }
9151exit_shake256:
9152 bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
9153 start, ret);
9154#ifdef MULTI_VALUE_STATISTICS
9155 bench_multi_value_stats(max, min, sum, squareSum, runs);
9156#endif
9157
9158exit:
9159
9160 if (WC_ARRAY_OK(hash)) {
9161 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9162 wc_Shake256_Free(hash[i]);
9163 }
9164 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
9165 }
9166 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
9167}
9168#endif /* WOLFSSL_SHAKE256 */
9169#endif
9170
9171#ifdef WOLFSSL_SM3
9172void bench_sm3(int useDeviceID)
9173{
9174 WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
9175 sizeof(wc_Sm3), HEAP_HINT);
9176 double start;
9177 int ret = 0, i, count = 0, times, pending = 0;
9178 DECLARE_MULTI_VALUE_STATS_VARS()
9179 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
9180 HEAP_HINT);
9181
9182 bench_stats_prepare();
9183
9184 WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
9185 sizeof(wc_Sm3), HEAP_HINT);
9186 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
9187 HEAP_HINT);
9188
9189 if (digest_stream) {
9190 /* init keys */
9191 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9192 ret = wc_InitSm3(hash[i], HEAP_HINT,
9193 useDeviceID ? devId: INVALID_DEVID);
9194 if (ret != 0) {
9195 printf("InitSm3 failed, ret = %d\n", ret);
9196 goto exit;
9197 }
9198 }
9199
9200 bench_stats_start(&count, &start);
9201 do {
9202 for (times = 0; times < numBlocks || pending > 0; ) {
9203 bench_async_poll(&pending);
9204
9205 /* while free pending slots in queue, submit ops */
9206 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9207 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
9208 0, ×, numBlocks, &pending)) {
9209 ret = wc_Sm3Update(hash[i], bench_plain,
9210 bench_size);
9211 if (!bench_async_handle(&ret,
9212 BENCH_ASYNC_GET_DEV(hash[i]), 0, ×, &pending)) {
9213 goto exit_sm3;
9214 }
9215 }
9216 } /* for i */
9217 RECORD_MULTI_VALUE_STATS();
9218 } /* for times */
9219 count += times;
9220
9221 times = 0;
9222 do {
9223 bench_async_poll(&pending);
9224 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9225 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
9226 0, ×, numBlocks, &pending)) {
9227 ret = wc_Sm3Final(hash[i], digest[i]);
9228 if (!bench_async_handle(&ret,
9229 BENCH_ASYNC_GET_DEV(hash[i]), 0, ×, &pending)) {
9230 goto exit_sm3;
9231 }
9232 }
9233 } /* for i */
9234 } while (pending > 0);
9235 } while (bench_stats_check(start)
9236 #ifdef MULTI_VALUE_STATISTICS
9237 || runs < minimum_runs
9238 #endif
9239 );
9240 }
9241 else {
9242 bench_stats_start(&count, &start);
9243 do {
9244 for (times = 0; times < numBlocks; times++) {
9245 ret = wc_InitSm3(hash[0], HEAP_HINT,
9246 useDeviceID ? devId: INVALID_DEVID);
9247 if (ret == 0)
9248 ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
9249 if (ret == 0)
9250 ret = wc_Sm3Final(hash[0], digest[0]);
9251 if (ret != 0)
9252 goto exit_sm3;
9253 RECORD_MULTI_VALUE_STATS();
9254 } /* for times */
9255 count += times;
9256 } while (bench_stats_check(start)
9257 #ifdef MULTI_VALUE_STATISTICS
9258 || runs < minimum_runs
9259 #endif
9260 );
9261 }
9262exit_sm3:
9263 bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
9264#ifdef MULTI_VALUE_STATISTICS
9265 bench_multi_value_stats(max, min, sum, squareSum, runs);
9266#endif
9267
9268exit:
9269
9270 if (WC_ARRAY_OK(hash)) {
9271 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9272 wc_Sm3Free(hash[i]);
9273 }
9274 WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
9275 }
9276 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
9277}
9278#endif
9279
9280
9281#ifdef WOLFSSL_RIPEMD
9282void bench_ripemd(void)
9283{
9284 RipeMd hash;
9285 byte digest[RIPEMD_DIGEST_SIZE];
9286 double start;
9287 int i, count, ret = 0;
9288 DECLARE_MULTI_VALUE_STATS_VARS()
9289
9290 bench_stats_prepare();
9291
9292 if (digest_stream) {
9293 ret = wc_InitRipeMd(&hash);
9294 if (ret != 0) {
9295 printf("wc_InitRipeMd failed, retval %d\n", ret);
9296 return;
9297 }
9298
9299 bench_stats_start(&count, &start);
9300 do {
9301 for (i = 0; i < numBlocks; i++) {
9302 ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
9303 if (ret != 0) {
9304 printf("wc_RipeMdUpdate failed, retval %d\n", ret);
9305 return;
9306 }
9307 RECORD_MULTI_VALUE_STATS();
9308 }
9309 ret = wc_RipeMdFinal(&hash, digest);
9310 if (ret != 0) {
9311 printf("wc_RipeMdFinal failed, retval %d\n", ret);
9312 return;
9313 }
9314
9315 count += i;
9316 } while (bench_stats_check(start)
9317 #ifdef MULTI_VALUE_STATISTICS
9318 || runs < minimum_runs
9319 #endif
9320 );
9321 }
9322 else {
9323 bench_stats_start(&count, &start);
9324 do {
9325 for (i = 0; i < numBlocks; i++) {
9326 ret = wc_InitRipeMd(&hash);
9327 if (ret != 0) {
9328 printf("wc_InitRipeMd failed, retval %d\n", ret);
9329 return;
9330 }
9331 ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
9332 if (ret != 0) {
9333 printf("wc_RipeMdUpdate failed, retval %d\n", ret);
9334 return;
9335 }
9336 ret = wc_RipeMdFinal(&hash, digest);
9337 if (ret != 0) {
9338 printf("wc_RipeMdFinal failed, retval %d\n", ret);
9339 return;
9340 }
9341 RECORD_MULTI_VALUE_STATS();
9342 }
9343 count += i;
9344 } while (bench_stats_check(start)
9345 #ifdef MULTI_VALUE_STATISTICS
9346 || runs < minimum_runs
9347 #endif
9348 );
9349 }
9350 bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
9351#ifdef MULTI_VALUE_STATISTICS
9352 bench_multi_value_stats(max, min, sum, squareSum, runs);
9353#endif
9354
9355 return;
9356}
9357#endif
9358
9359
9360#ifdef HAVE_BLAKE2B
9361void bench_blake2b(void)
9362{
9363 Blake2b b2b;
9364 byte digest[64];
9365 double start;
9366 int ret = 0, i, count;
9367 DECLARE_MULTI_VALUE_STATS_VARS()
9368
9369 bench_stats_prepare();
9370
9371 if (digest_stream) {
9372 ret = wc_InitBlake2b(&b2b, 64);
9373 if (ret != 0) {
9374 printf("InitBlake2b failed, ret = %d\n", ret);
9375 return;
9376 }
9377
9378 bench_stats_start(&count, &start);
9379 do {
9380 for (i = 0; i < numBlocks; i++) {
9381 ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
9382 if (ret != 0) {
9383 printf("Blake2bUpdate failed, ret = %d\n", ret);
9384 return;
9385 }
9386 RECORD_MULTI_VALUE_STATS();
9387 }
9388 ret = wc_Blake2bFinal(&b2b, digest, 64);
9389 if (ret != 0) {
9390 printf("Blake2bFinal failed, ret = %d\n", ret);
9391 return;
9392 }
9393 count += i;
9394 } while (bench_stats_check(start)
9395 #ifdef MULTI_VALUE_STATISTICS
9396 || runs < minimum_runs
9397 #endif
9398 );
9399 }
9400 else {
9401 bench_stats_start(&count, &start);
9402 do {
9403 for (i = 0; i < numBlocks; i++) {
9404 ret = wc_InitBlake2b(&b2b, 64);
9405 if (ret != 0) {
9406 printf("InitBlake2b failed, ret = %d\n", ret);
9407 return;
9408 }
9409 ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
9410 if (ret != 0) {
9411 printf("Blake2bUpdate failed, ret = %d\n", ret);
9412 return;
9413 }
9414 ret = wc_Blake2bFinal(&b2b, digest, 64);
9415 if (ret != 0) {
9416 printf("Blake2bFinal failed, ret = %d\n", ret);
9417 return;
9418 }
9419 RECORD_MULTI_VALUE_STATS();
9420 }
9421 count += i;
9422 } while (bench_stats_check(start)
9423 #ifdef MULTI_VALUE_STATISTICS
9424 || runs < minimum_runs
9425 #endif
9426 );
9427 }
9428 bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
9429#ifdef MULTI_VALUE_STATISTICS
9430 bench_multi_value_stats(max, min, sum, squareSum, runs);
9431#endif
9432}
9433#endif
9434
9435#if defined(HAVE_BLAKE2S)
9436void bench_blake2s(void)
9437{
9438 Blake2s b2s;
9439 byte digest[32];
9440 double start;
9441 int ret = 0, i, count;
9442 DECLARE_MULTI_VALUE_STATS_VARS()
9443
9444 bench_stats_prepare();
9445
9446 if (digest_stream) {
9447 ret = wc_InitBlake2s(&b2s, 32);
9448 if (ret != 0) {
9449 printf("InitBlake2s failed, ret = %d\n", ret);
9450 return;
9451 }
9452
9453 bench_stats_start(&count, &start);
9454 do {
9455 for (i = 0; i < numBlocks; i++) {
9456 ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
9457 if (ret != 0) {
9458 printf("Blake2sUpdate failed, ret = %d\n", ret);
9459 return;
9460 }
9461 RECORD_MULTI_VALUE_STATS();
9462 }
9463 ret = wc_Blake2sFinal(&b2s, digest, 32);
9464 if (ret != 0) {
9465 printf("Blake2sFinal failed, ret = %d\n", ret);
9466 return;
9467 }
9468 count += i;
9469 } while (bench_stats_check(start)
9470 #ifdef MULTI_VALUE_STATISTICS
9471 || runs < minimum_runs
9472 #endif
9473 );
9474 }
9475 else {
9476 bench_stats_start(&count, &start);
9477 do {
9478 for (i = 0; i < numBlocks; i++) {
9479 ret = wc_InitBlake2s(&b2s, 32);
9480 if (ret != 0) {
9481 printf("InitBlake2b failed, ret = %d\n", ret);
9482 return;
9483 }
9484 ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
9485 if (ret != 0) {
9486 printf("Blake2bUpdate failed, ret = %d\n", ret);
9487 return;
9488 }
9489 ret = wc_Blake2sFinal(&b2s, digest, 32);
9490 if (ret != 0) {
9491 printf("Blake2sFinal failed, ret = %d\n", ret);
9492 return;
9493 }
9494 RECORD_MULTI_VALUE_STATS();
9495 }
9496 count += i;
9497 } while (bench_stats_check(start)
9498 #ifdef MULTI_VALUE_STATISTICS
9499 || runs < minimum_runs
9500 #endif
9501 );
9502 }
9503 bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
9504#ifdef MULTI_VALUE_STATISTICS
9505 bench_multi_value_stats(max, min, sum, squareSum, runs);
9506#endif
9507}
9508#endif
9509
9510#ifdef HAVE_ASCON
9511void bench_ascon_hash(void)
9512{
9513 wc_AsconHash256 ascon;
9514 byte digest[ASCON_HASH256_SZ];
9515 double start;
9516 int ret = 0, i, count;
9517
9518 bench_stats_prepare();
9519
9520 if (digest_stream) {
9521 ret = wc_AsconHash256_Init(&ascon);
9522 if (ret != 0) {
9523 printf("wc_AsconHash256_Init failed, ret = %d\n", ret);
9524 return;
9525 }
9526
9527 bench_stats_start(&count, &start);
9528 do {
9529 for (i = 0; i < numBlocks; i++) {
9530 ret = wc_AsconHash256_Update(&ascon, bench_plain, bench_size);
9531 if (ret != 0) {
9532 printf("wc_AsconHash256_Update failed, ret = %d\n", ret);
9533 return;
9534 }
9535 }
9536 ret = wc_AsconHash256_Final(&ascon, digest);
9537 if (ret != 0) {
9538 printf("wc_AsconHash256_Final failed, ret = %d\n", ret);
9539 return;
9540 }
9541 count += i;
9542 } while (bench_stats_check(start));
9543 }
9544 else {
9545 bench_stats_start(&count, &start);
9546 do {
9547 for (i = 0; i < numBlocks; i++) {
9548 ret = wc_AsconHash256_Init(&ascon);
9549 if (ret != 0) {
9550 printf("wc_AsconHash256_Init failed, ret = %d\n", ret);
9551 return;
9552 }
9553 ret = wc_AsconHash256_Update(&ascon, bench_plain, bench_size);
9554 if (ret != 0) {
9555 printf("wc_AsconHash256_Update failed, ret = %d\n", ret);
9556 return;
9557 }
9558 ret = wc_AsconHash256_Final(&ascon, digest);
9559 if (ret != 0) {
9560 printf("wc_AsconHash256_Final failed, ret = %d\n", ret);
9561 return;
9562 }
9563 }
9564 count += i;
9565 } while (bench_stats_check(start));
9566 }
9567 bench_stats_sym_finish("ASCON hash", 0, count, bench_size, start, ret);
9568}
9569#endif
9570
9571#ifdef WOLFSSL_CMAC
9572
9573#if defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256)
9574static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
9575{
9576 Cmac cmac;
9577 byte digest[WC_AES_BLOCK_SIZE];
9578 word32 digestSz = sizeof(digest);
9579 double start;
9580 int ret, i, count;
9581 DECLARE_MULTI_VALUE_STATS_VARS()
9582#ifdef WOLFSSL_SECO_CAAM
9583 unsigned int keyID;
9584 int keyGroup = 1; /* group one was chosen arbitrarily */
9585 int keyInfo = CAAM_KEY_TRANSIENT;
9586 int keyType = CAAM_KEYTYPE_AES128;
9587 byte pubKey[AES_256_KEY_SIZE];
9588
9589 if (keySz == AES_256_KEY_SIZE) {
9590 keyType = CAAM_KEYTYPE_AES256;
9591 }
9592
9593 if (useDeviceID &&
9594 wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
9595 keyInfo, &keyID) != 0) {
9596 printf("Error generating key in hsm\n");
9597 return;
9598 }
9599#endif
9600 (void)useDeviceID;
9601
9602 bench_stats_prepare();
9603
9604 bench_stats_start(&count, &start);
9605 do {
9606 #ifdef HAVE_FIPS
9607 ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
9608 #else
9609 ret = bench_CmacInit(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
9610 HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
9611 #endif
9612 if (ret != 0) {
9613 printf("InitCmac failed, ret = %d\n", ret);
9614 return;
9615 }
9616 #ifdef WOLFSSL_SECO_CAAM
9617 if (useDeviceID) {
9618 wc_SECO_CMACSetKeyID(&cmac, keyID);
9619 }
9620 #endif
9621
9622 for (i = 0; i < numBlocks; i++) {
9623 ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
9624 if (ret != 0) {
9625 printf("CmacUpdate failed, ret = %d\n", ret);
9626 return;
9627 }
9628 RECORD_MULTI_VALUE_STATS();
9629 }
9630 /* Note: final force zero's the Cmac struct */
9631 ret = wc_CmacFinal(&cmac, digest, &digestSz);
9632 if (ret != 0) {
9633 printf("CmacFinal failed, ret = %d\n", ret);
9634 return;
9635 }
9636 count += i;
9637 } while (bench_stats_check(start)
9638#ifdef MULTI_VALUE_STATISTICS
9639 || runs < minimum_runs
9640#endif
9641 );
9642
9643 bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
9644#ifdef MULTI_VALUE_STATISTICS
9645 bench_multi_value_stats(max, min, sum, squareSum, runs);
9646#endif
9647}
9648#endif
9649
9650void bench_cmac(int useDeviceID)
9651{
9652#ifdef WOLFSSL_AES_128
9653 bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
9654#endif
9655#ifdef WOLFSSL_AES_256
9656 bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
9657#endif
9658 (void)useDeviceID;
9659}
9660#endif /* WOLFSSL_CMAC */
9661
9662#ifdef HAVE_SCRYPT
9663
9664#ifdef WOLFSSL_KERNEL_MODE
9665 #error wc_scrypt benchmarking with cost 14 is not kernel-compatible (requires 16 MB contiguous allocation)
9666#endif
9667
9668void bench_scrypt(void)
9669{
9670 byte derived[64];
9671 double start;
9672 int ret, i, count;
9673 DECLARE_MULTI_VALUE_STATS_VARS()
9674
9675 bench_stats_prepare();
9676
9677 bench_stats_start(&count, &start);
9678 do {
9679 for (i = 0; i < scryptCnt; i++) {
9680 ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
9681 (byte*)"SodiumChloride", 14, 14, 8, 1,
9682 sizeof(derived));
9683 if (ret != 0) {
9684 printf("scrypt failed, ret = %d\n", ret);
9685 goto exit;
9686 }
9687 RECORD_MULTI_VALUE_STATS();
9688 }
9689 count += i;
9690 } while (bench_stats_check(start)
9691#ifdef MULTI_VALUE_STATISTICS
9692 || runs < minimum_runs
9693#endif
9694 );
9695
9696exit:
9697 bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
9698#ifdef MULTI_VALUE_STATISTICS
9699 bench_multi_value_stats(max, min, sum, squareSum, runs);
9700#endif
9701}
9702
9703#endif /* HAVE_SCRYPT */
9704
9705#ifndef NO_HMAC
9706
9707static void bench_hmac(int useDeviceID, int type, int digestSz,
9708 const byte* key, word32 keySz, const char* label)
9709{
9710 WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
9711 sizeof(Hmac), HEAP_HINT);
9712 double start;
9713 int ret = 0, i, count = 0, times, pending = 0;
9714 DECLARE_MULTI_VALUE_STATS_VARS()
9715#ifdef WOLFSSL_ASYNC_CRYPT
9716 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
9717 WC_MAX_DIGEST_SIZE, HEAP_HINT);
9718 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
9719 WC_MAX_DIGEST_SIZE, HEAP_HINT);
9720#else
9721 byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
9722#endif
9723
9724 (void)digestSz;
9725
9726 bench_stats_prepare();
9727
9728 WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
9729 sizeof(Hmac), HEAP_HINT);
9730
9731 /* init keys */
9732 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9733 ret = wc_HmacInit(hmac[i], HEAP_HINT,
9734 useDeviceID ? devId : INVALID_DEVID);
9735 if (ret != 0) {
9736 printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
9737 goto exit;
9738 }
9739
9740 ret = wc_HmacSetKey(hmac[i], type, key, keySz);
9741 if (ret != 0) {
9742 printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
9743 goto exit;
9744 }
9745 }
9746
9747 if (mac_stream) {
9748 bench_stats_start(&count, &start);
9749 do {
9750 for (times = 0; times < numBlocks || pending > 0; ) {
9751 bench_async_poll(&pending);
9752
9753 /* while free pending slots in queue, submit ops */
9754 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9755 if (bench_async_check(&ret,
9756 BENCH_ASYNC_GET_DEV(hmac[i]), 0,
9757 ×, numBlocks, &pending)) {
9758 ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
9759 if (!bench_async_handle(&ret,
9760 BENCH_ASYNC_GET_DEV(hmac[i]),
9761 0, ×, &pending)) {
9762 goto exit_hmac;
9763 }
9764 }
9765 } /* for i */
9766 } /* for times */
9767 count += times;
9768
9769 times = 0;
9770 do {
9771 bench_async_poll(&pending);
9772
9773 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9774 if (bench_async_check(&ret,
9775 BENCH_ASYNC_GET_DEV(hmac[i]), 0,
9776 ×, numBlocks, &pending)) {
9777 ret = wc_HmacFinal(hmac[i], digest[i]);
9778 if (!bench_async_handle(&ret,
9779 BENCH_ASYNC_GET_DEV(hmac[i]),
9780 0, ×, &pending)) {
9781 goto exit_hmac;
9782 }
9783 }
9784 RECORD_MULTI_VALUE_STATS();
9785 } /* for i */
9786 } while (pending > 0);
9787 } while (bench_stats_check(start)
9788 #ifdef MULTI_VALUE_STATISTICS
9789 || runs < minimum_runs
9790 #endif
9791 );
9792 }
9793 else {
9794 bench_stats_start(&count, &start);
9795 do {
9796 for (times = 0; times < numBlocks || pending > 0; ) {
9797 bench_async_poll(&pending);
9798
9799 /* while free pending slots in queue, submit ops */
9800 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9801 if (bench_async_check(&ret,
9802 BENCH_ASYNC_GET_DEV(hmac[i]), 0,
9803 ×, numBlocks, &pending)) {
9804 ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
9805 if (!bench_async_handle(&ret,
9806 BENCH_ASYNC_GET_DEV(hmac[i]),
9807 0, ×, &pending)) {
9808 goto exit_hmac;
9809 }
9810 }
9811 if (bench_async_check(&ret,
9812 BENCH_ASYNC_GET_DEV(hmac[i]), 0,
9813 ×, numBlocks, &pending)) {
9814 ret = wc_HmacFinal(hmac[i], digest[i]);
9815 if (!bench_async_handle(&ret,
9816 BENCH_ASYNC_GET_DEV(hmac[i]),
9817 0, ×, &pending)) {
9818 goto exit_hmac;
9819 }
9820 }
9821 } /* for i */
9822 } /* for times */
9823 count += times;
9824 } while (bench_stats_check(start)
9825 #ifdef MULTI_VALUE_STATISTICS
9826 || runs < minimum_runs
9827 #endif
9828 );
9829 }
9830
9831exit_hmac:
9832 bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
9833#ifdef MULTI_VALUE_STATISTICS
9834 bench_multi_value_stats(max, min, sum, squareSum, runs);
9835#endif
9836
9837exit:
9838
9839 for (i = 0; i < BENCH_MAX_PENDING; i++) {
9840 wc_HmacFree(hmac[i]);
9841 }
9842
9843 WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
9844#ifdef WOLFSSL_ASYNC_CRYPT
9845 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
9846#endif
9847}
9848
9849#ifndef NO_MD5
9850
9851void bench_hmac_md5(int useDeviceID)
9852{
9853 WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
9854 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9855 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
9856
9857 bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
9858 "HMAC-MD5");
9859}
9860
9861#endif /* NO_MD5 */
9862
9863#ifndef NO_SHA
9864
9865void bench_hmac_sha(int useDeviceID)
9866{
9867 WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
9868 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9869 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9870 0x0b, 0x0b, 0x0b, 0x0b };
9871
9872 bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
9873 "HMAC-SHA");
9874}
9875
9876#endif /* NO_SHA */
9877
9878#ifdef WOLFSSL_SHA224
9879
9880void bench_hmac_sha224(int useDeviceID)
9881{
9882 WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
9883 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9884 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9885 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9886 0x0b, 0x0b, 0x0b, 0x0b };
9887
9888 bench_hmac(useDeviceID, WC_SHA224,
9889 WC_SHA224_DIGEST_SIZE, key, sizeof(key),
9890 "HMAC-SHA224");
9891}
9892
9893#endif /* WOLFSSL_SHA224 */
9894
9895#ifndef NO_SHA256
9896
9897void bench_hmac_sha256(int useDeviceID)
9898{
9899 WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
9900 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9901 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9902 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9903 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
9904
9905 bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
9906 "HMAC-SHA256");
9907}
9908
9909#endif /* NO_SHA256 */
9910
9911#ifdef WOLFSSL_SHA384
9912
9913void bench_hmac_sha384(int useDeviceID)
9914{
9915 WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
9916 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9917 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9918 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9919 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9920 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9921 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
9922
9923 bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
9924 "HMAC-SHA384");
9925}
9926
9927#endif /* WOLFSSL_SHA384 */
9928
9929#ifdef WOLFSSL_SHA512
9930
9931void bench_hmac_sha512(int useDeviceID)
9932{
9933 WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
9934 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9935 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9936 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9937 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9938 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9939 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9940 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
9941 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
9942
9943 bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
9944 "HMAC-SHA512");
9945}
9946
9947#endif /* WOLFSSL_SHA512 */
9948
9949#ifndef NO_PWDBASED
9950void bench_pbkdf2(void)
9951{
9952 double start;
9953 int ret = 0, count = 0;
9954 const char* passwd32 = "passwordpasswordpasswordpassword";
9955 WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
9956 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
9957 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
9958 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
9959 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
9960 byte derived[32];
9961 DECLARE_MULTI_VALUE_STATS_VARS()
9962
9963 bench_stats_prepare();
9964
9965 bench_stats_start(&count, &start);
9966 PRIVATE_KEY_UNLOCK();
9967 do {
9968 ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
9969 salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
9970 count++;
9971 RECORD_MULTI_VALUE_STATS();
9972 } while (bench_stats_check(start)
9973#ifdef MULTI_VALUE_STATISTICS
9974 || runs < minimum_runs
9975#endif
9976 );
9977 PRIVATE_KEY_LOCK();
9978
9979 bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
9980#ifdef MULTI_VALUE_STATISTICS
9981 bench_multi_value_stats(max, min, sum, squareSum, runs);
9982#endif
9983}
9984#endif /* !NO_PWDBASED */
9985
9986#endif /* NO_HMAC */
9987
9988#ifdef WOLFSSL_SIPHASH
9989void bench_siphash(void)
9990{
9991 double start;
9992 int ret = 0, count;
9993 const char* passwd16 = "passwordpassword";
9994 byte out[16];
9995 int i;
9996 DECLARE_MULTI_VALUE_STATS_VARS()
9997
9998 bench_stats_prepare();
9999
10000 bench_stats_start(&count, &start);
10001 do {
10002 for (i = 0; i < numBlocks; i++) {
10003 ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
10004 out, 8);
10005 RECORD_MULTI_VALUE_STATS();
10006 }
10007 count += i;
10008 } while (bench_stats_check(start)
10009#ifdef MULTI_VALUE_STATISTICS
10010 || runs < minimum_runs
10011#endif
10012 );
10013
10014 bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
10015#ifdef MULTI_VALUE_STATISTICS
10016 bench_multi_value_stats(max, min, sum, squareSum, runs);
10017#endif
10018
10019 RESET_MULTI_VALUE_STATS_VARS();
10020
10021 bench_stats_start(&count, &start);
10022 do {
10023 for (i = 0; i < numBlocks; i++) {
10024 ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
10025 out, 16);
10026 RECORD_MULTI_VALUE_STATS();
10027 }
10028 count += i;
10029 } while (bench_stats_check(start)
10030#ifdef MULTI_VALUE_STATISTICS
10031 || runs < minimum_runs
10032#endif
10033 );
10034
10035 bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
10036#ifdef MULTI_VALUE_STATISTICS
10037 bench_multi_value_stats(max, min, sum, squareSum, runs);
10038#endif
10039}
10040#endif
10041
10042#ifdef WC_SRTP_KDF
10043void bench_srtpkdf(void)
10044{
10045 double start;
10046 int count;
10047 int ret = 0;
10048 byte keyE[32];
10049 byte keyA[20];
10050 byte keyS[14];
10051 const byte *key = bench_key_buf;
10052 const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
10053 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
10054 const byte idx[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
10055 int kdrIdx = 0;
10056 int i;
10057 DECLARE_MULTI_VALUE_STATS_VARS()
10058
10059 bench_stats_prepare();
10060
10061 bench_stats_start(&count, &start);
10062 PRIVATE_KEY_UNLOCK();
10063 do {
10064 for (i = 0; i < numBlocks * 1000; i++) {
10065 ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
10066 kdrIdx, idx, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
10067 keyS, sizeof(keyS));
10068 RECORD_MULTI_VALUE_STATS();
10069 }
10070 count += i;
10071 } while (bench_stats_check(start)
10072#ifdef MULTI_VALUE_STATISTICS
10073 || runs < minimum_runs
10074#endif
10075 );
10076 PRIVATE_KEY_LOCK();
10077 bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
10078#ifdef MULTI_VALUE_STATISTICS
10079 bench_multi_value_stats(max, min, sum, squareSum, runs);
10080#endif
10081
10082 RESET_MULTI_VALUE_STATS_VARS();
10083
10084 bench_stats_start(&count, &start);
10085 PRIVATE_KEY_UNLOCK();
10086 do {
10087 for (i = 0; i < numBlocks * 1000; i++) {
10088 ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
10089 kdrIdx, idx, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
10090 keyS, sizeof(keyS));
10091 RECORD_MULTI_VALUE_STATS();
10092 }
10093 count += i;
10094 } while (bench_stats_check(start)
10095#ifdef MULTI_VALUE_STATISTICS
10096 || runs < minimum_runs
10097#endif
10098 );
10099 PRIVATE_KEY_LOCK();
10100 bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
10101#ifdef MULTI_VALUE_STATISTICS
10102 bench_multi_value_stats(max, min, sum, squareSum, runs);
10103#endif
10104
10105 RESET_MULTI_VALUE_STATS_VARS();
10106
10107 bench_stats_start(&count, &start);
10108 PRIVATE_KEY_UNLOCK();
10109 do {
10110 for (i = 0; i < numBlocks * 1000; i++) {
10111 ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
10112 kdrIdx, idx, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
10113 keyS, sizeof(keyS));
10114 RECORD_MULTI_VALUE_STATS();
10115 }
10116 count += i;
10117 } while (bench_stats_check(start)
10118#ifdef MULTI_VALUE_STATISTICS
10119 || runs < minimum_runs
10120#endif
10121 );
10122 PRIVATE_KEY_LOCK();
10123 bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
10124#ifdef MULTI_VALUE_STATISTICS
10125 bench_multi_value_stats(max, min, sum, squareSum, runs);
10126#endif
10127
10128 RESET_MULTI_VALUE_STATS_VARS();
10129
10130 bench_stats_start(&count, &start);
10131 PRIVATE_KEY_UNLOCK();
10132 do {
10133 for (i = 0; i < numBlocks * 1000; i++) {
10134 ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
10135 kdrIdx, idx, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
10136 keyS, sizeof(keyS));
10137 RECORD_MULTI_VALUE_STATS();
10138 }
10139 count += i;
10140 } while (bench_stats_check(start)
10141#ifdef MULTI_VALUE_STATISTICS
10142 || runs < minimum_runs
10143#endif
10144 );
10145 PRIVATE_KEY_LOCK();
10146 bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
10147#ifdef MULTI_VALUE_STATISTICS
10148 bench_multi_value_stats(max, min, sum, squareSum, runs);
10149#endif
10150
10151}
10152#endif
10153
10154#if !defined(NO_RSA) && !defined(WC_NO_RNG)
10155
10156#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
10157static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
10158{
10159 WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
10160 sizeof(RsaKey), HEAP_HINT);
10161 double start = 0;
10162 int ret = 0, i, count = 0, times, pending = 0;
10163 const long rsa_e_val = WC_RSA_EXPONENT;
10164 const char**desc = bench_desc_words[lng_index];
10165 DECLARE_MULTI_VALUE_STATS_VARS()
10166
10167 bench_stats_prepare();
10168
10169 WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
10170 sizeof(RsaKey), HEAP_HINT);
10171
10172 bench_stats_start(&count, &start);
10173 do {
10174 /* while free pending slots in queue, submit ops */
10175 for (times = 0; times < genTimes || pending > 0; ) {
10176 bench_async_poll(&pending);
10177
10178 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10179 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
10180 0, ×, genTimes, &pending)) {
10181 wc_FreeRsaKey(genKey[i]);
10182 ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
10183 if (ret < 0) {
10184 goto exit;
10185 }
10186
10187 ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
10188 &gRng);
10189 if (!bench_async_handle(&ret,
10190 BENCH_ASYNC_GET_DEV(genKey[i]), 0,
10191 ×, &pending)) {
10192 goto exit;
10193 }
10194 }
10195 } /* for i */
10196 RECORD_MULTI_VALUE_STATS();
10197 } /* for times */
10198 count += times;
10199 } while (bench_stats_check(start)
10200#ifdef MULTI_VALUE_STATISTICS
10201 || runs < minimum_runs
10202#endif
10203 );
10204
10205exit:
10206 bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
10207 start, ret);
10208#ifdef MULTI_VALUE_STATISTICS
10209 bench_multi_value_stats(max, min, sum, squareSum, runs);
10210#endif
10211
10212 /* cleanup */
10213 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10214 wc_FreeRsaKey(genKey[i]);
10215 }
10216
10217 WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
10218}
10219
10220void bench_rsaKeyGen(int useDeviceID)
10221{
10222 int k;
10223
10224#if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
10225 static const word32 keySizes[2] = {1024, 2048 };
10226#elif RSA_MAX_SIZE >= 4096
10227 #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
10228 (RSA_MIN_SIZE <= 1024)
10229 static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
10230 #else
10231 static const word32 keySizes[3] = {2048, 3072, 4096};
10232 #endif
10233#elif RSA_MAX_SIZE >= 3072
10234 #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
10235 (RSA_MIN_SIZE <= 1024)
10236 static const word32 keySizes[3] = {1024, 2048, 3072 };
10237 #else
10238 static const word32 keySizes[2] = {2048, 3072 };
10239 #endif
10240#elif RSA_MAX_SIZE >= 2048
10241 #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
10242 (RSA_MIN_SIZE <= 1024)
10243 static const word32 keySizes[2] = {1024, 2048 };
10244 #else
10245 static const word32 keySizes[1] = {2048};
10246 #endif
10247#else
10248 #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
10249 (RSA_MIN_SIZE <= 1024)
10250 static const word32 keySizes[1] = {1024 };
10251 #else
10252 #error No candidate RSA key sizes to benchmark.
10253 #endif
10254#endif
10255
10256 for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
10257 bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
10258 }
10259}
10260
10261
10262void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
10263{
10264 bench_rsaKeyGen_helper(useDeviceID, keySz);
10265}
10266#endif /* WOLFSSL_KEY_GEN && !WOLFSSL_RSA_PUBLIC_ONLY */
10267
10268#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
10269 !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
10270 #if defined(WOLFSSL_MDK_SHELL)
10271 static char *certRSAname = "certs/rsa2048.der";
10272 /* set by shell command */
10273 static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
10274 #elif defined(FREESCALE_MQX)
10275 static char *certRSAname = "a:\\certs\\rsa2048.der";
10276 #else
10277 static const char *certRSAname = "certs/rsa2048.der";
10278 #endif
10279#endif
10280
10281#define RSA_BUF_SIZE 384 /* for up to 3072 bit */
10282
10283#if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
10284#if defined(USE_CERT_BUFFERS_2048)
10285static const unsigned char rsa_2048_sig[] = {
10286 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
10287 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
10288 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
10289 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
10290 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
10291 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
10292 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
10293 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
10294 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
10295 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
10296 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
10297 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
10298 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
10299 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
10300 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
10301 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
10302 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
10303 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
10304 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
10305 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
10306 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
10307 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
10308 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
10309 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
10310 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
10311 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
10312 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
10313 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
10314 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
10315 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
10316 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
10317 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
10318};
10319#elif defined(USE_CERT_BUFFERS_3072)
10320static const unsigned char rsa_3072_sig[] = {
10321 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
10322 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
10323 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
10324 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
10325 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
10326 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
10327 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
10328 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
10329 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
10330 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
10331 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
10332 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
10333 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
10334 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
10335 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
10336 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
10337 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
10338 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
10339 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
10340 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
10341 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
10342 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
10343 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
10344 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
10345 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
10346 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
10347 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
10348 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
10349 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
10350 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
10351 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
10352 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
10353 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
10354 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
10355 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
10356 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
10357 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
10358 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
10359 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
10360 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
10361 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
10362 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
10363 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
10364 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
10365 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
10366 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
10367 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
10368 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
10369};
10370#else
10371 #error Not Supported Yet!
10372#endif
10373#endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
10374
10375static void bench_rsa_helper(int useDeviceID,
10376 WC_ARRAY_ARG(rsaKey,
10377 RsaKey,
10378 BENCH_MAX_PENDING,
10379 sizeof(RsaKey)),
10380 word32 rsaKeySz)
10381{
10382 int ret = 0, i, times, count = 0, pending = 0;
10383 word32 idx = 0;
10384#ifndef WOLFSSL_RSA_VERIFY_ONLY
10385 const char* messageStr = TEST_STRING;
10386 const int len = (int)TEST_STRING_SZ;
10387#endif
10388 double start = 0.0F;
10389 const char**desc = bench_desc_words[lng_index];
10390 DECLARE_MULTI_VALUE_STATS_VARS()
10391#ifndef WOLFSSL_RSA_VERIFY_ONLY
10392 WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
10393#endif
10394 WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
10395 rsaKeySz/8, HEAP_HINT);
10396
10397#if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(WOLFSSL_RSA_PUBLIC_ONLY)
10398 WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
10399 rsaKeySz/8, HEAP_HINT);
10400#else
10401 byte* out[BENCH_MAX_PENDING];
10402#endif
10403
10404 bench_stats_prepare();
10405
10406#if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(WOLFSSL_RSA_PUBLIC_ONLY)
10407 WC_CALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
10408 rsaKeySz/8, HEAP_HINT);
10409 if (out[0] == NULL) {
10410 ret = MEMORY_E;
10411 goto exit;
10412 }
10413#else
10414 XMEMSET(out, 0, sizeof(out));
10415#endif
10416
10417 WC_CALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
10418 rsaKeySz/8, HEAP_HINT);
10419 if (enc[0] == NULL) {
10420 ret = MEMORY_E;
10421 goto exit;
10422 }
10423
10424#ifndef WOLFSSL_RSA_VERIFY_ONLY
10425 WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
10426 XMEMCPY(message, messageStr, len);
10427#endif
10428
10429 if (!rsa_sign_verify) {
10430#ifndef WOLFSSL_RSA_VERIFY_ONLY
10431 /* begin public RSA */
10432 bench_stats_start(&count, &start);
10433 do {
10434 for (times = 0; times < ntimes || pending > 0; ) {
10435 bench_async_poll(&pending);
10436
10437 /* while free pending slots in queue, submit ops */
10438 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10439 if (bench_async_check(&ret,
10440 BENCH_ASYNC_GET_DEV(rsaKey[i]),
10441 1, ×, ntimes, &pending)) {
10442 ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
10443 rsaKeySz/8, rsaKey[i],
10444 GLOBAL_RNG);
10445 if (!bench_async_handle(&ret,
10446 BENCH_ASYNC_GET_DEV(
10447 rsaKey[i]), 1, ×,
10448 &pending)) {
10449 goto exit_rsa_verify;
10450 }
10451 }
10452 } /* for i */
10453 RECORD_MULTI_VALUE_STATS();
10454 } /* for times */
10455 count += times;
10456 } while (bench_stats_check(start)
10457 #ifdef MULTI_VALUE_STATISTICS
10458 || runs < minimum_runs
10459 #endif
10460 );
10461
10462exit_rsa_verify:
10463 bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
10464 useDeviceID, count, start, ret);
10465 #ifdef MULTI_VALUE_STATISTICS
10466 bench_multi_value_stats(max, min, sum, squareSum, runs);
10467 #endif
10468#endif /* !WOLFSSL_RSA_VERIFY_ONLY */
10469
10470#ifndef WOLFSSL_RSA_PUBLIC_ONLY
10471 if (ret < 0) {
10472 goto exit;
10473 }
10474
10475 RESET_MULTI_VALUE_STATS_VARS();
10476
10477 /* capture resulting encrypt length */
10478 idx = (word32)(rsaKeySz/8);
10479
10480 /* begin private async RSA */
10481 bench_stats_start(&count, &start);
10482 do {
10483 for (times = 0; times < ntimes || pending > 0; ) {
10484 bench_async_poll(&pending);
10485
10486 /* while free pending slots in queue, submit ops */
10487 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10488 if (bench_async_check(&ret,
10489 BENCH_ASYNC_GET_DEV(rsaKey[i]),
10490 1, ×, ntimes, &pending)) {
10491 ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
10492 rsaKeySz/8, rsaKey[i]);
10493 if (!bench_async_handle(&ret,
10494 BENCH_ASYNC_GET_DEV(rsaKey[i]),
10495 1, ×, &pending)) {
10496 goto exit_rsa_pub;
10497 }
10498 }
10499 } /* for i */
10500 RECORD_MULTI_VALUE_STATS();
10501 } /* for times */
10502 count += times;
10503 } while (bench_stats_check(start)
10504 #ifdef MULTI_VALUE_STATISTICS
10505 || runs < minimum_runs
10506 #endif
10507 );
10508
10509exit_rsa_pub:
10510 bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
10511 useDeviceID, count, start, ret);
10512 #ifdef MULTI_VALUE_STATISTICS
10513 bench_multi_value_stats(max, min, sum, squareSum, runs);
10514 #endif
10515#endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
10516 }
10517 else {
10518#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
10519 /* begin RSA sign */
10520 bench_stats_start(&count, &start);
10521 do {
10522 for (times = 0; times < ntimes || pending > 0; ) {
10523 bench_async_poll(&pending);
10524
10525 /* while free pending slots in queue, submit ops */
10526 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10527 if (bench_async_check(&ret,
10528 BENCH_ASYNC_GET_DEV(rsaKey[i]),
10529 1, ×, ntimes, &pending)) {
10530 ret = wc_RsaSSL_Sign(message, len, enc[i],
10531 rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
10532 if (!bench_async_handle(&ret,
10533 BENCH_ASYNC_GET_DEV(rsaKey[i]),
10534 1, ×, &pending)) {
10535 goto exit_rsa_sign;
10536 }
10537 }
10538 } /* for i */
10539 RECORD_MULTI_VALUE_STATS();
10540 } /* for times */
10541 count += times;
10542 } while (bench_stats_check(start)
10543 #ifdef MULTI_VALUE_STATISTICS
10544 || runs < minimum_runs
10545 #endif
10546 );
10547
10548exit_rsa_sign:
10549 bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
10550 count, start, ret);
10551 #ifdef MULTI_VALUE_STATISTICS
10552 bench_multi_value_stats(max, min, sum, squareSum, runs);
10553 #endif
10554 if (ret < 0) {
10555 goto exit;
10556 }
10557
10558 RESET_MULTI_VALUE_STATS_VARS();
10559
10560#endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
10561
10562 /* capture resulting encrypt length */
10563 idx = rsaKeySz/8;
10564
10565 /* begin RSA verify */
10566 bench_stats_start(&count, &start);
10567 do {
10568 for (times = 0; times < ntimes || pending > 0; ) {
10569 bench_async_poll(&pending);
10570
10571 /* while free pending slots in queue, submit ops */
10572 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10573 if (bench_async_check(&ret,
10574 BENCH_ASYNC_GET_DEV(rsaKey[i]),
10575 1, ×, ntimes, &pending)) {
10576 #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
10577 !defined(WOLFSSL_RSA_PUBLIC_ONLY)
10578 ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
10579 rsaKeySz/8, rsaKey[i]);
10580 #elif defined(USE_CERT_BUFFERS_2048)
10581 XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
10582 idx = sizeof(rsa_2048_sig);
10583 out[i] = NULL;
10584 ret = wc_RsaSSL_VerifyInline(enc[i], idx,
10585 &out[i], rsaKey[i]);
10586 if (ret > 0) {
10587 ret = 0;
10588 }
10589
10590 #elif defined(USE_CERT_BUFFERS_3072)
10591 XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
10592 idx = sizeof(rsa_3072_sig);
10593 out[i] = NULL;
10594 ret = wc_RsaSSL_VerifyInline(enc[i], idx,
10595 &out[i], rsaKey[i]);
10596 if (ret > 0)
10597 ret = 0;
10598 #endif
10599 if (!bench_async_handle(&ret,
10600 BENCH_ASYNC_GET_DEV(rsaKey[i]),
10601 1, ×, &pending)) {
10602 goto exit_rsa_verifyinline;
10603 }
10604 }
10605 } /* for i */
10606 RECORD_MULTI_VALUE_STATS();
10607 } /* for times */
10608 count += times;
10609 } while (bench_stats_check(start)
10610 #ifdef MULTI_VALUE_STATISTICS
10611 || runs < minimum_runs
10612 #endif
10613 );
10614
10615exit_rsa_verifyinline:
10616 bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
10617 useDeviceID, count, start, ret);
10618 #ifdef MULTI_VALUE_STATISTICS
10619 bench_multi_value_stats(max, min, sum, squareSum, runs);
10620 #endif
10621 }
10622
10623exit:
10624
10625 WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
10626#if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(WOLFSSL_RSA_PUBLIC_ONLY)
10627 WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
10628#endif
10629#ifndef WOLFSSL_RSA_VERIFY_ONLY
10630 WC_FREE_VAR(message, HEAP_HINT);
10631#endif
10632}
10633
10634void bench_rsa(int useDeviceID)
10635{
10636 int i;
10637 WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
10638 sizeof(RsaKey), HEAP_HINT);
10639 int ret = 0;
10640 word32 rsaKeySz = 0;
10641 const byte* tmp;
10642 size_t bytes;
10643#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
10644 word32 idx;
10645#endif
10646
10647 WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
10648 sizeof(RsaKey), HEAP_HINT);
10649
10650#ifdef USE_CERT_BUFFERS_1024
10651 tmp = rsa_key_der_1024;
10652 bytes = (size_t)sizeof_rsa_key_der_1024;
10653 rsaKeySz = 1024;
10654#elif defined(USE_CERT_BUFFERS_2048)
10655 tmp = rsa_key_der_2048;
10656 bytes = (size_t)sizeof_rsa_key_der_2048;
10657 rsaKeySz = 2048;
10658#elif defined(USE_CERT_BUFFERS_3072)
10659 tmp = rsa_key_der_3072;
10660 bytes = (size_t)sizeof_rsa_key_der_3072;
10661 rsaKeySz = 3072;
10662#elif defined(USE_CERT_BUFFERS_4096)
10663 tmp = client_key_der_4096;
10664 bytes = (size_t)sizeof_client_key_der_4096;
10665 rsaKeySz = 4096;
10666#else
10667 #error "need a cert buffer size"
10668#endif /* USE_CERT_BUFFERS */
10669
10670 /* init keys */
10671 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10672 /* setup an async context for each key */
10673 ret = bench_RsaInit(rsaKey[i], HEAP_HINT,
10674 useDeviceID ? devId : INVALID_DEVID);
10675 if (ret < 0) {
10676 goto exit;
10677 }
10678
10679#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
10680 #ifdef WC_RSA_BLINDING
10681 ret = wc_RsaSetRNG(rsaKey[i], &gRng);
10682 if (ret != 0)
10683 goto exit;
10684 #endif
10685#endif
10686
10687#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
10688 /* decode the private key */
10689 idx = 0;
10690 if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
10691 rsaKey[i], (word32)bytes)) != 0) {
10692 printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
10693 goto exit;
10694 }
10695#elif defined(WOLFSSL_PUBLIC_MP)
10696 /* get offset to public portion of the RSA key */
10697 #ifdef USE_CERT_BUFFERS_1024
10698 bytes = 11;
10699 #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
10700 bytes = 12;
10701 #endif
10702 ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
10703 if (ret != 0) {
10704 printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
10705 goto exit;
10706 }
10707 ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
10708 if (ret != 0) {
10709 printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
10710 goto exit;
10711 }
10712#else
10713 /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
10714 rsaKeySz = 0;
10715#endif
10716#if defined(WOLFSSL_KEY_GEN) && defined(WOLFSSL_MICROCHIP_TA100)
10717 /* Create new keys since you cannot import a private key to TA100 */
10718 ret = wc_MakeRsaKey(rsaKey[i], rsaKeySz, WC_RSA_EXPONENT, &gRng);
10719 if (ret) {
10720 goto exit;
10721 }
10722#endif
10723 }
10724
10725 if (rsaKeySz > 0) {
10726 bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
10727 }
10728
10729 (void)bytes;
10730 (void)tmp;
10731
10732exit:
10733 /* cleanup */
10734 if (WC_ARRAY_OK(rsaKey)) {
10735 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10736 wc_FreeRsaKey(rsaKey[i]);
10737 }
10738 WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
10739 }
10740}
10741
10742
10743#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
10744/* bench any size of RSA key */
10745void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
10746{
10747 int ret = 0, i, pending = 0;
10748 WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
10749 sizeof(RsaKey), HEAP_HINT);
10750 int isPending[BENCH_MAX_PENDING];
10751 long exp = 65537L;
10752
10753 /* clear for done cleanup */
10754 XMEMSET(isPending, 0, sizeof(isPending));
10755
10756 WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
10757 sizeof(RsaKey), HEAP_HINT);
10758
10759 /* init keys */
10760 do {
10761 pending = 0;
10762 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10763 if (!isPending[i]) { /* if making the key is pending then just call
10764 * wc_MakeRsaKey again */
10765 /* setup an async context for each key */
10766 if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
10767 useDeviceID ? devId : INVALID_DEVID) < 0) {
10768 goto exit;
10769 }
10770
10771 #ifdef WC_RSA_BLINDING
10772 ret = wc_RsaSetRNG(rsaKey[i], &gRng);
10773 if (ret != 0)
10774 goto exit;
10775 #endif
10776 }
10777
10778 /* create the RSA key */
10779 ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
10780 if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
10781 isPending[i] = 1;
10782 pending = 1;
10783 }
10784 else if (ret != 0) {
10785 printf("wc_MakeRsaKey failed! %d\n", ret);
10786 goto exit;
10787 }
10788 } /* for i */
10789 } while (pending > 0);
10790
10791 bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
10792exit:
10793
10794 /* cleanup */
10795 if (WC_ARRAY_OK(rsaKey)) {
10796 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10797 wc_FreeRsaKey(rsaKey[i]);
10798 }
10799 WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
10800 }
10801}
10802#endif /* WOLFSSL_KEY_GEN */
10803#endif /* !NO_RSA && !WC_NO_RNG */
10804
10805
10806#if !defined(NO_DH) && !defined(WC_NO_RNG)
10807
10808#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
10809 !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
10810 #if defined(WOLFSSL_MDK_SHELL)
10811 static char *certDHname = "certs/dh2048.der";
10812 /* set by shell command */
10813 void set_Bench_DH_File(char * cert) { certDHname = cert ; }
10814 #elif defined(FREESCALE_MQX)
10815 static char *certDHname = "a:\\certs\\dh2048.der";
10816 #elif defined(NO_ASN)
10817 /* do nothing, but don't need a file */
10818 #else
10819 static const char *certDHname = "certs/dh2048.der";
10820 #endif
10821#endif
10822
10823#ifdef HAVE_FFDHE_4096
10824#define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
10825#else
10826#define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
10827#endif
10828#define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
10829
10830void bench_dh(int useDeviceID)
10831{
10832 int ret = 0, i;
10833 int count = 0, times, pending = 0;
10834 const byte* tmp = NULL;
10835 double start = 0.0F;
10836 WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
10837 sizeof(DhKey), HEAP_HINT);
10838 int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
10839 const char**desc = bench_desc_words[lng_index];
10840#ifndef NO_ASN
10841 size_t bytes = 0;
10842 word32 idx;
10843#endif
10844 word32 pubSz[BENCH_MAX_PENDING];
10845 word32 privSz[BENCH_MAX_PENDING];
10846 word32 pubSz2 = BENCH_DH_KEY_SIZE;
10847 word32 privSz2 = BENCH_DH_PRIV_SIZE;
10848 word32 agreeSz[BENCH_MAX_PENDING];
10849#if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
10850#ifdef HAVE_PUBLIC_FFDHE
10851 const DhParams *params = NULL;
10852#else
10853 int paramName = 0;
10854#endif
10855#endif
10856 DECLARE_MULTI_VALUE_STATS_VARS()
10857
10858 WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
10859 BENCH_DH_KEY_SIZE, HEAP_HINT);
10860 WC_DECLARE_VAR(pub2, byte,
10861 BENCH_DH_KEY_SIZE, HEAP_HINT);
10862 WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
10863 BENCH_DH_KEY_SIZE, HEAP_HINT);
10864 WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
10865 BENCH_DH_PRIV_SIZE, HEAP_HINT);
10866 WC_DECLARE_VAR(priv2, byte,
10867 BENCH_DH_PRIV_SIZE, HEAP_HINT);
10868
10869 bench_stats_prepare();
10870
10871 /* old scan-build misfires -Wmaybe-uninitialized on these. */
10872 XMEMSET(pub, 0, sizeof(pub));
10873 XMEMSET(agree, 0, sizeof(agree));
10874 XMEMSET(priv, 0, sizeof(priv));
10875
10876 WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
10877 sizeof(DhKey), HEAP_HINT);
10878 WC_ALLOC_ARRAY(pub, byte,
10879 BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
10880 WC_ALLOC_ARRAY(agree, byte,
10881 BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
10882 WC_ALLOC_ARRAY(priv, byte,
10883 BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
10884
10885 WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
10886 WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
10887
10888 (void)tmp;
10889
10890 if (!use_ffdhe) {
10891#if defined(NO_ASN)
10892 dhKeySz = 1024;
10893 /* do nothing, but don't use default FILE */
10894#elif defined(USE_CERT_BUFFERS_1024)
10895 tmp = dh_key_der_1024;
10896 bytes = (size_t)sizeof_dh_key_der_1024;
10897 dhKeySz = 1024;
10898#elif defined(USE_CERT_BUFFERS_2048)
10899 tmp = dh_key_der_2048;
10900 bytes = (size_t)sizeof_dh_key_der_2048;
10901 dhKeySz = 2048;
10902#elif defined(USE_CERT_BUFFERS_3072)
10903 tmp = dh_key_der_3072;
10904 bytes = (size_t)sizeof_dh_key_der_3072;
10905 dhKeySz = 3072;
10906#elif defined(USE_CERT_BUFFERS_4096)
10907 tmp = dh_key_der_4096;
10908 bytes = (size_t)sizeof_dh_key_der_4096;
10909 dhKeySz = 4096;
10910#else
10911 #error "need to define a cert buffer size"
10912#endif /* USE_CERT_BUFFERS */
10913 }
10914#ifdef HAVE_FFDHE_2048
10915 else if (use_ffdhe == 2048) {
10916#ifdef HAVE_PUBLIC_FFDHE
10917 params = wc_Dh_ffdhe2048_Get();
10918#else
10919 paramName = WC_FFDHE_2048;
10920#endif
10921 dhKeySz = 2048;
10922 }
10923#endif
10924#ifdef HAVE_FFDHE_3072
10925 else if (use_ffdhe == 3072) {
10926#ifdef HAVE_PUBLIC_FFDHE
10927 params = wc_Dh_ffdhe3072_Get();
10928#else
10929 paramName = WC_FFDHE_3072;
10930#endif
10931 dhKeySz = 3072;
10932 }
10933#endif
10934#ifdef HAVE_FFDHE_4096
10935 else if (use_ffdhe == 4096) {
10936#ifdef HAVE_PUBLIC_FFDHE
10937 params = wc_Dh_ffdhe4096_Get();
10938#else
10939 paramName = WC_FFDHE_4096;
10940#endif
10941 dhKeySz = 4096;
10942 }
10943#endif
10944
10945 /* init keys */
10946 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10947 /* setup an async context for each key */
10948 ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
10949 useDeviceID ? devId : INVALID_DEVID);
10950 if (ret != 0)
10951 goto exit;
10952
10953 /* setup key */
10954 if (!use_ffdhe) {
10955 #ifdef NO_ASN
10956 ret = wc_DhSetKey(dhKey[i], dh_p,
10957 sizeof(dh_p), dh_g, sizeof(dh_g));
10958 #else
10959 idx = 0;
10960 ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
10961 #endif
10962 }
10963 #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || \
10964 defined(HAVE_FFDHE_4096)
10965 #ifdef HAVE_PUBLIC_FFDHE
10966 else if (params != NULL) {
10967 ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
10968 params->g, params->g_len);
10969 }
10970 #else
10971 else if (paramName != 0) {
10972 ret = wc_DhSetNamedKey(dhKey[i], paramName);
10973 }
10974 #endif
10975 #endif
10976 if (ret != 0) {
10977 printf("DhKeyDecode failed %d, can't benchmark\n", ret);
10978 goto exit;
10979 }
10980 }
10981
10982
10983 /* Key Gen */
10984 bench_stats_start(&count, &start);
10985 PRIVATE_KEY_UNLOCK();
10986 do {
10987 /* while free pending slots in queue, submit ops */
10988 for (times = 0; times < genTimes || pending > 0; ) {
10989 bench_async_poll(&pending);
10990
10991 for (i = 0; i < BENCH_MAX_PENDING; i++) {
10992 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
10993 0, ×, genTimes, &pending)) {
10994 privSz[i] = BENCH_DH_PRIV_SIZE;
10995 pubSz[i] = BENCH_DH_KEY_SIZE;
10996 ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
10997 priv[i], &privSz[i],
10998 pub[i], &pubSz[i]);
10999 if (!bench_async_handle(&ret,
11000 BENCH_ASYNC_GET_DEV(dhKey[i]),
11001 0, ×, &pending)) {
11002 goto exit_dh_gen;
11003 }
11004 }
11005 } /* for i */
11006 RECORD_MULTI_VALUE_STATS();
11007 } /* for times */
11008 count += times;
11009 } while (bench_stats_check(start)
11010#ifdef MULTI_VALUE_STATISTICS
11011 || runs < minimum_runs
11012#endif
11013 );
11014
11015 PRIVATE_KEY_LOCK();
11016exit_dh_gen:
11017 bench_stats_asym_finish("DH", dhKeySz, desc[2],
11018 useDeviceID, count, start, ret);
11019#ifdef MULTI_VALUE_STATISTICS
11020 bench_multi_value_stats(max, min, sum, squareSum, runs);
11021#endif
11022
11023 if (ret < 0) {
11024 goto exit;
11025 }
11026
11027 RESET_MULTI_VALUE_STATS_VARS();
11028
11029 /* Generate key to use as other public */
11030 PRIVATE_KEY_UNLOCK();
11031 ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
11032 priv2, &privSz2, pub2, &pubSz2);
11033 PRIVATE_KEY_LOCK();
11034#ifdef WOLFSSL_ASYNC_CRYPT
11035 ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
11036#endif
11037
11038 /* Key Agree */
11039 bench_stats_start(&count, &start);
11040 PRIVATE_KEY_UNLOCK();
11041 do {
11042 for (times = 0; times < agreeTimes || pending > 0; ) {
11043 bench_async_poll(&pending);
11044
11045 /* while free pending slots in queue, submit ops */
11046 for (i = 0; i < BENCH_MAX_PENDING; i++) {
11047 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
11048 0, ×, agreeTimes, &pending)) {
11049 ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
11050 privSz[i], pub2, pubSz2);
11051 if (!bench_async_handle(&ret,
11052 BENCH_ASYNC_GET_DEV(dhKey[i]), 0, ×, &pending)) {
11053 goto exit;
11054 }
11055 }
11056 } /* for i */
11057 RECORD_MULTI_VALUE_STATS();
11058 } /* for times */
11059 count += times;
11060 } while (bench_stats_check(start)
11061#ifdef MULTI_VALUE_STATISTICS
11062 || runs < minimum_runs
11063#endif
11064 );
11065
11066 PRIVATE_KEY_LOCK();
11067
11068exit:
11069 bench_stats_asym_finish("DH", dhKeySz, desc[3],
11070 useDeviceID, count, start, ret);
11071#ifdef MULTI_VALUE_STATISTICS
11072 bench_multi_value_stats(max, min, sum, squareSum, runs);
11073#endif
11074
11075 /* cleanup */
11076 if (WC_ARRAY_OK(dhKey)) {
11077 for (i = 0; i < BENCH_MAX_PENDING; i++) {
11078 wc_FreeDhKey(dhKey[i]);
11079 }
11080 WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
11081 }
11082 WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
11083 WC_FREE_VAR(pub2, HEAP_HINT);
11084 WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
11085 WC_FREE_VAR(priv2, HEAP_HINT);
11086 WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
11087}
11088#endif /* !NO_DH && !WC_NO_RNG */
11089
11090#ifdef WOLFSSL_HAVE_MLKEM
11091static void bench_mlkem_keygen(int type, const char* name, int keySize,
11092 KyberKey* key)
11093{
11094#ifndef WOLFSSL_MLKEM_NO_MAKE_KEY
11095 int ret = 0, times, count, pending = 0;
11096 double start;
11097 const char**desc = bench_desc_words[lng_index];
11098 DECLARE_MULTI_VALUE_STATS_VARS()
11099
11100 bench_stats_prepare();
11101
11102 /* MLKEM Make Key */
11103 bench_stats_start(&count, &start);
11104 do {
11105 /* while free pending slots in queue, submit ops */
11106 for (times = 0; times < agreeTimes || pending > 0; times++) {
11107 wc_KyberKey_Free(key);
11108 ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
11109 if (ret != 0)
11110 goto exit;
11111
11112#ifdef MLKEM_NONDETERMINISTIC
11113 ret = wc_KyberKey_MakeKey(key, &gRng);
11114#else
11115 {
11116 unsigned char rand[WC_ML_KEM_MAKEKEY_RAND_SZ] = {0,};
11117 ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
11118 }
11119#endif
11120 if (ret != 0)
11121 goto exit;
11122 RECORD_MULTI_VALUE_STATS();
11123 } /* for times */
11124 count += times;
11125 } while (bench_stats_check(start)
11126#ifdef MULTI_VALUE_STATISTICS
11127 || runs < minimum_runs
11128#endif
11129 );
11130
11131exit:
11132 bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
11133#ifdef MULTI_VALUE_STATISTICS
11134 bench_multi_value_stats(max, min, sum, squareSum, runs);
11135#endif
11136#else
11137 (void)type;
11138 (void)name;
11139 (void)keySize;
11140 (void)key;
11141#endif /* !WOLFSSL_MLKEM_NO_MAKE_KEY */
11142}
11143
11144#if !defined(WOLFSSL_MLKEM_NO_ENCAPSULATE) || \
11145 !defined(WOLFSSL_MLKEM_NO_DECAPSULATE)
11146static void bench_mlkem_encap(int type, const char* name, int keySize,
11147 KyberKey* key1, KyberKey* key2)
11148{
11149 int ret = 0, times, count, pending = 0;
11150 double start;
11151 const char**desc = bench_desc_words[lng_index];
11152 WC_DECLARE_VAR(ct, byte, WC_ML_KEM_MAX_CIPHER_TEXT_SIZE, HEAP_HINT);
11153 WC_DECLARE_VAR(ss, byte, WC_ML_KEM_SS_SZ, HEAP_HINT);
11154 WC_DECLARE_VAR(pub, byte, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE, HEAP_HINT);
11155 word32 pubLen;
11156 word32 ctSz;
11157 DECLARE_MULTI_VALUE_STATS_VARS()
11158
11159 bench_stats_prepare();
11160
11161 WC_ALLOC_VAR(ct, byte, WC_ML_KEM_MAX_CIPHER_TEXT_SIZE, HEAP_HINT);
11162 WC_ALLOC_VAR(ss, byte, WC_ML_KEM_SS_SZ, HEAP_HINT);
11163 WC_ALLOC_VAR(pub, byte, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE, HEAP_HINT);
11164
11165 ret = wc_KyberKey_PublicKeySize(key1, &pubLen);
11166 if (ret != 0) {
11167 goto exit;
11168 }
11169 ret = wc_KyberKey_EncodePublicKey(key1, pub, pubLen);
11170 if (ret != 0) {
11171 goto exit;
11172 }
11173 ret = wc_KyberKey_Init(type, key2, HEAP_HINT, INVALID_DEVID);
11174 if (ret != 0) {
11175 goto exit;
11176 }
11177 ret = wc_KyberKey_DecodePublicKey(key2, pub, pubLen);
11178 if (ret != 0) {
11179 goto exit;
11180 }
11181
11182 ret = wc_KyberKey_CipherTextSize(key2, &ctSz);
11183 if (ret != 0) {
11184 goto exit;
11185 }
11186
11187#ifndef WOLFSSL_MLKEM_NO_ENCAPSULATE
11188 /* MLKEM Encapsulate */
11189 bench_stats_start(&count, &start);
11190 do {
11191 /* while free pending slots in queue, submit ops */
11192 for (times = 0; times < agreeTimes || pending > 0; times++) {
11193#ifdef MLKEM_NONDETERMINISTIC
11194 ret = wc_KyberKey_Encapsulate(key2, ct, ss, &gRng);
11195#else
11196 unsigned char rand[WC_ML_KEM_ENC_RAND_SZ] = {0,};
11197 ret = wc_KyberKey_EncapsulateWithRandom(key2, ct, ss, rand,
11198 sizeof(rand));
11199#endif
11200 if (ret != 0)
11201 goto exit_encap;
11202 RECORD_MULTI_VALUE_STATS();
11203 } /* for times */
11204 count += times;
11205 } while (bench_stats_check(start)
11206#ifdef MULTI_VALUE_STATISTICS
11207 || runs < minimum_runs
11208#endif
11209 );
11210
11211exit_encap:
11212 bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
11213#ifdef MULTI_VALUE_STATISTICS
11214 bench_multi_value_stats(max, min, sum, squareSum, runs);
11215#endif
11216#endif
11217
11218#ifndef WOLFSSL_MLKEM_NO_DECAPSULATE
11219 RESET_MULTI_VALUE_STATS_VARS();
11220
11221 /* MLKEM Decapsulate */
11222 PRIVATE_KEY_UNLOCK();
11223 bench_stats_start(&count, &start);
11224 do {
11225 /* while free pending slots in queue, submit ops */
11226 for (times = 0; times < agreeTimes || pending > 0; times++) {
11227 ret = wc_KyberKey_Decapsulate(key1, ss, ct, ctSz);
11228 if (ret != 0)
11229 goto exit_decap;
11230 RECORD_MULTI_VALUE_STATS();
11231 } /* for times */
11232 count += times;
11233 } while (bench_stats_check(start)
11234#ifdef MULTI_VALUE_STATISTICS
11235 || runs < minimum_runs
11236#endif
11237 );
11238
11239exit_decap:
11240 PRIVATE_KEY_LOCK();
11241 bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
11242#ifdef MULTI_VALUE_STATISTICS
11243 bench_multi_value_stats(max, min, sum, squareSum, runs);
11244#endif
11245
11246#endif
11247
11248exit:
11249
11250 WC_FREE_VAR(ct, HEAP_HINT);
11251 WC_FREE_VAR(ss, HEAP_HINT);
11252 WC_FREE_VAR(pub, HEAP_HINT);
11253
11254 if (ret != 0)
11255 printf("error: bench_mlkem_encap() failed with code %d.\n", ret);
11256
11257 return;
11258}
11259#endif
11260
11261void bench_mlkem(int type)
11262{
11263#ifdef WOLFSSL_SMALL_STACK
11264 KyberKey *key1 = NULL;
11265 KyberKey *key2 = NULL;
11266#else
11267 KyberKey key1[1];
11268 KyberKey key2[1];
11269#endif
11270 const char* name = NULL;
11271 int keySize = 0;
11272
11273 switch (type) {
11274#ifndef WOLFSSL_NO_ML_KEM
11275#ifdef WOLFSSL_WC_ML_KEM_512
11276 case WC_ML_KEM_512:
11277 name = "ML-KEM 512 ";
11278 keySize = 128;
11279 break;
11280#endif
11281#ifdef WOLFSSL_WC_ML_KEM_768
11282 case WC_ML_KEM_768:
11283 name = "ML-KEM 768 ";
11284 keySize = 192;
11285 break;
11286#endif
11287#ifdef WOLFSSL_WC_ML_KEM_1024
11288 case WC_ML_KEM_1024:
11289 name = "ML-KEM 1024";
11290 keySize = 256;
11291 break;
11292#endif
11293#endif
11294#ifdef WOLFSSL_MLKEM_KYBER
11295#ifdef WOLFSSL_KYBER512
11296 case KYBER512:
11297 name = "KYBER512 ";
11298 keySize = 128;
11299 break;
11300#endif
11301#ifdef WOLFSSL_KYBER768
11302 case KYBER768:
11303 name = "KYBER768 ";
11304 keySize = 192;
11305 break;
11306#endif
11307#ifdef WOLFSSL_KYBER1024
11308 case KYBER1024:
11309 name = "KYBER1024";
11310 keySize = 256;
11311 break;
11312#endif
11313#endif
11314 default:
11315 return;
11316 }
11317
11318#ifdef WOLFSSL_SMALL_STACK
11319 key1 = (KyberKey *)XMALLOC(sizeof(*key1), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
11320 if (key1 == NULL)
11321 return;
11322 key2 = (KyberKey *)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
11323 if (key2 == NULL) {
11324 XFREE(key1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
11325 return;
11326 }
11327#endif
11328
11329 bench_mlkem_keygen(type, name, keySize, key1);
11330#if !defined(WOLFSSL_MLKEM_NO_ENCAPSULATE) || \
11331 !defined(WOLFSSL_MLKEM_NO_DECAPSULATE)
11332 bench_mlkem_encap(type, name, keySize, key1, key2);
11333#endif
11334
11335 wc_KyberKey_Free(key2);
11336 wc_KyberKey_Free(key1);
11337
11338 WC_FREE_VAR_EX(key1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
11339 WC_FREE_VAR_EX(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
11340}
11341#endif
11342
11343#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
11344#ifndef WOLFSSL_WC_LMS_SERIALIZE_STATE
11345#ifndef WOLFSSL_NO_LMS_SHA256_256
11346/* WC_LMS_PARM_L2_H10_W2
11347 * signature length: 9300 */
11348static const byte lms_priv_L2_H10_W2[64] =
11349{
11350 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
11351 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
11352 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
11353 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
11354 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
11355 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
11356 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
11357 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
11358};
11359
11360static const byte lms_pub_L2_H10_W2[60] =
11361{
11362 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
11363 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
11364 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
11365 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
11366 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
11367 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
11368 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
11369 0x7F,0xC8,0x91,0xB0
11370};
11371
11372/* WC_LMS_PARM_L2_H10_W4
11373 * signature length: 5076 */
11374static const byte lms_priv_L2_H10_W4[64] =
11375{
11376 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
11377 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
11378 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
11379 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
11380 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
11381 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
11382 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
11383 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
11384};
11385
11386static const byte lms_pub_L2_H10_W4[60] =
11387{
11388 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
11389 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
11390 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
11391 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
11392 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
11393 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
11394 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
11395 0x6B,0x9A,0xD3,0x14
11396};
11397
11398/* WC_LMS_PARM_L3_H5_W4
11399 * signature length: 7160 */
11400static const byte lms_priv_L3_H5_W4[64] =
11401{
11402 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
11403 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
11404 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
11405 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
11406 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
11407 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
11408 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
11409 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
11410};
11411
11412static const byte lms_pub_L3_H5_W4[60] =
11413{
11414 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
11415 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
11416 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
11417 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
11418 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
11419 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
11420 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
11421 0xAB,0x4B,0x51,0x39
11422};
11423
11424/* WC_LMS_PARM_L3_H5_W8
11425 * signature length: 3992 */
11426static const byte lms_priv_L3_H5_W8[64] =
11427{
11428 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
11429 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
11430 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
11431 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
11432 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
11433 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
11434 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
11435 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
11436};
11437
11438static const byte lms_pub_L3_H5_W8[60] =
11439{
11440 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
11441 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
11442 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
11443 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
11444 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
11445 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
11446 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
11447 0x83,0xAB,0x43,0xAF
11448};
11449
11450/* WC_LMS_PARM_L3_H10_W4
11451 * signature length: 7640 */
11452static const byte lms_priv_L3_H10_W4[64] =
11453{
11454 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
11455 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
11456 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
11457 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
11458 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
11459 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
11460 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
11461 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
11462};
11463
11464static const byte lms_pub_L3_H10_W4[60] =
11465{
11466 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
11467 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
11468 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
11469 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
11470 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
11471 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
11472 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
11473 0x8D,0x78,0xD5,0xA8
11474};
11475
11476/* WC_LMS_PARM_L4_H5_W8
11477 * signature length: 5340 */
11478static const byte lms_priv_L4_H5_W8[64] =
11479{
11480 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
11481 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
11482 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
11483 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
11484 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
11485 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
11486 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
11487 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
11488};
11489
11490static const byte lms_pub_L4_H5_W8[60] =
11491{
11492 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
11493 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
11494 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
11495 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
11496 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
11497 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
11498 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
11499 0x74,0x24,0x12,0xC8
11500};
11501#endif
11502#endif /* WOLFSSL_WC_LMS_SERIALIZE_STATE */
11503
11504static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
11505{
11506 /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
11507 * BE USED FOR TESTING PURPOSES! Production applications should
11508 * write only to non-volatile storage. */
11509 XMEMCPY(context, priv, privSz);
11510 return WC_LMS_RC_SAVED_TO_NV_MEMORY;
11511}
11512
11513static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
11514{
11515 /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
11516 * BE USED FOR TESTING PURPOSES! */
11517 XMEMCPY(priv, context, privSz);
11518 return WC_LMS_RC_READ_TO_MEMORY;
11519}
11520#ifdef WOLFSSL_WC_LMS_SERIALIZE_STATE
11521static byte lms_priv[64*1024 + HSS_MAX_PRIVATE_KEY_LEN];
11522#else
11523static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
11524#endif
11525
11526static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
11527{
11528 WC_RNG rng;
11529 LmsKey key;
11530 int ret;
11531 word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
11532 int times = 0;
11533 int count = 0;
11534 double start = 0.0F;
11535 int levels;
11536 int height;
11537 int winternitz;
11538 const char* str = wc_LmsKey_ParmToStr(parm);
11539 DECLARE_MULTI_VALUE_STATS_VARS()
11540
11541 bench_stats_prepare();
11542
11543#ifndef HAVE_FIPS
11544 ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
11545#else
11546 ret = wc_InitRng(&rng);
11547#endif
11548 if (ret != 0) {
11549 printf("error: wc_InitRng failed: %d\n", ret);
11550 return;
11551 }
11552
11553 ret = wc_LmsKey_Init(&key, HEAP_HINT, INVALID_DEVID);
11554 if (ret) {
11555 printf("wc_LmsKey_Init failed: %d\n", ret);
11556 wc_FreeRng(&rng);
11557 return;
11558 }
11559
11560 count = 0;
11561 bench_stats_start(&count, &start);
11562
11563 do {
11564 /* LMS is stateful. Async queuing not practical. */
11565 for (times = 0; times < 1; ++times) {
11566
11567 wc_LmsKey_Free(&key);
11568
11569 ret = wc_LmsKey_Init(&key, HEAP_HINT, INVALID_DEVID);
11570 if (ret) {
11571 printf("wc_LmsKey_Init failed: %d\n", ret);
11572 goto exit_lms_keygen;
11573 }
11574
11575 ret = wc_LmsKey_SetLmsParm(&key, parm);
11576 if (ret) {
11577 printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
11578 goto exit_lms_keygen;
11579 }
11580
11581 ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
11582 if (ret) {
11583 printf("error: wc_LmsKey_GetParameters failed: %d\n",
11584 ret);
11585 goto exit_lms_keygen;
11586 }
11587
11588 ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
11589 if (ret) {
11590 printf("error: wc_LmsKey_SetWriteCb failed: %d\n",
11591 ret);
11592 goto exit_lms_keygen;
11593 }
11594
11595 ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
11596 if (ret) {
11597 printf("error: wc_LmsKey_SetReadCb failed: %d\n", ret);
11598 goto exit_lms_keygen;
11599 }
11600
11601 ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
11602 if (ret) {
11603 printf("error: wc_LmsKey_SetContext failed: %d\n",
11604 ret);
11605 goto exit_lms_keygen;
11606 }
11607
11608 ret = wc_LmsKey_MakeKey(&key, &rng);
11609 if (ret) {
11610 printf("wc_LmsKey_MakeKey failed: %d\n", ret);
11611 goto exit_lms_keygen;
11612 }
11613
11614 RECORD_MULTI_VALUE_STATS();
11615 }
11616
11617 count += times;
11618 } while (bench_stats_check(start)
11619#ifdef MULTI_VALUE_STATISTICS
11620 || runs < minimum_runs
11621#endif
11622 );
11623
11624 bench_stats_asym_finish(str, levels * height, "keygen", 0,
11625 count, start, ret);
11626#ifdef MULTI_VALUE_STATISTICS
11627 bench_multi_value_stats(max, min, sum, squareSum, runs);
11628#endif
11629
11630 ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
11631 if (ret) {
11632 printf("error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
11633 }
11634
11635exit_lms_keygen:
11636 wc_LmsKey_Free(&key);
11637 wc_FreeRng(&rng);
11638}
11639
11640static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
11641{
11642 LmsKey key;
11643 int ret = 0;
11644 const char * msg = TEST_STRING;
11645 word32 msgSz = TEST_STRING_SZ;
11646 byte * sig = NULL;
11647 word32 sigSz = 0;
11648 word32 privLen = 0;
11649 int loaded = 0;
11650 int times = 0;
11651 int count = 0;
11652 double start = 0.0F;
11653 const char * str = wc_LmsKey_ParmToStr(parm);
11654 DECLARE_MULTI_VALUE_STATS_VARS()
11655
11656 bench_stats_prepare();
11657
11658 ret = wc_LmsKey_Init(&key, HEAP_HINT, INVALID_DEVID);
11659 if (ret) {
11660 printf("wc_LmsKey_Init failed: %d\n", ret);
11661 goto exit_lms_sign_verify;
11662 }
11663
11664 ret = wc_LmsKey_SetLmsParm(&key, parm);
11665 if (ret) {
11666 printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
11667 goto exit_lms_sign_verify;
11668 }
11669
11670#ifndef WOLFSSL_WC_LMS_SERIALIZE_STATE
11671 switch (parm) {
11672#ifndef WOLFSSL_NO_LMS_SHA256_256
11673 case WC_LMS_PARM_L2_H10_W2:
11674 XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
11675 XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
11676 break;
11677
11678 case WC_LMS_PARM_L2_H10_W4:
11679 XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
11680 XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
11681 break;
11682
11683 case WC_LMS_PARM_L3_H5_W4:
11684 XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
11685 XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
11686 break;
11687
11688 case WC_LMS_PARM_L3_H5_W8:
11689 XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
11690 XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
11691 break;
11692
11693 case WC_LMS_PARM_L3_H10_W4:
11694 XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
11695 XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
11696 break;
11697
11698 case WC_LMS_PARM_L4_H5_W8:
11699 XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
11700 XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
11701 break;
11702
11703 case WC_LMS_PARM_L1_H15_W2:
11704 case WC_LMS_PARM_L1_H15_W4:
11705 case WC_LMS_PARM_L2_H10_W8:
11706 case WC_LMS_PARM_L3_H5_W2:
11707 case WC_LMS_PARM_L1_H5_W1:
11708 case WC_LMS_PARM_L1_H5_W2:
11709 case WC_LMS_PARM_L1_H5_W4:
11710 case WC_LMS_PARM_L1_H5_W8:
11711 case WC_LMS_PARM_L1_H10_W2:
11712 case WC_LMS_PARM_L1_H10_W4:
11713 case WC_LMS_PARM_L1_H10_W8:
11714 case WC_LMS_PARM_L1_H15_W8:
11715 case WC_LMS_PARM_L1_H20_W2:
11716 case WC_LMS_PARM_L1_H20_W4:
11717 case WC_LMS_PARM_L1_H20_W8:
11718 case WC_LMS_PARM_L2_H5_W2:
11719 case WC_LMS_PARM_L2_H5_W4:
11720 case WC_LMS_PARM_L2_H5_W8:
11721 case WC_LMS_PARM_L2_H15_W2:
11722 case WC_LMS_PARM_L2_H15_W4:
11723 case WC_LMS_PARM_L2_H15_W8:
11724 case WC_LMS_PARM_L2_H20_W2:
11725 case WC_LMS_PARM_L2_H20_W4:
11726 case WC_LMS_PARM_L2_H20_W8:
11727 case WC_LMS_PARM_L3_H10_W8:
11728 case WC_LMS_PARM_L4_H5_W2:
11729 case WC_LMS_PARM_L4_H5_W4:
11730 case WC_LMS_PARM_L4_H10_W4:
11731 case WC_LMS_PARM_L4_H10_W8:
11732 case WC_LMS_PARM_L1_H25_W1:
11733 case WC_LMS_PARM_L1_H25_W2:
11734 case WC_LMS_PARM_L1_H25_W4:
11735 case WC_LMS_PARM_L1_H25_W8:
11736 case WC_LMS_PARM_L1_H10_W1:
11737 case WC_LMS_PARM_L1_H15_W1:
11738 case WC_LMS_PARM_L1_H20_W1:
11739#endif
11740
11741#ifdef WOLFSSL_LMS_SHA256_192
11742 case WC_LMS_PARM_SHA256_192_L1_H5_W1:
11743 case WC_LMS_PARM_SHA256_192_L1_H5_W2:
11744 case WC_LMS_PARM_SHA256_192_L1_H5_W4:
11745 case WC_LMS_PARM_SHA256_192_L1_H5_W8:
11746 case WC_LMS_PARM_SHA256_192_L1_H10_W2:
11747 case WC_LMS_PARM_SHA256_192_L1_H10_W4:
11748 case WC_LMS_PARM_SHA256_192_L1_H10_W8:
11749 case WC_LMS_PARM_SHA256_192_L1_H15_W2:
11750 case WC_LMS_PARM_SHA256_192_L1_H15_W4:
11751 case WC_LMS_PARM_SHA256_192_L1_H20_W2:
11752 case WC_LMS_PARM_SHA256_192_L1_H20_W4:
11753 case WC_LMS_PARM_SHA256_192_L1_H20_W8:
11754 case WC_LMS_PARM_SHA256_192_L2_H10_W2:
11755 case WC_LMS_PARM_SHA256_192_L2_H10_W4:
11756 case WC_LMS_PARM_SHA256_192_L2_H10_W8:
11757 case WC_LMS_PARM_SHA256_192_L3_H5_W2:
11758 case WC_LMS_PARM_SHA256_192_L3_H5_W4:
11759 case WC_LMS_PARM_SHA256_192_L3_H5_W8:
11760 case WC_LMS_PARM_SHA256_192_L3_H10_W4:
11761 case WC_LMS_PARM_SHA256_192_L4_H5_W8:
11762 case WC_LMS_PARM_SHA256_192_L1_H25_W1:
11763 case WC_LMS_PARM_SHA256_192_L1_H25_W2:
11764 case WC_LMS_PARM_SHA256_192_L1_H25_W4:
11765 case WC_LMS_PARM_SHA256_192_L1_H25_W8:
11766 case WC_LMS_PARM_SHA256_192_L1_H10_W1:
11767 case WC_LMS_PARM_SHA256_192_L1_H15_W1:
11768 case WC_LMS_PARM_SHA256_192_L1_H20_W1:
11769 case WC_LMS_PARM_SHA256_192_L1_H15_W8:
11770#endif
11771
11772#ifdef WOLFSSL_LMS_SHAKE256
11773 case WC_LMS_PARM_SHAKE_L1_H5_W1:
11774 case WC_LMS_PARM_SHAKE_L1_H5_W2:
11775 case WC_LMS_PARM_SHAKE_L1_H5_W4:
11776 case WC_LMS_PARM_SHAKE_L1_H5_W8:
11777 case WC_LMS_PARM_SHAKE_L1_H10_W1:
11778 case WC_LMS_PARM_SHAKE_L1_H10_W2:
11779 case WC_LMS_PARM_SHAKE_L1_H10_W4:
11780 case WC_LMS_PARM_SHAKE_L1_H10_W8:
11781 case WC_LMS_PARM_SHAKE_L1_H15_W1:
11782 case WC_LMS_PARM_SHAKE_L1_H15_W2:
11783 case WC_LMS_PARM_SHAKE_L1_H15_W4:
11784 case WC_LMS_PARM_SHAKE_L1_H15_W8:
11785 case WC_LMS_PARM_SHAKE_L1_H20_W1:
11786 case WC_LMS_PARM_SHAKE_L1_H20_W2:
11787 case WC_LMS_PARM_SHAKE_L1_H20_W4:
11788 case WC_LMS_PARM_SHAKE_L1_H20_W8:
11789 case WC_LMS_PARM_SHAKE_L1_H25_W1:
11790 case WC_LMS_PARM_SHAKE_L1_H25_W2:
11791 case WC_LMS_PARM_SHAKE_L1_H25_W4:
11792 case WC_LMS_PARM_SHAKE_L1_H25_W8:
11793 case WC_LMS_PARM_SHAKE192_L1_H5_W1:
11794 case WC_LMS_PARM_SHAKE192_L1_H5_W2:
11795 case WC_LMS_PARM_SHAKE192_L1_H5_W4:
11796 case WC_LMS_PARM_SHAKE192_L1_H5_W8:
11797 case WC_LMS_PARM_SHAKE192_L1_H10_W1:
11798 case WC_LMS_PARM_SHAKE192_L1_H10_W2:
11799 case WC_LMS_PARM_SHAKE192_L1_H10_W4:
11800 case WC_LMS_PARM_SHAKE192_L1_H10_W8:
11801 case WC_LMS_PARM_SHAKE192_L1_H15_W1:
11802 case WC_LMS_PARM_SHAKE192_L1_H15_W2:
11803 case WC_LMS_PARM_SHAKE192_L1_H15_W4:
11804 case WC_LMS_PARM_SHAKE192_L1_H15_W8:
11805 case WC_LMS_PARM_SHAKE192_L1_H20_W1:
11806 case WC_LMS_PARM_SHAKE192_L1_H20_W2:
11807 case WC_LMS_PARM_SHAKE192_L1_H20_W4:
11808 case WC_LMS_PARM_SHAKE192_L1_H20_W8:
11809 case WC_LMS_PARM_SHAKE192_L1_H25_W1:
11810 case WC_LMS_PARM_SHAKE192_L1_H25_W2:
11811 case WC_LMS_PARM_SHAKE192_L1_H25_W4:
11812 case WC_LMS_PARM_SHAKE192_L1_H25_W8:
11813#endif
11814
11815 default:
11816 XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
11817 break;
11818 }
11819#else
11820 XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
11821#endif
11822
11823 ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
11824 if (ret) {
11825 printf("error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
11826 goto exit_lms_sign_verify;
11827 }
11828
11829 ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
11830 if (ret) {
11831 printf("error: wc_LmsKey_SetReadCb failed: %d\n", ret);
11832 goto exit_lms_sign_verify;
11833 }
11834
11835 ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
11836 if (ret) {
11837 printf("error: wc_LmsKey_SetContext failed: %d\n", ret);
11838 goto exit_lms_sign_verify;
11839 }
11840
11841 /* Even with saved priv/pub keys, we must still reload the private
11842 * key before using it. Reloading the private key is the bottleneck
11843 * for larger heights. Only print load time in debug builds. */
11844 count = 0;
11845 bench_stats_start(&count, &start);
11846
11847#ifndef WOLFSSL_WC_LMS_SMALL
11848 do {
11849 key.priv.inited = 0;
11850 key.state = WC_LMS_STATE_PARMSET;
11851 ret = wc_LmsKey_Reload(&key);
11852 if (ret) {
11853 printf("wc_LmsKey_Reload failed: %d\n", ret);
11854 goto exit_lms_sign_verify;
11855 }
11856 RECORD_MULTI_VALUE_STATS();
11857
11858 count++;
11859
11860 ret = wc_LmsKey_GetSigLen(&key, &sigSz);
11861 if (ret) {
11862 printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
11863 goto exit_lms_sign_verify;
11864 }
11865
11866 ret = wc_LmsKey_GetPrivLen(&key, &privLen);
11867 if (ret) {
11868 printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
11869 goto exit_lms_sign_verify;
11870 }
11871 } while (bench_stats_check(start)
11872#ifdef MULTI_VALUE_STATISTICS
11873 || runs < minimum_runs
11874#endif
11875 );
11876
11877 bench_stats_asym_finish(str, (int)privLen, "load", 0,
11878 count, start, ret);
11879#ifdef MULTI_VALUE_STATISTICS
11880 bench_multi_value_stats(max, min, sum, squareSum, runs);
11881#endif
11882
11883 RESET_MULTI_VALUE_STATS_VARS();
11884#else
11885 ret = wc_LmsKey_Reload(&key);
11886 if (ret) {
11887 printf("wc_LmsKey_Reload failed: %d\n", ret);
11888 goto exit_lms_sign_verify;
11889 }
11890 ret = wc_LmsKey_GetSigLen(&key, &sigSz);
11891 if (ret) {
11892 printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
11893 goto exit_lms_sign_verify;
11894 }
11895 ret = wc_LmsKey_GetPrivLen(&key, &privLen);
11896 if (ret) {
11897 printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
11898 goto exit_lms_sign_verify;
11899 }
11900#endif
11901
11902 loaded = 1;
11903
11904 sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
11905 if (sig == NULL) {
11906 printf("bench_lms_sign_verify malloc failed\n");
11907 goto exit_lms_sign_verify;
11908 }
11909
11910 count = 0;
11911 bench_stats_start(&count, &start);
11912
11913 do {
11914 /* LMS is stateful. Async queuing not practical. */
11915#ifndef WOLFSSL_WC_LMS_SMALL
11916 for (times = 0; times < ntimes; ++times)
11917#else
11918 for (times = 0; times < 1; ++times)
11919#endif
11920 {
11921 ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
11922 if (ret) {
11923 printf("wc_LmsKey_Sign failed: %d\n", ret);
11924 goto exit_lms_sign_verify;
11925 }
11926 RECORD_MULTI_VALUE_STATS();
11927 if (!wc_LmsKey_SigsLeft(&key)) {
11928 break;
11929 }
11930 }
11931
11932 count += times;
11933 } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
11934#ifdef MULTI_VALUE_STATISTICS
11935 || runs < minimum_runs
11936#endif
11937 ));
11938
11939 bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
11940 count, start, ret);
11941#ifdef MULTI_VALUE_STATISTICS
11942 bench_multi_value_stats(max, min, sum, squareSum, runs);
11943#endif
11944
11945 RESET_MULTI_VALUE_STATS_VARS();
11946 count = 0;
11947 bench_stats_start(&count, &start);
11948
11949 do {
11950 /* LMS is stateful. Async queuing not practical. */
11951 for (times = 0; times < ntimes; ++times) {
11952 ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
11953 if (ret) {
11954 printf("wc_LmsKey_Verify failed: %d\n", ret);
11955 goto exit_lms_sign_verify;
11956 }
11957 RECORD_MULTI_VALUE_STATS();
11958 }
11959
11960 count += times;
11961 } while (bench_stats_check(start)
11962#ifdef MULTI_VALUE_STATISTICS
11963 || runs < minimum_runs
11964#endif
11965 );
11966
11967exit_lms_sign_verify:
11968 bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
11969 count, start, ret);
11970#ifdef MULTI_VALUE_STATISTICS
11971 bench_multi_value_stats(max, min, sum, squareSum, runs);
11972#endif
11973
11974
11975 if (loaded) {
11976 wc_LmsKey_Free(&key);
11977 }
11978 XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
11979
11980 return;
11981}
11982
11983void bench_lms(void)
11984{
11985 byte pub[HSS_MAX_PUBLIC_KEY_LEN];
11986
11987#ifndef WOLFSSL_NO_LMS_SHA256_256
11988#ifdef BENCH_LMS_SLOW_KEYGEN
11989#if (LMS_MAX_HEIGHT >= 15)
11990 bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
11991 bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
11992 bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
11993 bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
11994 #undef LMS_PARAMS_BENCHED
11995 #define LMS_PARAMS_BENCHED
11996#endif
11997#endif
11998#if (LMS_MAX_LEVELS >= 2) && (LMS_MAX_HEIGHT >= 10)
11999 bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
12000 bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
12001 bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
12002 bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
12003 #undef LMS_PARAMS_BENCHED
12004 #define LMS_PARAMS_BENCHED
12005#ifdef BENCH_LMS_SLOW_KEYGEN
12006 bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
12007 bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
12008#endif
12009#endif
12010#if (LMS_MAX_LEVELS >= 3)
12011 bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
12012 bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
12013 bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
12014 bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
12015 #undef LMS_PARAMS_BENCHED
12016 #define LMS_PARAMS_BENCHED
12017#endif
12018#if (LMS_MAX_LEVELS >= 3) && (LMS_MAX_HEIGHT >= 10)
12019 bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
12020 bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
12021#endif
12022#if (LMS_MAX_LEVELS >= 4)
12023 bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
12024 bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
12025#endif
12026
12027#ifndef LMS_PARAMS_BENCHED
12028 bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
12029 bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
12030#endif
12031#endif /* !WOLFSSL_NO_LMS_SHA256_256 */
12032
12033#ifdef WOLFSSL_LMS_SHA256_192
12034#ifdef BENCH_LMS_SLOW_KEYGEN
12035#if (LMS_MAX_HEIGHT >= 15)
12036 bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
12037 bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
12038 bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
12039 bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
12040 #undef LMS_PARAMS_BENCHED
12041 #define LMS_PARAMS_BENCHED
12042#endif
12043#endif
12044#if (LMS_MAX_LEVELS >= 2) && (LMS_MAX_HEIGHT >= 10)
12045 bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
12046 bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
12047 bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
12048 bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
12049 #undef LMS_PARAMS_BENCHED
12050 #define LMS_PARAMS_BENCHED
12051#ifdef BENCH_LMS_SLOW_KEYGEN
12052 bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
12053 bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
12054#endif
12055#endif
12056#if (LMS_MAX_LEVELS >= 3)
12057 bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
12058 bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
12059 bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
12060 bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
12061 #undef LMS_PARAMS_BENCHED
12062 #define LMS_PARAMS_BENCHED
12063#endif
12064#if (LMS_MAX_LEVELS >= 3) && (LMS_MAX_HEIGHT >= 10)
12065 bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
12066 bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
12067#endif
12068#if (LMS_MAX_LEVELS >= 4)
12069 bench_lms_keygen(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
12070 bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
12071#endif
12072
12073#ifndef LMS_PARAMS_BENCHED
12074 bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
12075 bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
12076#endif
12077#endif /* WOLFSSL_LMS_SHA256_192 */
12078
12079 return;
12080}
12081
12082#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
12083
12084#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
12085
12086static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
12087 void *context)
12088{
12089 /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
12090 * BE USED FOR TESTING PURPOSES! Production applications should
12091 * write only to non-volatile storage. */
12092 XMEMCPY(context, priv, privSz);
12093 return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
12094}
12095
12096static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
12097 void *context)
12098{
12099 /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
12100 * BE USED FOR TESTING PURPOSES! */
12101 XMEMCPY(priv, context, privSz);
12102 return WC_XMSS_RC_READ_TO_MEMORY;
12103}
12104
12105static void bench_xmss_sign_verify(const char * params)
12106{
12107 WC_RNG rng;
12108 XmssKey key;
12109 word32 pkSz = 0;
12110 word32 skSz = 0;
12111 int freeRng = 0;
12112 int freeKey = 0;
12113 unsigned char * sk = NULL;
12114 const char * msg = "XMSS post quantum signature test";
12115 word32 msgSz = (word32) XSTRLEN(msg);
12116 int ret = 0;
12117 byte * sig = NULL;
12118 word32 sigSz = 0;
12119 int times = 0;
12120 int count = 0;
12121 double start = 0.0F;
12122
12123 bench_stats_prepare();
12124
12125#ifndef HAVE_FIPS
12126 ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
12127#else
12128 ret = wc_InitRng(&rng);
12129#endif
12130 if (ret != 0) {
12131 printf("error: wc_InitRng failed: %d\n", ret);
12132 goto exit_xmss_sign_verify;
12133 }
12134
12135 freeRng = 1;
12136
12137 ret = wc_XmssKey_Init(&key, HEAP_HINT, INVALID_DEVID);
12138 if (ret != 0) {
12139 printf("wc_XmssKey_Init failed: %d\n", ret);
12140 goto exit_xmss_sign_verify;
12141 }
12142
12143 ret = wc_XmssKey_SetParamStr(&key, params);
12144 if (ret != 0) {
12145 printf("wc_XmssKey_SetParamStr failed: %d\n", ret);
12146 goto exit_xmss_sign_verify;
12147 }
12148
12149 ret = wc_XmssKey_GetPubLen(&key, &pkSz);
12150 if (ret != 0) {
12151 printf("wc_XmssKey_GetPubLen failed: %d\n", ret);
12152 goto exit_xmss_sign_verify;
12153 }
12154
12155 ret = wc_XmssKey_GetPrivLen(&key, &skSz);
12156 if (ret != 0 || skSz <= 0) {
12157 printf("error: wc_XmssKey_GetPrivLen failed\n");
12158 goto exit_xmss_sign_verify;
12159 }
12160
12161 ret = wc_XmssKey_GetSigLen(&key, &sigSz);
12162 if (ret != 0 || sigSz <= 0) {
12163 printf("error: wc_XmssKey_GetSigLen failed\n");
12164 goto exit_xmss_sign_verify;
12165 }
12166
12167 /* Allocate secret keys.*/
12168 sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
12169 if (sk == NULL) {
12170 printf("error: allocate xmss sk failed\n");
12171 goto exit_xmss_sign_verify;
12172 }
12173
12174 /* Allocate signature array. */
12175 sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
12176 if (sig == NULL) {
12177 printf("error: allocate xmss sig failed\n");
12178 goto exit_xmss_sign_verify;
12179 }
12180
12181 ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
12182 if (ret != 0) {
12183 printf("error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
12184 goto exit_xmss_sign_verify;
12185 }
12186
12187 ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
12188 if (ret != 0) {
12189 printf("error: wc_XmssKey_SetReadCb failed: %d\n", ret);
12190 goto exit_xmss_sign_verify;
12191 }
12192
12193 ret = wc_XmssKey_SetContext(&key, (void *)sk);
12194 if (ret != 0) {
12195 printf("error: wc_XmssKey_SetContext failed: %d\n", ret);
12196 goto exit_xmss_sign_verify;
12197 }
12198
12199#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
12200 printf("params: %s\n", params);
12201 printf("pkSz: %d\n", pkSz);
12202 printf("skSz: %d\n", skSz);
12203 printf("sigSz: %d\n", sigSz);
12204#endif
12205
12206 /* Making the private key is the bottleneck for larger heights. */
12207 count = 0;
12208 bench_stats_start(&count, &start);
12209
12210 ret = wc_XmssKey_MakeKey(&key, &rng);
12211 if (ret != 0) {
12212 printf("wc_XmssKey_MakeKey failed: %d\n", ret);
12213 goto exit_xmss_sign_verify;
12214 }
12215 /* Can only do one at a time - state changes after make key. */
12216
12217 count +=1;
12218
12219 bench_stats_check(start);
12220 bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
12221
12222 freeKey = 1;
12223
12224 count = 0;
12225 bench_stats_start(&count, &start);
12226
12227 do {
12228 /* XMSS is stateful. Async queuing not practical. */
12229#ifndef WOLFSSL_WC_XMSS_SMALL
12230 for (times = 0; times < ntimes; ++times)
12231#else
12232 for (times = 0; times < 1; ++times)
12233#endif
12234 {
12235 if (!wc_XmssKey_SigsLeft(&key))
12236 break;
12237 ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
12238 if (ret) {
12239 printf("wc_XmssKey_Sign failed: %d\n", ret);
12240 goto exit_xmss_sign_verify;
12241 }
12242 }
12243 count += times;
12244 } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
12245
12246 bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
12247
12248 count = 0;
12249 bench_stats_start(&count, &start);
12250
12251 do {
12252 /* XMSS is stateful. Async queuing not practical. */
12253 for (times = 0; times < ntimes; ++times) {
12254 ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
12255 if (ret) {
12256 printf("wc_XmssKey_Verify failed: %d\n", ret);
12257 goto exit_xmss_sign_verify;
12258 }
12259 }
12260 count += times;
12261 } while (bench_stats_check(start));
12262
12263exit_xmss_sign_verify:
12264 bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
12265
12266 /* Cleanup everything. */
12267 XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
12268 sig = NULL;
12269
12270 XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
12271 sk = NULL;
12272
12273 if (freeRng) {
12274 wc_FreeRng(&rng);
12275 }
12276
12277 if (freeKey) {
12278 wc_XmssKey_Free(&key);
12279 }
12280
12281 return;
12282}
12283
12284void bench_xmss(int hash)
12285{
12286 /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
12287 * sets.
12288 *
12289 * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
12290 * and "XMSSMT-SHA2_60/3_256", because their keygen can be
12291 * very slow, their signatures and private keys quite large,
12292 * and xmss private keys are not portable across different
12293 * XMSS/XMSS^MT implementations.
12294 *
12295 * The bottleneck in key generation is the height of the first
12296 * level tree (or h/d).
12297 *
12298 * h is the total height of the hyper tree, and d the number of
12299 * trees.
12300 */
12301 /* h/d h d */
12302#ifdef WC_XMSS_SHA256
12303 if (hash == WC_HASH_TYPE_SHA256) {
12304#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
12305#if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
12306 bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
12307#endif
12308#if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
12309#ifdef BENCH_XMSS_SLOW_KEYGEN
12310 bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
12311#endif
12312#endif
12313#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12314#ifdef BENCH_XMSS_SLOW_KEYGEN
12315 bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
12316#endif
12317#endif
12318#endif /* HASH_SIZE 256 */
12319#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
12320#if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
12321 bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
12322#endif
12323#if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
12324#ifdef BENCH_XMSS_SLOW_KEYGEN
12325 bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
12326#endif
12327#endif
12328#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12329#ifdef BENCH_XMSS_SLOW_KEYGEN
12330 bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
12331#endif
12332#endif
12333#endif /* HASH_SIZE 192 */
12334#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
12335#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12336 bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
12337 bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
12338#endif
12339#if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
12340#ifdef BENCH_XMSS_SLOW_KEYGEN
12341 bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
12342#endif
12343 bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
12344 bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
12345#endif
12346#if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
12347#ifdef BENCH_XMSS_SLOW_KEYGEN
12348 bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
12349#endif
12350 bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
12351 bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
12352#endif
12353#endif /* HASH_SIZE 256 */
12354#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
12355#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12356 bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
12357 bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
12358#endif
12359#if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
12360#ifdef BENCH_XMSS_SLOW_KEYGEN
12361 bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
12362#endif
12363 bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
12364 bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
12365#endif
12366#if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
12367#ifdef BENCH_XMSS_SLOW_KEYGEN
12368 bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
12369#endif
12370 bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
12371 bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
12372#endif
12373#endif /* HASH_SIZE 192 */
12374 }
12375#endif
12376#ifdef WC_XMSS_SHA512
12377#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
12378 if (hash == WC_HASH_TYPE_SHA512) {
12379#if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
12380 bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
12381#endif
12382#if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
12383#ifdef BENCH_XMSS_SLOW_KEYGEN
12384 bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
12385#endif
12386#endif
12387#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12388#ifdef BENCH_XMSS_SLOW_KEYGEN
12389 bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
12390#endif
12391#endif
12392#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12393 bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
12394 bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
12395#endif
12396#if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
12397#ifdef BENCH_XMSS_SLOW_KEYGEN
12398 bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
12399#endif
12400#ifdef BENCH_XMSS_SLOW_KEYGEN
12401 bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
12402#endif
12403 bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
12404#endif
12405#if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
12406#ifdef BENCH_XMSS_SLOW_KEYGEN
12407 bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
12408#endif
12409#ifdef BENCH_XMSS_SLOW_KEYGEN
12410 bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
12411#endif
12412 bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
12413#endif
12414 }
12415#endif /* HASH_SIZE 512 */
12416#endif
12417#ifdef WC_XMSS_SHAKE128
12418#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
12419 if (hash == WC_HASH_TYPE_SHAKE128) {
12420#if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
12421 bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
12422#endif
12423#if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
12424#ifdef BENCH_XMSS_SLOW_KEYGEN
12425 bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
12426#endif
12427#endif
12428#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12429#ifdef BENCH_XMSS_SLOW_KEYGEN
12430 bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
12431#endif
12432#endif
12433#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12434 bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
12435 bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
12436#endif
12437#if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
12438#ifdef BENCH_XMSS_SLOW_KEYGEN
12439 bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
12440#endif
12441#ifdef BENCH_XMSS_SLOW_KEYGEN
12442 bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
12443#endif
12444 bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
12445#endif
12446#if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
12447#ifdef BENCH_XMSS_SLOW_KEYGEN
12448 bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
12449#endif
12450#ifdef BENCH_XMSS_SLOW_KEYGEN
12451 bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
12452#endif
12453 bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
12454#endif
12455 }
12456#endif /* HASH_SIZE 256 */
12457#endif
12458#ifdef WC_XMSS_SHAKE256
12459 if (hash == WC_HASH_TYPE_SHAKE256) {
12460#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
12461#if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
12462 bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
12463#endif
12464#if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
12465#ifdef BENCH_XMSS_SLOW_KEYGEN
12466 bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
12467#endif
12468#endif
12469#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12470#ifdef BENCH_XMSS_SLOW_KEYGEN
12471 bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
12472#endif
12473#endif
12474#endif /* HASH_SIZE 512 */
12475#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
12476#if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
12477 bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
12478#endif
12479#if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
12480#ifdef BENCH_XMSS_SLOW_KEYGEN
12481 bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
12482#endif
12483#endif
12484#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12485#ifdef BENCH_XMSS_SLOW_KEYGEN
12486 bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
12487#endif
12488#endif
12489#endif /* HASH_SIZE 256 */
12490#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
12491#if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
12492 bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
12493#endif
12494#if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
12495#ifdef BENCH_XMSS_SLOW_KEYGEN
12496 bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
12497#endif
12498#endif
12499#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12500#ifdef BENCH_XMSS_SLOW_KEYGEN
12501 bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
12502#endif
12503#endif
12504#endif /* HASH_SIZE 192 */
12505#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
12506#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12507#ifdef BENCH_XMSS_SLOW_KEYGEN
12508 bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
12509#endif
12510 bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
12511#endif
12512#if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
12513#ifdef BENCH_XMSS_SLOW_KEYGEN
12514 bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
12515#endif
12516#ifdef BENCH_XMSS_SLOW_KEYGEN
12517 bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
12518#endif
12519 bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
12520#endif
12521#if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
12522#ifdef BENCH_XMSS_SLOW_KEYGEN
12523 bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
12524#endif
12525#ifdef BENCH_XMSS_SLOW_KEYGEN
12526 bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
12527#endif
12528 bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
12529#endif
12530#endif /* HASH_SIZE 512 */
12531#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
12532#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12533 bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
12534 bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
12535#endif
12536#if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
12537#ifdef BENCH_XMSS_SLOW_KEYGEN
12538 bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
12539#endif
12540#ifdef BENCH_XMSS_SLOW_KEYGEN
12541 bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
12542#endif
12543 bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
12544#endif
12545#if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
12546#ifdef BENCH_XMSS_SLOW_KEYGEN
12547 bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
12548#endif
12549#ifdef BENCH_XMSS_SLOW_KEYGEN
12550 bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
12551#endif
12552 bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
12553#endif
12554#endif /* HASH_SIZE 256 */
12555#if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
12556#if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
12557 bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
12558 bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
12559#endif
12560#if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
12561#ifdef BENCH_XMSS_SLOW_KEYGEN
12562 bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
12563#endif
12564#ifdef BENCH_XMSS_SLOW_KEYGEN
12565 bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
12566#endif
12567 bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
12568#endif
12569#if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
12570#ifdef BENCH_XMSS_SLOW_KEYGEN
12571 bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
12572#endif
12573#ifdef BENCH_XMSS_SLOW_KEYGEN
12574 bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
12575#endif
12576 bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
12577#endif
12578#endif /* HASH_SIZE 192 */
12579 }
12580#endif
12581 return;
12582}
12583#endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
12584
12585#if defined(WOLFSSL_HAVE_SLHDSA) && !defined(WOLFSSL_SLHDSA_VERIFY_ONLY)
12586void bench_slhdsa(int param)
12587{
12588 int ret = 0, count = 0;
12589 double start = 0;
12590 WC_DECLARE_VAR(key, SlhDsaKey, 1, HEAP_HINT);
12591 WC_DECLARE_VAR(key_vfy, SlhDsaKey, 1, HEAP_HINT);
12592 WC_DECLARE_VAR(sig, byte, WC_SLHDSA_MAX_SIG_LEN, HEAP_HINT);
12593 word32 sigLen;
12594 byte pk[2 * 32];
12595 word32 outLen;
12596 static const byte msg[] = {
12597 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f,
12598 0x72, 0x6c, 0x64, 0x21
12599 };
12600 byte ctx[1];
12601 char name[30];
12602 int len;
12603
12604 WC_ALLOC_VAR_EX(key_vfy, SlhDsaKey, 1, HEAP_HINT,
12605 DYNAMIC_TYPE_TMP_BUFFER, goto exit);
12606 XMEMSET(key_vfy, 0, sizeof(*key_vfy));
12607
12608 WC_ALLOC_VAR_EX(key, SlhDsaKey, 1, HEAP_HINT,
12609 DYNAMIC_TYPE_TMP_BUFFER, goto exit);
12610 XMEMSET(key, 0, sizeof(*key));
12611
12612 WC_ALLOC_VAR_EX(sig, byte, WC_SLHDSA_MAX_SIG_LEN, HEAP_HINT,
12613 DYNAMIC_TYPE_TMP_BUFFER, goto exit);
12614
12615 ret = wc_SlhDsaKey_Init(key, (enum SlhDsaParam)param, HEAP_HINT,
12616 INVALID_DEVID);
12617 if (ret != 0) {
12618 goto exit;
12619 }
12620
12621 len = wc_SlhDsaKey_PublicSize(key) / 2 * 8;
12622 if (SLHDSA_IS_SHA2((enum SlhDsaParam)param)) {
12623 XMEMCPY(name, "SLH-DSA-SHA2-S", 15);
12624 if ((param & 1) == 1) {
12625 name[13] = 'F';
12626 }
12627 }
12628 else {
12629 /* SHAKE family: include the SHAKE token explicitly so output rows
12630 * are symmetric with the SHA2 branch (e.g. "SLH-DSA-SHAKE-S" /
12631 * "SLH-DSA-SHAKE-F" rather than the previous "SLH-DSA-S"). */
12632 XMEMCPY(name, "SLH-DSA-SHAKE-S", 16);
12633 if ((param & 1) == 1) {
12634 name[14] = 'F';
12635 }
12636 }
12637
12638 bench_stats_start(&count, &start);
12639 do {
12640 ret = wc_SlhDsaKey_MakeKey(key, &gRng);
12641 if (ret != 0) {
12642 goto exit;
12643 }
12644 count++;
12645 RECORD_MULTI_VALUE_STATS();
12646 } while (bench_stats_check(start)
12647#ifdef MULTI_VALUE_STATISTICS
12648 || runs < minimum_runs
12649#endif
12650 );
12651 bench_stats_asym_finish(name, len, "gen", 0, count, start, ret);
12652
12653 PRIVATE_KEY_UNLOCK();
12654 bench_stats_start(&count, &start);
12655 do {
12656 sigLen = WC_SLHDSA_MAX_SIG_LEN;
12657 ret = wc_SlhDsaKey_Sign(key, ctx, 0, msg, (word32)sizeof(msg),
12658 sig, &sigLen, &gRng);
12659 if (ret != 0) {
12660 goto exit;
12661 }
12662 count++;
12663 RECORD_MULTI_VALUE_STATS();
12664 } while (bench_stats_check(start)
12665#ifdef MULTI_VALUE_STATISTICS
12666 || runs < minimum_runs
12667#endif
12668 );
12669 PRIVATE_KEY_LOCK();
12670 bench_stats_asym_finish(name, len, "sign", 0, count, start, ret);
12671
12672 outLen = (word32)sizeof(pk);
12673 ret = wc_SlhDsaKey_ExportPublic(key, pk, &outLen);
12674 if (ret != 0) {
12675 goto exit;
12676 }
12677
12678 ret = wc_SlhDsaKey_Init(key_vfy, (enum SlhDsaParam)param, HEAP_HINT,
12679 INVALID_DEVID);
12680 if (ret != 0) {
12681 goto exit;
12682 }
12683 ret = wc_SlhDsaKey_ImportPublic(key_vfy, pk, outLen);
12684 if (ret != 0) {
12685 goto exit;
12686 }
12687 bench_stats_start(&count, &start);
12688 do {
12689 ret = wc_SlhDsaKey_Verify(key_vfy, ctx, 0, msg, (word32)sizeof(msg),
12690 sig, sigLen);
12691 if (ret != 0) {
12692 goto exit;
12693 }
12694 count++;
12695 RECORD_MULTI_VALUE_STATS();
12696 } while (bench_stats_check(start)
12697#ifdef MULTI_VALUE_STATISTICS
12698 || runs < minimum_runs
12699#endif
12700 );
12701 bench_stats_asym_finish(name, len, "verify", 0, count, start, ret);
12702
12703 /* Internal interface: sign M' directly (no M' construction). */
12704 PRIVATE_KEY_UNLOCK();
12705 bench_stats_start(&count, &start);
12706 do {
12707 sigLen = WC_SLHDSA_MAX_SIG_LEN;
12708 ret = wc_SlhDsaKey_SignMsgDeterministic(key, msg,
12709 (word32)sizeof(msg), sig, &sigLen);
12710 if (ret != 0) {
12711 goto exit;
12712 }
12713 count++;
12714 RECORD_MULTI_VALUE_STATS();
12715 } while (bench_stats_check(start)
12716#ifdef MULTI_VALUE_STATISTICS
12717 || runs < minimum_runs
12718#endif
12719 );
12720 PRIVATE_KEY_LOCK();
12721 bench_stats_asym_finish(name, len, "sign-msg", 0, count, start, ret);
12722
12723 bench_stats_start(&count, &start);
12724 do {
12725 ret = wc_SlhDsaKey_VerifyMsg(key_vfy, msg, (word32)sizeof(msg),
12726 sig, sigLen);
12727 if (ret != 0) {
12728 goto exit;
12729 }
12730 count++;
12731 RECORD_MULTI_VALUE_STATS();
12732 } while (bench_stats_check(start)
12733#ifdef MULTI_VALUE_STATISTICS
12734 || runs < minimum_runs
12735#endif
12736 );
12737 bench_stats_asym_finish(name, len, "vrfy-msg", 0, count, start, ret);
12738
12739#ifndef NO_SHA256
12740 /* Pre-hash interface: hash message ONCE outside the timed loop (the
12741 * bench measures sign/verify, not the application-side hash), then sign
12742 * and verify the digest. SHA-256 path: only built when SHA-256 is
12743 * available; HashSLH-DSA still works at runtime with any hashType the
12744 * build supports, but the bench needs a compile-time choice. */
12745 {
12746 byte digest[WC_SHA256_DIGEST_SIZE];
12747
12748 ret = wc_Sha256Hash(msg, (word32)sizeof(msg), digest);
12749 if (ret != 0) {
12750 goto exit;
12751 }
12752
12753 PRIVATE_KEY_UNLOCK();
12754 bench_stats_start(&count, &start);
12755 do {
12756 sigLen = WC_SLHDSA_MAX_SIG_LEN;
12757 ret = wc_SlhDsaKey_SignHashDeterministic(key, ctx, 0, digest,
12758 (word32)sizeof(digest), WC_HASH_TYPE_SHA256, sig, &sigLen);
12759 if (ret != 0) {
12760 goto exit;
12761 }
12762 count++;
12763 RECORD_MULTI_VALUE_STATS();
12764 } while (bench_stats_check(start)
12765#ifdef MULTI_VALUE_STATISTICS
12766 || runs < minimum_runs
12767#endif
12768 );
12769 PRIVATE_KEY_LOCK();
12770 bench_stats_asym_finish(name, len, "sign-pre", 0, count, start, ret);
12771
12772 bench_stats_start(&count, &start);
12773 do {
12774 ret = wc_SlhDsaKey_VerifyHash(key_vfy, ctx, 0, digest,
12775 (word32)sizeof(digest), WC_HASH_TYPE_SHA256, sig, sigLen);
12776 if (ret != 0) {
12777 goto exit;
12778 }
12779 count++;
12780 RECORD_MULTI_VALUE_STATS();
12781 } while (bench_stats_check(start)
12782#ifdef MULTI_VALUE_STATISTICS
12783 || runs < minimum_runs
12784#endif
12785 );
12786 bench_stats_asym_finish(name, len, "vrfy-pre", 0, count, start, ret);
12787 }
12788#elif defined(WOLFSSL_SHAKE256)
12789 /* SHAKE-only build (NO_SHA256): use SHAKE256 prehash bench instead. */
12790 {
12791 byte digest[WC_SHA3_512_DIGEST_SIZE];
12792
12793 ret = wc_Shake256Hash(msg, (word32)sizeof(msg), digest,
12794 WC_SHA3_512_DIGEST_SIZE);
12795 if (ret != 0) {
12796 goto exit;
12797 }
12798
12799 PRIVATE_KEY_UNLOCK();
12800 bench_stats_start(&count, &start);
12801 do {
12802 sigLen = WC_SLHDSA_MAX_SIG_LEN;
12803 ret = wc_SlhDsaKey_SignHashDeterministic(key, ctx, 0, digest,
12804 (word32)sizeof(digest), WC_HASH_TYPE_SHAKE256, sig, &sigLen);
12805 if (ret != 0) {
12806 goto exit;
12807 }
12808 count++;
12809 RECORD_MULTI_VALUE_STATS();
12810 } while (bench_stats_check(start)
12811#ifdef MULTI_VALUE_STATISTICS
12812 || runs < minimum_runs
12813#endif
12814 );
12815 PRIVATE_KEY_LOCK();
12816 bench_stats_asym_finish(name, len, "sign-pre", 0, count, start, ret);
12817
12818 bench_stats_start(&count, &start);
12819 do {
12820 ret = wc_SlhDsaKey_VerifyHash(key_vfy, ctx, 0, digest,
12821 (word32)sizeof(digest), WC_HASH_TYPE_SHAKE256, sig, sigLen);
12822 if (ret != 0) {
12823 goto exit;
12824 }
12825 count++;
12826 RECORD_MULTI_VALUE_STATS();
12827 } while (bench_stats_check(start)
12828#ifdef MULTI_VALUE_STATISTICS
12829 || runs < minimum_runs
12830#endif
12831 );
12832 bench_stats_asym_finish(name, len, "vrfy-pre", 0, count, start, ret);
12833 }
12834#endif /* NO_SHA256 / WOLFSSL_SHAKE256 */
12835
12836exit:
12837#ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
12838 if (key_vfy)
12839#endif
12840 {
12841 wc_SlhDsaKey_Free(key_vfy);
12842 }
12843#ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
12844 if (key)
12845#endif
12846 {
12847 wc_SlhDsaKey_Free(key);
12848 }
12849
12850 WC_FREE_VAR_EX(key_vfy, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
12851 WC_FREE_VAR_EX(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
12852 WC_FREE_VAR_EX(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
12853}
12854#endif
12855
12856#if defined(HAVE_ECC) && !defined(WC_NO_RNG)
12857
12858/* Maximum ECC name plus null terminator:
12859 * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
12860#define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
12861
12862/* run all benchmarks on a curve */
12863void bench_ecc_curve(int curveId)
12864{
12865 if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
12866 #ifndef NO_SW_BENCH
12867 bench_eccMakeKey(0, curveId);
12868 #endif
12869 #if defined(BENCH_DEVID)
12870 bench_eccMakeKey(1, curveId);
12871 #endif
12872 }
12873 if (bench_all || (bench_asym_algs & BENCH_ECC)) {
12874 #ifndef NO_SW_BENCH
12875 bench_ecc(0, curveId);
12876 #endif
12877 #if defined(BENCH_DEVID)
12878 bench_ecc(1, curveId);
12879 #endif
12880 }
12881 #ifdef HAVE_ECC_ENCRYPT
12882 if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
12883 bench_eccEncrypt(curveId);
12884 #endif
12885}
12886
12887
12888void bench_eccMakeKey(int useDeviceID, int curveId)
12889{
12890 int ret = 0, i, times, count = 0, pending = 0;
12891 int deviceID;
12892 int keySize = 0;
12893 WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
12894 sizeof(ecc_key), HEAP_HINT);
12895 char name[BENCH_ECC_NAME_SZ];
12896 double start = 0;
12897 const char**desc = bench_desc_words[lng_index];
12898 DECLARE_MULTI_VALUE_STATS_VARS()
12899
12900 bench_stats_prepare();
12901
12902 WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
12903 sizeof(ecc_key), HEAP_HINT);
12904
12905 deviceID = useDeviceID ? devId : INVALID_DEVID;
12906 keySize = wc_ecc_get_curve_size_from_id(curveId);
12907
12908 /* ECC Make Key */
12909 bench_stats_start(&count, &start);
12910 do {
12911 /* while free pending slots in queue, submit ops */
12912 for (times = 0; times < agreeTimes || pending > 0; ) {
12913 bench_async_poll(&pending);
12914
12915 for (i = 0; i < BENCH_MAX_PENDING; i++) {
12916 if (bench_async_check(&ret,
12917 BENCH_ASYNC_GET_DEV(genKey[i]), 0,
12918 ×, agreeTimes, &pending)) {
12919
12920 wc_ecc_free(genKey[i]);
12921 ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
12922 if (ret < 0) {
12923 goto exit;
12924 }
12925
12926 ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
12927 curveId);
12928 if (!bench_async_handle(&ret,
12929 BENCH_ASYNC_GET_DEV(genKey[i]), 0, ×,
12930 &pending)) {
12931 goto exit;
12932 }
12933 }
12934 } /* for i */
12935 RECORD_MULTI_VALUE_STATS();
12936 } /* for times */
12937 count += times;
12938 } while (bench_stats_check(start)
12939#ifdef MULTI_VALUE_STATISTICS
12940 || runs < minimum_runs
12941#endif
12942 );
12943
12944exit:
12945 (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
12946 wc_ecc_get_name(curveId));
12947 bench_stats_asym_finish(name, keySize * 8, desc[2],
12948 useDeviceID, count, start, ret);
12949#ifdef MULTI_VALUE_STATISTICS
12950 bench_multi_value_stats(max, min, sum, squareSum, runs);
12951#endif
12952
12953 /* cleanup */
12954 if (WC_ARRAY_OK(genKey)) {
12955 for (i = 0; i < BENCH_MAX_PENDING; i++) {
12956 wc_ecc_free(genKey[i]);
12957 }
12958 WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
12959 }
12960}
12961
12962
12963void bench_ecc(int useDeviceID, int curveId)
12964{
12965 int ret = 0, i, times, count, pending = 0;
12966 int deviceID;
12967 int keySize;
12968 int dgstSize;
12969 char name[BENCH_ECC_NAME_SZ];
12970 WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
12971 sizeof(ecc_key), HEAP_HINT);
12972#ifdef HAVE_ECC_DHE
12973 WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
12974 sizeof(ecc_key), HEAP_HINT);
12975#endif
12976
12977#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
12978 #ifdef HAVE_ECC_VERIFY
12979 int verify[BENCH_MAX_PENDING];
12980 #endif
12981#endif
12982
12983 word32 x[BENCH_MAX_PENDING];
12984 double start = 0;
12985 const char**desc = bench_desc_words[lng_index];
12986 DECLARE_MULTI_VALUE_STATS_VARS()
12987
12988#ifdef HAVE_ECC_DHE
12989 WC_DECLARE_ARRAY(shared, byte,
12990 BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
12991#endif
12992
12993#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
12994 WC_DECLARE_ARRAY(sig, byte,
12995 BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
12996 WC_DECLARE_ARRAY(digest, byte,
12997 BENCH_MAX_PENDING, WC_MAX_DIGEST_SIZE, HEAP_HINT);
12998#endif
12999
13000 bench_stats_prepare();
13001
13002#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
13003 /* old scan-build misfires -Wmaybe-uninitialized on these. */
13004 XMEMSET(sig, 0, sizeof(sig));
13005 XMEMSET(digest, 0, sizeof(digest));
13006#endif
13007
13008#ifdef HAVE_ECC_DHE
13009 XMEMSET(shared, 0, sizeof(shared));
13010#endif
13011 WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
13012 sizeof(ecc_key), HEAP_HINT);
13013
13014#ifdef HAVE_ECC_DHE
13015 WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
13016 sizeof(ecc_key), HEAP_HINT);
13017 WC_ALLOC_ARRAY(shared, byte,
13018 BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
13019#endif
13020
13021#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
13022 WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
13023 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
13024#endif
13025 deviceID = useDeviceID ? devId : INVALID_DEVID;
13026
13027 keySize = wc_ecc_get_curve_size_from_id(curveId);
13028 if (keySize < 28) {
13029 /* SHA-1 */
13030 dgstSize = 20;
13031 }
13032 else if (keySize < 32) {
13033 /* SHA-224/SHA512-224/SHA3-224 */
13034 dgstSize = 28;
13035 }
13036 else if (keySize < 48) {
13037 /* SHA-256/SHA512-256/SHA3-256 */
13038 dgstSize = 32;
13039 }
13040 else if (keySize < 64) {
13041 /* SHA-384/SHA3-384 */
13042 dgstSize = 48;
13043 }
13044 else {
13045 /* SHA-512/SHA3-512 */
13046 dgstSize = 64;
13047 }
13048 if (dgstSize > WC_MAX_DIGEST_SIZE) {
13049 dgstSize = WC_MAX_DIGEST_SIZE;
13050 }
13051
13052 /* init keys */
13053 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13054 /* setup an context for each key */
13055 if ((ret = bench_EccInit_Pair(genKey[i], keySize, HEAP_HINT,
13056 deviceID)) < 0) {
13057 goto exit;
13058 }
13059#if defined(WOLFSSL_MICROCHIP_TA100)
13060 genKey[i]->slot = atmel_ecc_alloc(ATMEL_SLOT_ECDHE_ALICE);
13061#endif
13062 ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
13063 #ifdef WOLFSSL_ASYNC_CRYPT
13064 ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
13065 #endif
13066 if (ret < 0) {
13067 goto exit;
13068 }
13069
13070 #ifdef HAVE_ECC_DHE
13071 if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
13072 goto exit;
13073 }
13074#if defined(WOLFSSL_MICROCHIP_TA100)
13075 genKey2[i]->slot = atmel_ecc_alloc(ATMEL_SLOT_ECDHE_BOB);
13076#endif
13077 if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
13078 curveId)) > 0) {
13079 goto exit;
13080 }
13081 #endif
13082 }
13083
13084#ifdef HAVE_ECC_DHE
13085#if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
13086 (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
13087 !defined(HAVE_SELFTEST)
13088 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13089 (void)wc_ecc_set_rng(genKey[i], &gRng);
13090 }
13091#endif
13092
13093 /* ECC Shared Secret */
13094 bench_stats_start(&count, &start);
13095 PRIVATE_KEY_UNLOCK();
13096 do {
13097 for (times = 0; times < agreeTimes || pending > 0; ) {
13098 bench_async_poll(&pending);
13099
13100 /* while free pending slots in queue, submit ops */
13101 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13102 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
13103 ×, agreeTimes, &pending)) {
13104 x[i] = (word32)keySize;
13105 ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
13106 shared[i], &x[i]);
13107 if (!bench_async_handle(&ret,
13108 BENCH_ASYNC_GET_DEV(genKey[i]), 1, ×,
13109 &pending)) {
13110 goto exit_ecdhe;
13111 }
13112 }
13113 } /* for i */
13114 RECORD_MULTI_VALUE_STATS();
13115 } /* for times */
13116 count += times;
13117 } while (bench_stats_check(start)
13118#ifdef MULTI_VALUE_STATISTICS
13119 || runs < minimum_runs
13120#endif
13121 );
13122
13123 PRIVATE_KEY_UNLOCK();
13124exit_ecdhe:
13125 (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
13126 wc_ecc_get_name(curveId));
13127
13128 bench_stats_asym_finish(name, keySize * 8, desc[3],
13129 useDeviceID, count, start, ret);
13130#ifdef MULTI_VALUE_STATISTICS
13131 bench_multi_value_stats(max, min, sum, squareSum, runs);
13132#endif
13133
13134 RESET_MULTI_VALUE_STATS_VARS();
13135
13136 if (ret < 0) {
13137 goto exit;
13138 }
13139
13140#endif /* HAVE_ECC_DHE */
13141
13142#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
13143
13144 /* Init digest to sign */
13145 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13146 for (count = 0; count < dgstSize; count++) {
13147 digest[i][count] = (byte)count;
13148 }
13149 }
13150
13151 /* ECC Sign */
13152 bench_stats_start(&count, &start);
13153 do {
13154 for (times = 0; times < agreeTimes || pending > 0; ) {
13155 bench_async_poll(&pending);
13156
13157 /* while free pending slots in queue, submit ops */
13158 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13159 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
13160 ×, agreeTimes, &pending)) {
13161
13162 if (genKey[i]->state == 0) {
13163 x[i] = ECC_MAX_SIG_SIZE;
13164 }
13165
13166 ret = wc_ecc_sign_hash(digest[i], (word32)dgstSize, sig[i],
13167 &x[i], GLOBAL_RNG, genKey[i]);
13168
13169 if (!bench_async_handle(&ret,
13170 BENCH_ASYNC_GET_DEV(genKey[i]), 1, ×,
13171 &pending)) {
13172 goto exit_ecdsa_sign;
13173 }
13174 } /* bench_async_check */
13175 } /* for i */
13176 RECORD_MULTI_VALUE_STATS();
13177 } /* for times */
13178 count += times;
13179 } while (bench_stats_check(start)
13180#ifdef MULTI_VALUE_STATISTICS
13181 || runs < minimum_runs
13182#endif
13183 );
13184
13185exit_ecdsa_sign:
13186 (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
13187 wc_ecc_get_name(curveId));
13188
13189 bench_stats_asym_finish(name, keySize * 8, desc[4],
13190 useDeviceID, count, start, ret);
13191#ifdef MULTI_VALUE_STATISTICS
13192 bench_multi_value_stats(max, min, sum, squareSum, runs);
13193#endif
13194
13195 RESET_MULTI_VALUE_STATS_VARS();
13196
13197 if (ret < 0) {
13198 goto exit;
13199 }
13200
13201#ifdef HAVE_ECC_VERIFY
13202
13203 /* ECC Verify */
13204 bench_stats_start(&count, &start);
13205 do {
13206 for (times = 0; times < agreeTimes || pending > 0; ) {
13207 bench_async_poll(&pending);
13208
13209 /* while free pending slots in queue, submit ops */
13210 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13211 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
13212 ×, agreeTimes, &pending)) {
13213 if (genKey[i]->state == 0) {
13214 verify[i] = 0;
13215 }
13216
13217 ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
13218 (word32)dgstSize, &verify[i],
13219 genKey[i]);
13220
13221 if (!bench_async_handle(&ret,
13222 BENCH_ASYNC_GET_DEV(genKey[i]),
13223 1, ×,
13224 &pending)) {
13225 goto exit_ecdsa_verify;
13226 }
13227 } /* if bench_async_check */
13228 } /* for i */
13229 RECORD_MULTI_VALUE_STATS();
13230 } /* for times */
13231 count += times;
13232 } while (bench_stats_check(start)
13233#ifdef MULTI_VALUE_STATISTICS
13234 || runs < minimum_runs
13235#endif
13236 );
13237
13238exit_ecdsa_verify:
13239 (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
13240 wc_ecc_get_name(curveId));
13241
13242 bench_stats_asym_finish(name, keySize * 8, desc[5],
13243 useDeviceID, count, start, ret);
13244#ifdef MULTI_VALUE_STATISTICS
13245 bench_multi_value_stats(max, min, sum, squareSum, runs);
13246#endif
13247#endif /* HAVE_ECC_VERIFY */
13248#endif /* !NO_ASN && HAVE_ECC_SIGN */
13249
13250exit:
13251
13252 /* cleanup */
13253 if (WC_ARRAY_OK(genKey)) {
13254 for (i = 0; i < BENCH_MAX_PENDING; i++)
13255 wc_ecc_free(genKey[i]);
13256 WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
13257 }
13258 #ifdef HAVE_ECC_DHE
13259 if (WC_ARRAY_OK(genKey2)) {
13260 for (i = 0; i < BENCH_MAX_PENDING; i++)
13261 wc_ecc_free(genKey2[i]);
13262 WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
13263 }
13264 #endif
13265
13266#ifdef HAVE_ECC_DHE
13267 WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
13268#endif
13269#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
13270 WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
13271 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
13272#endif
13273#if defined(WOLFSSL_MICROCHIP_TA100)
13274 atmel_ecc_free(ATMEL_SLOT_ECDHE_ALICE);
13275 atmel_ecc_free(ATMEL_SLOT_ECDHE_BOB);
13276#endif
13277 (void)useDeviceID;
13278 (void)pending;
13279 (void)x;
13280 (void)count;
13281 (void)times;
13282 (void)desc;
13283 (void)start;
13284 (void)name;
13285}
13286
13287
13288#ifdef HAVE_ECC_ENCRYPT
13289void bench_eccEncrypt(int curveId)
13290{
13291#define BENCH_ECCENCRYPT_MSG_SIZE 48
13292#define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
13293 WC_SHA256_DIGEST_SIZE + \
13294 (MAX_ECC_BITS+3)/4 + 2)
13295 word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
13296#ifdef WOLFSSL_SMALL_STACK
13297 ecc_key *userA = NULL, *userB = NULL;
13298 byte *msg = NULL;
13299 byte *out = NULL;
13300#else
13301 ecc_key userA[1], userB[1];
13302 byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
13303 byte out[BENCH_ECCENCRYPT_OUT_SIZE];
13304#endif
13305 char name[BENCH_ECC_NAME_SZ];
13306 int keySize;
13307 word32 bench_plainSz = bench_size;
13308 int ret, i, count;
13309 double start;
13310 const char**desc = bench_desc_words[lng_index];
13311 DECLARE_MULTI_VALUE_STATS_VARS()
13312
13313 bench_stats_prepare();
13314
13315#ifdef WOLFSSL_SMALL_STACK
13316 userA = (ecc_key *)XMALLOC(sizeof(*userA),
13317 HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
13318 userB = (ecc_key *)XMALLOC(sizeof(*userB),
13319 HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
13320 msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
13321 HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
13322 out = (byte *)XMALLOC(outSz,
13323 HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
13324 if ((! userA) || (! userB) || (! msg) || (! out)) {
13325 printf("bench_eccEncrypt malloc failed\n");
13326 goto exit;
13327 }
13328#endif
13329
13330 keySize = wc_ecc_get_curve_size_from_id(curveId);
13331 ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
13332 if (ret != 0) {
13333 printf("wc_ecc_encrypt make key A failed: %d\n", ret);
13334 goto exit;
13335 }
13336
13337 ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
13338 if (ret != 0) {
13339 printf("wc_ecc_encrypt make key B failed: %d\n", ret);
13340 goto exit;
13341 }
13342
13343#if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
13344 (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
13345 !defined(HAVE_SELFTEST)
13346 ret = wc_ecc_set_rng(userA, &gRng);
13347 if (ret != 0) {
13348 goto exit;
13349 }
13350 ret = wc_ecc_set_rng(userB, &gRng);
13351 if (ret != 0) {
13352 goto exit;
13353 }
13354#endif
13355
13356 ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
13357#ifdef WOLFSSL_ASYNC_CRYPT
13358 ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
13359#endif
13360 if (ret != 0)
13361 goto exit;
13362 ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
13363#ifdef WOLFSSL_ASYNC_CRYPT
13364 ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
13365#endif
13366 if (ret != 0)
13367 goto exit;
13368
13369 for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
13370 msg[i] = (byte)i;
13371 }
13372
13373 bench_stats_start(&count, &start);
13374 do {
13375 for (i = 0; i < ntimes; i++) {
13376 /* encrypt msg to B */
13377 ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
13378 out, &outSz, NULL);
13379 if (ret != 0) {
13380 printf("wc_ecc_encrypt failed! %d\n", ret);
13381 goto exit_enc;
13382 }
13383 RECORD_MULTI_VALUE_STATS();
13384 }
13385 count += i;
13386 } while (bench_stats_check(start)
13387#ifdef MULTI_VALUE_STATISTICS
13388 || runs < minimum_runs
13389#endif
13390 );
13391
13392exit_enc:
13393 (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
13394 wc_ecc_get_name(curveId));
13395 bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
13396#ifdef MULTI_VALUE_STATISTICS
13397 bench_multi_value_stats(max, min, sum, squareSum, runs);
13398#endif
13399
13400 RESET_MULTI_VALUE_STATS_VARS();
13401
13402 if (ret != 0)
13403 goto exit;
13404
13405 bench_stats_start(&count, &start);
13406 do {
13407 for (i = 0; i < ntimes; i++) {
13408 /* decrypt msg from A */
13409 ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
13410 &bench_plainSz, NULL);
13411 if (ret != 0) {
13412 printf("wc_ecc_decrypt failed! %d\n", ret);
13413 goto exit_dec;
13414 }
13415 RECORD_MULTI_VALUE_STATS();
13416 }
13417 count += i;
13418 } while (bench_stats_check(start)
13419#ifdef MULTI_VALUE_STATISTICS
13420 || runs < minimum_runs
13421#endif
13422 );
13423
13424exit_dec:
13425 bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
13426#ifdef MULTI_VALUE_STATISTICS
13427 bench_multi_value_stats(max, min, sum, squareSum, runs);
13428#endif
13429
13430exit:
13431
13432 /* cleanup */
13433#ifdef WOLFSSL_SMALL_STACK
13434 if (userA) {
13435 wc_ecc_free(userA);
13436 XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
13437 }
13438 if (userB) {
13439 wc_ecc_free(userB);
13440 XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
13441 }
13442 XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
13443 XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
13444#else
13445 wc_ecc_free(userB);
13446 wc_ecc_free(userA);
13447#endif
13448}
13449#endif
13450
13451#ifdef WOLFSSL_SM2
13452static void bench_sm2_MakeKey(int useDeviceID)
13453{
13454 int ret = 0, i, times, count = 0, pending = 0;
13455 int deviceID;
13456 int keySize;
13457 WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
13458 sizeof(ecc_key), HEAP_HINT);
13459 char name[BENCH_ECC_NAME_SZ];
13460 double start = 0;
13461 const char**desc = bench_desc_words[lng_index];
13462 DECLARE_MULTI_VALUE_STATS_VARS()
13463
13464 bench_stats_prepare();
13465
13466 deviceID = useDeviceID ? devId : INVALID_DEVID;
13467 keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
13468
13469 WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
13470 sizeof(ecc_key), HEAP_HINT);
13471
13472 /* ECC Make Key */
13473 bench_stats_start(&count, &start);
13474 do {
13475 /* while free pending slots in queue, submit ops */
13476 for (times = 0; times < agreeTimes || pending > 0; ) {
13477 bench_async_poll(&pending);
13478
13479 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13480 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
13481 ×, agreeTimes, &pending)) {
13482
13483 wc_ecc_free(genKey[i]);
13484 ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
13485 if (ret < 0) {
13486 goto exit;
13487 }
13488
13489 ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
13490 WC_ECC_FLAG_NONE);
13491 if (!bench_async_handle(&ret,
13492 BENCH_ASYNC_GET_DEV(genKey[i]), 0, ×,
13493 &pending)) {
13494 goto exit;
13495 }
13496 }
13497 } /* for i */
13498 RECORD_MULTI_VALUE_STATS();
13499 } /* for times */
13500 count += times;
13501 } while (bench_stats_check(start)
13502#ifdef MULTI_VALUE_STATISTICS
13503 || runs < minimum_runs
13504#endif
13505 );
13506
13507exit:
13508 (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
13509 wc_ecc_get_name(ECC_SM2P256V1));
13510 bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
13511 start, ret);
13512#ifdef MULTI_VALUE_STATISTICS
13513 bench_multi_value_stats(max, min, sum, squareSum, runs);
13514#endif
13515
13516 /* cleanup */
13517 if (WC_ARRAY_OK(genKey)) {
13518 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13519 wc_ecc_free(genKey[i]);
13520 }
13521 WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
13522 }
13523}
13524
13525
13526void bench_sm2(int useDeviceID)
13527{
13528 int ret = 0, i, times, count, pending = 0;
13529 int deviceID;
13530 int keySize;
13531 char name[BENCH_ECC_NAME_SZ];
13532 WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
13533 sizeof(ecc_key), HEAP_HINT);
13534#ifdef HAVE_ECC_DHE
13535 WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
13536 sizeof(ecc_key), HEAP_HINT);
13537#endif
13538#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
13539#ifdef HAVE_ECC_VERIFY
13540 int verify[BENCH_MAX_PENDING];
13541#endif
13542#endif
13543 word32 x[BENCH_MAX_PENDING];
13544 double start = 0;
13545 const char**desc = bench_desc_words[lng_index];
13546 DECLARE_MULTI_VALUE_STATS_VARS()
13547
13548#ifdef HAVE_ECC_DHE
13549 WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
13550#endif
13551#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
13552 WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
13553 WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
13554#endif
13555
13556 bench_stats_prepare();
13557
13558#ifdef HAVE_ECC_DHE
13559 WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
13560#endif
13561#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
13562 WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
13563 WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
13564#endif
13565 deviceID = useDeviceID ? devId : INVALID_DEVID;
13566
13567 bench_sm2_MakeKey(useDeviceID);
13568
13569 WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
13570 sizeof(ecc_key), HEAP_HINT);
13571#ifdef HAVE_ECC_DHE
13572 WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
13573 sizeof(ecc_key), HEAP_HINT);
13574#endif
13575
13576 keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
13577
13578 /* init keys */
13579 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13580 /* setup an context for each key */
13581 if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
13582 goto exit;
13583 }
13584 ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
13585 #ifdef WOLFSSL_ASYNC_CRYPT
13586 ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
13587 #endif
13588 if (ret < 0) {
13589 goto exit;
13590 }
13591
13592 #ifdef HAVE_ECC_DHE
13593 if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
13594 goto exit;
13595 }
13596 if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
13597 WC_ECC_FLAG_NONE)) > 0) {
13598 goto exit;
13599 }
13600 #endif
13601 }
13602
13603#ifdef HAVE_ECC_DHE
13604#if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
13605 (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
13606 !defined(HAVE_SELFTEST)
13607 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13608 (void)wc_ecc_set_rng(genKey[i], &gRng);
13609 }
13610#endif
13611
13612 /* ECC Shared Secret */
13613 bench_stats_start(&count, &start);
13614 PRIVATE_KEY_UNLOCK();
13615 do {
13616 for (times = 0; times < agreeTimes || pending > 0; ) {
13617 bench_async_poll(&pending);
13618
13619 /* while free pending slots in queue, submit ops */
13620 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13621 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
13622 ×, agreeTimes, &pending)) {
13623 x[i] = (word32)keySize;
13624 ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
13625 shared[i], &x[i]);
13626 if (!bench_async_handle(&ret,
13627 BENCH_ASYNC_GET_DEV(genKey[i]), 1, ×,
13628 &pending)) {
13629 goto exit_ecdhe;
13630 }
13631 }
13632 } /* for i */
13633 RECORD_MULTI_VALUE_STATS();
13634 } /* for times */
13635 count += times;
13636 } while (bench_stats_check(start)
13637#ifdef MULTI_VALUE_STATISTICS
13638 || runs < minimum_runs
13639#endif
13640 );
13641
13642 PRIVATE_KEY_UNLOCK();
13643exit_ecdhe:
13644 (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
13645 wc_ecc_get_name(ECC_SM2P256V1));
13646
13647 bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
13648 start, ret);
13649#ifdef MULTI_VALUE_STATISTICS
13650 bench_multi_value_stats(max, min, sum, squareSum, runs);
13651#endif
13652
13653 if (ret < 0) {
13654 goto exit;
13655 }
13656#endif /* HAVE_ECC_DHE */
13657
13658#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
13659
13660 /* Init digest to sign */
13661 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13662 for (count = 0; count < keySize; count++) {
13663 digest[i][count] = (byte)count;
13664 }
13665 }
13666
13667 RESET_MULTI_VALUE_STATS_VARS();
13668
13669 /* ECC Sign */
13670 bench_stats_start(&count, &start);
13671 do {
13672 for (times = 0; times < agreeTimes || pending > 0; ) {
13673 bench_async_poll(&pending);
13674
13675 /* while free pending slots in queue, submit ops */
13676 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13677 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
13678 ×, agreeTimes, &pending)) {
13679 if (genKey[i]->state == 0)
13680 x[i] = ECC_MAX_SIG_SIZE;
13681 ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
13682 sig[i], &x[i], &gRng, genKey[i]);
13683 if (!bench_async_handle(&ret,
13684 BENCH_ASYNC_GET_DEV(genKey[i]), 1, ×,
13685 &pending)) {
13686 goto exit_ecdsa_sign;
13687 }
13688 }
13689 } /* for i */
13690 RECORD_MULTI_VALUE_STATS();
13691 } /* for times */
13692 count += times;
13693 } while (bench_stats_check(start)
13694#ifdef MULTI_VALUE_STATISTICS
13695 || runs < minimum_runs
13696#endif
13697 );
13698
13699exit_ecdsa_sign:
13700 (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
13701 wc_ecc_get_name(ECC_SM2P256V1));
13702
13703 bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
13704 start, ret);
13705#ifdef MULTI_VALUE_STATISTICS
13706 bench_multi_value_stats(max, min, sum, squareSum, runs);
13707#endif
13708
13709 if (ret < 0) {
13710 goto exit;
13711 }
13712
13713#ifdef HAVE_ECC_VERIFY
13714
13715 /* ECC Verify */
13716 bench_stats_start(&count, &start);
13717 do {
13718 for (times = 0; times < agreeTimes || pending > 0; ) {
13719 bench_async_poll(&pending);
13720
13721 /* while free pending slots in queue, submit ops */
13722 for (i = 0; i < BENCH_MAX_PENDING; i++) {
13723 if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
13724 ×, agreeTimes, &pending)) {
13725 if (genKey[i]->state == 0)
13726 verify[i] = 0;
13727 ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
13728 (word32)keySize, &verify[i], genKey[i]);
13729 if (!bench_async_handle(&ret,
13730 BENCH_ASYNC_GET_DEV(genKey[i]), 1, ×,
13731 &pending)) {
13732 goto exit_ecdsa_verify;
13733 }
13734 }
13735 } /* for i */
13736 RECORD_MULTI_VALUE_STATS();
13737 } /* for times */
13738 count += times;
13739 } while (bench_stats_check(start)
13740#ifdef MULTI_VALUE_STATISTICS
13741 || runs < minimum_runs
13742#endif
13743 );
13744
13745exit_ecdsa_verify:
13746 (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
13747 wc_ecc_get_name(ECC_SM2P256V1));
13748
13749 bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
13750 start, ret);
13751#ifdef MULTI_VALUE_STATISTICS
13752 bench_multi_value_stats(max, min, sum, squareSum, runs);
13753#endif
13754
13755#endif /* HAVE_ECC_VERIFY */
13756#endif /* !NO_ASN && HAVE_ECC_SIGN */
13757
13758exit:
13759
13760 /* cleanup */
13761 if (WC_ARRAY_OK(genKey)) {
13762 for (i = 0; i < BENCH_MAX_PENDING; i++)
13763 wc_ecc_free(genKey[i]);
13764 WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
13765 }
13766 #ifdef HAVE_ECC_DHE
13767 if (WC_ARRAY_OK(genKey2)) {
13768 for (i = 0; i < BENCH_MAX_PENDING; i++)
13769 wc_ecc_free(genKey2[i]);
13770 WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
13771 }
13772 #endif
13773
13774#ifdef HAVE_ECC_DHE
13775 WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
13776#endif
13777#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
13778 WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
13779 WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
13780#endif
13781
13782
13783 (void)useDeviceID;
13784 (void)pending;
13785 (void)x;
13786 (void)count;
13787 (void)times;
13788 (void)desc;
13789 (void)start;
13790 (void)name;
13791}
13792#endif /* WOLFSSL_SM2 */
13793#endif /* HAVE_ECC && && !defined(WC_NO_RNG) */
13794
13795#ifdef HAVE_CURVE25519
13796void bench_curve25519KeyGen(int useDeviceID)
13797{
13798 curve25519_key genKey;
13799 double start;
13800 int ret = 0, i, count;
13801 const char**desc = bench_desc_words[lng_index];
13802 DECLARE_MULTI_VALUE_STATS_VARS()
13803
13804 bench_stats_prepare();
13805
13806 /* Key Gen */
13807 bench_stats_start(&count, &start);
13808 do {
13809 for (i = 0; i < genTimes; i++) {
13810 ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
13811 useDeviceID ? devId : INVALID_DEVID);
13812 if (ret != 0) {
13813 printf("wc_curve25519_init_ex failed: %d\n", ret);
13814 break;
13815 }
13816
13817 ret = wc_curve25519_make_key(&gRng, 32, &genKey);
13818 wc_curve25519_free(&genKey);
13819 if (ret != 0) {
13820 printf("wc_curve25519_make_key failed: %d\n", ret);
13821 break;
13822 }
13823 RECORD_MULTI_VALUE_STATS();
13824 }
13825 count += i;
13826 } while (bench_stats_check(start)
13827#ifdef MULTI_VALUE_STATISTICS
13828 || runs < minimum_runs
13829#endif
13830 );
13831
13832 bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
13833 ret);
13834#ifdef MULTI_VALUE_STATISTICS
13835 bench_multi_value_stats(max, min, sum, squareSum, runs);
13836#endif
13837}
13838
13839#ifdef HAVE_CURVE25519_SHARED_SECRET
13840void bench_curve25519KeyAgree(int useDeviceID)
13841{
13842 curve25519_key genKey, genKey2;
13843 double start;
13844 int ret, i, count;
13845 byte shared[32];
13846 const char**desc = bench_desc_words[lng_index];
13847 word32 x = 0;
13848 DECLARE_MULTI_VALUE_STATS_VARS()
13849
13850 bench_stats_prepare();
13851
13852 wc_curve25519_init_ex(&genKey, HEAP_HINT,
13853 useDeviceID ? devId : INVALID_DEVID);
13854 wc_curve25519_init_ex(&genKey2, HEAP_HINT,
13855 useDeviceID ? devId : INVALID_DEVID);
13856
13857 ret = wc_curve25519_make_key(&gRng, 32, &genKey);
13858 if (ret != 0) {
13859 printf("curve25519_make_key failed\n");
13860 return;
13861 }
13862 ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
13863 if (ret != 0) {
13864 printf("curve25519_make_key failed: %d\n", ret);
13865 wc_curve25519_free(&genKey);
13866 return;
13867 }
13868
13869#ifdef WOLFSSL_CURVE25519_BLINDING
13870 ret = wc_curve25519_set_rng(&genKey, &gRng);
13871 if (ret != 0) {
13872 wc_curve25519_free(&genKey);
13873 wc_curve25519_free(&genKey2);
13874 return;
13875 }
13876 ret = wc_curve25519_set_rng(&genKey2, &gRng);
13877 if (ret != 0) {
13878 wc_curve25519_free(&genKey);
13879 wc_curve25519_free(&genKey2);
13880 return;
13881 }
13882#endif
13883
13884 /* Shared secret */
13885 bench_stats_start(&count, &start);
13886 do {
13887 for (i = 0; i < agreeTimes; i++) {
13888 x = sizeof(shared);
13889 ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
13890 if (ret != 0) {
13891 printf("curve25519_shared_secret failed: %d\n", ret);
13892 goto exit;
13893 }
13894 RECORD_MULTI_VALUE_STATS();
13895 }
13896 count += i;
13897 } while (bench_stats_check(start)
13898#ifdef MULTI_VALUE_STATISTICS
13899 || runs < minimum_runs
13900#endif
13901 );
13902
13903exit:
13904 bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
13905 ret);
13906#ifdef MULTI_VALUE_STATISTICS
13907 bench_multi_value_stats(max, min, sum, squareSum, runs);
13908#endif
13909
13910 wc_curve25519_free(&genKey2);
13911 wc_curve25519_free(&genKey);
13912}
13913#endif /* HAVE_CURVE25519_SHARED_SECRET */
13914#endif /* HAVE_CURVE25519 */
13915
13916#ifdef HAVE_ED25519
13917void bench_ed25519KeyGen(int useDeviceID)
13918{
13919#ifndef HAVE_ED25519_MAKE_KEY
13920 (void)useDeviceID;
13921#endif
13922#ifdef HAVE_ED25519_MAKE_KEY
13923 ed25519_key genKey;
13924 double start;
13925 int ret = 0, i, count;
13926 const char**desc = bench_desc_words[lng_index];
13927 DECLARE_MULTI_VALUE_STATS_VARS()
13928
13929 bench_stats_prepare();
13930
13931 /* Key Gen */
13932 bench_stats_start(&count, &start);
13933 do {
13934 for (i = 0; i < genTimes; i++) {
13935 ret = wc_ed25519_init_ex(&genKey, HEAP_HINT,
13936 useDeviceID ? devId : INVALID_DEVID);
13937 if (ret != 0) {
13938 printf("wc_ed25519_init_ex failed: %d\n", ret);
13939 break;
13940 }
13941
13942 ret = wc_ed25519_make_key(&gRng, 32, &genKey);
13943 wc_ed25519_free(&genKey);
13944 if (ret != 0) {
13945 printf("wc_ed25519_make_key failed: %d\n", ret);
13946 break;
13947 }
13948 RECORD_MULTI_VALUE_STATS();
13949 }
13950 count += i;
13951 } while (bench_stats_check(start)
13952#ifdef MULTI_VALUE_STATISTICS
13953 || runs < minimum_runs
13954#endif
13955 );
13956
13957 bench_stats_asym_finish("ED", 25519, desc[2], useDeviceID, count, start,
13958 ret);
13959#ifdef MULTI_VALUE_STATISTICS
13960 bench_multi_value_stats(max, min, sum, squareSum, runs);
13961#endif
13962#endif /* HAVE_ED25519_MAKE_KEY */
13963}
13964
13965
13966void bench_ed25519KeySign(int useDeviceID)
13967{
13968 int ret = 0;
13969 ed25519_key genKey;
13970#ifdef HAVE_ED25519_SIGN
13971 double start;
13972 int i, count;
13973 byte sig[ED25519_SIG_SIZE];
13974 byte msg[512];
13975 word32 x = 0;
13976 const char**desc = bench_desc_words[lng_index];
13977 DECLARE_MULTI_VALUE_STATS_VARS()
13978#endif
13979
13980 bench_stats_prepare();
13981
13982 ret = wc_ed25519_init_ex(&genKey, HEAP_HINT,
13983 useDeviceID ? devId : INVALID_DEVID);
13984 if (ret != 0) {
13985 printf("wc_ed25519_init_ex failed: %d\n", ret);
13986 return;
13987 }
13988
13989#ifdef HAVE_ED25519_MAKE_KEY
13990 ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
13991 if (ret != 0) {
13992 printf("ed25519_make_key failed\n");
13993 return;
13994 }
13995#endif
13996
13997#ifdef HAVE_ED25519_SIGN
13998 /* make dummy msg */
13999 for (i = 0; i < (int)sizeof(msg); i++)
14000 msg[i] = (byte)i;
14001
14002 bench_stats_start(&count, &start);
14003 do {
14004 for (i = 0; i < agreeTimes; i++) {
14005 x = sizeof(sig);
14006 ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
14007 if (ret != 0) {
14008 printf("ed25519_sign_msg failed\n");
14009 goto exit_ed_sign;
14010 }
14011 RECORD_MULTI_VALUE_STATS();
14012 }
14013 count += i;
14014 } while (bench_stats_check(start)
14015#ifdef MULTI_VALUE_STATISTICS
14016 || runs < minimum_runs
14017#endif
14018 );
14019
14020exit_ed_sign:
14021 bench_stats_asym_finish("ED", 25519, desc[4], useDeviceID, count, start,
14022 ret);
14023#ifdef MULTI_VALUE_STATISTICS
14024 bench_multi_value_stats(max, min, sum, squareSum, runs);
14025#endif
14026
14027 RESET_MULTI_VALUE_STATS_VARS();
14028
14029#ifdef HAVE_ED25519_VERIFY
14030 bench_stats_start(&count, &start);
14031 do {
14032 for (i = 0; i < agreeTimes; i++) {
14033 int verify = 0;
14034 ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
14035 &genKey);
14036 if (ret != 0 || verify != 1) {
14037 printf("ed25519_verify_msg failed\n");
14038 goto exit_ed_verify;
14039 }
14040 RECORD_MULTI_VALUE_STATS();
14041 }
14042 count += i;
14043 } while (bench_stats_check(start)
14044#ifdef MULTI_VALUE_STATISTICS
14045 || runs < minimum_runs
14046#endif
14047 );
14048
14049exit_ed_verify:
14050 bench_stats_asym_finish("ED", 25519, desc[5], useDeviceID, count, start,
14051 ret);
14052#ifdef MULTI_VALUE_STATISTICS
14053 bench_multi_value_stats(max, min, sum, squareSum, runs);
14054#endif
14055#endif /* HAVE_ED25519_VERIFY */
14056#endif /* HAVE_ED25519_SIGN */
14057
14058 wc_ed25519_free(&genKey);
14059}
14060#endif /* HAVE_ED25519 */
14061
14062#ifdef HAVE_CURVE448
14063void bench_curve448KeyGen(void)
14064{
14065 curve448_key genKey;
14066 double start;
14067 int ret = 0, i, count;
14068 const char**desc = bench_desc_words[lng_index];
14069 DECLARE_MULTI_VALUE_STATS_VARS()
14070
14071 bench_stats_prepare();
14072
14073 /* Key Gen */
14074 bench_stats_start(&count, &start);
14075 do {
14076 for (i = 0; i < genTimes; i++) {
14077 ret = wc_curve448_make_key(&gRng, 56, &genKey);
14078 wc_curve448_free(&genKey);
14079 if (ret != 0) {
14080 printf("wc_curve448_make_key failed: %d\n", ret);
14081 break;
14082 }
14083 RECORD_MULTI_VALUE_STATS();
14084 }
14085 count += i;
14086 } while (bench_stats_check(start)
14087#ifdef MULTI_VALUE_STATISTICS
14088 || runs < minimum_runs
14089#endif
14090 );
14091
14092 bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
14093#ifdef MULTI_VALUE_STATISTICS
14094 bench_multi_value_stats(max, min, sum, squareSum, runs);
14095#endif
14096}
14097
14098#ifdef HAVE_CURVE448_SHARED_SECRET
14099void bench_curve448KeyAgree(void)
14100{
14101 curve448_key genKey, genKey2;
14102 double start;
14103 int ret, i, count;
14104 byte shared[56];
14105 const char**desc = bench_desc_words[lng_index];
14106 word32 x = 0;
14107 DECLARE_MULTI_VALUE_STATS_VARS()
14108
14109 bench_stats_prepare();
14110
14111 wc_curve448_init(&genKey);
14112 wc_curve448_init(&genKey2);
14113
14114 ret = wc_curve448_make_key(&gRng, 56, &genKey);
14115 if (ret != 0) {
14116 printf("curve448_make_key failed\n");
14117 return;
14118 }
14119 ret = wc_curve448_make_key(&gRng, 56, &genKey2);
14120 if (ret != 0) {
14121 printf("curve448_make_key failed: %d\n", ret);
14122 wc_curve448_free(&genKey);
14123 return;
14124 }
14125
14126 /* Shared secret */
14127 bench_stats_start(&count, &start);
14128 do {
14129 for (i = 0; i < agreeTimes; i++) {
14130 x = sizeof(shared);
14131 ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
14132 if (ret != 0) {
14133 printf("curve448_shared_secret failed: %d\n", ret);
14134 goto exit;
14135 }
14136 RECORD_MULTI_VALUE_STATS();
14137 }
14138 count += i;
14139 } while (bench_stats_check(start)
14140#ifdef MULTI_VALUE_STATISTICS
14141 || runs < minimum_runs
14142#endif
14143 );
14144
14145exit:
14146 bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
14147#ifdef MULTI_VALUE_STATISTICS
14148 bench_multi_value_stats(max, min, sum, squareSum, runs);
14149#endif
14150
14151 wc_curve448_free(&genKey2);
14152 wc_curve448_free(&genKey);
14153}
14154#endif /* HAVE_CURVE448_SHARED_SECRET */
14155#endif /* HAVE_CURVE448 */
14156
14157#ifdef HAVE_ED448
14158void bench_ed448KeyGen(void)
14159{
14160 ed448_key genKey;
14161 double start;
14162 int i, count;
14163 const char**desc = bench_desc_words[lng_index];
14164 DECLARE_MULTI_VALUE_STATS_VARS()
14165
14166 bench_stats_prepare();
14167
14168 /* Key Gen */
14169 bench_stats_start(&count, &start);
14170 do {
14171 for (i = 0; i < genTimes; i++) {
14172 wc_ed448_init(&genKey);
14173 (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
14174 wc_ed448_free(&genKey);
14175 RECORD_MULTI_VALUE_STATS();
14176 }
14177 count += i;
14178 } while (bench_stats_check(start)
14179#ifdef MULTI_VALUE_STATISTICS
14180 || runs < minimum_runs
14181#endif
14182 );
14183
14184 bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
14185#ifdef MULTI_VALUE_STATISTICS
14186 bench_multi_value_stats(max, min, sum, squareSum, runs);
14187#endif
14188}
14189
14190void bench_ed448KeySign(void)
14191{
14192 int ret;
14193 WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
14194#ifdef HAVE_ED448_SIGN
14195 double start;
14196 int i, count;
14197 byte sig[ED448_SIG_SIZE];
14198 byte msg[512];
14199 word32 x = 0;
14200 const char**desc = bench_desc_words[lng_index];
14201 DECLARE_MULTI_VALUE_STATS_VARS()
14202#endif
14203
14204 bench_stats_prepare();
14205
14206 WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
14207
14208 wc_ed448_init(genKey);
14209
14210 ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
14211 if (ret != 0) {
14212 printf("ed448_make_key failed\n");
14213 goto exit;
14214 }
14215
14216#ifdef HAVE_ED448_SIGN
14217 /* make dummy msg */
14218 for (i = 0; i < (int)sizeof(msg); i++)
14219 msg[i] = (byte)i;
14220
14221 bench_stats_start(&count, &start);
14222 do {
14223 for (i = 0; i < agreeTimes; i++) {
14224 x = sizeof(sig);
14225 ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
14226 NULL, 0);
14227 if (ret != 0) {
14228 printf("ed448_sign_msg failed\n");
14229 goto exit;
14230 }
14231 RECORD_MULTI_VALUE_STATS();
14232 }
14233 count += i;
14234 } while (bench_stats_check(start)
14235#ifdef MULTI_VALUE_STATISTICS
14236 || runs < minimum_runs
14237#endif
14238 );
14239
14240 bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
14241#ifdef MULTI_VALUE_STATISTICS
14242 bench_multi_value_stats(max, min, sum, squareSum, runs);
14243#endif
14244
14245 RESET_MULTI_VALUE_STATS_VARS();
14246
14247#ifdef HAVE_ED448_VERIFY
14248 bench_stats_start(&count, &start);
14249 do {
14250 for (i = 0; i < agreeTimes; i++) {
14251 int verify = 0;
14252 ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
14253 genKey, NULL, 0);
14254 if (ret != 0 || verify != 1) {
14255 printf("ed448_verify_msg failed\n");
14256 goto exit;
14257 }
14258 RECORD_MULTI_VALUE_STATS();
14259 }
14260 count += i;
14261 } while (bench_stats_check(start)
14262#ifdef MULTI_VALUE_STATISTICS
14263 || runs < minimum_runs
14264#endif
14265 );
14266
14267 bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
14268#ifdef MULTI_VALUE_STATISTICS
14269 bench_multi_value_stats(max, min, sum, squareSum, runs);
14270#endif
14271#endif /* HAVE_ED448_VERIFY */
14272#endif /* HAVE_ED448_SIGN */
14273
14274exit:
14275
14276 wc_ed448_free(genKey);
14277 WC_FREE_VAR(genKey, HEAP_HINT);
14278}
14279#endif /* HAVE_ED448 */
14280
14281#ifdef WOLFCRYPT_HAVE_ECCSI
14282#ifdef WOLFCRYPT_ECCSI_KMS
14283void bench_eccsiKeyGen(void)
14284{
14285 WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
14286 double start;
14287 int i, count;
14288 const char**desc = bench_desc_words[lng_index];
14289 int ret;
14290 DECLARE_MULTI_VALUE_STATS_VARS()
14291
14292 bench_stats_prepare();
14293
14294 WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
14295
14296 /* Key Gen */
14297 bench_stats_start(&count, &start);
14298 do {
14299 for (i = 0; i < genTimes; i++) {
14300 wc_InitEccsiKey(genKey, HEAP_HINT, INVALID_DEVID);
14301 ret = wc_MakeEccsiKey(genKey, &gRng);
14302 wc_FreeEccsiKey(genKey);
14303 if (ret != 0) {
14304 printf("wc_MakeEccsiKey failed: %d\n", ret);
14305 goto exit;
14306 }
14307 RECORD_MULTI_VALUE_STATS();
14308 }
14309 count += i;
14310 } while (bench_stats_check(start)
14311#ifdef MULTI_VALUE_STATISTICS
14312 || runs < minimum_runs
14313#endif
14314 );
14315
14316 bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
14317#ifdef MULTI_VALUE_STATISTICS
14318 bench_multi_value_stats(max, min, sum, squareSum, runs);
14319#endif
14320
14321exit:
14322
14323 WC_FREE_VAR(genKey, HEAP_HINT);
14324}
14325
14326void bench_eccsiPairGen(void)
14327{
14328 WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
14329 double start;
14330 int i, count;
14331 const char**desc = bench_desc_words[lng_index];
14332 WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
14333 ecc_point* pvt;
14334 static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
14335 int ret;
14336 DECLARE_MULTI_VALUE_STATS_VARS()
14337
14338 bench_stats_prepare();
14339
14340 WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
14341 WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
14342
14343 (void)mp_init(ssk);
14344 pvt = wc_ecc_new_point();
14345 wc_InitEccsiKey(genKey, HEAP_HINT, INVALID_DEVID);
14346 (void)wc_MakeEccsiKey(genKey, &gRng);
14347
14348 /* RSK Gen */
14349 bench_stats_start(&count, &start);
14350 do {
14351 for (i = 0; i < genTimes; i++) {
14352 ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
14353 sizeof(id), ssk, pvt);
14354 if (ret != 0) {
14355 printf("wc_MakeEccsiPair failed: %d\n", ret);
14356 goto exit;
14357 }
14358 RECORD_MULTI_VALUE_STATS();
14359 }
14360 count += i;
14361 } while (bench_stats_check(start)
14362#ifdef MULTI_VALUE_STATISTICS
14363 || runs < minimum_runs
14364#endif
14365 );
14366
14367 bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
14368#ifdef MULTI_VALUE_STATISTICS
14369 bench_multi_value_stats(max, min, sum, squareSum, runs);
14370#endif
14371
14372 wc_FreeEccsiKey(genKey);
14373 wc_ecc_del_point(pvt);
14374 mp_free(ssk);
14375
14376exit:
14377
14378 WC_FREE_VAR(genKey, HEAP_HINT);
14379 WC_FREE_VAR(ssk, HEAP_HINT);
14380}
14381#endif
14382
14383#ifdef WOLFCRYPT_ECCSI_CLIENT
14384void bench_eccsiValidate(void)
14385{
14386 WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
14387 double start;
14388 int i, count;
14389 const char**desc = bench_desc_words[lng_index];
14390 WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
14391 ecc_point* pvt;
14392 static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
14393 int valid;
14394 int ret;
14395 DECLARE_MULTI_VALUE_STATS_VARS()
14396
14397 bench_stats_prepare();
14398
14399 WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
14400 WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
14401
14402 (void)mp_init(ssk);
14403 pvt = wc_ecc_new_point();
14404 wc_InitEccsiKey(genKey, HEAP_HINT, INVALID_DEVID);
14405 (void)wc_MakeEccsiKey(genKey, &gRng);
14406 (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
14407 ssk, pvt);
14408
14409 /* Validation of RSK */
14410 bench_stats_start(&count, &start);
14411 do {
14412 for (i = 0; i < genTimes; i++) {
14413 ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
14414 sizeof(id), ssk, pvt, &valid);
14415 if (ret != 0 || !valid) {
14416 printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
14417 valid);
14418 goto exit;
14419 }
14420 RECORD_MULTI_VALUE_STATS();
14421 }
14422 count += i;
14423 } while (bench_stats_check(start)
14424#ifdef MULTI_VALUE_STATISTICS
14425 || runs < minimum_runs
14426#endif
14427 );
14428
14429 bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
14430#ifdef MULTI_VALUE_STATISTICS
14431 bench_multi_value_stats(max, min, sum, squareSum, runs);
14432#endif
14433
14434 wc_FreeEccsiKey(genKey);
14435 wc_ecc_del_point(pvt);
14436 mp_free(ssk);
14437
14438exit:
14439
14440 WC_FREE_VAR(genKey, HEAP_HINT);
14441 WC_FREE_VAR(ssk, HEAP_HINT);
14442}
14443
14444void bench_eccsi(void)
14445{
14446 WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
14447 double start;
14448 int i, count;
14449 const char**desc = bench_desc_words[lng_index];
14450 WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
14451 ecc_point* pvt;
14452 static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
14453 static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
14454 byte hash[WC_SHA256_DIGEST_SIZE];
14455 byte hashSz = (byte)sizeof(hash);
14456 byte sig[257];
14457 word32 sigSz = sizeof(sig);
14458 int ret;
14459 int verified;
14460 DECLARE_MULTI_VALUE_STATS_VARS()
14461
14462 bench_stats_prepare();
14463
14464 WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
14465 WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
14466
14467 (void)mp_init(ssk);
14468 pvt = wc_ecc_new_point();
14469 (void)wc_InitEccsiKey(genKey, HEAP_HINT, INVALID_DEVID);
14470 (void)wc_MakeEccsiKey(genKey, &gRng);
14471 (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
14472 ssk, pvt);
14473 (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
14474 hash, &hashSz);
14475 (void)wc_SetEccsiHash(genKey, hash, hashSz);
14476 (void)wc_SetEccsiPair(genKey, ssk, pvt);
14477
14478 /* Encapsulate */
14479 bench_stats_start(&count, &start);
14480 do {
14481 for (i = 0; i < genTimes; i++) {
14482 ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
14483 sizeof(msg), sig, &sigSz);
14484 if (ret != 0) {
14485 printf("wc_SignEccsiHash failed: %d\n", ret);
14486 break;
14487 }
14488 RECORD_MULTI_VALUE_STATS();
14489 }
14490 count += i;
14491 } while (bench_stats_check(start)
14492#ifdef MULTI_VALUE_STATISTICS
14493 || runs < minimum_runs
14494#endif
14495 );
14496
14497 bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
14498#ifdef MULTI_VALUE_STATISTICS
14499 bench_multi_value_stats(max, min, sum, squareSum, runs);
14500#endif
14501
14502 RESET_MULTI_VALUE_STATS_VARS();
14503
14504 /* Derive */
14505 bench_stats_start(&count, &start);
14506 do {
14507 for (i = 0; i < genTimes; i++) {
14508 ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
14509 sizeof(msg), sig, sigSz, &verified);
14510
14511 if (ret != 0 || !verified) {
14512 printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
14513 verified);
14514 goto exit;
14515 }
14516 RECORD_MULTI_VALUE_STATS();
14517 }
14518 count += i;
14519 } while (bench_stats_check(start)
14520#ifdef MULTI_VALUE_STATISTICS
14521 || runs < minimum_runs
14522#endif
14523 );
14524
14525 bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
14526#ifdef MULTI_VALUE_STATISTICS
14527 bench_multi_value_stats(max, min, sum, squareSum, runs);
14528#endif
14529
14530 wc_FreeEccsiKey(genKey);
14531 wc_ecc_del_point(pvt);
14532
14533exit:
14534
14535 WC_FREE_VAR(genKey, HEAP_HINT);
14536 WC_FREE_VAR(ssk, HEAP_HINT);
14537}
14538#endif /* WOLFCRYPT_ECCSI_CLIENT */
14539#endif /* WOLFCRYPT_HAVE_ECCSI */
14540
14541#ifdef WOLFCRYPT_HAVE_SAKKE
14542#ifdef WOLFCRYPT_SAKKE_KMS
14543void bench_sakkeKeyGen(void)
14544{
14545 WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
14546 double start;
14547 int i, count;
14548 const char**desc = bench_desc_words[lng_index];
14549 int ret;
14550 DECLARE_MULTI_VALUE_STATS_VARS()
14551
14552 bench_stats_prepare();
14553
14554 WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
14555
14556 /* Key Gen */
14557 bench_stats_start(&count, &start);
14558 do {
14559 for (i = 0; i < genTimes; i++) {
14560 wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
14561 ret = wc_MakeSakkeKey(genKey, &gRng);
14562 if (ret != 0) {
14563 printf("wc_MakeSakkeKey failed: %d\n", ret);
14564 goto exit;
14565 }
14566 wc_FreeSakkeKey(genKey);
14567 RECORD_MULTI_VALUE_STATS();
14568 }
14569 count += i;
14570 } while (bench_stats_check(start)
14571#ifdef MULTI_VALUE_STATISTICS
14572 || runs < minimum_runs
14573#endif
14574 );
14575
14576 bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
14577#ifdef MULTI_VALUE_STATISTICS
14578 bench_multi_value_stats(max, min, sum, squareSum, runs);
14579#endif
14580
14581exit:
14582
14583 WC_FREE_VAR(genKey, HEAP_HINT);
14584}
14585
14586void bench_sakkeRskGen(void)
14587{
14588 WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
14589 double start;
14590 int i, count;
14591 const char**desc = bench_desc_words[lng_index];
14592 ecc_point* rsk;
14593 static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
14594 int ret;
14595 DECLARE_MULTI_VALUE_STATS_VARS()
14596
14597 bench_stats_prepare();
14598
14599 WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
14600
14601 rsk = wc_ecc_new_point();
14602 wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
14603 (void)wc_MakeSakkeKey(genKey, &gRng);
14604
14605 /* RSK Gen */
14606 bench_stats_start(&count, &start);
14607 do {
14608 for (i = 0; i < genTimes; i++) {
14609 ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
14610 if (ret != 0) {
14611 printf("wc_MakeSakkeRsk failed: %d\n", ret);
14612 goto exit;
14613 }
14614 RECORD_MULTI_VALUE_STATS();
14615 }
14616 count += i;
14617 } while (bench_stats_check(start)
14618#ifdef MULTI_VALUE_STATISTICS
14619 || runs < minimum_runs
14620#endif
14621 );
14622
14623 bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
14624#ifdef MULTI_VALUE_STATISTICS
14625 bench_multi_value_stats(max, min, sum, squareSum, runs);
14626#endif
14627
14628 wc_FreeSakkeKey(genKey);
14629 wc_ecc_del_point(rsk);
14630
14631exit:
14632
14633 WC_FREE_VAR(genKey, HEAP_HINT);
14634}
14635#endif
14636
14637#ifdef WOLFCRYPT_SAKKE_CLIENT
14638void bench_sakkeValidate(void)
14639{
14640 WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
14641 double start;
14642 int i, count;
14643 const char**desc = bench_desc_words[lng_index];
14644 ecc_point* rsk;
14645 static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
14646 int valid;
14647 int ret;
14648 DECLARE_MULTI_VALUE_STATS_VARS()
14649
14650 bench_stats_prepare();
14651
14652 WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
14653
14654 rsk = wc_ecc_new_point();
14655 (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
14656 (void)wc_MakeSakkeKey(genKey, &gRng);
14657 (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
14658 (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
14659
14660 /* Validation of RSK */
14661 bench_stats_start(&count, &start);
14662 do {
14663 for (i = 0; i < genTimes; i++) {
14664 ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
14665 if (ret != 0 || !valid) {
14666 printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
14667 valid);
14668 goto exit;
14669 }
14670 RECORD_MULTI_VALUE_STATS();
14671 }
14672 count += i;
14673 } while (bench_stats_check(start)
14674#ifdef MULTI_VALUE_STATISTICS
14675 || runs < minimum_runs
14676#endif
14677 );
14678
14679 bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
14680#ifdef MULTI_VALUE_STATISTICS
14681 bench_multi_value_stats(max, min, sum, squareSum, runs);
14682#endif
14683
14684 wc_FreeSakkeKey(genKey);
14685 wc_ecc_del_point(rsk);
14686
14687exit:
14688
14689 WC_FREE_VAR(genKey, HEAP_HINT);
14690}
14691
14692void bench_sakke(void)
14693{
14694 WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
14695 double start;
14696 int i, count;
14697 const char**desc = bench_desc_words[lng_index];
14698 ecc_point* rsk;
14699 static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
14700 static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
14701 byte ssv[sizeof(ssv_init)];
14702 byte derSSV[sizeof(ssv)];
14703 byte auth[257];
14704 word16 authSz = sizeof(auth);
14705 int ret = 0;
14706 byte* table = NULL;
14707 word32 len = 0;
14708 byte* iTable = NULL;
14709 word32 iTableLen = 0;
14710 DECLARE_MULTI_VALUE_STATS_VARS()
14711
14712 bench_stats_prepare();
14713
14714 WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
14715
14716 XMEMCPY(ssv, ssv_init, sizeof ssv);
14717
14718 rsk = wc_ecc_new_point();
14719 (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
14720 (void)wc_MakeSakkeKey(genKey, &gRng);
14721 (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
14722 (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
14723 (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
14724
14725 /* Encapsulate */
14726 bench_stats_start(&count, &start);
14727 do {
14728 for (i = 0; i < genTimes; i++) {
14729 ret = wc_MakeSakkeEncapsulatedSSV(genKey,
14730 WC_HASH_TYPE_SHA256,
14731 ssv, sizeof(ssv), auth, &authSz);
14732 if (ret != 0) {
14733 printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
14734 break;
14735 }
14736 RECORD_MULTI_VALUE_STATS();
14737 } /* for */
14738 count += i;
14739 } while (bench_stats_check(start)
14740#ifdef MULTI_VALUE_STATISTICS
14741 || runs < minimum_runs
14742#endif
14743 );
14744
14745 bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
14746 0, count, start, 0);
14747#ifdef MULTI_VALUE_STATISTICS
14748 bench_multi_value_stats(max, min, sum, squareSum, runs);
14749#endif
14750
14751 RESET_MULTI_VALUE_STATS_VARS();
14752
14753 /* Derive */
14754 bench_stats_start(&count, &start);
14755 do {
14756 for (i = 0; i < genTimes; i++) {
14757 XMEMCPY(derSSV, ssv, sizeof(ssv));
14758 ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
14759 sizeof(derSSV), auth, authSz);
14760 if (ret != 0) {
14761 printf("wc_DeriveSakkeSSV failed: %d\n", ret);
14762 break;
14763 }
14764 RECORD_MULTI_VALUE_STATS();
14765 }
14766 if (ret != 0) break;
14767 count += i;
14768 } while (bench_stats_check(start)
14769#ifdef MULTI_VALUE_STATISTICS
14770 || runs < minimum_runs
14771#endif
14772 );
14773
14774 bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
14775 0, count, start, 0);
14776#ifdef MULTI_VALUE_STATISTICS
14777 bench_multi_value_stats(max, min, sum, squareSum, runs);
14778#endif
14779
14780 /* Calculate Point I and generate table. */
14781 (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
14782 iTableLen = 0;
14783 (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
14784 if (iTableLen != 0) {
14785 iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
14786 if (iTable == NULL)
14787 WC_ALLOC_DO_ON_FAILURE();
14788 (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
14789 }
14790
14791 /* Encapsulate with Point I table */
14792 bench_stats_start(&count, &start);
14793 do {
14794 for (i = 0; i < genTimes; i++) {
14795 ret = wc_MakeSakkeEncapsulatedSSV(genKey,
14796 WC_HASH_TYPE_SHA256, ssv,
14797 sizeof(ssv), auth, &authSz);
14798 if (ret != 0) {
14799 printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
14800 break;
14801 }
14802 RECORD_MULTI_VALUE_STATS();
14803 }
14804 count += i;
14805 } while (bench_stats_check(start)
14806#ifdef MULTI_VALUE_STATISTICS
14807 || runs < minimum_runs
14808#endif
14809 );
14810
14811 bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
14812 count, start, 0);
14813#ifdef MULTI_VALUE_STATISTICS
14814 bench_multi_value_stats(max, min, sum, squareSum, runs);
14815#endif
14816
14817 RESET_MULTI_VALUE_STATS_VARS();
14818
14819 (void)wc_SetSakkeRsk(genKey, rsk, table, len);
14820
14821 /* Derive with Point I table */
14822 bench_stats_start(&count, &start);
14823 do {
14824 for (i = 0; i < genTimes; i++) {
14825 XMEMCPY(derSSV, ssv, sizeof(ssv));
14826 ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
14827 sizeof(derSSV), auth, authSz);
14828 if (ret != 0) {
14829 printf("wc_DeriveSakkeSSV failed: %d\n", ret);
14830 break;
14831 }
14832 RECORD_MULTI_VALUE_STATS();
14833 }
14834 if (ret != 0) break;
14835 count += i;
14836 } while (bench_stats_check(start)
14837#ifdef MULTI_VALUE_STATISTICS
14838 || runs < minimum_runs
14839#endif
14840 );
14841
14842 bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
14843 count, start, 0);
14844#ifdef MULTI_VALUE_STATISTICS
14845 bench_multi_value_stats(max, min, sum, squareSum, runs);
14846#endif
14847
14848 RESET_MULTI_VALUE_STATS_VARS();
14849
14850 len = 0;
14851 (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
14852 if (len > 0) {
14853 table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
14854 if (table == NULL)
14855 WC_ALLOC_DO_ON_FAILURE();
14856 (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
14857 }
14858 (void)wc_SetSakkeRsk(genKey, rsk, table, len);
14859
14860 /* Derive with Point I table and RSK table */
14861 bench_stats_start(&count, &start);
14862 do {
14863 for (i = 0; i < genTimes; i++) {
14864 XMEMCPY(derSSV, ssv, sizeof(ssv));
14865 ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
14866 sizeof(derSSV), auth, authSz);
14867 if (ret != 0) {
14868 printf("wc_DeriveSakkeSSV failed: %d\n", ret);
14869 break;
14870 }
14871 RECORD_MULTI_VALUE_STATS();
14872 }
14873 if (ret != 0) break;
14874 count += i;
14875 } while (bench_stats_check(start)
14876#ifdef MULTI_VALUE_STATISTICS
14877 || runs < minimum_runs
14878#endif
14879 );
14880
14881 bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
14882 0, count, start, 0);
14883#ifdef MULTI_VALUE_STATISTICS
14884 bench_multi_value_stats(max, min, sum, squareSum, runs);
14885#endif
14886
14887 RESET_MULTI_VALUE_STATS_VARS();
14888
14889 wc_ClearSakkePointITable(genKey);
14890 /* Derive with RSK table */
14891 bench_stats_start(&count, &start);
14892 do {
14893 for (i = 0; i < genTimes; i++) {
14894 XMEMCPY(derSSV, ssv, sizeof(ssv));
14895 ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
14896 sizeof(derSSV), auth, authSz);
14897 if (ret != 0) {
14898 printf("wc_DeriveSakkeSSV failed: %d\n", ret);
14899 break;
14900 }
14901 RECORD_MULTI_VALUE_STATS();
14902 }
14903 if (ret != 0) break;
14904 count += i;
14905 } while (bench_stats_check(start)
14906#ifdef MULTI_VALUE_STATISTICS
14907 || runs < minimum_runs
14908#endif
14909 );
14910
14911 bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
14912 count, start, 0);
14913#ifdef MULTI_VALUE_STATISTICS
14914 bench_multi_value_stats(max, min, sum, squareSum, runs);
14915#endif
14916
14917 wc_FreeSakkeKey(genKey);
14918 wc_ecc_del_point(rsk);
14919
14920exit:
14921
14922 XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
14923
14924 XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
14925
14926 WC_FREE_VAR(genKey, HEAP_HINT);
14927}
14928#endif /* WOLFCRYPT_SAKKE_CLIENT */
14929#endif /* WOLFCRYPT_HAVE_SAKKE */
14930
14931#ifdef HAVE_FALCON
14932void bench_falconKeySign(byte level)
14933{
14934 int ret = 0;
14935 falcon_key key;
14936 double start;
14937 int i, count;
14938 byte sig[FALCON_MAX_SIG_SIZE];
14939 byte msg[512];
14940 word32 x = 0;
14941 const char**desc = bench_desc_words[lng_index];
14942 DECLARE_MULTI_VALUE_STATS_VARS()
14943
14944 bench_stats_prepare();
14945
14946 ret = wc_falcon_init_ex(&key, HEAP_HINT, devId);
14947 if (ret != 0) {
14948 printf("wc_falcon_init_ex failed %d\n", ret);
14949 return;
14950 }
14951
14952 ret = wc_falcon_set_level(&key, level);
14953 if (ret != 0) {
14954 printf("wc_falcon_set_level failed %d\n", ret);
14955 }
14956
14957 if (ret == 0) {
14958 word32 idx = 0;
14959 if (level == 1) {
14960 ret = wc_Falcon_PrivateKeyDecode(bench_falcon_level1_key, &idx,
14961 &key,
14962 sizeof_bench_falcon_level1_key);
14963 }
14964 else {
14965 ret = wc_Falcon_PrivateKeyDecode(bench_falcon_level5_key, &idx,
14966 &key,
14967 sizeof_bench_falcon_level5_key);
14968 }
14969
14970 if (ret != 0) {
14971 printf("wc_Falcon_PrivateKeyDecode failed %d\n", ret);
14972 }
14973 }
14974
14975 /* make dummy msg */
14976 for (i = 0; i < (int)sizeof(msg); i++) {
14977 msg[i] = (byte)i;
14978 }
14979
14980 bench_stats_start(&count, &start);
14981 do {
14982 for (i = 0; i < agreeTimes; i++) {
14983 if (ret == 0) {
14984 if (level == 1) {
14985 x = FALCON_LEVEL1_SIG_SIZE;
14986 }
14987 else {
14988 x = FALCON_LEVEL5_SIG_SIZE;
14989 }
14990
14991 ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
14992 if (ret != 0) {
14993 printf("wc_falcon_sign_msg failed\n");
14994 }
14995 }
14996 RECORD_MULTI_VALUE_STATS();
14997 }
14998 count += i;
14999 } while (bench_stats_check(start)
15000#ifdef MULTI_VALUE_STATISTICS
15001 || runs < minimum_runs
15002#endif
15003 );
15004
15005 if (ret == 0) {
15006 bench_stats_asym_finish("FALCON", level, desc[4], 0,
15007 count, start, ret);
15008 #ifdef MULTI_VALUE_STATISTICS
15009 bench_multi_value_stats(max, min, sum, squareSum, runs);
15010 #endif
15011 }
15012
15013 RESET_MULTI_VALUE_STATS_VARS();
15014
15015 bench_stats_start(&count, &start);
15016 do {
15017 for (i = 0; i < agreeTimes; i++) {
15018 if (ret == 0) {
15019 int verify = 0;
15020 ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
15021 &key);
15022 if (ret != 0 || verify != 1) {
15023 printf("wc_falcon_verify_msg failed %d, verify %d\n",
15024 ret, verify);
15025 ret = -1;
15026 }
15027 }
15028 RECORD_MULTI_VALUE_STATS();
15029 }
15030 count += i;
15031 } while (bench_stats_check(start)
15032#ifdef MULTI_VALUE_STATISTICS
15033 || runs < minimum_runs
15034#endif
15035 );
15036
15037 if (ret == 0) {
15038 bench_stats_asym_finish("FALCON", level, desc[5],
15039 0, count, start, ret);
15040 #ifdef MULTI_VALUE_STATISTICS
15041 bench_multi_value_stats(max, min, sum, squareSum, runs);
15042 #endif
15043 }
15044
15045 wc_falcon_free(&key);
15046}
15047#endif /* HAVE_FALCON */
15048
15049#if defined(HAVE_DILITHIUM) && !defined(WC_NO_RNG)
15050
15051#if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
15052
15053#ifndef WOLFSSL_NO_ML_DSA_44
15054static const unsigned char bench_dilithium_level2_sig[] = {
15055 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
15056 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
15057 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
15058 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
15059 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
15060 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
15061 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
15062 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
15063 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
15064 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
15065 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
15066 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
15067 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
15068 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
15069 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
15070 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
15071 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
15072 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
15073 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
15074 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
15075 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
15076 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
15077 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
15078 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
15079 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
15080 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
15081 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
15082 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
15083 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
15084 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
15085 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
15086 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
15087 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
15088 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
15089 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
15090 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
15091 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
15092 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
15093 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
15094 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
15095 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
15096 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
15097 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
15098 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
15099 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
15100 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
15101 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
15102 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
15103 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
15104 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
15105 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
15106 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
15107 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
15108 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
15109 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
15110 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
15111 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
15112 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
15113 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
15114 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
15115 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
15116 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
15117 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
15118 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
15119 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
15120 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
15121 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
15122 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
15123 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
15124 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
15125 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
15126 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
15127 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
15128 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
15129 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
15130 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
15131 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
15132 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
15133 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
15134 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
15135 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
15136 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
15137 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
15138 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
15139 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
15140 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
15141 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
15142 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
15143 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
15144 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
15145 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
15146 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
15147 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
15148 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
15149 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
15150 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
15151 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
15152 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
15153 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
15154 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
15155 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
15156 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
15157 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
15158 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
15159 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
15160 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
15161 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
15162 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
15163 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
15164 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
15165 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
15166 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
15167 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
15168 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
15169 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
15170 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
15171 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
15172 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
15173 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
15174 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
15175 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
15176 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
15177 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
15178 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
15179 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
15180 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
15181 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
15182 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
15183 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
15184 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
15185 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
15186 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
15187 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
15188 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
15189 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
15190 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
15191 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
15192 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
15193 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
15194 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
15195 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
15196 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
15197 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
15198 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
15199 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
15200 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
15201 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
15202 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
15203 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
15204 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
15205 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
15206 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
15207 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
15208 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
15209 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
15210 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
15211 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
15212 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
15213 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
15214 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
15215 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
15216 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
15217 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
15218 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
15219 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
15220 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
15221 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
15222 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
15223 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
15224 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
15225 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
15226 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
15227 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
15228 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
15229 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
15230 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
15231 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
15232 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
15233 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
15234 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
15235 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
15236 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
15237 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
15238 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
15239 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
15240 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
15241 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
15242 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
15243 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
15244 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
15245 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
15246 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
15247 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
15248 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
15249 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
15250 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
15251 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
15252 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
15253 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
15254 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
15255 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
15256 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
15257 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
15258 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
15259 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
15260 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
15261 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
15262 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
15263 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
15264 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
15265 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
15266 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
15267 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
15268 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
15269 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
15270 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
15271 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
15272 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
15273 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
15274 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
15275 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
15276 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
15277 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
15278 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
15279 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
15280 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
15281 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
15282 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
15283 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
15284 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
15285 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
15286 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
15287 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
15288 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
15289 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
15290 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
15291 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
15292 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
15293 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
15294 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
15295 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
15296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
15297};
15298static const int sizeof_bench_dilithium_level2_sig =
15299 sizeof(bench_dilithium_level2_sig);
15300#endif
15301
15302#ifndef WOLFSSL_NO_ML_DSA_65
15303static const unsigned char bench_dilithium_level3_sig[] = {
15304 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
15305 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
15306 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
15307 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
15308 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
15309 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
15310 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
15311 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
15312 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
15313 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
15314 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
15315 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
15316 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
15317 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
15318 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
15319 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
15320 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
15321 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
15322 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
15323 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
15324 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
15325 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
15326 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
15327 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
15328 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
15329 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
15330 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
15331 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
15332 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
15333 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
15334 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
15335 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
15336 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
15337 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
15338 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
15339 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
15340 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
15341 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
15342 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
15343 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
15344 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
15345 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
15346 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
15347 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
15348 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
15349 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
15350 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
15351 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
15352 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
15353 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
15354 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
15355 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
15356 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
15357 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
15358 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
15359 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
15360 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
15361 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
15362 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
15363 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
15364 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
15365 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
15366 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
15367 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
15368 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
15369 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
15370 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
15371 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
15372 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
15373 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
15374 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
15375 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
15376 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
15377 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
15378 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
15379 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
15380 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
15381 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
15382 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
15383 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
15384 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
15385 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
15386 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
15387 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
15388 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
15389 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
15390 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
15391 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
15392 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
15393 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
15394 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
15395 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
15396 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
15397 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
15398 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
15399 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
15400 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
15401 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
15402 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
15403 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
15404 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
15405 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
15406 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
15407 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
15408 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
15409 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
15410 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
15411 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
15412 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
15413 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
15414 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
15415 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
15416 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
15417 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
15418 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
15419 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
15420 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
15421 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
15422 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
15423 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
15424 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
15425 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
15426 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
15427 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
15428 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
15429 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
15430 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
15431 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
15432 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
15433 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
15434 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
15435 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
15436 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
15437 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
15438 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
15439 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
15440 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
15441 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
15442 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
15443 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
15444 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
15445 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
15446 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
15447 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
15448 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
15449 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
15450 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
15451 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
15452 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
15453 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
15454 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
15455 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
15456 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
15457 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
15458 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
15459 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
15460 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
15461 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
15462 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
15463 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
15464 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
15465 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
15466 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
15467 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
15468 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
15469 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
15470 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
15471 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
15472 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
15473 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
15474 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
15475 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
15476 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
15477 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
15478 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
15479 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
15480 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
15481 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
15482 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
15483 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
15484 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
15485 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
15486 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
15487 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
15488 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
15489 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
15490 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
15491 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
15492 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
15493 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
15494 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
15495 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
15496 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
15497 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
15498 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
15499 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
15500 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
15501 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
15502 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
15503 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
15504 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
15505 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
15506 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
15507 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
15508 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
15509 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
15510 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
15511 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
15512 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
15513 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
15514 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
15515 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
15516 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
15517 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
15518 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
15519 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
15520 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
15521 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
15522 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
15523 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
15524 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
15525 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
15526 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
15527 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
15528 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
15529 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
15530 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
15531 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
15532 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
15533 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
15534 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
15535 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
15536 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
15537 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
15538 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
15539 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
15540 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
15541 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
15542 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
15543 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
15544 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
15545 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
15546 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
15547 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
15548 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
15549 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
15550 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
15551 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
15552 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
15553 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
15554 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
15555 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
15556 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
15557 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
15558 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
15559 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
15560 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
15561 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
15562 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
15563 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
15564 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
15565 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
15566 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
15567 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
15568 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
15569 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
15570 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
15571 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
15572 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
15573 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
15574 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
15575 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
15576 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
15577 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
15578 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
15579 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
15580 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
15581 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
15582 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
15583 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
15584 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
15585 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
15586 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
15587 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
15588 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
15589 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
15590 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
15591 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
15592 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
15593 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
15594 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
15595 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
15596 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
15597 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
15598 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
15599 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
15600 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
15601 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
15602 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
15603 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
15604 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
15605 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
15606 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
15607 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
15608 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
15609 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
15610 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
15611 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
15612 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
15613 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
15614 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
15615 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
15616 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
15617 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
15618 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
15619 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
15620 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
15621 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
15622 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
15623 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
15624 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
15625 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
15626 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
15627 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
15628 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
15629 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
15630 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
15631 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
15632 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
15633 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
15634 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
15635};
15636static const int sizeof_bench_dilithium_level3_sig =
15637 sizeof(bench_dilithium_level3_sig);
15638#endif
15639
15640#ifndef WOLFSSL_NO_ML_DSA_87
15641static const unsigned char bench_dilithium_level5_sig[] = {
15642 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
15643 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
15644 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
15645 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
15646 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
15647 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
15648 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
15649 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
15650 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
15651 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
15652 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
15653 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
15654 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
15655 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
15656 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
15657 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
15658 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
15659 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
15660 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
15661 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
15662 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
15663 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
15664 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
15665 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
15666 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
15667 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
15668 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
15669 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
15670 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
15671 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
15672 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
15673 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
15674 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
15675 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
15676 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
15677 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
15678 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
15679 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
15680 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
15681 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
15682 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
15683 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
15684 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
15685 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
15686 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
15687 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
15688 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
15689 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
15690 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
15691 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
15692 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
15693 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
15694 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
15695 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
15696 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
15697 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
15698 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
15699 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
15700 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
15701 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
15702 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
15703 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
15704 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
15705 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
15706 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
15707 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
15708 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
15709 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
15710 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
15711 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
15712 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
15713 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
15714 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
15715 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
15716 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
15717 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
15718 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
15719 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
15720 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
15721 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
15722 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
15723 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
15724 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
15725 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
15726 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
15727 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
15728 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
15729 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
15730 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
15731 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
15732 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
15733 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
15734 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
15735 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
15736 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
15737 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
15738 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
15739 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
15740 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
15741 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
15742 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
15743 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
15744 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
15745 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
15746 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
15747 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
15748 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
15749 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
15750 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
15751 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
15752 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
15753 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
15754 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
15755 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
15756 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
15757 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
15758 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
15759 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
15760 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
15761 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
15762 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
15763 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
15764 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
15765 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
15766 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
15767 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
15768 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
15769 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
15770 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
15771 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
15772 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
15773 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
15774 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
15775 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
15776 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
15777 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
15778 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
15779 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
15780 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
15781 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
15782 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
15783 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
15784 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
15785 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
15786 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
15787 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
15788 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
15789 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
15790 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
15791 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
15792 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
15793 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
15794 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
15795 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
15796 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
15797 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
15798 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
15799 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
15800 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
15801 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
15802 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
15803 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
15804 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
15805 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
15806 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
15807 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
15808 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
15809 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
15810 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
15811 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
15812 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
15813 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
15814 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
15815 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
15816 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
15817 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
15818 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
15819 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
15820 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
15821 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
15822 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
15823 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
15824 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
15825 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
15826 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
15827 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
15828 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
15829 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
15830 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
15831 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
15832 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
15833 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
15834 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
15835 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
15836 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
15837 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
15838 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
15839 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
15840 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
15841 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
15842 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
15843 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
15844 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
15845 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
15846 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
15847 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
15848 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
15849 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
15850 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
15851 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
15852 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
15853 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
15854 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
15855 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
15856 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
15857 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
15858 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
15859 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
15860 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
15861 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
15862 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
15863 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
15864 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
15865 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
15866 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
15867 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
15868 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
15869 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
15870 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
15871 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
15872 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
15873 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
15874 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
15875 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
15876 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
15877 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
15878 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
15879 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
15880 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
15881 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
15882 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
15883 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
15884 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
15885 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
15886 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
15887 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
15888 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
15889 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
15890 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
15891 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
15892 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
15893 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
15894 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
15895 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
15896 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
15897 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
15898 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
15899 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
15900 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
15901 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
15902 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
15903 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
15904 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
15905 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
15906 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
15907 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
15908 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
15909 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
15910 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
15911 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
15912 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
15913 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
15914 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
15915 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
15916 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
15917 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
15918 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
15919 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
15920 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
15921 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
15922 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
15923 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
15924 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
15925 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
15926 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
15927 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
15928 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
15929 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
15930 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
15931 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
15932 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
15933 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
15934 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
15935 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
15936 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
15937 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
15938 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
15939 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
15940 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
15941 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
15942 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
15943 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
15944 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
15945 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
15946 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
15947 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
15948 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
15949 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
15950 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
15951 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
15952 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
15953 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
15954 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
15955 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
15956 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
15957 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
15958 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
15959 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
15960 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
15961 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
15962 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
15963 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
15964 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
15965 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
15966 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
15967 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
15968 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
15969 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
15970 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
15971 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
15972 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
15973 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
15974 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
15975 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
15976 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
15977 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
15978 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
15979 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
15980 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
15981 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
15982 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
15983 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
15984 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
15985 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
15986 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
15987 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
15988 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
15989 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
15990 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
15991 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
15992 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
15993 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
15994 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
15995 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
15996 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
15997 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
15998 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
15999 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
16000 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
16001 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
16002 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
16003 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
16004 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
16005 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
16006 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
16007 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
16008 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
16009 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
16010 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
16011 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
16012 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
16013 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
16014 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
16015 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
16016 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
16017 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
16018 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
16019 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
16020 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
16021 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
16022 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
16023 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
16024 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
16025 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
16026 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
16027 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
16028 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
16029 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
16030 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
16031 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
16032 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
16033 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
16034 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
16035 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
16036 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
16037 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
16038 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
16039 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
16040 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
16041 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
16042 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
16043 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
16044 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
16045 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
16046 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
16047 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
16048 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
16049 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
16050 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
16051 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
16052 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
16053 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
16054 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
16055 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
16056 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
16057 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
16058 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
16059 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
16060 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
16061 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
16062 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
16063 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
16064 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
16065 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
16066 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
16067 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
16068 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
16069 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
16070 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
16071 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
16072 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
16073 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
16074 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
16075 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
16076 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
16077 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
16078 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
16079 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
16080 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
16081 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
16082 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
16083 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
16084 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
16085 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
16086 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
16087 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
16088 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
16089 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
16090 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
16091 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
16092 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
16093 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
16094 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
16095 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
16096 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
16097 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
16098 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
16099 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
16100 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
16101 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
16102 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
16103 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
16104 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
16105};
16106static const int sizeof_bench_dilithium_level5_sig =
16107 sizeof(bench_dilithium_level5_sig);
16108#endif
16109
16110#endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
16111
16112
16113void bench_dilithiumKeySign(byte level)
16114{
16115 int ret = 0;
16116 double start;
16117 int i, count;
16118#if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
16119 word32 x = 0;
16120#endif
16121
16122#define DILITHIUM_BENCH_MSG_SIZE 512
16123#ifdef WOLFSSL_SMALL_STACK
16124 dilithium_key *key = NULL;
16125 #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
16126 !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
16127 byte *sig = NULL;
16128 byte *msg = NULL;
16129 #endif
16130#else
16131 dilithium_key key[1];
16132 #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
16133 !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
16134 byte sig[DILITHIUM_MAX_SIG_SIZE];
16135 byte msg[DILITHIUM_BENCH_MSG_SIZE];
16136 #endif
16137#endif
16138
16139 const char**desc = bench_desc_words[lng_index];
16140 DECLARE_MULTI_VALUE_STATS_VARS()
16141 byte params = 0;
16142
16143 bench_stats_prepare();
16144
16145#ifdef WOLFSSL_SMALL_STACK
16146 key = (dilithium_key *)XMALLOC(sizeof(*key), HEAP_HINT,
16147 DYNAMIC_TYPE_TMP_BUFFER);
16148 #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
16149 !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
16150 sig = (byte *)XMALLOC(DILITHIUM_MAX_SIG_SIZE, HEAP_HINT,
16151 DYNAMIC_TYPE_TMP_BUFFER);
16152 msg = (byte *)XMALLOC(DILITHIUM_BENCH_MSG_SIZE, HEAP_HINT,
16153 DYNAMIC_TYPE_TMP_BUFFER);
16154 #endif
16155
16156 if (key == NULL) {
16157 #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
16158 !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
16159 XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
16160 sig = NULL;
16161 XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
16162 msg = NULL;
16163 #endif
16164 goto out;
16165 }
16166 #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
16167 !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
16168 if ((sig == NULL) || (msg == NULL)) {
16169 XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
16170 key = NULL;
16171 XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
16172 sig = NULL;
16173 XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
16174 msg = NULL;
16175 goto out;
16176 }
16177 #endif
16178#endif /* WOLFSSL_SMALL_STACK */
16179
16180 if (level == 2) {
16181 params = 44;
16182 }
16183 else if (level == 3) {
16184 params = 65;
16185 }
16186 else if (level == 5) {
16187 params = 87;
16188 }
16189
16190#if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
16191 /* make dummy msg */
16192 for (i = 0; i < DILITHIUM_BENCH_MSG_SIZE; i++) {
16193 msg[i] = (byte)i;
16194 }
16195#endif
16196
16197 ret = wc_dilithium_init_ex(key, HEAP_HINT, devId);
16198 if (ret != 0) {
16199 printf("wc_dilithium_init_ex failed %d\n", ret);
16200 goto out;
16201 }
16202
16203 ret = wc_dilithium_set_level(key, level);
16204 if (ret != 0) {
16205 printf("wc_dilithium_set_level() failed %d\n", ret);
16206 }
16207
16208#ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
16209 bench_stats_start(&count, &start);
16210 do {
16211 for (i = 0; i < agreeTimes; i++) {
16212 ret = wc_dilithium_make_key(key, GLOBAL_RNG);
16213 if (ret != 0) {
16214 printf("wc_dilithium_import_private_key failed %d\n", ret);
16215 goto out;
16216 }
16217 }
16218 count += i;
16219 } while (bench_stats_check(start)
16220#ifdef MULTI_VALUE_STATISTICS
16221 || runs < minimum_runs
16222#endif
16223 );
16224
16225 if (ret == 0) {
16226 bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
16227 start, ret);
16228 #ifdef MULTI_VALUE_STATISTICS
16229 bench_multi_value_stats(max, min, sum, squareSum, runs);
16230 #endif
16231 }
16232
16233#elif !defined WOLFSSL_DILITHIUM_NO_SIGN
16234
16235 PRIVATE_KEY_UNLOCK();
16236#ifndef WOLFSSL_NO_ML_DSA_44
16237 if (level == 2) {
16238 ret = wc_dilithium_import_private(bench_dilithium_level2_key,
16239 sizeof_bench_dilithium_level2_key, key);
16240 }
16241#endif
16242#ifndef WOLFSSL_NO_ML_DSA_65
16243 if (level == 3) {
16244 ret = wc_dilithium_import_private(bench_dilithium_level3_key,
16245 sizeof_bench_dilithium_level3_key, key);
16246 }
16247#endif
16248#ifndef WOLFSSL_NO_ML_DSA_87
16249 if (level == 5) {
16250 ret = wc_dilithium_import_private(bench_dilithium_level5_key,
16251 sizeof_bench_dilithium_level5_key, key);
16252 }
16253#endif
16254 PRIVATE_KEY_LOCK();
16255 if (ret != 0) {
16256 printf("Failed to load private key\n");
16257 goto out;
16258 }
16259
16260#endif
16261
16262#ifndef WOLFSSL_DILITHIUM_NO_SIGN
16263 if (level == 2) {
16264 x = DILITHIUM_LEVEL2_SIG_SIZE;
16265 }
16266 else if (level == 3) {
16267 x = DILITHIUM_LEVEL3_SIG_SIZE;
16268 }
16269 else {
16270 x = DILITHIUM_LEVEL5_SIG_SIZE;
16271 }
16272
16273 RESET_MULTI_VALUE_STATS_VARS();
16274
16275 bench_stats_start(&count, &start);
16276 do {
16277 for (i = 0; i < agreeTimes; i++) {
16278 if (ret == 0) {
16279 ret = wc_dilithium_sign_ctx_msg(NULL, 0, msg,
16280 DILITHIUM_BENCH_MSG_SIZE, sig, &x, key, GLOBAL_RNG);
16281 if (ret != 0) {
16282 printf("wc_dilithium_sign_ctx_msg failed\n");
16283 }
16284 }
16285 RECORD_MULTI_VALUE_STATS();
16286 }
16287 count += i;
16288 } while (bench_stats_check(start)
16289#ifdef MULTI_VALUE_STATISTICS
16290 || runs < minimum_runs
16291#endif
16292 );
16293
16294 if (ret == 0) {
16295 bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
16296 ret);
16297 #ifdef MULTI_VALUE_STATISTICS
16298 bench_multi_value_stats(max, min, sum, squareSum, runs);
16299 #endif
16300 }
16301
16302#endif
16303
16304#if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
16305 (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
16306 defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
16307
16308#ifndef WOLFSSL_NO_ML_DSA_44
16309 if (level == 2) {
16310 #ifdef WOLFSSL_DILITHIUM_NO_SIGN
16311 x = sizeof_bench_dilithium_level2_sig;
16312 XMEMCPY(sig, bench_dilithium_level2_sig, x);
16313 #endif
16314 ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
16315 sizeof_bench_dilithium_level2_pubkey, key);
16316 }
16317#endif
16318#ifndef WOLFSSL_NO_ML_DSA_65
16319 if (level == 3) {
16320 #ifdef WOLFSSL_DILITHIUM_NO_SIGN
16321 x = sizeof_bench_dilithium_level3_sig;
16322 XMEMCPY(sig, bench_dilithium_level3_sig, x);
16323 #endif
16324 ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
16325 sizeof_bench_dilithium_level3_pubkey, key);
16326 }
16327#endif
16328#ifndef WOLFSSL_NO_ML_DSA_87
16329 if (level == 5) {
16330 #ifdef WOLFSSL_DILITHIUM_NO_SIGN
16331 x = sizeof_bench_dilithium_level5_sig;
16332 XMEMCPY(sig, bench_dilithium_level5_sig, x);
16333 #endif
16334 ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
16335 sizeof_bench_dilithium_level5_pubkey, key);
16336 }
16337#endif
16338 if (ret != 0) {
16339 printf("Failed to load public key\n");
16340 goto out;
16341 }
16342
16343#endif
16344
16345#ifndef WOLFSSL_DILITHIUM_NO_VERIFY
16346 RESET_MULTI_VALUE_STATS_VARS();
16347
16348 bench_stats_start(&count, &start);
16349 do {
16350 for (i = 0; i < agreeTimes; i++) {
16351 if (ret == 0) {
16352 int verify = 0;
16353 ret = wc_dilithium_verify_ctx_msg(sig, x, NULL, 0, msg,
16354 DILITHIUM_BENCH_MSG_SIZE, &verify, key);
16355
16356 if (ret != 0 || verify != 1) {
16357 printf("wc_dilithium_verify_ctx_msg failed %d, verify %d\n",
16358 ret, verify);
16359 ret = -1;
16360 }
16361 }
16362 RECORD_MULTI_VALUE_STATS();
16363 }
16364 count += i;
16365 } while (bench_stats_check(start)
16366#ifdef MULTI_VALUE_STATISTICS
16367 || runs < minimum_runs
16368#endif
16369 );
16370
16371 if (ret == 0) {
16372 bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
16373 ret);
16374 #ifdef MULTI_VALUE_STATISTICS
16375 bench_multi_value_stats(max, min, sum, squareSum, runs);
16376 #endif
16377 }
16378#endif
16379
16380out:
16381
16382#ifdef WOLFSSL_SMALL_STACK
16383 if (key)
16384#endif
16385 {
16386 wc_dilithium_free(key);
16387 }
16388
16389#ifdef WOLFSSL_SMALL_STACK
16390 XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
16391 #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
16392 XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
16393 XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
16394 #endif
16395#endif
16396}
16397#endif /* HAVE_DILITHIUM && !WC_NO_RNG */
16398
16399
16400#if defined(_WIN32) && !defined(INTIME_RTOS)
16401
16402 #define WIN32_LEAN_AND_MEAN
16403 #define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
16404 #include <windows.h>
16405 #undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
16406
16407 double current_time(int reset)
16408 {
16409 static int init = 0;
16410 static LARGE_INTEGER freq;
16411
16412 LARGE_INTEGER count;
16413
16414 (void)reset;
16415
16416 if (!init) {
16417 QueryPerformanceFrequency(&freq);
16418 init = 1;
16419 }
16420
16421 QueryPerformanceCounter(&count);
16422
16423#ifdef BENCH_MICROSECOND
16424 return ((double)count.QuadPart * 1000000) / freq.QuadPart;
16425#else
16426 return (double)count.QuadPart / freq.QuadPart;
16427#endif
16428 }
16429
16430#elif defined MICROCHIP_PIC32
16431 #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
16432 #define CLOCK 80000000.0
16433 #else
16434 #define CLOCK 40000000.0
16435 #endif
16436 extern void WriteCoreTimer(word32 t);
16437 extern word32 ReadCoreTimer(void);
16438 double current_time(int reset)
16439 {
16440 unsigned int ns;
16441
16442 if (reset) {
16443 WriteCoreTimer(0);
16444 }
16445
16446 /* get timer in ns */
16447 ns = ReadCoreTimer();
16448
16449 /* return seconds as a double */
16450 return ( ns / CLOCK * 2.0);
16451 }
16452
16453#elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
16454 defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
16455 /* declared above at line 239 */
16456 /* extern double current_time(int reset); */
16457
16458#elif defined(FREERTOS)
16459
16460 #ifdef PLATFORMIO
16461 #include <freertos/FreeRTOS.h>
16462 #include <freertos/task.h>
16463 #else
16464 #include "task.h"
16465 #endif
16466
16467#if defined(WOLFSSL_ESPIDF)
16468 /* prototype definition */
16469 int construct_argv();
16470 extern char* __argv[22];
16471
16472 /* current_time(reset)
16473 *
16474 * Benchmark passage of time, in fractional seconds.
16475 * [reset] is non zero to adjust timer or counter to zero
16476 *
16477 * Use care when repeatedly calling calling. See implementation. */
16478 double current_time(int reset)
16479 {
16480 double ret;
16481 #if ESP_IDF_VERSION_MAJOR >= 4
16482 TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
16483 #else
16484 portTickType tickCount;
16485 #endif
16486
16487 #if defined(__XTENSA__)
16488 (void)reset;
16489
16490 if (reset) {
16491 /* TODO: Determine a mechanism for reset that does not interfere
16492 * with freeRTOS tick. Using this code for Xtensa appears to cause
16493 * RTOS tick timer to stick. See "last_tickCount unchanged".
16494 ESP_LOGW(TAG, "Current_time() reset!");
16495 portTICK_TYPE_ENTER_CRITICAL();
16496 {
16497 esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
16498 _esp_cpu_count_last = xthal_get_ccount();
16499 _esp_cpu_count_last = esp_cpu_get_cycle_count();
16500 }
16501 portTICK_TYPE_EXIT_CRITICAL();
16502 */
16503 }
16504 #else
16505 /* Only reset the CPU counter for RISC-V */
16506 if (reset) {
16507 ESP_LOGV(TAG, "current_time() reset!");
16508 /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
16509 * unexpected rollovers in return values for Xtensa but not RISC-V?
16510 * See also esp_get_cycle_count_ex() */
16511 #ifdef __XTENSA__
16512 _esp_cpu_count_last = xthal_get_ccount();
16513 #else
16514 #if ESP_IDF_VERSION_MAJOR >= 5
16515 esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
16516 _esp_cpu_count_last = esp_cpu_get_cycle_count();
16517 #else
16518 cpu_hal_set_cycle_count((uint32_t)0);
16519 _esp_cpu_count_last = cpu_hal_get_cycle_count();
16520 #endif
16521 #endif
16522 }
16523 #endif
16524
16525 /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
16526 tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
16527 The count of ticks since vTaskStartScheduler was called,
16528 typiclly in app_startup.c */
16529
16530 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
16531 ESP_LOGV(TAG, "tickCount = " TFMT, tickCount);
16532 if (tickCount == last_tickCount) {
16533 ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT, tickCount);
16534
16535 }
16536 if (tickCount < last_tickCount) {
16537 ESP_LOGW(TAG, "last_tickCount overflow?");
16538 }
16539 #endif
16540
16541 if (reset) {
16542 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
16543 ESP_LOGW(TAG, "Assign last_tickCount = " TFMT, tickCount);
16544 #endif
16545 last_tickCount = tickCount;
16546 }
16547 else {
16548 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
16549 ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT, tickCount);
16550 #endif
16551 }
16552
16553 #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
16554 ret = (double)tickCount / configTICK_RATE_HZ;
16555 #else
16556 ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
16557 "assuming 1000 Hz.");
16558 ret = (double)(tickCount / 1000.0);
16559 #endif /* configTICK_RATE_HZ */
16560
16561 return ret;
16562
16563 } /* current_time */
16564#else
16565 /* current_time(reset)
16566 *
16567 * Benchmark passage of time, in fractional seconds.
16568 * [reset] is non zero to adjust timer or counter to zero
16569 *
16570 * Use care when repeatedly calling calling. See implementation. */
16571 double current_time(int reset)
16572 {
16573 portTickType tickCount = xTaskGetTickCount();
16574 (void)reset;
16575 /* if configTICK_RATE_HZ is available use if (default is 1000) */
16576 #ifdef configTICK_RATE_HZ
16577 return (double)tickCount / configTICK_RATE_HZ;
16578 #else
16579 return (double)tickCount / 1000;
16580 #endif
16581 }
16582#endif
16583
16584
16585#elif defined (WOLFSSL_TIRTOS)
16586
16587 extern double current_time(int reset);
16588
16589#elif defined(FREESCALE_MQX)
16590
16591 double current_time(int reset)
16592 {
16593 TIME_STRUCT tv;
16594 _time_get(&tv);
16595
16596 return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
16597 }
16598
16599#elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
16600 && defined(MAX3266X_RTC)
16601
16602 double current_time(int reset)
16603 {
16604 (void)reset;
16605 return wc_MXC_RTC_Time();
16606 }
16607
16608#elif defined(FREESCALE_KSDK_BM)
16609
16610 double current_time(int reset)
16611 {
16612 return (double)OSA_TimeGetMsec() / 1000;
16613 }
16614
16615#elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
16616
16617 double current_time(int reset)
16618 {
16619 (void)reset;
16620 return (double)osKernelGetTickCount() / 1000.0;
16621 }
16622
16623#elif defined(WOLFSSL_EMBOS)
16624
16625 #include "RTOS.h"
16626
16627 double current_time(int reset)
16628 {
16629 double time_now;
16630 double current_s = OS_GetTime() / 1000.0;
16631 double current_us = OS_GetTime_us() / MILLION_VALUE;
16632 time_now = (double)( current_s + current_us);
16633
16634 (void) reset;
16635
16636 return time_now;
16637 }
16638#elif defined(WOLFSSL_SGX)
16639 double current_time(int reset);
16640
16641#elif defined(WOLFSSL_DEOS)
16642 double current_time(int reset)
16643 {
16644 const uint32_t systemTickTimeInHz
16645 = 1000000 / systemTickInMicroseconds();
16646
16647 const volatile uint32_t *systemTickPtr = systemTickPointer();
16648
16649 (void)reset;
16650
16651 return (double) *systemTickPtr/systemTickTimeInHz;
16652 }
16653
16654#elif defined(MICRIUM)
16655 double current_time(int reset)
16656 {
16657
16658#if (OS_VERSION < 50000)
16659 CPU_ERR err;
16660 (void)reset;
16661 return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
16662#else
16663 RTOS_ERR err;
16664 double ret = 0;
16665 OS_TICK tick = OSTimeGet(&err);
16666 OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
16667 (void)reset;
16668
16669 if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
16670 ret = ((double)tick)/rate;
16671 }
16672 return ret;
16673#endif
16674 }
16675#elif defined(WOLFSSL_ZEPHYR)
16676
16677 #include <time.h>
16678
16679 double current_time(int reset)
16680 {
16681 int64_t t;
16682 (void)reset;
16683 #if defined(CONFIG_ARCH_POSIX)
16684 #if defined(CONFIG_BOARD_NATIVE_SIM)
16685 k_msleep(1);
16686 #else
16687 k_cpu_idle();
16688 #endif
16689 #endif
16690 t = k_uptime_get(); /* returns current uptime in milliseconds */
16691 return (double)(t / 1000);
16692 }
16693
16694#elif defined(WOLFSSL_NETBURNER)
16695 #include <predef.h>
16696 #include <utils.h>
16697 #include <constants.h>
16698
16699 double current_time(int reset)
16700 {
16701 DWORD ticks = TimeTick; /* ticks since system start */
16702 (void)reset;
16703
16704 return (double) ticks/TICKS_PER_SECOND;
16705 }
16706#elif defined(WOLFSSL_RPIPICO)
16707 #include "pico/stdlib.h"
16708
16709 double current_time(int reset)
16710 {
16711 (void)reset;
16712
16713 return (double) time_us_64() / 1000000;
16714 }
16715#elif defined(THREADX)
16716 #include "tx_api.h"
16717 double current_time(int reset)
16718 {
16719 (void)reset;
16720 return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
16721 }
16722
16723#elif defined(WOLFSSL_XILINX)
16724 #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
16725 #define COUNTS_PER_SECOND \
16726 XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
16727 #else
16728 #define COUNTS_PER_SECOND \
16729 XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
16730 #endif
16731
16732 double current_time(int reset)
16733 {
16734 double timer;
16735 uint64_t cntPct = 0;
16736 asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
16737
16738 /* Convert to milliseconds */
16739 timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
16740 /* Convert to seconds.millisecond */
16741 timer /= 1000;
16742 return timer;
16743 }
16744
16745#elif defined(LINUX_RUSAGE_UTIME)
16746
16747 #include <sys/time.h>
16748 #include <sys/resource.h>
16749
16750 static struct rusage base_rusage;
16751 static struct rusage cur_rusage;
16752
16753 double current_time(int reset)
16754 {
16755 struct rusage rusage;
16756
16757 (void)reset;
16758
16759 LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
16760
16761 if (reset)
16762 base_rusage = rusage;
16763 else
16764 cur_rusage = rusage;
16765
16766 /* only consider user time, as system time is host-related overhead
16767 * outside wolfcrypt.
16768 */
16769 return (double)rusage.ru_utime.tv_sec +
16770 (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
16771 }
16772
16773 static void check_for_excessive_stime(const char *algo,
16774 int strength,
16775 const char *desc,
16776 const char *desc_extra)
16777 {
16778 double start_utime = (double)base_rusage.ru_utime.tv_sec +
16779 (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
16780 double start_stime = (double)base_rusage.ru_stime.tv_sec +
16781 (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
16782 double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
16783 (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
16784 double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
16785 (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
16786 double stime_utime_ratio =
16787 (cur_stime - start_stime) / (cur_utime - start_utime);
16788 if (stime_utime_ratio > .1) {
16789 if (strength > 0) {
16790 printf("%swarning, "
16791 "excessive system time ratio for %s-%d-%s%s (" FLT_FMT_PREC "%%).\n",
16792 err_prefix, algo, strength, desc, desc_extra,
16793 FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
16794 }
16795 else {
16796 printf("%swarning, "
16797 "excessive system time ratio for %s%s%s (" FLT_FMT_PREC "%%).\n",
16798 err_prefix, algo, desc, desc_extra,
16799 FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
16800 }
16801 }
16802 }
16803
16804#elif defined(WOLFSSL_LINUXKM)
16805
16806 double current_time(int reset)
16807 {
16808 (void)reset;
16809 u64 ns = ktime_get_ns();
16810 return (double)ns / 1000000000.0;
16811 }
16812
16813#elif defined(WOLFSSL_BSDKM)
16814
16815 #include <sys/timex.h>
16816 double current_time(int reset)
16817 {
16818 (void)reset;
16819 struct timespec ts;
16820 int64_t result = 0;
16821
16822 getnanouptime(&ts);
16823 result = (int64_t) ts.tv_sec + (int64_t) ts.tv_nsec / NANOSECOND;
16824 return (double)result;
16825 }
16826
16827#elif defined(WOLFSSL_GAISLER_BCC)
16828
16829 #include <bcc/bcc.h>
16830 double current_time(int reset)
16831 {
16832 (void)reset;
16833 uint32_t us = bcc_timer_get_us();
16834 return (double)us / 1000000.0;
16835 }
16836
16837#elif defined(__WATCOMC__)
16838
16839 #include <time.h>
16840 WC_INLINE double current_time(int reset)
16841 {
16842 (void)reset;
16843 return ((double)clock())/CLOCKS_PER_SEC;
16844 }
16845#else
16846
16847 #include <time.h>
16848 #include <sys/time.h>
16849
16850 double current_time(int reset)
16851 {
16852 struct timespec tv;
16853
16854 (void)reset;
16855
16856 LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
16857
16858 #ifdef BENCH_MICROSECOND
16859 return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
16860 #else
16861 return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
16862 #endif
16863 }
16864
16865#endif /* _WIN32 */
16866
16867#if defined(HAVE_GET_CYCLES)
16868
16869 #if defined(WOLFSSL_ESPIDF)
16870 /* Generic CPU cycle counter for either Xtensa or RISC-V */
16871 static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
16872 {
16873 /* Reminder for long duration between calls with
16874 * multiple overflows will not be detected. */
16875 return esp_get_cycle_count_ex();
16876 }
16877
16878 #elif defined(__aarch64__)
16879 static WC_INLINE word64 get_aarch64_cycles(void)
16880 {
16881 word64 ticks;
16882 __asm__ __volatile__ (
16883 "isb\n\t"
16884 #ifdef __APPLE__
16885 "mrs %[ticks], cntpct_el0\n\t"
16886 #else
16887 "mrs %[ticks], cntvct_el0\n\t"
16888 #endif
16889 : [ticks] "=r" (ticks)
16890 :
16891 :
16892 );
16893 if ((tick_freq != 0) && (actual_freq != 0)) {
16894 ticks *= actual_freq / tick_freq;
16895 }
16896 return ticks;
16897 }
16898
16899 /* implement other architectures here */
16900
16901 #else
16902 static WC_INLINE word64 get_intel_cycles(void)
16903 {
16904 unsigned int lo_c, hi_c;
16905 __asm__ __volatile__ (
16906 "cpuid\n\t"
16907 "rdtsc"
16908 : "=a"(lo_c), "=d"(hi_c) /* out */
16909 : "a"(0) /* in */
16910 : "%ebx", "%ecx"); /* clobber */
16911 return ((word64)lo_c) | (((word64)hi_c) << 32);
16912 }
16913 #endif
16914
16915#endif /* HAVE_GET_CYCLES */
16916
16917void benchmark_configure(word32 block_size)
16918{
16919 /* must be greater than 0 */
16920 if (block_size > 0) {
16921 numBlocks = (int)((word32)numBlocks * bench_size / block_size);
16922 bench_size = block_size;
16923 }
16924}
16925
16926#ifndef NO_MAIN_DRIVER
16927
16928#ifndef MAIN_NO_ARGS
16929
16930#ifndef WOLFSSL_BENCHMARK_ALL
16931/* Display the algorithm string and keep to 80 characters per line.
16932 *
16933 * str Algorithm string to print.
16934 * line Length of line used so far.
16935 */
16936#ifndef BENCH_MAX_LINE
16937#define BENCH_MAX_LINE 80
16938#endif
16939static void print_alg(const char* str, int* line)
16940{
16941 const char* const ident = " ";
16942 if (*line == 0) {
16943 printf("%s", ident);
16944 *line = (int)XSTRLEN(ident);
16945 }
16946 printf(" %s", str);
16947 *line += (int)XSTRLEN(str) + 1;
16948 if (*line > BENCH_MAX_LINE) {
16949 printf("\n");
16950 *line = 0;
16951 }
16952}
16953#endif /* WOLFSSL_BENCHMARK_ALL */
16954
16955/* Display the usage options of the benchmark program. */
16956static void Usage(void)
16957{
16958 int e = 0;
16959#ifndef WOLFSSL_BENCHMARK_ALL
16960 int i;
16961 int line;
16962#endif
16963
16964 printf("benchmark\n");
16965 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
16966 printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
16967 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
16968 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
16969#if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || \
16970 defined(HAVE_AESGCM)
16971 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -same_buf */
16972#else
16973 e++;
16974#endif
16975#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
16976 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
16977 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
16978 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
16979#else
16980 e += 3;
16981#endif
16982 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
16983#ifndef NO_HMAC
16984 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -mac_final */
16985#else
16986 e++;
16987#endif
16988#ifdef HAVE_AESGCM
16989 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aead_set_key */
16990#else
16991 e++;
16992#endif
16993#ifndef NO_RSA
16994 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -rsa_sign */
16995 #ifdef WOLFSSL_KEY_GEN
16996 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
16997 #endif
16998 e++;
16999#else
17000 e += 2;
17001#endif
17002#if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
17003 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
17004#endif
17005 e++;
17006#if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
17007 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
17008#endif
17009 e++;
17010#if defined(HAVE_ECC) && !defined(NO_ECC256)
17011 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
17012#endif
17013 e++;
17014#if defined(HAVE_ECC) && defined(HAVE_ECC384)
17015 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
17016#endif
17017 e++;
17018#if defined(HAVE_ECC) && defined(HAVE_ECC521)
17019 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
17020#endif
17021 e++;
17022#if defined(HAVE_ECC)
17023 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
17024#endif
17025 e++;
17026#ifndef WOLFSSL_BENCHMARK_ALL
17027 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
17028 line = 0;
17029 for (i=0; bench_cipher_opt[i].str != NULL; i++)
17030 print_alg(bench_cipher_opt[i].str, &line);
17031 for (i=0; bench_digest_opt[i].str != NULL; i++)
17032 print_alg(bench_digest_opt[i].str, &line);
17033 for (i=0; bench_mac_opt[i].str != NULL; i++)
17034 print_alg(bench_mac_opt[i].str, &line);
17035 for (i=0; bench_kdf_opt[i].str != NULL; i++)
17036 print_alg(bench_kdf_opt[i].str, &line);
17037 for (i=0; bench_asym_opt[i].str != NULL; i++)
17038 print_alg(bench_asym_opt[i].str, &line);
17039 for (i=0; bench_other_opt[i].str != NULL; i++)
17040 print_alg(bench_other_opt[i].str, &line);
17041#if defined(WOLFSSL_HAVE_MLKEM) || defined(HAVE_FALCON) || \
17042 defined(HAVE_DILITHIUM)
17043 for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
17044 print_alg(bench_pq_asym_opt[i].str, &line);
17045#endif
17046#if defined(BENCH_PQ_STATEFUL_HBS)
17047 for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
17048 print_alg(bench_pq_hash_sig_opt[i].str, &line);
17049#endif /* BENCH_PQ_STATEFUL_HBS */
17050 printf("\n");
17051#endif /* !WOLFSSL_BENCHMARK_ALL */
17052 e++;
17053 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
17054 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
17055 printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
17056#ifdef WC_ENABLE_BENCH_THREADING
17057 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
17058#endif
17059 e++;
17060#ifdef WC_BENCH_TRACK_STATS
17061 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
17062#endif
17063 e++;
17064#ifndef NO_FILESYSTEM
17065 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
17066#endif
17067 e++;
17068#ifndef NO_FILESYSTEM
17069 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
17070#endif
17071 e++;
17072#ifdef MULTI_VALUE_STATISTICS
17073 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
17074#endif
17075 e++;
17076#if defined(__aarch64__)
17077 printf("%s", bench_Usage_msg1[lng_index][e]); /* option -freq */
17078#endif
17079}
17080
17081/* Match the command line argument with the string.
17082 *
17083 * arg Command line argument.
17084 * str String to check for.
17085 * return 1 if the command line argument matches the string, 0 otherwise.
17086 */
17087static int string_matches(const char* arg, const char* str)
17088{
17089 return XSTRCMP(arg, str) == 0;
17090}
17091#endif /* MAIN_NO_ARGS */
17092
17093/*
17094** ----------------------------------------------------------------------------
17095** determine how the benchmarks are called, the function name varies:
17096** ----------------------------------------------------------------------------
17097*/
17098#if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
17099 #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
17100
17101 /* for some environments, we'll call a function wolf_benchmark_task: */
17102 int wolf_benchmark_task(void)
17103
17104 #elif defined(MAIN_NO_ARGS)
17105
17106 /* otherwise we'll use main() with no arguments as desired: */
17107 int main()
17108
17109 #else
17110
17111 /* else we'll be calling main with default arg parameters */
17112 int main(int argc, char** argv)
17113
17114 #endif
17115{
17116 /* Code for main() or wolf_benchmark_task() */
17117 #ifdef WOLFSSL_ESPIDF
17118 int argc = construct_argv();
17119 char** argv = (char**)__argv;
17120 #elif defined(MAIN_NO_ARGS)
17121 int argc = 0;
17122 char** argv = NULL;
17123 #endif
17124
17125 return wolfcrypt_benchmark_main(argc, argv);
17126}
17127#endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
17128
17129int wolfcrypt_benchmark_main(int argc, char** argv)
17130{
17131 int ret = 0;
17132
17133#ifndef MAIN_NO_ARGS
17134 int optMatched;
17135 #ifndef WOLFSSL_BENCHMARK_ALL
17136 int i;
17137 #endif
17138#endif
17139
17140 benchmark_static_init(1);
17141
17142 printf("%s------------------------------------------------------------------------------\n",
17143 info_prefix);
17144 printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
17145 printf("%s------------------------------------------------------------------------------\n",
17146 info_prefix);
17147
17148#ifndef MAIN_NO_ARGS
17149 while (argc > 1) {
17150 if (string_matches(argv[1], "-?")) {
17151 if (--argc > 1) {
17152 lng_index = XATOI((++argv)[1]);
17153 if (lng_index<0 || lng_index>1) {
17154 lng_index = 0;
17155 }
17156 }
17157 Usage();
17158 return 0;
17159 }
17160 else if (string_matches(argv[1], "-lng")) {
17161 argc--;
17162 argv++;
17163 if (argc > 1) {
17164 lng_index = XATOI(argv[1]);
17165 if (lng_index<0 || lng_index>1) {
17166 printf("invalid number(%d) is specified. [<num> :0-1]\n",
17167 lng_index);
17168 lng_index = 0;
17169 }
17170 }
17171 }
17172 else if (string_matches(argv[1], "-base10"))
17173 base2 = 0;
17174#if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || \
17175 defined(HAVE_AESGCM)
17176 else if (string_matches(argv[1], "-same_buf"))
17177 cipher_same_buffer = 1;
17178#endif
17179#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
17180 else if (string_matches(argv[1], "-no_aad"))
17181 aes_aad_options = AAD_SIZE_ZERO;
17182 else if (string_matches(argv[1], "-all_aad"))
17183 aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
17184 else if (string_matches(argv[1], "-aad_size")) {
17185 argc--;
17186 argv++;
17187 if (argc > 1) {
17188 aes_aad_size = (word32)XATOI(argv[1]);
17189 aes_aad_options |= AAD_SIZE_CUSTOM;
17190 }
17191 }
17192#endif
17193 else if (string_matches(argv[1], "-dgst_full"))
17194 digest_stream = 0;
17195#ifndef NO_HMAC
17196 else if (string_matches(argv[1], "-mac_final"))
17197 mac_stream = 0;
17198#endif
17199#ifdef HAVE_AESGCM
17200 else if (string_matches(argv[1], "-aead_set_key"))
17201 aead_set_key = 1;
17202#endif
17203#ifdef HAVE_CHACHA
17204 else if (string_matches(argv[1], "-enc_only"))
17205 encrypt_only = 1;
17206#endif
17207#ifndef NO_RSA
17208 else if (string_matches(argv[1], "-rsa_sign"))
17209 rsa_sign_verify = 1;
17210#endif
17211#if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
17212 else if (string_matches(argv[1], "-ffdhe2048"))
17213 use_ffdhe = 2048;
17214#endif
17215#if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
17216 else if (string_matches(argv[1], "-ffdhe3072"))
17217 use_ffdhe = 3072;
17218#endif
17219#if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
17220 else if (string_matches(argv[1], "-ffdhe4096"))
17221 use_ffdhe = 4096;
17222#endif
17223#if defined(HAVE_ECC) && !defined(NO_ECC256)
17224 else if (string_matches(argv[1], "-p256"))
17225 bench_asym_algs |= BENCH_ECC_P256;
17226#endif
17227#if defined(HAVE_ECC) && defined(HAVE_ECC384)
17228 else if (string_matches(argv[1], "-p384"))
17229 bench_asym_algs |= BENCH_ECC_P384;
17230#endif
17231#if defined(HAVE_ECC) && defined(HAVE_ECC521)
17232 else if (string_matches(argv[1], "-p521"))
17233 bench_asym_algs |= BENCH_ECC_P521;
17234#endif
17235#ifdef BENCH_ASYM
17236 else if (string_matches(argv[1], "-csv")) {
17237 csv_format = 1;
17238 }
17239#endif
17240
17241#ifdef WC_ENABLE_BENCH_THREADING
17242 else if (string_matches(argv[1], "-threads")) {
17243 argc--;
17244 argv++;
17245 if (argc > 1) {
17246 g_threadCount = XATOI(argv[1]);
17247 if (g_threadCount < 1 || lng_index > 128){
17248 printf("invalid number(%d) is specified. [<num> :1-128]\n",
17249 g_threadCount);
17250 g_threadCount = 0;
17251 }
17252 }
17253 }
17254#endif
17255#ifdef WC_BENCH_TRACK_STATS
17256 else if (string_matches(argv[1], "-print")) {
17257 gPrintStats = 1;
17258 }
17259#endif
17260 else if (string_matches(argv[1], "-blocks")) {
17261 argc--;
17262 argv++;
17263 if (argc > 1)
17264 numBlocks = XATOI(argv[1]);
17265 }
17266#ifndef NO_FILESYSTEM
17267 else if (string_matches(argv[1], "-hash_input")) {
17268 argc--;
17269 argv++;
17270 if (argc > 1)
17271 hash_input = argv[1];
17272 }
17273 else if (string_matches(argv[1], "-cipher_input")) {
17274 argc--;
17275 argv++;
17276 if (argc > 1)
17277 cipher_input = argv[1];
17278 }
17279#endif
17280#ifdef MULTI_VALUE_STATISTICS
17281 else if (string_matches(argv[1], "-min_runs")) {
17282 argc--;
17283 argv++;
17284 if (argc > 1) {
17285 minimum_runs = XATOI(argv[1]);
17286 }
17287 }
17288#endif
17289#ifdef __aarch64__
17290 else if (string_matches(argv[1], "-freq")) {
17291 argc--;
17292 argv++;
17293 if (argc > 1) {
17294 actual_freq = strtol(argv[1], NULL, 10);
17295 }
17296 }
17297#endif
17298 else if (argv[1][0] == '-') {
17299 optMatched = 0;
17300#ifndef WOLFSSL_BENCHMARK_ALL
17301 /* Check known algorithm choosing command line options. */
17302 /* Known cipher algorithms */
17303 for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
17304 if (string_matches(argv[1], bench_cipher_opt[i].str)) {
17305 bench_cipher_algs |= bench_cipher_opt[i].val;
17306 bench_all = 0;
17307 optMatched = 1;
17308 }
17309 }
17310 /* Known digest algorithms */
17311 for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
17312 if (string_matches(argv[1], bench_digest_opt[i].str)) {
17313 bench_digest_algs |= bench_digest_opt[i].val;
17314 bench_all = 0;
17315 optMatched = 1;
17316 }
17317 }
17318 /* Known MAC algorithms */
17319 for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
17320 if (string_matches(argv[1], bench_mac_opt[i].str)) {
17321 bench_mac_algs |= bench_mac_opt[i].val;
17322 bench_all = 0;
17323 optMatched = 1;
17324 }
17325 }
17326 /* Known KDF algorithms */
17327 for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
17328 if (string_matches(argv[1], bench_kdf_opt[i].str)) {
17329 bench_kdf_algs |= bench_kdf_opt[i].val;
17330 bench_all = 0;
17331 optMatched = 1;
17332 }
17333 }
17334 /* Known asymmetric algorithms */
17335 for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
17336 if (string_matches(argv[1], bench_asym_opt[i].str)) {
17337 bench_asym_algs |= bench_asym_opt[i].val;
17338 bench_all = 0;
17339 optMatched = 1;
17340 }
17341 }
17342 #if defined(WOLFSSL_HAVE_MLKEM) || defined(HAVE_FALCON) || \
17343 defined(HAVE_DILITHIUM)
17344 /* Known asymmetric post-quantum algorithms */
17345 for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
17346 if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
17347 bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
17348 bench_all = 0;
17349 optMatched = 1;
17350 }
17351 }
17352 #endif
17353 /* Other known cryptographic algorithms */
17354 for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
17355 if (string_matches(argv[1], bench_other_opt[i].str)) {
17356 bench_other_algs |= bench_other_opt[i].val;
17357 bench_all = 0;
17358 optMatched = 1;
17359 }
17360 }
17361
17362 #if defined(BENCH_PQ_STATEFUL_HBS)
17363 /* post-quantum stateful hash-based signatures */
17364 for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
17365 if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
17366 bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
17367 bench_all = 0;
17368 optMatched = 1;
17369 }
17370 }
17371 #endif /* BENCH_PQ_STATEFUL_HBS */
17372#endif
17373 if (!optMatched) {
17374 printf("Option not recognized: %s\n", argv[1]);
17375 Usage();
17376 return 1;
17377 }
17378 }
17379 else {
17380 /* parse for block size */
17381 benchmark_configure((word32)XATOI(argv[1]));
17382 }
17383 argc--;
17384 argv++;
17385 }
17386#endif /* MAIN_NO_ARGS */
17387
17388#if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
17389 /* when defined, we'll always output CSV regardless of params.
17390 ** this is typically convenient in embedded environments.
17391 */
17392 csv_format = 1;
17393#endif
17394
17395#if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
17396 if (g_threadCount > 1) {
17397 ret = benchmark_test_threaded(NULL);
17398 }
17399 else
17400#endif
17401 {
17402 #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
17403 defined(CONFIG_IDF_TARGET_ESP32C3) || \
17404 defined(CONFIG_IDF_TARGET_ESP32C6)
17405 {
17406 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
17407 if (esp_gptimer == NULL) {
17408 ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
17409 &esp_gptimer) );
17410 }
17411 ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
17412 ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
17413 ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
17414 #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
17415 }
17416 #endif
17417
17418 #ifdef HAVE_STACK_SIZE
17419 ret = StackSizeCheck(NULL, benchmark_test);
17420 #else
17421 ret = benchmark_test(NULL);
17422 #endif
17423 }
17424
17425 #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
17426 defined(CONFIG_IDF_TARGET_ESP32C3) || \
17427 defined(CONFIG_IDF_TARGET_ESP32C6)
17428 {
17429 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
17430 ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
17431 ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
17432 #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
17433 }
17434 #endif
17435
17436 return ret;
17437}
17438#endif /* !NO_MAIN_DRIVER */
17439
17440#else
17441 #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
17442 int main(void) { return 0; }
17443 #endif
17444#endif /* !NO_CRYPT_BENCHMARK */