cjson
.github
workflows CI.yml ci-fuzz.yml
CONTRIBUTING.md
fuzzing
inputs test1 test10 test11 test2 test3 test3.bu test3.uf test3.uu test4 test5 test6 test7 test8 test9
.gitignore CMakeLists.txt afl-prepare-linux.sh afl.c afl.sh cjson_read_fuzzer.c fuzz_main.c json.dict ossfuzz.sh
library_config cJSONConfig.cmake.in cJSONConfigVersion.cmake.in libcjson.pc.in libcjson_utils.pc.in uninstall.cmake
tests
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.expected
json-patch-tests .editorconfig .gitignore .npmignore README.md cjson-utils-tests.json package.json spec_tests.json tests.json
unity
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.py
docs ThrowTheSwitchCodingStandard.md UnityAssertionsCheatSheetSuitableforPrintingandPossiblyFraming.pdf UnityAssertionsReference.md UnityConfigurationGuide.md UnityGettingStartedGuide.md UnityHelperScriptsGuide.md license.txt
examples
example_1
src ProductionCode.c ProductionCode.h ProductionCode2.c ProductionCode2.h
makefile readme.txt
example_2
src ProductionCode.c ProductionCode.h ProductionCode2.c ProductionCode2.h
makefile readme.txt
example_3
helper UnityHelper.c UnityHelper.h
src ProductionCode.c ProductionCode.h ProductionCode2.c ProductionCode2.h
rakefile.rb rakefile_helper.rb readme.txt target_gcc_32.yml
unity_config.h
extras
eclipse error_parsers.txt
fixture
src unity_fixture.c unity_fixture.h unity_fixture_internals.h unity_fixture_malloc_overrides.h
rakefile.rb rakefile_helper.rb readme.txt
release build.info version.info
src unity.c unity.h unity_internals.h
.gitattributes .gitignore .travis.yml README.md
CMakeLists.txt cjson_add.c common.h compare_tests.c json_patch_tests.c minify_tests.c misc_tests.c misc_utils_tests.c old_utils_tests.c parse_array.c parse_examples.c parse_hex4.c parse_number.c parse_object.c parse_string.c parse_value.c parse_with_opts.c print_array.c print_number.c print_object.c print_string.c print_value.c readme_examples.c unity_setup.c
.editorconfig .gitattributes .gitignore .travis.yml CHANGELOG.md CMakeLists.txt CONTRIBUTORS.md LICENSE Makefile README.md SECURITY.md appveyor.yml cJSON.c cJSON.h cJSON_Utils.c cJSON_Utils.h test.c valgrind.supp
curl
.circleci config.yml
.github
ISSUE_TEMPLATE bug_report.yml config.yml docs.yml
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.yaml
workflows 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.yml
CODEOWNERS CONTRIBUTING.md FUNDING.yml dependabot.yml labeler.yml lock.yml stale.yml
CMake 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.cmake
LICENSES BSD-4-Clause-UC.txt ISC.txt curl.txt
docs
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.md
examples .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.c
internals 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.md
libcurl
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.inc
.gitignore ABI.md CMakeLists.txt Makefile.am Makefile.inc curl_easy_cleanup.md curl_easy_duphandle.md curl_easy_escape.md curl_easy_getinfo.md curl_easy_header.md curl_easy_init.md curl_easy_nextheader.md curl_easy_option_by_id.md curl_easy_option_by_name.md curl_easy_option_next.md curl_easy_pause.md curl_easy_perform.md curl_easy_recv.md curl_easy_reset.md curl_easy_send.md curl_easy_setopt.md curl_easy_ssls_export.md curl_easy_ssls_import.md curl_easy_strerror.md curl_easy_unescape.md curl_easy_upkeep.md curl_escape.md curl_formadd.md curl_formfree.md curl_formget.md curl_free.md curl_getdate.md curl_getenv.md curl_global_cleanup.md curl_global_init.md curl_global_init_mem.md curl_global_sslset.md curl_global_trace.md curl_mime_addpart.md curl_mime_data.md curl_mime_data_cb.md curl_mime_encoder.md curl_mime_filedata.md curl_mime_filename.md curl_mime_free.md curl_mime_headers.md curl_mime_init.md curl_mime_name.md curl_mime_subparts.md curl_mime_type.md curl_mprintf.md curl_multi_add_handle.md curl_multi_assign.md curl_multi_cleanup.md curl_multi_fdset.md curl_multi_get_handles.md curl_multi_get_offt.md curl_multi_info_read.md curl_multi_init.md curl_multi_notify_disable.md curl_multi_notify_enable.md curl_multi_perform.md curl_multi_poll.md curl_multi_remove_handle.md curl_multi_setopt.md curl_multi_socket.md curl_multi_socket_action.md curl_multi_socket_all.md curl_multi_strerror.md curl_multi_timeout.md curl_multi_wait.md curl_multi_waitfds.md curl_multi_wakeup.md curl_pushheader_byname.md curl_pushheader_bynum.md curl_share_cleanup.md curl_share_init.md curl_share_setopt.md curl_share_strerror.md curl_slist_append.md curl_slist_free_all.md curl_strequal.md curl_strnequal.md curl_unescape.md curl_url.md curl_url_cleanup.md curl_url_dup.md curl_url_get.md curl_url_set.md curl_url_strerror.md curl_version.md curl_version_info.md curl_ws_meta.md curl_ws_recv.md curl_ws_send.md curl_ws_start_frame.md libcurl-easy.md libcurl-env-dbg.md libcurl-env.md libcurl-errors.md libcurl-multi.md libcurl-security.md libcurl-share.md libcurl-thread.md libcurl-tutorial.md libcurl-url.md libcurl-ws.md libcurl.m4 libcurl.md mksymbolsmanpage.pl symbols-in-versions symbols.pl
tests CI.md FILEFORMAT.md HTTP.md TEST-SUITE.md
.gitignore ALTSVC.md BINDINGS.md BUG-BOUNTY.md BUGS.md CIPHERS-TLS12.md CIPHERS.md CMakeLists.txt CODE_OF_CONDUCT.md CODE_REVIEW.md CONTRIBUTE.md CURL-DISABLE.md CURLDOWN.md DEPRECATE.md DISTROS.md EARLY-RELEASE.md ECH.md EXPERIMENTAL.md FAQ.md FEATURES.md GOVERNANCE.md HELP-US.md HISTORY.md HSTS.md HTTP-COOKIES.md HTTP3.md HTTPSRR.md INFRASTRUCTURE.md INSTALL-CMAKE.md INSTALL.md INTERNALS.md IPFS.md KNOWN_BUGS.md KNOWN_RISKS.md MAIL-ETIQUETTE.md MANUAL.md Makefile.am README.md RELEASE-PROCEDURE.md ROADMAP.md RUSTLS.md SECURITY-ADVISORY.md SPONSORS.md SSL-PROBLEMS.md SSLCERTS.md THANKS THANKS-filter TODO.md TheArtOfHttpScripting.md URL-SYNTAX.md VERIFY.md VERSIONS.md VULN-DISCLOSURE-POLICY.md curl-config.md mk-ca-bundle.md options-in-versions runtests.md testcurl.md wcurl.md
include
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.h
Makefile.am README.md
lib
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.h
vauth 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.h
vquic curl_ngtcp2.c curl_ngtcp2.h curl_quiche.c curl_quiche.h vquic-tls.c vquic-tls.h vquic.c vquic.h vquic_int.h
vssh libssh.c libssh2.c ssh.h vssh.c vssh.h
vtls 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.h
.gitignore CMakeLists.txt Makefile.am Makefile.inc Makefile.soname altsvc.c altsvc.h amigaos.c amigaos.h arpa_telnet.h asyn-ares.c asyn-base.c asyn-thrdd.c asyn.h bufq.c bufq.h bufref.c bufref.h cf-dns.c cf-dns.h cf-h1-proxy.c cf-h1-proxy.h cf-h2-proxy.c cf-h2-proxy.h cf-haproxy.c cf-haproxy.h cf-https-connect.c cf-https-connect.h cf-ip-happy.c cf-ip-happy.h cf-socket.c cf-socket.h cfilters.c cfilters.h config-mac.h config-os400.h config-riscos.h config-win32.h conncache.c conncache.h connect.c connect.h content_encoding.c content_encoding.h cookie.c cookie.h creds.c creds.h cshutdn.c cshutdn.h curl_addrinfo.c curl_addrinfo.h curl_config-cmake.h.in curl_ctype.h curl_endian.c curl_endian.h curl_fnmatch.c curl_fnmatch.h curl_fopen.c curl_fopen.h curl_get_line.c curl_get_line.h curl_gethostname.c curl_gethostname.h curl_gssapi.c curl_gssapi.h curl_hmac.h curl_ldap.h curl_md4.h curl_md5.h curl_memrchr.c curl_memrchr.h curl_ntlm_core.c curl_ntlm_core.h curl_printf.h curl_range.c curl_range.h curl_sasl.c curl_sasl.h curl_setup.h curl_sha256.h curl_sha512_256.c curl_sha512_256.h curl_share.c curl_share.h curl_sspi.c curl_sspi.h curl_threads.c curl_threads.h curl_trc.c curl_trc.h cw-out.c cw-out.h cw-pause.c cw-pause.h dict.c dict.h dllmain.c dnscache.c dnscache.h doh.c doh.h dynhds.c dynhds.h easy.c easy_lock.h easygetopt.c easyif.h easyoptions.c easyoptions.h escape.c escape.h fake_addrinfo.c fake_addrinfo.h file.c file.h fileinfo.c fileinfo.h formdata.c formdata.h ftp-int.h ftp.c ftp.h ftplistparser.c ftplistparser.h functypes.h getenv.c getinfo.c getinfo.h gopher.c gopher.h hash.c hash.h headers.c headers.h hmac.c hostip.c hostip.h hostip4.c hostip6.c hsts.c hsts.h http.c http.h http1.c http1.h http2.c http2.h http_aws_sigv4.c http_aws_sigv4.h http_chunks.c http_chunks.h http_digest.c http_digest.h http_negotiate.c http_negotiate.h http_ntlm.c http_ntlm.h http_proxy.c http_proxy.h httpsrr.c httpsrr.h idn.c idn.h if2ip.c if2ip.h imap.c imap.h ldap.c libcurl.def libcurl.rc libcurl.vers.in llist.c llist.h macos.c macos.h md4.c md5.c memdebug.c mime.c mime.h mprintf.c mqtt.c mqtt.h multi.c multi_ev.c multi_ev.h multi_ntfy.c multi_ntfy.h multihandle.h multiif.h netrc.c netrc.h noproxy.c noproxy.h openldap.c optiontable.pl parsedate.c parsedate.h peer.c peer.h pingpong.c pingpong.h pop3.c pop3.h progress.c progress.h protocol.c protocol.h psl.c psl.h rand.c rand.h ratelimit.c ratelimit.h request.c request.h rtsp.c rtsp.h select.c select.h sendf.c sendf.h setopt.c setopt.h setup-os400.h setup-vms.h setup-win32.h sha256.c sigpipe.h slist.c slist.h smb.c smb.h smtp.c smtp.h sockaddr.h socketpair.c socketpair.h socks.c socks.h socks_gssapi.c socks_sspi.c splay.c splay.h strcase.c strcase.h strequal.c strerror.c strerror.h system_win32.c system_win32.h telnet.c telnet.h tftp.c tftp.h thrdpool.c thrdpool.h thrdqueue.c thrdqueue.h transfer.c transfer.h uint-bset.c uint-bset.h uint-hash.c uint-hash.h uint-spbset.c uint-spbset.h uint-table.c uint-table.h url.c url.h urlapi-int.h urlapi.c urldata.h version.c ws.c ws.h
m4 .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.m4
projects
OS400
rpg-examples HEADERAPI HTTPPOST INMEMORY SIMPLE1 SIMPLE2 SMTPSRCMBR
.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.h
Windows
tmpl .gitattributes README.txt curl-all.sln curl.sln curl.vcxproj curl.vcxproj.filters libcurl.sln libcurl.vcxproj libcurl.vcxproj.filters
.gitignore README.md generate.bat
vms 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.h
Makefile.am README.md
scripts .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 wcurl
src
toolx tool_time.c tool_time.h
.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.h
tests
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.prm
cmake CMakeLists.txt test.c test.cpp test.sh
data .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 test999
http
testenv
mod_curltest .gitignore mod_curltest.c
__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.py
.gitignore CMakeLists.txt Makefile.am config.ini.in conftest.py requirements.txt scorecard.py test_01_basic.py test_02_download.py test_03_goaway.py test_04_stuttered.py test_05_errors.py test_06_eyeballs.py test_07_upload.py test_08_caddy.py test_09_push.py test_10_proxy.py test_11_unix.py test_12_reuse.py test_13_proxy_auth.py test_14_auth.py test_15_tracing.py test_16_info.py test_17_ssl_use.py test_18_methods.py test_19_shutdown.py test_20_websockets.py test_21_resolve.py test_22_httpsrr.py test_30_vsftpd.py test_31_vsftpds.py test_32_ftps_vsftpd.py test_40_socks.py test_50_scp.py test_51_sftp.py
libtest .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.h
server .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.c
tunit .gitignore CMakeLists.txt Makefile.am Makefile.inc README.md tool1394.c tool1604.c tool1621.c tool1622.c tool1623.c tool1720.c
unit .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.c
.gitignore CMakeLists.txt Makefile.am allversions.pm appveyor.pm azure.pm config.in configurehelp.pm.in devtest.pl dictserver.py directories.pm ech_combos.py ech_tests.sh ftpserver.pl getpart.pm globalconfig.pm http-server.pl http2-server.pl http3-server.pl memanalyze.pl memanalyzer.pm negtelnetserver.py nghttpx.conf pathhelp.pm processhelp.pm requirements.txt rtspserver.pl runner.pm runtests.pl secureserver.pl serverhelp.pm servers.pm smbserver.py sshhelp.pm sshserver.pl test1119.pl test1135.pl test1139.pl test1140.pl test1165.pl test1167.pl test1173.pl test1175.pl test1177.pl test1222.pl test1275.pl test1276.pl test1477.pl test1486.pl test1488.pl test1544.pl test1707.pl test745.pl test971.pl testcurl.pl testutil.pm tftpserver.pl util.py valgrind.pm valgrind.supp
.clang-tidy.yml .dir-locals.el .editorconfig .git-blame-ignore-revs .gitattributes .gitignore .mailmap CHANGES.md CMakeLists.txt COPYING Dockerfile GIT-INFO.md Makefile.am README README.md RELEASE-NOTES REUSE.toml SECURITY.md acinclude.m4 appveyor.sh appveyor.yml configure.ac curl-config.in libcurl.pc.in renovate.json
examples .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.lua
iniparser
.github
ISSUE_TEMPLATE config.yml
workflows disable-pull-requests.yml trigger-gitlab-ci.yml
cmake JoinPaths.cmake config.cmake.in pc.in
example iniexample.c iniwrite.c parse.c twisted-errors.ini twisted-genhuge.py twisted-ofkey.ini twisted-ofval.ini twisted.ini
src dictionary.c dictionary.h iniparser.c iniparser.h
test
ressources
bad_ini ends_well.ini twisted-errors.ini twisted-ofkey.ini twisted-ofval.ini
good_ini empty.ini spaced.ini spaced2.ini twisted.ini
gruezi.ini old.ini quotes.ini utf8.ini
CMakeLists.txt test_dictionary.c test_iniparser.c unity-config.yml unity_config.h
.cmake-format.py .gitignore .gitlab-ci.yml .gitmessage .travis.yml AUTHORS CMakeLists.txt FAQ-en.md FAQ-zhcn.md INSTALL LICENSE README.md compile_commands.json
jinjac
example CMakeLists.txt example.c
jinjac_test_app CMakeLists.txt jinjac_test_app.c
libjinjac
include jinjac.h
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.h
CMakeLists.txt
test .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.jinja
.gitignore CMakeLists.txt LICENSE.txt README.md build_coverage.sh build_debug.sh build_release.sh cppcheck_analysis.sh
libev 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-h1
luajit
doc
img contact.png
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.html
dynasm 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.lua
etc luajit.1 luajit.pc
src
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.c
jit .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.lua
.gitignore Makefile Makefile.dep lauxlib.h lib_aux.c lib_base.c lib_bit.c lib_buffer.c lib_debug.c lib_ffi.c lib_init.c lib_io.c lib_jit.c lib_math.c lib_os.c lib_package.c lib_string.c lib_table.c lj_alloc.c lj_alloc.h lj_api.c lj_arch.h lj_asm.c lj_asm.h lj_asm_arm.h lj_asm_arm64.h lj_asm_mips.h lj_asm_ppc.h lj_asm_x86.h lj_assert.c lj_bc.c lj_bc.h lj_bcdump.h lj_bcread.c lj_bcwrite.c lj_buf.c lj_buf.h lj_carith.c lj_carith.h lj_ccall.c lj_ccall.h lj_ccallback.c lj_ccallback.h lj_cconv.c lj_cconv.h lj_cdata.c lj_cdata.h lj_char.c lj_char.h lj_clib.c lj_clib.h lj_cparse.c lj_cparse.h lj_crecord.c lj_crecord.h lj_ctype.c lj_ctype.h lj_debug.c lj_debug.h lj_def.h lj_dispatch.c lj_dispatch.h lj_emit_arm.h lj_emit_arm64.h lj_emit_mips.h lj_emit_ppc.h lj_emit_x86.h lj_err.c lj_err.h lj_errmsg.h lj_ff.h lj_ffrecord.c lj_ffrecord.h lj_frame.h lj_func.c lj_func.h lj_gc.c lj_gc.h lj_gdbjit.c lj_gdbjit.h lj_ir.c lj_ir.h lj_ircall.h lj_iropt.h lj_jit.h lj_lex.c lj_lex.h lj_lib.c lj_lib.h lj_load.c lj_mcode.c lj_mcode.h lj_meta.c lj_meta.h lj_obj.c lj_obj.h lj_opt_dce.c lj_opt_fold.c lj_opt_loop.c lj_opt_mem.c lj_opt_narrow.c lj_opt_sink.c lj_opt_split.c lj_parse.c lj_parse.h lj_prng.c lj_prng.h lj_profile.c lj_profile.h lj_record.c lj_record.h lj_serialize.c lj_serialize.h lj_snap.c lj_snap.h lj_state.c lj_state.h lj_str.c lj_str.h lj_strfmt.c lj_strfmt.h lj_strfmt_num.c lj_strscan.c lj_strscan.h lj_tab.c lj_tab.h lj_target.h lj_target_arm.h lj_target_arm64.h lj_target_mips.h lj_target_ppc.h lj_target_x86.h lj_trace.c lj_trace.h lj_traceerr.h lj_udata.c lj_udata.h lj_vm.h lj_vmevent.c lj_vmevent.h lj_vmmath.c ljamalg.c lua.h lua.hpp luaconf.h luajit.c luajit_rolling.h lualib.h msvcbuild.bat nxbuild.bat ps4build.bat ps5build.bat psvitabuild.bat vm_arm.dasc vm_arm64.dasc vm_mips.dasc vm_mips64.dasc vm_ppc.dasc vm_x64.dasc vm_x86.dasc xb1build.bat xedkbuild.bat
.gitattributes .gitignore .relver COPYRIGHT Makefile README
sqlite shell.c sqlite3.c sqlite3.h sqlite3ext.h
wolfssl
.github
ISSUE_TEMPLATE bug_report.yaml other.yaml
actions
install-apt-deps action.yml
scripts
zephyr-4.x external_libc.conf zephyr-test.sh
openssl-ech.sh tls-anvil-test.sh
workflows
disabled haproxy.yml hitch.yml hostap.yml
hostap-files
configs
07c9f183ea744ac04585fb6dd10220c75a5e2e74 hostapd.config tests wpa_supplicant.config
b607d2723e927a3446d89aed813f1aa6068186bb hostapd.config tests wpa_supplicant.config
hostap_2_10 extra.patch hostapd.config tests wpa_supplicant.config
Makefile README dbus-wpa_supplicant.conf
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.yml
PULL_REQUEST_TEMPLATE.md SECURITY.md membrowse-targets.json
Docker
OpenWrt Dockerfile README.md runTests.sh
packaging
debian Dockerfile
fedora Dockerfile
wolfCLU Dockerfile README.md
yocto Dockerfile buildAndPush.sh
Dockerfile Dockerfile.cross-compiler README.md buildAndPush.sh include.am run.sh
IDE
ARDUINO
sketches
wolfssl_client README.md
wolfssl_server README.md
wolfssl_version README.md
README.md
Arduino_README_prepend.md README.md include.am keywords.txt library.properties.template wolfssl-arduino.cpp wolfssl-arduino.sh wolfssl.h
AURIX Cpu0_Main.c README.md include.am user_settings.h wolf_main.c
Android Android.bp README.md include.am user_settings.h
CRYPTOCELL README.md include.am main.c user_settings.h
CSBENCH include.am user_settings.h
ECLIPSE
DEOS
deos_wolfssl .options
README.md deos_malloc.c include.am tls_wolfssl.c tls_wolfssl.h user_settings.h
MICRIUM README.md client_wolfssl.c client_wolfssl.h include.am server_wolfssl.c server_wolfssl.h user_settings.h wolfsslRunTests.c
RTTHREAD README.md include.am user_settings.h wolfssl_test.c
SIFIVE README.md include.am
Espressif
ESP-IDF
examples
template
VisualGDB wolfssl_template_IDF_v5.1_ESP32.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h
CMakeLists.txt Kconfig.projbuild component.mk main.c
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp8266
wolfssl_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.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h
CMakeLists.txt Kconfig.projbuild component.mk main.c
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp8266
wolfssl_client
VisualGDB README.md wolfssl_client_IDF_v5_ESP32.sln wolfssl_client_IDF_v5_ESP32.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include client-tls.h main.h time_helper.h wifi_connect.h
CMakeLists.txt Kconfig.projbuild client-tls.c component.mk main.c time_helper.c wifi_connect.c
CMakeLists.txt Makefile README.md README_server_sm.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32c2 sdkconfig.defaults.esp8266 wolfssl_client_ESP8266.vgdbproj
wolfssl_server
VisualGDB README.md wolfssl_server_IDF_v5_ESP32.sln wolfssl_server_IDF_v5_ESP32.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h server-tls.h time_helper.h wifi_connect.h
CMakeLists.txt Kconfig.projbuild component.mk main.c server-tls.c time_helper.c wifi_connect.c
CMakeLists.txt Makefile README.md README_server_sm.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32c2 sdkconfig.defaults.esp8266 wolfssl_server_ESP8266.vgdbproj
wolfssl_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.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h
CMakeLists.txt Kconfig.projbuild component.mk main.c
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32 sdkconfig.defaults.esp32c3 sdkconfig.defaults.esp32c6 sdkconfig.defaults.esp32h2 sdkconfig.defaults.esp32s2 sdkconfig.defaults.esp32s3 sdkconfig.defaults.esp8266 testAll.sh testMonitor.sh wolfssl_test_ESP8266.sln wolfssl_test_ESP8266.vgdbproj
wolfssl_test_idf
VisualGDB VisualGDB_wolfssl_test_idf.sln VisualGDB_wolfssl_test_idf.vgdbproj
main CMakeLists.txt Kconfig.projbuild component.mk main.c main_wip.c.ex time_helper.c time_helper.h
CMakeLists.txt Kconfig.projbuild README.md component.mk sdkconfig.defaults
README.md
libs CMakeLists.txt README.md component.mk tigard.cfg
test CMakeLists.txt README.md component.mk test_wolfssl.c
README.md README_32se.md UPDATE.md compileAllExamples.sh dummy_config_h dummy_test_paths.h setup.sh setup_win.bat user_settings.h
README.md include.am
GCC-ARM
Header user_settings.h
Source armtarget.c benchmark_main.c test_main.c tls_client.c tls_server.c wolf_main.c
Makefile Makefile.bench Makefile.client Makefile.common Makefile.server Makefile.static Makefile.test README.md include.am linker.ld linker_fips.ld
Gaisler-BCC README.md include.am
HEXAGON
DSP Makefile wolfssl_dsp.idl
Makefile README.md build.sh ecc-verify-benchmark.c ecc-verify.c include.am user_settings.h
HEXIWEAR
wolfSSL_HW .cwGeneratedFileSetLog user_settings.h
IAR-EWARM
Projects
benchmark benchmark-main.c current_time.c wolfCrypt-benchmark.ewd wolfCrypt-benchmark.ewp
common minimum-startup.c wolfssl.icf
lib wolfSSL-Lib.ewd wolfSSL-Lib.ewp
test test-main.c wolfCrypt-test.ewd wolfCrypt-test.ewp
user_settings.h wolfssl.eww
embOS
SAMV71_XULT
embOS_SAMV71_XULT_Linker_Script samv71q21_wolfssl.icf
embOS_SAMV71_XULT_user_settings user_settings.h user_settings_simple_example.h user_settings_verbose_example.h
embOS_wolfcrypt_benchmark_SAMV71_XULT
Application runBenchmarks.c
README_wolfcrypt_benchmark wolfcrypt_benchmark.ewd wolfcrypt_benchmark.ewp
embOS_wolfcrypt_lib_SAMV71_XULT README_wolfcrypt_lib wolfcrypt_lib.ewd wolfcrypt_lib.ewp
embOS_wolfcrypt_test_SAMV71_XULT
Application runWolfcryptTests.c
README_wolfcrypt_test wolfcrypt_test.ewd wolfcrypt_test.ewp
README_SAMV71
custom_port
custom_port_Linker_Script samv71q21_wolfssl.icf
custom_port_user_settings user_settings.h
wolfcrypt_benchmark_custom_port
Application runBenchmarks.c
wolfcrypt_test_custom_port
Application runWolfcryptTests.c
README_custom_port
extract_trial_here README_extract_trial_here
README
.gitignore README
IAR-MSP430 Makefile README.md include.am main.c user_settings.h
INTIME-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.vcxproj
Infineon README.md include.am user_settings.h
KDS
config user_settings.h
include.am
LINUX-SGX README.md build.sh clean.sh include.am sgx_t_static.mk
LPCXPRESSO
lib_wolfssl lpc_18xx_port.c user_settings.h
wolf_example
src lpc_18xx_startup.c wolfssl_example.c
readme.txt
README.md
M68K
benchmark Makefile main.cpp
testwolfcrypt Makefile main.cpp
Makefile README.md include.am user_settings.h
MCUEXPRESSO
RT1170 fsl_caam_c.patch fsl_caam_h.patch user_settings.h
benchmark
source run_benchmark.c
wolfssl liblinks.xml
README.md include.am user_settings.h wolfcrypt_test.c
MDK-ARM
LPC43xx time-LCP43xx.c
MDK-ARM
wolfSSL Retarget.c cert_data.c cert_data.h config-BARE-METAL.h config-FS.h config-RTX-TCP-FS.h config-WOLFLIB.h main.c shell.c time-CortexM3-4.c time-dummy.c wolfssl_MDK_ARM.c wolfssl_MDK_ARM.h
STM32F2xx_StdPeriph_Lib time-STM32F2xx.c
MDK5-ARM
Conf user_settings.h
Inc wolfssl_MDK_ARM.h
Projects
CryptBenchmark Abstract.txt CryptBenchmark.sct CryptBenchmark.uvoptx CryptBenchmark.uvprojx main.c
CryptTest Abstract.txt CryptTest.sct CryptTest.uvoptx CryptTest.uvprojx main.c
EchoClient Abstract.txt EchoClient.uvoptx EchoClient.uvprojx main.c wolfssl-link.sct
EchoServer Abstract.txt EchoServer.uvoptx EchoServer.uvprojx main.c wolfssl-link.sct
SimpleClient Abstract.txt SimpleClient.uvoptx SimpleClient.uvprojx main.c wolfssl-link.sct
SimpleServer Abstract.txt SimpleServer.uvoptx SimpleServer.uvprojx main.c wolfssl-link.sct
wolfSSL-Full Abstract.txt main.c shell.c time-CortexM3-4.c wolfsslFull.uvoptx wolfsslFull.uvprojx
wolfSSL-Lib Abstract.txt wolfSSL-Lib.uvoptx wolfSSL-Lib.uvprojx
Src ssl-dummy.c
README.md include.am
MPLABX16
wolfcrypt_test.X
nbproject
private configurations.xml private.xml
configurations.xml include.am project.xml
Makefile
wolfssl.X
nbproject configurations.xml include.am project.xml
Makefile
README.md include.am main.c user_settings.h
MQX Makefile README-jp.md README.md client-tls.c include.am server-tls.c user_config.h user_settings.h
MSVS-2019-AZSPHERE
client client.c client.h
server server.c server.h
shared util.h
wolfssl_new_azsphere
HardwareDefinitions
avnet_mt3620_sk
inc
hw template_appliance.h
template_appliance.json
mt3620_rdb
inc
hw template_appliance.h
template_appliance.json
seeed_mt3620_mdb
inc
hw template_appliance.h
template_appliance.json
.gitignore CMakeLists.txt CMakeSettings.json app_manifest.json applibs_versions.h launch.vs.json main.c
README.md include.am user_settings.h
MYSQL CMakeLists_wolfCrypt.txt CMakeLists_wolfSSL.txt do.sh
NDS README.md
NETOS Makefile.wolfcrypt.inc README.md include.am user_settings.h user_settings.h-cert2425 user_settings.h-cert3389 wolfssl_netos_custom.c
OPENSTM32 README.md
PlatformIO
examples
wolfssl_benchmark
include README main.h
lib README
src CMakeLists.txt main.c
test README
CMakeLists.txt README.md platformio.ini sdkconfig.defaults wolfssl_benchmark.code-workspace
wolfssl_test
include README main.h
lib README
src CMakeLists.txt main.c
test README
CMakeLists.txt README.md platformio.ini sdkconfig.defaults wolfssl_test.code-workspace
README.md wolfssl_platformio.code-workspace
README.md include.am
QNX
CAAM-DRIVER Makefile
example-client Makefile client-tls.c
example-cmac Makefile cmac-test.c
example-server Makefile server-tls.c
testwolfcrypt Makefile
wolfssl Makefile user_settings.h
README.md include.am
RISCV
SIFIVE-HIFIVE1 Makefile README.md include.am main.c user_settings.h
SIFIVE-UNLEASHED README.md include.am
include.am
ROWLEY-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.hzp
Renesas
cs+
Projects
common strings.h unistd.h user_settings.h wolfssl_dummy.c
t4_demo README_en.txt README_jp.txt t4_demo.mtpj wolf_client.c wolf_demo.h wolf_main.c wolf_server.c
test test.mtpj test_main.c
wolfssl_lib wolfssl_lib.mtpj
README include.am
e2studio
DK-S7G2
benchmark-template
src app_entry.c
example_server-template
src app_entry.c
wolfcrypttest-template
src app_entry.c
wolfssl-template-project configuration.xml
README.md include.am user_settings.h
Projects
common strings.h unistd.h user_settings.h wolfssl_dummy.c
test
src key_data.c key_data.h test_main.c wolf_client.c wolf_server.c wolfssl_demo.h
tools generate_rsa_keypair.sh genhexbuf.pl rsa_pss_sign.sh
wolfssl
src .gitkeep
wolfcrypt
src .gitkeep
README include.am
RA6M3
benchmark-wolfcrypt
common .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
client-wolfssl
common
src .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
wolfssl_thread_entry.h
common
ra6m3g README.md
src freertos_tcp_port.c
user_settings.h util.h
server-wolfssl
common
src .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
wolfssl_thread_entry.h
test-wolfcrypt
common .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
wolfssl
src .gitkeep
wolfcrypt .gitkeep
README.md README_APRA6M_en.md README_APRA6M_jp.md include.am
RA6M3G README.md
RA6M4
common user_settings.h wolfssl_demo.h
test
key_data key_data.h key_data_sce.c
src
SEGGER_RTT myprint.c
common .gitignore
test_main.c wolf_client.c wolfssl_sce_unit_test.c
test_RA6M4Debug.launch
tools
example_keys generate_SignedCA.sh rsa_private.pem rsa_public.pem
README.md
README.md include.am
RX65N
GR-ROSE
common strings.h unistd.h user_settings.h wolfssl_dummy.c
smc smc.scfg
test
src key_data.c key_data.h test_main.c wolf_client.c wolf_server.c wolfssl_demo.h
test.rcpc test_HardwareDebug.launch
tools
example_keys generate_SignedCA.sh rsa_private.pem rsa_public.pem
README.md
wolfssl wolfssl.rcpc
README_EN.md README_JP.md include.am
RSK
resource section.esi
wolfssl wolfssl.rcpc
wolfssl_demo key_data.c key_data.h user_settings.h wolfssl_demo.c wolfssl_demo.h
InstructionManualForExample_RSK+RX65N-2MB_EN.pdf InstructionManualForExample_RSK+RX65N-2MB_JP.pdf README_EN.md README_JP.md include.am
RX72N
EnvisionKit
Simple
common sectioninfo.esi wolfssl_dummy.c
test
src
client simple_tcp_client.c simple_tls_tsip_client.c
server simple_tcp_server.c simple_tls_server.c
test_main.c wolfssl_simple_demo.h
test.rcpc test.scfg test_HardwareDebug.launch
wolfssl wolfssl.rcpc
README_EN.md README_JP.md
resource section.esi
tools
example_keys generate_SignedCA.sh rsa_private.pem rsa_public.pem
README.md
wolfssl wolfssl.rcpc
wolfssl_demo key_data.c key_data.h user_settings.h wolfssl_demo.c wolfssl_demo.h wolfssl_tsip_unit_test.c
InstructionManualForExample_RX72N_EnvisonKit_EN.pdf InstructionManualForExample_RX72N_EnvisonKit_JP.pdf README_EN.md README_JP.md include.am
RZN2L
common user_settings.h wolfssl_demo.h
test
src
serial_io app_print.c
test wolf_client.c wolf_server.c wolfssl_rsip_unit_test.c
wolfCrypt .gitignore
wolfSSL .gitignore
local_system_init.c rzn2l_tst_thread_entry.c wolfssl_dummy.c
README.md include.am
SK-S7G2
common user_settings.h
wolfssl_lib configuration.xml
.gitignore README.md include.am
STARCORE README.txt include.am starcore_test.c user_settings.h
STM32Cube README.md STM32_Benchmarks.md default_conf.ftl include.am main.c wolfssl_example.c wolfssl_example.h
SimplicityStudio README.md include.am test_wolf.c user_settings.h
TRUESTUDIO
wolfssl user_settings.h
README include.am
VS-ARM README.md include.am user_settings.h wolfssl.sln wolfssl.vcxproj
VS-AZURE-SPHERE
client app_manifest.json client.c client.h client.vcxproj
server app_manifest.json server.c server.h server.vcxproj
shared util.h
wolfcrypt_test app_manifest.json wolfcrypt_test.vcxproj
README.md include.am user_settings.h wolfssl.sln wolfssl.vcxproj
VisualDSP include.am user_settings.h wolf_tasks.c
WICED-STUDIO README include.am user_settings.h
WIN README.txt include.am test.vcxproj user_settings.h user_settings_dtls.h wolfssl-fips.sln wolfssl-fips.vcxproj
WIN-SGX ReadMe.txt include.am wolfSSL_SGX.edl wolfSSL_SGX.sln wolfSSL_SGX.vcxproj
WIN-SRTP-KDF-140-3 README.txt include.am resource.h test.vcxproj user_settings.h wolfssl-fips.rc wolfssl-fips.sln wolfssl-fips.vcxproj
WIN10 README.txt include.am resource.h test.vcxproj user_settings.h wolfssl-fips.rc wolfssl-fips.sln wolfssl-fips.vcxproj
WINCE README.md include.am user_settings.h user_settings.h.140-2-deprecated
WORKBENCH README.md include.am
XCODE
Benchmark
wolfBench
Assets.xcassets
AppIcon.appiconset Contents.json
Base.lproj LaunchScreen.storyboard Main.storyboard
AppDelegate.h AppDelegate.m Info.plist ViewController.h ViewController.m main.m
wolfBench.xcodeproj project.pbxproj
include.am
wolfssl-FIPS.xcodeproj project.pbxproj
wolfssl.xcodeproj project.pbxproj
wolfssl_testsuite.xcodeproj project.pbxproj
README.md build-for-i386.sh include.am user_settings.h
XCODE-FIPSv2
macOS-C++
Intel user_settings.h
M1 user_settings.h
include.am user_settings.h
XCODE-FIPSv5 README include.am user_settings.h
XCODE-FIPSv6 README include.am user_settings.h
XilinxSDK
2018_2 lscript.ld
2019_2
wolfCrypt_example
src lscript.ld
wolfCrypt_example_system wolfCrypt_example_system.sprj
2022_1
wolfCrypt_FreeRTOS_example wolfCrypt_FreeRTOS_example.prj
wolfCrypt_FreeRTOS_example_system wolfCrypt_FreeRTOS_example_system.sprj
wolfCrypt_example wolfCrypt_example.prj
wolfCrypt_example_system wolfCrypt_example_system.sprj
.gitignore
README.md bench.sh combine.sh eclipse_formatter_profile.xml graph.sh include.am user_settings.h wolfssl_example.c
apple-universal
wolfssl-multiplatform
wolfssl-multiplatform
Assets.xcassets
AccentColor.colorset Contents.json
AppIcon.appiconset Contents.json
Contents.json
ContentView.swift simple_client_example.c simple_client_example.h wolfssl-multiplatform-Bridging-Header.h wolfssl_multiplatform.entitlements wolfssl_multiplatformApp.swift wolfssl_test_driver.c wolfssl_test_driver.h
wolfssl-multiplatform.xcodeproj project.pbxproj
.gitignore README.md build-wolfssl-framework.sh include.am
iotsafe Makefile README.md ca-cert.c devices.c devices.h include.am main.c memory-tls.c startup.c target.ld user_settings.h
iotsafe-raspberrypi Makefile README.md client-tls13.c include.am main.c
mynewt README.md apps.wolfcrypttest.pkg.yml crypto.wolfssl.pkg.yml crypto.wolfssl.syscfg.yml include.am setup.sh
zephyr README.md include.am
include.am
RTOS
nuttx
wolfssl .gitignore Kconfig Make.defs Makefile README.md setup-wolfssl.sh user_settings.h
include.am
bsdkm Makefile README.md bsdkm_wc_port.h include.am wolfkmod.c wolfkmod_aes.c x86_vecreg.c
certs
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.pem
3072 client-cert.der client-cert.pem client-key.der client-key.pem client-keyPub.der include.am
4096 client-cert.der client-cert.pem client-key.der client-key.pem client-keyPub.der include.am
acert
rsa_pss acert.pem acert_ietf.pem acert_ietf_pubkey.pem acert_pubkey.pem
acert.pem acert_ietf.pem acert_ietf_pubkey.pem acert_pubkey.pem include.am
aia ca-issuers-cert.pem multi-aia-cert.pem overflow-aia-cert.pem
crl
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.pem
hash_der 0fdb2da4.r0
hash_pem 0fdb2da4.r0
bad_time_fmt.pem ca-int-ecc.pem ca-int.pem ca-int2-ecc.pem ca-int2.pem caEcc384Crl.pem caEccCrl.der caEccCrl.pem cliCrl.pem client-int-ecc.pem client-int.pem crl.der crl.pem crl.revoked crl2.der crl2.pem crl_reason.pem crl_rsapss.pem eccCliCRL.pem eccSrvCRL.pem gencrls.sh include.am server-goodaltCrl.pem server-goodaltwildCrl.pem server-goodcnCrl.pem server-goodcnwildCrl.pem server-int-ecc.pem server-int.pem wolfssl.cnf
dilithium bench_dilithium_level2_key.der bench_dilithium_level3_key.der bench_dilithium_level5_key.der include.am
ecc 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.cnf
ed25519 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.pem
ed448 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.pem
external DigiCertGlobalRootCA.pem README.txt ca-digicert-ev.pem ca-globalsign-root.pem ca-google-root.pem ca_collection.pem include.am
falcon bench_falcon_level1_key.der bench_falcon_level5_key.der include.am
intermediate
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.conf
ca-ecc-bad-aki.der ca-ecc-bad-aki.pem ca-int-cert.der ca-int-cert.pem ca-int-ecc-cert.der ca-int-ecc-cert.pem ca-int-ecc-key.der ca-int-ecc-key.pem ca-int-key.der ca-int-key.pem ca-int2-cert.der ca-int2-cert.pem ca-int2-ecc-cert.der ca-int2-ecc-cert.pem ca-int2-ecc-key.der ca-int2-ecc-key.pem ca-int2-key.der ca-int2-key.pem client-chain-alt-ecc.pem client-chain-alt.pem client-chain-ecc.der client-chain-ecc.pem client-chain.der client-chain.pem client-int-cert.der client-int-cert.pem client-int-ecc-cert.der client-int-ecc-cert.pem genintcerts.sh include.am server-chain-alt-ecc.pem server-chain-alt.pem server-chain-ecc.der server-chain-ecc.pem server-chain-short.pem server-chain.der server-chain.pem server-int-cert.der server-int-cert.pem server-int-ecc-cert.der server-int-ecc-cert.pem
lms 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.am
mldsa 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.der
ocsp 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.der
p521 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.pem
renewcerts wolfssl.cnf
rpk client-cert-rpk.der client-ecc-cert-rpk.der include.am server-cert-rpk.der server-ecc-cert-rpk.der
rsapss 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.pem
sia timestamping-sia-cert.pem
slhdsa 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.pem
sm2 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.pem
statickeys 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.pem
test
expired expired-ca.der expired-ca.pem expired-cert.der expired-cert.pem
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.p7s
test-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.sh
test-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.pem
xmss 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.am
ca-cert-chain.der ca-cert.der ca-cert.pem ca-ecc-cert.der ca-ecc-cert.pem ca-ecc-key.der ca-ecc-key.pem ca-ecc384-cert.der ca-ecc384-cert.pem ca-ecc384-key.der ca-ecc384-key.pem ca-key-pkcs8-attribute.der ca-key.der ca-key.pem check_dates.sh client-absolute-urn.pem client-ca-cert.der client-ca-cert.pem client-ca.pem client-cert-ext.der client-cert-ext.pem client-cert.der client-cert.pem client-crl-dist.der client-crl-dist.pem client-ecc-ca-cert.der client-ecc-ca-cert.pem client-ecc-cert.der client-ecc-cert.pem client-ecc384-cert.der client-ecc384-cert.pem client-ecc384-key.der client-ecc384-key.pem client-key.der client-key.pem client-keyEnc.pem client-keyPub.der client-keyPub.pem client-relative-uri.pem client-uri-cert.pem csr.attr.der csr.dsa.der csr.dsa.pem csr.ext.der csr.signed.der dh-priv-2048.der dh-priv-2048.pem dh-pub-2048.der dh-pub-2048.pem dh-pubkey-2048.der dh2048.der dh2048.pem dh3072.der dh3072.pem dh4096.der dh4096.pem dsa-pubkey-2048.der dsa2048.der dsa2048.pem dsa3072.der dsaparams.der dsaparams.pem ecc-client-key.der ecc-client-key.pem ecc-client-keyPub.der ecc-client-keyPub.pem ecc-key-comp.pem ecc-keyPkcs8.der ecc-keyPkcs8.pem ecc-keyPkcs8Enc.der ecc-keyPkcs8Enc.pem ecc-keyPub.der ecc-keyPub.pem ecc-params.der ecc-params.pem ecc-privOnlyCert.pem ecc-privOnlyKey.pem ecc-privkey.der ecc-privkey.pem ecc-privkeyPkcs8.der ecc-privkeyPkcs8.pem ecc-rsa-server.p12 empty-issuer-cert.pem entity-no-ca-bool-cert.pem entity-no-ca-bool-key.pem fpki-cert.der fpki-certpol-cert.der gen_revoked.sh include.am renewcerts.sh rid-cert.der rsa-pub-2048.pem rsa2048.der rsa3072.der server-cert-chain.der server-cert.der server-cert.pem server-ecc-comp.der server-ecc-comp.pem server-ecc-rsa.der server-ecc-rsa.pem server-ecc-self.der server-ecc-self.pem server-ecc.der server-ecc.pem server-ecc384-cert.der server-ecc384-cert.pem server-ecc384-key.der server-ecc384-key.pem server-key.der server-key.pem server-keyEnc.pem server-keyPkcs8.der server-keyPkcs8.pem server-keyPkcs8Enc.der server-keyPkcs8Enc.pem server-keyPkcs8Enc12.pem server-keyPkcs8Enc2.pem server-keyPub.der server-keyPub.pem server-revoked-cert.pem server-revoked-key.pem taoCert.txt test-ber-exp02-05-2022.p7b test-degenerate.p7b test-multiple-recipients.p7b test-servercert-rc2.p12 test-servercert.p12 test-stream-dec.p7b test-stream-sign.p7b wolfssl-website-ca.pem x942dh2048.der x942dh2048.pem
cmake
consumer CMakeLists.txt README.md main.c
modules FindARIA.cmake FindOQS.cmake
Config.cmake.in README.md config.in functions.cmake include.am options.h.in wolfssl-config-version.cmake.in wolfssl-targets.cmake.in
debian
source format
changelog.in control.in copyright include.am libwolfssl-dev.install libwolfssl.install rules.in
doc
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.h
header_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.h
formats
html
html_changes
search search.css search.js
customdoxygen.css doxygen.css menu.js menudata.js tabs.css
Doxyfile footer.html header.html mainpage.dox
pdf Doxyfile header.tex
images wolfssl_logo.png
QUIC.md README.txt README_DOXYGEN check_api.sh generate_documentation.sh include.am
examples
asn1 asn1.c dumpasn1.cfg gen_oid_names.rb include.am oid_names.h
async Makefile README.md async_client.c async_server.c async_tls.c async_tls.h include.am user_settings.h
benchmark include.am tls_bench.c tls_bench.h
client client.c client.h client.sln client.vcproj client.vcxproj include.am
configs 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.h
crypto_policies
default wolfssl.txt
future wolfssl.txt
legacy wolfssl.txt
echoclient echoclient.c echoclient.h echoclient.sln echoclient.vcproj echoclient.vcxproj include.am quit
echoserver echoserver.c echoserver.h echoserver.sln echoserver.vcproj echoserver.vcxproj include.am
ocsp_responder include.am ocsp_responder.c ocsp_responder.h
pem include.am pem.c
sctp include.am sctp-client-dtls.c sctp-client.c sctp-server-dtls.c sctp-server.c
server include.am server.c server.h server.sln server.vcproj server.vcxproj
README.md include.am
linuxkm
patches
5.10.17 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v10v17.patch
5.10.236 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v10v236.patch
5.14.0-570.58.1.el9_6 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v14-570v58v1-el9_6.patch
5.15 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v15.patch
5.17 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v17.patch
5.17-ubuntu-jammy-tegra WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v17-ubuntu-jammy-tegra.patch
6.1.73 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-6v1v73.patch
6.12 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-6v12.patch
6.15 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-6v15.patch
7.0 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-7v0.patch
regen-patches.sh
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.c
m4 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.m4
mcapi
wolfcrypt_mcapi.X
nbproject configurations.xml include.am project.xml
Makefile
wolfcrypt_test.X
nbproject configurations.xml include.am project.xml
Makefile
wolfssl.X
nbproject configurations.xml include.am project.xml
Makefile
zlib.X
nbproject configurations.xml include.am project.xml
Makefile
PIC32MZ-serial.h README crypto.c crypto.h include.am mcapi_test.c user_settings.h
mplabx
wolfcrypt_benchmark.X
nbproject configurations.xml include.am project.xml
Makefile
wolfcrypt_test.X
nbproject configurations.xml include.am project.xml
Makefile
wolfssl.X
nbproject configurations.xml include.am project.xml
Makefile
PIC32MZ-serial.h README benchmark_main.c include.am test_main.c user_settings.h
mqx
util_lib
Sources include.am util.c util.h
wolfcrypt_benchmark
Debugger K70FN1M0.mem init_kinetis.tcl mass_erase_kinetis.tcl
Sources include.am main.c main.h
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.launch
wolfcrypt_test
Debugger K70FN1M0.mem init_kinetis.tcl mass_erase_kinetis.tcl
Sources include.am main.c main.h
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.launch
wolfssl include.am
wolfssl_client
Debugger K70FN1M0.mem init_kinetis.tcl mass_erase_kinetis.tcl
Sources include.am main.c main.h
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.launch
README
rpm include.am spec.in
scripts
bench bench_functions.sh
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.sh
src 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.c
sslSniffer
sslSnifferTest README_WIN.md include.am snifftest.c sslSniffTest.vcproj sslSniffTest.vcxproj
README.md sslSniffer.vcproj sslSniffer.vcxproj
support gen-debug-trace-error-codes.sh include.am wolfssl.pc.in
tests
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.h
emnet
IP IP.h
Makefile emnet_nonblock_test.c emnet_shim.c
freertos-mem-track-repro FreeRTOS.h repro.c run.sh semphr.h task.h user_settings.h
swdev .gitignore Makefile README.md swdev.c swdev.h swdev_loader.c swdev_loader.h user_settings.h
CONF_FILES_README.md NCONF_test.cnf README TXT_DB.txt api.c include.am quic.c srp.c suites.c test-altchains.conf test-chains.conf test-dhprime.conf test-dtls-downgrade.conf test-dtls-fails-cipher.conf test-dtls-fails.conf test-dtls-group.conf test-dtls-mtu.conf test-dtls-reneg-client.conf test-dtls-reneg-server.conf test-dtls-resume.conf test-dtls-sha2.conf test-dtls-srtp-fails.conf test-dtls-srtp.conf test-dtls.conf test-dtls13-cid.conf test-dtls13-downgrade-fails.conf test-dtls13-downgrade.conf test-dtls13-pq-hybrid-extra-frag.conf test-dtls13-pq-hybrid-extra.conf test-dtls13-pq-hybrid-frag.conf test-dtls13-pq-standalone-frag.conf test-dtls13-pq-standalone.conf test-dtls13-psk.conf test-dtls13.conf test-ecc-cust-curves.conf test-ed25519.conf test-ed448.conf test-enckeys.conf test-fails.conf test-maxfrag-dtls.conf test-maxfrag.conf test-p521.conf test-psk-no-id-sha2.conf test-psk-no-id.conf test-psk.conf test-rsapss.conf test-sctp-sha2.conf test-sctp.conf test-sha2.conf test-sig.conf test-sm2.conf test-tls-downgrade.conf test-tls13-down.conf test-tls13-ecc.conf test-tls13-pq-hybrid-extra.conf test-tls13-pq-hybrid.conf test-tls13-pq-standalone.conf test-tls13-psk-certs.conf test-tls13-psk.conf test-tls13-slhdsa-fail.conf test-tls13-slhdsa-sha2.conf test-tls13-slhdsa-shake.conf test-tls13.conf test-trustpeer.conf test.conf unit.c unit.h utils.c utils.h w64wrapper.c
testsuite include.am testsuite.c testsuite.sln testsuite.vcproj testsuite.vcxproj utils.c utils.h
tirtos
packages
ti
net
wolfssl
tests
EK_TM4C1294XL
wolfcrypt
benchmark TM4C1294NC.icf benchmark.cfg main.c package.bld.hide package.xdc
test TM4C1294NC.icf main.c package.bld.hide package.xdc test.cfg
package.bld package.xdc package.xs
.gitignore README include.am products.mak wolfssl.bld wolfssl.mak
wolfcrypt
benchmark README.md benchmark-VS2022.sln benchmark-VS2022.vcxproj benchmark-VS2022.vcxproj.user benchmark.c benchmark.h benchmark.sln benchmark.vcproj benchmark.vcxproj include.am
src
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.py
README.md esp32_aes.c esp32_mp.c esp32_sha.c esp32_util.c esp_sdk_mem_lib.c esp_sdk_time_lib.c esp_sdk_wifi_lib.c
Renesas 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.c
af_alg afalg_aes.c afalg_hash.c wc_afalg.c
aria aria-crypt.c aria-cryptocb.c
arm 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.c
atmel README.md atmel.c
autosar README.md cryif.c crypto.c csm.c include.am test.c
caam 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.c
cavium README.md README_Octeon.md cavium_nitrox.c cavium_octeon_sync.c
cuda README.md aes-cuda.cu
cypress README.md psoc6_crypto.c
devcrypto README.md devcrypto_aes.c devcrypto_ecdsa.c devcrypto_hash.c devcrypto_hmac.c devcrypto_rsa.c devcrypto_x25519.c wc_devcrypto.c
intel README.md quickassist.c quickassist_mem.c quickassist_sync.c
iotsafe iotsafe.c
kcapi README.md kcapi_aes.c kcapi_dh.c kcapi_ecc.c kcapi_hash.c kcapi_hmac.c kcapi_rsa.c
liboqs liboqs.c
maxim README.md max3266x.c maxq10xx.c
mynewt mynewt_port.c
nxp README.md README_SE050.md casper_port.c dcp_port.c hashcrypt_port.c ksdk_port.c se050_port.c
pic32 pic32mz-crypt.c
ppc32 ppc32-sha256-asm.S ppc32-sha256-asm_c.c ppc32-sha256-asm_cr.c
psa README.md psa.c psa_aes.c psa_hash.c psa_pkcbs.c
riscv riscv-64-aes.c riscv-64-chacha.c riscv-64-poly1305.c riscv-64-sha256.c riscv-64-sha3.c riscv-64-sha512.c
rpi_pico README.md pico.c
silabs README.md silabs_aes.c silabs_ecc.c silabs_hash.c silabs_random.c
st README.md STM32MP13.md STM32MP25.md stm32.c stsafe.c
ti ti-aes.c ti-ccm.c ti-des3.c ti-hash.c
tropicsquare README.md tropic01.c
xilinx xil-aesgcm.c xil-sha3.c xil-versal-glue.c xil-versal-trng.c
nrf51.c
ASN_TEMPLATE.md aes.c aes_asm.S aes_asm.asm aes_gcm_asm.S aes_gcm_asm.asm aes_gcm_x86_asm.S aes_xts_asm.S aes_xts_asm.asm arc4.c ascon.c asm.c asn.c asn_orig.c async.c blake2b.c blake2s.c camellia.c chacha.c chacha20_poly1305.c chacha_asm.S chacha_asm.asm cmac.c coding.c compress.c cpuid.c cryptocb.c curve25519.c curve448.c des3.c dh.c dilithium.c dsa.c ecc.c ecc_fp.c eccsi.c ed25519.c ed448.c error.c evp.c evp_pk.c falcon.c fe_448.c fe_low_mem.c fe_operations.c fe_x25519_128.h fe_x25519_asm.S fp_mont_small.i fp_mul_comba_12.i fp_mul_comba_17.i fp_mul_comba_20.i fp_mul_comba_24.i fp_mul_comba_28.i fp_mul_comba_3.i fp_mul_comba_32.i fp_mul_comba_4.i fp_mul_comba_48.i fp_mul_comba_6.i fp_mul_comba_64.i fp_mul_comba_7.i fp_mul_comba_8.i fp_mul_comba_9.i fp_mul_comba_small_set.i fp_sqr_comba_12.i fp_sqr_comba_17.i fp_sqr_comba_20.i fp_sqr_comba_24.i fp_sqr_comba_28.i fp_sqr_comba_3.i fp_sqr_comba_32.i fp_sqr_comba_4.i fp_sqr_comba_48.i fp_sqr_comba_6.i fp_sqr_comba_64.i fp_sqr_comba_7.i fp_sqr_comba_8.i fp_sqr_comba_9.i fp_sqr_comba_small_set.i ge_448.c ge_low_mem.c ge_operations.c hash.c hmac.c hpke.c include.am integer.c kdf.c logging.c md2.c md4.c md5.c memory.c misc.c pkcs12.c pkcs7.c poly1305.c poly1305_asm.S poly1305_asm.asm puf.c pwdbased.c random.c rc2.c ripemd.c rng_bank.c rsa.c sakke.c sha.c sha256.c sha256_asm.S sha3.c sha3_asm.S sha512.c sha512_asm.S signature.c siphash.c sm2.c sm3.c sm3_asm.S sm4.c sp_arm32.c sp_arm64.c sp_armthumb.c sp_c32.c sp_c64.c sp_cortexm.c sp_dsp32.c sp_int.c sp_sm2_arm32.c sp_sm2_arm64.c sp_sm2_armthumb.c sp_sm2_c32.c sp_sm2_c64.c sp_sm2_cortexm.c sp_sm2_x86_64.c sp_sm2_x86_64_asm.S sp_x86_64.c sp_x86_64_asm.S sp_x86_64_asm.asm srp.c tfm.c wc_dsp.c wc_encrypt.c wc_lms.c wc_lms_impl.c wc_mldsa_asm.S wc_mlkem.c wc_mlkem_asm.S wc_mlkem_poly.c wc_pkcs11.c wc_port.c wc_she.c wc_slhdsa.c wc_xmss.c wc_xmss_impl.c wolfentropy.c wolfevent.c wolfmath.c
test README.md include.am test-VS2022.sln test-VS2022.vcxproj test-VS2022.vcxproj.user test.c test.h test.sln test.vcproj test_paths.h.in
wolfssl
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.h
wolfcrypt
port
Espressif esp-sdk-lib.h esp32-crypt.h esp_crt_bundle.h
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.h
af_alg afalg_hash.h wc_afalg.h
aria aria-crypt.h aria-cryptocb.h
arm cryptoCell.h
atmel atmel.h
autosar CryIf.h Crypto.h Csm.h StandardTypes.h
caam 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.h
cavium cavium_nitrox.h cavium_octeon_sync.h
cypress psoc6_crypto.h
devcrypto wc_devcrypto.h
intel quickassist.h quickassist_mem.h quickassist_sync.h
iotsafe iotsafe.h
kcapi kcapi_dh.h kcapi_ecc.h kcapi_hash.h kcapi_hmac.h kcapi_rsa.h wc_kcapi.h
liboqs liboqs.h
maxim max3266x-cryptocb.h max3266x.h maxq10xx.h
nxp casper_port.h dcp_port.h hashcrypt_port.h ksdk_port.h se050_port.h
pic32 pic32mz-crypt.h
psa psa.h
riscv riscv-64-asm.h
rpi_pico pico.h
silabs silabs_aes.h silabs_ecc.h silabs_hash.h silabs_random.h
st stm32.h stsafe.h
ti ti-ccm.h ti-hash.h
tropicsquare tropic01.h
xilinx xil-sha3.h xil-versal-glue.h xil-versal-trng.h
nrf51.h
aes.h arc4.h ascon.h asn.h asn_public.h async.h blake2-impl.h blake2-int.h blake2.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cpuid.h cryptocb.h curve25519.h curve448.h des3.h dh.h dilithium.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h falcon.h fe_448.h fe_operations.h fips_test.h ge_448.h ge_operations.h hash.h hmac.h hpke.h include.am integer.h kdf.h libwolfssl_sources.h libwolfssl_sources_asm.h logging.h md2.h md4.h md5.h mem_track.h memory.h misc.h mpi_class.h mpi_superclass.h oid_sum.h pkcs11.h pkcs12.h pkcs7.h poly1305.h puf.h pwdbased.h random.h rc2.h ripemd.h rng_bank.h rsa.h sakke.h selftest.h settings.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h sm2.h sm3.h sm4.h sp.h sp_int.h srp.h tfm.h types.h visibility.h wc_encrypt.h wc_lms.h wc_mlkem.h wc_pkcs11.h wc_port.h wc_she.h wc_slhdsa.h wc_xmss.h wolfentropy.h wolfevent.h wolfmath.h
callbacks.h certs_test.h certs_test_sm.h crl.h error-ssl.h include.am internal.h ocsp.h options.h.in quic.h sniffer.h sniffer_error.h sniffer_error.rc ssl.h test.h version.h version.h.in wolfio.h
wrapper
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.adb
.gitignore alire.toml examples.gpr
tests
src
support test_support.adb test_support.ads tests_root_suite.adb tests_root_suite.ads
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.adb
.gitignore README.md alire.toml tests.gpr valgrind.supp
.gitignore README.md ada_binding.c alire.toml default.gpr include.am restricted.adc user_settings.h wolfssl-full_runtime.adb wolfssl-full_runtime.ads wolfssl.adb wolfssl.ads wolfssl.gpr
CSharp
wolfCrypt-Test
Properties AssemblyInfo.cs
App.config wolfCrypt-Test.cs wolfCrypt-Test.csproj
wolfSSL-DTLS-PSK-Server
Properties AssemblyInfo.cs
App.config wolfSSL-DTLS-PSK-Server.cs wolfSSL-DTLS-PSK-Server.csproj
wolfSSL-DTLS-Server
Properties AssemblyInfo.cs
App.config wolfSSL-DTLS-Server.cs wolfSSL-DTLS-Server.csproj
wolfSSL-Example-IOCallbacks
Properties AssemblyInfo.cs
App.config wolfSSL-Example-IOCallbacks.cs wolfSSL-Example-IOCallbacks.csproj
wolfSSL-TLS-Client
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-Client.cs wolfSSL-TLS-Client.csproj
wolfSSL-TLS-PSK-Client
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-PSK-Client.cs wolfSSL-TLS-PSK-Client.csproj
wolfSSL-TLS-PSK-Server
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-PSK-Server.cs wolfSSL-TLS-PSK-Server.csproj
wolfSSL-TLS-Server
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-Server.cs wolfSSL-TLS-Server.csproj
wolfSSL-TLS-ServerThreaded
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-ServerThreaded.cs wolfSSL-TLS-ServerThreaded.csproj
wolfSSL_CSharp
Properties AssemblyInfo.cs Resources.Designer.cs Resources.resx
X509.cs wolfCrypt.cs wolfSSL.cs wolfSSL_CSharp.csproj
README.md include.am user_settings.h wolfSSL_CSharp.sln wolfssl.vcxproj
python README.md
rust
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.rs
tests
common mod.rs
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.rs
CHANGELOG.md Cargo.lock Cargo.toml Makefile README.md build.rs headers.h
Makefile README.md include.am
include.am
zephyr
samples
wolfssl_benchmark
boards native_sim.conf nrf5340dk_nrf5340_cpuapp.conf nrf5340dk_nrf5340_cpuapp_ns.conf
CMakeLists.txt README install_test.sh prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl_test
boards native_sim.conf nrf5340dk_nrf5340_cpuapp.conf nrf5340dk_nrf5340_cpuapp_ns.conf
CMakeLists.txt README install_test.sh prj-no-malloc.conf prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl_tls_sock
boards native_sim.conf
src tls_sock.c
CMakeLists.txt README install_sample.sh prj-no-malloc.conf prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl_tls_thread
boards native_sim.conf nrf5340dk_nrf5340_cpuapp.conf nrf5340dk_nrf5340_cpuapp_ns.conf
src tls_threaded.c
CMakeLists.txt README install_sample.sh prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl options.h
CMakeLists.txt Kconfig Kconfig.tls-generic README.md include.am module.yml user_settings-no-malloc.h user_settings.h zephyr_init.c
.codespellexcludelines .cyignore .editorconfig .gitignore .wolfssl_known_macro_extras AUTHORS CMakeLists.txt CMakePresets.json CMakeSettings.json COPYING ChangeLog.md INSTALL LICENSING LPCExpresso.cproject LPCExpresso.project Makefile.am README README-async.md README.md SCRIPTS-LIST SECURITY-POLICY.md SECURITY-REPORT-TEMPLATE.md Vagrantfile autogen.sh commit-tests.sh configure.ac fips-check.sh fips-hash.sh gencertbuf.pl input pull_to_vagrant.sh quit resource.h stamp-h.in valgrind-bash.supp valgrind-error.sh wnr-example.conf wolfssl-VS2022.vcxproj wolfssl.rc wolfssl.vcproj wolfssl.vcxproj wolfssl64.sln
.clangd .gitignore DOCS.md Makefile README.md assert.c core.c crypto.c env.c fs.c http.c ini.c json.c log.c luna.h main.c makext.mk path.c process.c request.c sqlite.c stash.c template.c util.c
wolfssl/src/ssl_asn1.c raw
   1/* ssl_asn1.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#include <wolfssl/wolfcrypt/libwolfssl_sources.h>
  23
  24#include <wolfssl/internal.h>
  25#ifndef WC_NO_RNG
  26    #include <wolfssl/wolfcrypt/random.h>
  27#endif
  28
  29#if !defined(WOLFSSL_SSL_ASN1_INCLUDED)
  30    #ifndef WOLFSSL_IGNORE_FILE_WARN
  31        #warning ssl_asn1.c does not need to be compiled separately from ssl.c
  32    #endif
  33#else
  34
  35/*******************************************************************************
  36 * ASN1_item APIs
  37 ******************************************************************************/
  38
  39#ifndef NO_ASN
  40
  41#ifdef OPENSSL_EXTRA
  42
  43#ifdef OPENSSL_ALL
  44
  45/* Provides access to the member of the obj offset by offset */
  46#define asn1Mem(obj, offset) (*(void**)(((byte*)(obj)) + (offset)))
  47#define asn1Type(obj, offset) (*(int*)(((byte*)(obj)) + (offset)))
  48
  49static void* asn1_new_tpl(const WOLFSSL_ASN1_TEMPLATE *mem)
  50{
  51    if (mem->sequence)
  52        return wolfSSL_sk_new_null();
  53    else
  54        return mem->new_func();
  55}
  56
  57static void* asn1_item_alloc(const WOLFSSL_ASN1_ITEM* item)
  58{
  59    void* ret = NULL;
  60
  61    /* allocation */
  62    switch (item->type) {
  63        case WOLFSSL_ASN1_SEQUENCE:
  64        case WOLFSSL_ASN1_CHOICE:
  65            ret = (void *)XMALLOC(item->size, NULL, DYNAMIC_TYPE_OPENSSL);
  66            if (ret != NULL)
  67                XMEMSET(ret, 0, item->size);
  68            break;
  69        case WOLFSSL_ASN1_OBJECT_TYPE:
  70            if (item->mcount != 1 || item->members->offset) {
  71                WOLFSSL_MSG("incorrect member count or offset");
  72                return NULL;
  73            }
  74            ret = asn1_new_tpl(item->members);
  75            break;
  76        default:
  77            WOLFSSL_MSG("ASN1 type not implemented");
  78            return NULL;
  79    }
  80
  81    return ret;
  82}
  83
  84static int asn1_item_init(void* obj, const WOLFSSL_ASN1_ITEM* item)
  85{
  86    const WOLFSSL_ASN1_TEMPLATE *mem = NULL;
  87    size_t i;
  88    int ret = 0;
  89
  90    switch (item->type) {
  91        case WOLFSSL_ASN1_SEQUENCE:
  92            for (mem = item->members, i = 0; i < item->mcount; mem++, i++) {
  93                asn1Mem(obj, mem->offset) = asn1_new_tpl(mem);
  94                if (asn1Mem(obj, mem->offset) == NULL) {
  95                    ret = WOLFSSL_FATAL_ERROR;
  96                    break;
  97                }
  98            }
  99            break;
 100        case WOLFSSL_ASN1_OBJECT_TYPE:
 101            /* Initialized by new_func. Nothing to do. */
 102            break;
 103        case WOLFSSL_ASN1_CHOICE:
 104            asn1Type(obj, item->toffset) = -1;
 105            /* We don't know what to initialize. Nothing to do. */
 106            break;
 107        default:
 108            WOLFSSL_MSG("ASN1 type not implemented");
 109            ret = WOLFSSL_FATAL_ERROR;
 110            break;
 111    }
 112
 113    return ret;
 114}
 115
 116/* Create a new ASN1 item based on a template.
 117 *
 118 * @param [in] item  Info about ASN1 items.
 119 * @return  A new ASN1 item on success.
 120 * @return  NULL when item is NULL, dynamic memory allocation fails or ASN1
 121 *          item type not supported.
 122 */
 123void* wolfSSL_ASN1_item_new(const WOLFSSL_ASN1_ITEM* item)
 124{
 125    void* ret = NULL;
 126
 127    WOLFSSL_ENTER("wolfSSL_ASN1_item_new");
 128
 129    if (item == NULL)
 130        return NULL;
 131
 132    /* allocation */
 133    ret = asn1_item_alloc(item);
 134    if (ret == NULL)
 135        return NULL;
 136
 137    /* initialization */
 138    if (asn1_item_init(ret, item) != 0) {
 139        wolfSSL_ASN1_item_free(ret, item);
 140        ret = NULL;
 141    }
 142
 143    return ret;
 144}
 145
 146static void asn1_free_tpl(void *obj, const WOLFSSL_ASN1_TEMPLATE *mem)
 147{
 148    if (obj != NULL) {
 149        if (mem->sequence)
 150            wolfSSL_sk_pop_free((WOLFSSL_STACK *)obj, mem->free_func);
 151        else
 152            mem->free_func(obj);
 153    }
 154}
 155
 156/* Dispose of ASN1 item based on a template.
 157 *
 158 * @param [in, out] val  ASN item to free.
 159 * @param [in,      item Info about ASN1 items.
 160 */
 161void wolfSSL_ASN1_item_free(void *obj, const WOLFSSL_ASN1_ITEM *item)
 162{
 163    const WOLFSSL_ASN1_TEMPLATE *mem = NULL;
 164    size_t i;
 165
 166    WOLFSSL_ENTER("wolfSSL_ASN1_item_free");
 167
 168    if (obj != NULL) {
 169        switch (item->type) {
 170            case WOLFSSL_ASN1_SEQUENCE:
 171                for (mem = item->members, i = 0; i < item->mcount; mem++, i++)
 172                    asn1_free_tpl(asn1Mem(obj, mem->offset), mem);
 173                XFREE(obj, NULL, DYNAMIC_TYPE_OPENSSL);
 174                break;
 175            case WOLFSSL_ASN1_CHOICE:
 176                if (asn1Type(obj, item->toffset) < 0)
 177                    break; /* type not set */
 178                for (mem = item->members, i = 0; i < item->mcount; mem++, i++) {
 179                    if (asn1Type(obj, item->toffset) == mem->tag) {
 180                        asn1_free_tpl(asn1Mem(obj, mem->offset), mem);
 181                        break;
 182                    }
 183                }
 184                XFREE(obj, NULL, DYNAMIC_TYPE_OPENSSL);
 185                break;
 186            case WOLFSSL_ASN1_OBJECT_TYPE:
 187                asn1_free_tpl(obj, item->members);
 188                break;
 189            default:
 190                WOLFSSL_MSG("ASN1 type not implemented");
 191                break;
 192        }
 193    }
 194}
 195
 196static int i2d_asn1_items(const void* obj, byte** buf,
 197        const WOLFSSL_ASN1_TEMPLATE* mem)
 198{
 199    int len = 0;
 200    int ret = 0;
 201    if (mem->sequence) {
 202        const WOLFSSL_STACK* sk = (WOLFSSL_STACK *)asn1Mem(obj, mem->offset);
 203        int ski; /* stack index */
 204        int innerLen = 0;
 205        /* Figure out the inner length first */
 206        for (ski = 0; ski < wolfSSL_sk_num(sk); ski++) {
 207            ret = mem->i2d_func(wolfSSL_sk_value(sk, ski), NULL);
 208            if (ret <= 0)
 209                break;
 210            innerLen += ret;
 211        }
 212        if (ret <= 0)
 213            return 0;
 214        if (buf != NULL && *buf != NULL) {
 215            /* Now write it out */
 216            int writeLen = 0;
 217            *buf += SetSequence((word32)innerLen, *buf);
 218            for (ski = 0; ski < wolfSSL_sk_num(sk); ski++) {
 219                ret = mem->i2d_func(wolfSSL_sk_value(sk, ski), buf);
 220                if (ret <= 0)
 221                    break;
 222                writeLen += ret;
 223            }
 224            if (ret <= 0 || writeLen != innerLen)
 225                return 0;
 226        }
 227        len = (int)SetSequence((word32)innerLen, NULL) + innerLen;
 228    }
 229    else {
 230        ret = mem->i2d_func(asn1Mem(obj, mem->offset),
 231                buf != NULL && *buf != NULL ? buf : NULL);
 232        if (ret <= 0)
 233            return 0;
 234        len = ret;
 235    }
 236    return len;
 237}
 238
 239/* Encode members of an ASN.1 SEQUENCE as DER.
 240 *
 241 * @param [in]      src      ASN1 items to encode.
 242 * @param [in, out] buf      Buffer to encode into. May be NULL.
 243 * @param [in]      members  ASN1 template members.
 244 * @param [in]      mcount   Count of template members.
 245 * @return  Length of DER encoding on success.
 246 * @return  0 on failure.
 247 */
 248static int wolfssl_i2d_asn1_items(const void* obj, byte* buf,
 249    const WOLFSSL_ASN1_TEMPLATE* members, size_t mcount)
 250{
 251    const WOLFSSL_ASN1_TEMPLATE* mem = NULL;
 252    int len = 0;
 253    int ret;
 254    size_t i;
 255
 256    WOLFSSL_ENTER("wolfssl_i2d_asn1_items");
 257
 258    for (mem = members, i = 0; i < mcount; mem++, i++) {
 259        byte* tmp = buf;
 260        if (mem->ex && mem->tag >= 0) {
 261            /* Figure out the inner length */
 262            int innerLen = 0;
 263            int hdrLen = 0;
 264            ret = i2d_asn1_items(obj, NULL, mem);
 265            if (ret <= 0) {
 266                len = 0;
 267                break;
 268            }
 269            innerLen = ret;
 270            hdrLen = SetExplicit((byte)mem->tag, (word32)innerLen, buf, 0);
 271            len += hdrLen;
 272            if (buf != NULL)
 273                buf += hdrLen;
 274        }
 275
 276        ret = i2d_asn1_items(obj, &buf, mem);
 277        if (ret <= 0) {
 278            len = 0;
 279            break;
 280        }
 281
 282        if (buf != NULL && tmp != NULL && !mem->ex && mem->tag >= 0) {
 283            byte imp[ASN_TAG_SZ + MAX_LENGTH_SZ];
 284            /* Encode the implicit tag; There's other stuff in the upper bits
 285             * of the integer tag, so strip out everything else for value. */
 286            SetImplicit(tmp[0], (byte)(mem->tag), 0, imp, 0);
 287            tmp[0] = imp[0];
 288        }
 289        len += ret;
 290    }
 291
 292    WOLFSSL_LEAVE("wolfssl_i2d_asn1_items", len);
 293
 294    return len;
 295}
 296
 297/* Encode sequence and items under it.
 298 *
 299 * @param [in]      src  ASN1 items to encode.
 300 * @param [in, out] buf  Buffer to encode into. May be NULL.
 301 * @param [in]      tpl  Template of ASN1 items.
 302 * @return  Length of DER encoding on success.
 303 * @return  0 on failure.
 304 */
 305static int i2d_ASN_SEQUENCE(const void* obj, byte* buf,
 306    const WOLFSSL_ASN1_ITEM* item)
 307{
 308    word32 seq_len;
 309    word32 len = 0;
 310
 311    seq_len = (word32)wolfssl_i2d_asn1_items(obj, NULL, item->members,
 312        item->mcount);
 313    if (seq_len != 0) {
 314        len = SetSequence(seq_len, buf);
 315        if (buf != NULL) {
 316            if (wolfssl_i2d_asn1_items(obj, buf + len, item->members,
 317                    item->mcount) > 0)
 318                len += seq_len; /* success */
 319            else
 320                len = 0; /* error */
 321        }
 322        else
 323            len += seq_len;
 324    }
 325
 326    return (int)len;
 327}
 328
 329static int i2d_ASN_CHOICE(const void* obj, byte* buf,
 330        const WOLFSSL_ASN1_ITEM* item)
 331{
 332    const WOLFSSL_ASN1_TEMPLATE* mem = NULL;
 333    size_t i;
 334
 335    if (asn1Type(obj, item->toffset) < 0)
 336        return 0; /* type not set */
 337    for (mem = item->members, i = 0; i < item->mcount; mem++, i++) {
 338        if (asn1Type(obj, item->toffset) == mem->tag) {
 339            return wolfssl_i2d_asn1_items(obj, buf, mem, 1);
 340        }
 341    }
 342    return 0;
 343}
 344
 345static int i2d_ASN_OBJECT_TYPE(const void* obj, byte* buf,
 346        const WOLFSSL_ASN1_ITEM* item)
 347{
 348    /* To be able to use wolfssl_i2d_asn1_items without any modifications,
 349     * pass in a pointer to obj so that asn1Mem uses the correct pointer. */
 350    const void ** obj_pp = &obj;
 351    return wolfssl_i2d_asn1_items(obj_pp, buf, item->members, item->mcount);
 352}
 353
 354/* Encode ASN1 template item.
 355 *
 356 * @param [in]      src  ASN1 items to encode.
 357 * @param [in, out] buf  Buffer to encode into. May be NULL.
 358 * @param [in]      tpl  Template of ASN1 items.
 359 * @return  Length of DER encoding on success.
 360 * @return  0 on failure.
 361 */
 362static int wolfssl_asn1_item_encode(const void* obj, byte* buf,
 363    const WOLFSSL_ASN1_ITEM* item)
 364{
 365    int len;
 366
 367    switch (item->type) {
 368        case WOLFSSL_ASN1_SEQUENCE:
 369            len = i2d_ASN_SEQUENCE(obj, buf, item);
 370            break;
 371        case WOLFSSL_ASN1_OBJECT_TYPE:
 372            len = i2d_ASN_OBJECT_TYPE(obj, buf, item);
 373            break;
 374        case WOLFSSL_ASN1_CHOICE:
 375            len = i2d_ASN_CHOICE(obj, buf, item);
 376            break;
 377        default:
 378            WOLFSSL_MSG("Type not supported in wolfSSL_ASN1_item_i2d");
 379            len = 0;
 380    }
 381
 382    return len;
 383}
 384
 385/* Encode ASN1 template.
 386 *
 387 * @param [in]      src   ASN1 items to encode.
 388 * @param [in, out] dest  Pointer to buffer to encode into. May be NULL.
 389 * @param [in]      tpl   Template of ASN1 items.
 390 * @return  Length of DER encoding on success.
 391 * @return  WOLFSSL_FATAL_ERROR on failure.
 392 */
 393int wolfSSL_ASN1_item_i2d(const void* obj, byte** dest,
 394    const WOLFSSL_ASN1_ITEM* item)
 395{
 396    int ret = 1;
 397    int len = 0;
 398
 399    WOLFSSL_ENTER("wolfSSL_ASN1_item_i2d");
 400
 401    /* Validate parameters. */
 402    if ((obj == NULL) || (item == NULL)) {
 403        ret = 0;
 404    }
 405
 406    if ((ret == 1) && ((len = wolfssl_asn1_item_encode(obj, NULL, item)) == 0))
 407        ret = 0;
 408
 409    if ((ret == 1) && (dest != NULL)) {
 410        byte* buf = NULL;
 411        if (*dest == NULL) {
 412            buf = (byte*)XMALLOC((size_t)len, NULL, DYNAMIC_TYPE_ASN1);
 413            if (buf == NULL)
 414                ret = 0;
 415        }
 416        else
 417            buf = *dest;
 418
 419        if (ret == 1) {
 420            len = wolfssl_asn1_item_encode(obj, buf, item);
 421            if (len <= 0)
 422                ret = 0;
 423        }
 424
 425        if (ret == 1) {
 426            if (*dest == NULL)
 427                *dest = buf;
 428            else
 429                *dest += len;
 430        }
 431        if (ret == 0 && *dest == NULL)
 432            XFREE(buf, NULL, DYNAMIC_TYPE_ASN1);
 433    }
 434
 435    if (ret == 0) {
 436        len = WOLFSSL_FATAL_ERROR;
 437    }
 438    WOLFSSL_LEAVE("wolfSSL_ASN1_item_i2d", len);
 439    return len;
 440}
 441
 442static void* d2i_obj(const WOLFSSL_ASN1_TEMPLATE* mem, const byte** src,
 443        long* len)
 444{
 445    void* ret;
 446    const byte* tmp = *src;
 447    ret = mem->d2i_func(NULL, &tmp, *len);
 448    if (ret == NULL) {
 449        WOLFSSL_MSG("d2i error");
 450        return NULL;
 451    }
 452    if (tmp <= *src) {
 453        WOLFSSL_MSG("ptr not advanced");
 454        mem->free_func(ret); /* never a stack so we can call this directly */
 455        return NULL;
 456    }
 457    *len -= (long)(tmp - *src);
 458    *src = tmp;
 459    return ret;
 460}
 461
 462static void* d2i_generic_obj(const WOLFSSL_ASN1_TEMPLATE* mem, const byte** src,
 463        long* len)
 464{
 465    void* ret = NULL;
 466    if (mem->sequence) {
 467        long skl = 0;
 468        int slen = 0;
 469        WOLFSSL_STACK* sk = NULL;
 470        word32 idx = 0;
 471        const byte* tmp = *src;
 472        if (GetSequence(tmp, &idx, &slen, (word32)*len) < 0)
 473            goto error;
 474        skl = (long)slen;
 475        tmp += idx;
 476        ret = sk = wolfSSL_sk_new_null();
 477        while (skl > 0) {
 478            void* new_obj = d2i_obj(mem, &tmp, &skl);
 479            if (new_obj == NULL) {
 480                WOLFSSL_MSG("d2i_obj failed");
 481                goto error;
 482            }
 483            if (wolfSSL_sk_insert(sk, new_obj, -1) <= 0) {
 484                mem->free_func(new_obj);
 485                WOLFSSL_MSG("push failed");
 486                goto error;
 487            }
 488        }
 489        if (skl != 0) {
 490            WOLFSSL_MSG("l not zero after sequence");
 491            goto error;
 492        }
 493        *len -= (long)slen;
 494        *src = tmp;
 495    }
 496    else {
 497        ret = d2i_obj(mem, src, len);
 498    }
 499    return ret;
 500error:
 501    asn1_free_tpl(ret, mem);
 502    return NULL;
 503}
 504
 505static int d2i_handle_tags(const WOLFSSL_ASN1_TEMPLATE* mem, const byte** src,
 506        long* len, byte** impBuf, int* asnLen)
 507{
 508    if (mem->tag >= 0) {
 509        byte tag = 0;
 510        word32 idx = 0;
 511        if (mem->ex) {
 512            if (GetASNTag(*src, &idx, &tag, (word32)*len) < 0 ||
 513                    (byte)(ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | mem->tag)
 514                        != tag ||
 515                    GetLength(*src, &idx, asnLen, (word32)*len) < 0) {
 516                WOLFSSL_MSG("asn tag error");
 517                return WOLFSSL_FATAL_ERROR;
 518            }
 519            *len -= idx;
 520            *src += idx;
 521        }
 522        else {
 523            /* Underlying d2i functions won't be able to handle the implicit
 524             * tag so we substitute it for the expected tag. */
 525            if (mem->first_byte == 0) {
 526                WOLFSSL_MSG("first byte not set");
 527                return WOLFSSL_FATAL_ERROR;
 528            }
 529            if (GetASNTag(*src, &idx, &tag, (word32)*len) < 0 ||
 530                    (byte)mem->tag != (tag & ASN_TYPE_MASK) ||
 531                    GetLength(*src, &idx, asnLen, (word32)*len) < 0) {
 532                WOLFSSL_MSG("asn tag error");
 533                return WOLFSSL_FATAL_ERROR;
 534            }
 535            *asnLen += idx; /* total buffer length */
 536            *impBuf = (byte*)XMALLOC(*asnLen, NULL,
 537                    DYNAMIC_TYPE_TMP_BUFFER);
 538            if (*impBuf == NULL) {
 539                WOLFSSL_MSG("malloc error");
 540                return WOLFSSL_FATAL_ERROR;
 541            }
 542            XMEMCPY(*impBuf, *src, *asnLen);
 543            (*impBuf)[0] = mem->first_byte;
 544        }
 545    }
 546    return 0;
 547}
 548
 549static void* d2i_generic(const WOLFSSL_ASN1_TEMPLATE* mem,
 550        const byte** src, long* len)
 551{
 552    int asnLen = -1;
 553    const byte *tmp = NULL;
 554    void* ret = NULL;
 555    byte* impBuf = NULL;
 556    long l;
 557
 558    if (*len <= 0) {
 559        WOLFSSL_MSG("buffer too short");
 560        return NULL;
 561    }
 562
 563    if (d2i_handle_tags(mem, src, len, &impBuf, &asnLen) != 0) {
 564        WOLFSSL_MSG("tags error");
 565        goto error;
 566    }
 567
 568    if (impBuf != NULL)
 569        tmp = impBuf;
 570    else
 571        tmp = *src;
 572    l = (long)(asnLen >= 0 ? asnLen : *len);
 573    ret = d2i_generic_obj(mem, &tmp, &l);
 574    if (l < 0) {
 575        WOLFSSL_MSG("ptr advanced too far");
 576        goto error;
 577    }
 578    if (impBuf != NULL) {
 579        tmp = *src + (tmp - impBuf); /* for the next calculation */
 580        XFREE(impBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
 581        impBuf = NULL;
 582    }
 583    if (asnLen >= 0 && (int)(tmp - *src) != asnLen) {
 584        WOLFSSL_MSG("ptr not advanced enough");
 585        goto error;
 586    }
 587    *len -= (long)(tmp - *src);
 588    *src = tmp;
 589    return ret;
 590error:
 591    asn1_free_tpl(ret, mem);
 592    if (impBuf != NULL)
 593        XFREE(impBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
 594    return NULL;
 595}
 596
 597static int d2i_ASN_SEQUENCE(void* obj, const byte **src, long len,
 598        const WOLFSSL_ASN1_ITEM* item)
 599{
 600    const WOLFSSL_ASN1_TEMPLATE* mem = NULL;
 601    int err;
 602    word32 idx = 0;
 603    int slen = 0;
 604    size_t i;
 605    const byte* s = *src;
 606
 607    err = GetSequence(s, &idx, &slen, (word32)len);
 608    if (err <= 0) {
 609        WOLFSSL_MSG("GetSequence error");
 610        return WOLFSSL_FATAL_ERROR;
 611    }
 612    s += idx;
 613    len -= idx;
 614
 615    for (mem = item->members, i = 0; i < item->mcount; mem++, i++) {
 616        asn1Mem(obj, mem->offset) = d2i_generic(mem, &s, &len);
 617        if (asn1Mem(obj, mem->offset) == NULL) {
 618            WOLFSSL_MSG("d2i error");
 619            return WOLFSSL_FATAL_ERROR;
 620        }
 621    }
 622    *src = s;
 623    return 0;
 624}
 625
 626static int d2i_ASN_CHOICE(void* obj, const byte **src, long len,
 627        const WOLFSSL_ASN1_ITEM* item)
 628{
 629    const WOLFSSL_ASN1_TEMPLATE* mem = NULL;
 630    size_t i;
 631
 632    for (mem = item->members, i = 0; i < item->mcount; mem++, i++) {
 633        asn1Mem(obj, mem->offset) = d2i_generic(mem, src, &len);
 634        if (asn1Mem(obj, mem->offset) != NULL) {
 635            asn1Type(obj, item->toffset) = mem->tag;
 636            return 0;
 637        }
 638    }
 639    WOLFSSL_MSG("der does not decode with any CHOICE");
 640    return WOLFSSL_FATAL_ERROR;
 641}
 642
 643static void* d2i_ASN_OBJECT_TYPE(const byte **src, long len,
 644        const WOLFSSL_ASN1_ITEM* item)
 645{
 646    return d2i_generic(item->members, src, &len);
 647}
 648
 649void* wolfSSL_ASN1_item_d2i(void** dst, const byte **src, long len,
 650        const WOLFSSL_ASN1_ITEM* item)
 651{
 652    void* obj = NULL;
 653    int err = 0;
 654    const byte *tmp;
 655
 656    WOLFSSL_ENTER("wolfSSL_ASN1_item_d2i");
 657
 658    if (src == NULL || *src == NULL || len <= 0 || item == NULL) {
 659        WOLFSSL_LEAVE("wolfSSL_ASN1_item_d2i", 0);
 660        return NULL;
 661    }
 662
 663    tmp = *src;
 664
 665    /* Create an empty object. */
 666
 667    switch (item->type) {
 668        case WOLFSSL_ASN1_SEQUENCE:
 669        case WOLFSSL_ASN1_CHOICE:
 670            obj = asn1_item_alloc(item);
 671            if (obj == NULL)
 672                return NULL;
 673            break;
 674        case WOLFSSL_ASN1_OBJECT_TYPE:
 675            /* allocated later */
 676            break;
 677        default:
 678            WOLFSSL_MSG("Type not supported in wolfSSL_ASN1_item_d2i");
 679            return NULL;
 680    }
 681
 682    switch (item->type) {
 683        case WOLFSSL_ASN1_SEQUENCE:
 684            err = d2i_ASN_SEQUENCE(obj, &tmp, len, item);
 685            break;
 686        case WOLFSSL_ASN1_CHOICE:
 687            err = d2i_ASN_CHOICE(obj, &tmp, len, item);
 688            break;
 689        case WOLFSSL_ASN1_OBJECT_TYPE:
 690            obj = d2i_ASN_OBJECT_TYPE(&tmp, len, item);
 691            if (obj == NULL)
 692                err = WOLFSSL_FATAL_ERROR;
 693            break;
 694        default:
 695            WOLFSSL_MSG("Type not supported in wolfSSL_ASN1_item_d2i");
 696            err = WOLFSSL_FATAL_ERROR;
 697            break;
 698    }
 699
 700    if (err == 0)
 701        *src = tmp;
 702    else {
 703        wolfSSL_ASN1_item_free(obj, item);
 704        obj = NULL;
 705    }
 706
 707    if (dst != NULL && obj != NULL) {
 708        if (*dst != NULL)
 709            wolfSSL_ASN1_item_free(*dst, item);
 710        *dst = obj;
 711    }
 712
 713    WOLFSSL_LEAVE("wolfSSL_ASN1_item_d2i", obj != NULL);
 714    return obj;
 715}
 716
 717#endif /* OPENSSL_ALL */
 718
 719#endif /* OPENSSL_EXTRA */
 720
 721/*******************************************************************************
 722 * ASN1_BIT_STRING APIs
 723 ******************************************************************************/
 724
 725#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
 726    defined(WOLFSSL_WPAS_SMALL)
 727/* Create a new ASN.1 BIT_STRING object.
 728 *
 729 * @return  ASN.1 BIT_STRING object on success.
 730 * @return  NULL when dynamic memory allocation fails.
 731 */
 732WOLFSSL_ASN1_BIT_STRING* wolfSSL_ASN1_BIT_STRING_new(void)
 733{
 734    WOLFSSL_ASN1_BIT_STRING* bitStr;
 735
 736    bitStr = (WOLFSSL_ASN1_BIT_STRING*)XMALLOC(sizeof(WOLFSSL_ASN1_BIT_STRING),
 737        NULL, DYNAMIC_TYPE_OPENSSL);
 738    if (bitStr) {
 739        XMEMSET(bitStr, 0, sizeof(WOLFSSL_ASN1_BIT_STRING));
 740    }
 741
 742    return bitStr;
 743}
 744
 745/* Dispose of ASN.1 BIT_STRING object.
 746 *
 747 * Do not use bitStr after calling this function.
 748 *
 749 * @param [in, out] bitStr  ASN.1 BIT_STRING to free. May be NULL.
 750 */
 751void wolfSSL_ASN1_BIT_STRING_free(WOLFSSL_ASN1_BIT_STRING* bitStr)
 752{
 753    if (bitStr != NULL) {
 754        /* Dispose of any data allocated in BIT_STRING. */
 755        XFREE(bitStr->data, NULL, DYNAMIC_TYPE_OPENSSL);
 756    }
 757    /* Dispose of the ASN.1 BIT_STRING object. */
 758    XFREE(bitStr, NULL, DYNAMIC_TYPE_OPENSSL);
 759}
 760
 761/* Get the value of the bit from the ASN.1 BIT_STRING at specified index.
 762 *
 763 * A NULL object a value of 0 for the bit at all indices.
 764 * A negative index has a value of 0 for the bit.
 765 *
 766 * @param [in] bitStr  ASN.1 BIT_STRING object.
 767 * @param [in] i       Index of bit.
 768 * @return  Value of bit.
 769 */
 770int wolfSSL_ASN1_BIT_STRING_get_bit(const WOLFSSL_ASN1_BIT_STRING* bitStr,
 771    int i)
 772{
 773    int bit = 0;
 774
 775    /* Check for data and whether index is in range. */
 776    if ((bitStr != NULL) && (bitStr->data != NULL) && (i >= 0) &&
 777            (bitStr->length > (i / 8))) {
 778        bit = (bitStr->data[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0;
 779    }
 780
 781    return bit;
 782}
 783
 784/* Grow data to require length.
 785 *
 786 * @param [in] bitStr  ASN.1 BIT_STRING object.
 787 * @param [in] len     Length, in bytes, of data required.
 788 * @return  1 on success.
 789 * @return  0 when dynamic memory allocation fails.
 790 */
 791static int wolfssl_asn1_bit_string_grow(WOLFSSL_ASN1_BIT_STRING* bitStr,
 792    int len)
 793{
 794    int ret = 1;
 795    byte* tmp;
 796
 797#ifdef WOLFSSL_NO_REALLOC
 798    tmp = (byte*)XMALLOC((size_t)len, NULL, DYNAMIC_TYPE_OPENSSL);
 799    if (tmp != NULL && bitStr->data != NULL) {
 800       XMEMCPY(tmp, bitStr->data, bitStr->length);
 801       XFREE(bitStr->data, NULL, DYNAMIC_TYPE_OPENSSL);
 802       bitStr->data = NULL;
 803    }
 804#else
 805    /* Realloc to length required. */
 806    tmp = (byte*)XREALLOC(bitStr->data, (size_t)len, NULL,
 807        DYNAMIC_TYPE_OPENSSL);
 808#endif
 809    if (tmp == NULL) {
 810        ret = 0;
 811    }
 812    else {
 813        /* Clear out new, top bytes. */
 814        if (len > bitStr->length)
 815            XMEMSET(tmp + bitStr->length, 0, (size_t)(len - bitStr->length));
 816        bitStr->data = tmp;
 817        bitStr->length = len;
 818    }
 819
 820    return ret;
 821}
 822
 823/* Set the value of a bit in the ASN.1 BIT_STRING at specified index.
 824 *
 825 * @param [in] bitStr  ASN.1 BIT_STRING object.
 826 * @param [in] idx     Index of bit to set.
 827 * @param [in] val     Value of bit to set. Valid values: 0 or 1.
 828 * @return  1 on success.
 829 * @return  0 when bitStr is NULL, idx is negative, val is not 0 or 1, or
 830 *          dynamic memory allocation fails.
 831 */
 832int wolfSSL_ASN1_BIT_STRING_set_bit(WOLFSSL_ASN1_BIT_STRING* bitStr, int idx,
 833    int val)
 834{
 835    int ret = 1;
 836    int i = 0;
 837
 838    /* Validate parameters. */
 839    if ((bitStr == NULL) || (idx < 0) || ((val != 0) && (val != 1))) {
 840        ret = 0;
 841    }
 842
 843    if (ret == 1) {
 844        i = idx / 8;
 845
 846        /* Check if we need to extend data range. */
 847        if ((i >= bitStr->length) && (val != 0)) {
 848            /* Realloc data to handle having bit set at index. */
 849            ret = wolfssl_asn1_bit_string_grow(bitStr, i + 1);
 850        }
 851    }
 852    if ((ret == 1) && (i < bitStr->length)) {
 853        /* Bit on at index. */
 854        byte bit = 1 << (7 - (idx % 8));
 855
 856        /* Clear bit and set to value. */
 857        bitStr->data[i] &= ~bit;
 858        bitStr->data[i] |= bit & (byte)(0 - val);
 859    }
 860
 861    return ret;
 862}
 863
 864/* Serialize object to DER encoding
 865 *
 866 * @param bstr Object to serialize
 867 * @param pp  Output
 868 * @return Length on success
 869 *         Negative number on failure
 870 */
 871int wolfSSL_i2d_ASN1_BIT_STRING(const WOLFSSL_ASN1_BIT_STRING* bstr,
 872        unsigned char** pp)
 873{
 874    int len;
 875    unsigned char* buf;
 876
 877    if (bstr == NULL || (bstr->data == NULL && bstr->length != 0))
 878        return WOLFSSL_FATAL_ERROR;
 879
 880    len = (int)SetBitString((word32)bstr->length, 0, NULL) + bstr->length;
 881    if (pp != NULL) {
 882        word32 idx;
 883
 884        if (*pp != NULL)
 885            buf = *pp;
 886        else {
 887            buf = (byte*)XMALLOC((size_t)len, NULL, DYNAMIC_TYPE_ASN1);
 888            if (buf == NULL)
 889                return WOLFSSL_FATAL_ERROR;
 890        }
 891
 892        idx = SetBitString((word32)bstr->length, 0, buf);
 893        if (bstr->length > 0)
 894            XMEMCPY(buf + idx, bstr->data, (size_t)bstr->length);
 895
 896        if (*pp != NULL)
 897            *pp += len;
 898        else
 899            *pp = buf;
 900    }
 901
 902    return len;
 903}
 904
 905WOLFSSL_ASN1_BIT_STRING* wolfSSL_d2i_ASN1_BIT_STRING(
 906        WOLFSSL_ASN1_BIT_STRING** out, const byte** src, long len)
 907{
 908    WOLFSSL_ASN1_BIT_STRING* ret = NULL;
 909#ifdef WOLFSSL_ASN_TEMPLATE
 910    word32 idx = 0;
 911    byte tag = 0;
 912    int length = 0;
 913
 914    WOLFSSL_ENTER("wolfSSL_d2i_ASN1_BIT_STRING");
 915
 916    if (src == NULL || *src == NULL || len == 0)
 917        return NULL;
 918
 919    if (GetASNTag(*src, &idx, &tag, (word32)len) < 0)
 920        return NULL;
 921    if (tag != ASN_BIT_STRING)
 922        return NULL;
 923    if (GetLength(*src, &idx, &length, (word32)len) < 0)
 924        return NULL;
 925    if (GetASN_BitString(*src, idx, length) != 0)
 926        return NULL;
 927    idx++; /* step over unused bits */
 928    length--;
 929
 930    ret = wolfSSL_ASN1_BIT_STRING_new();
 931    if (ret == NULL)
 932        return NULL;
 933
 934    if (wolfssl_asn1_bit_string_grow(ret, length) != 1) {
 935        wolfSSL_ASN1_BIT_STRING_free(ret);
 936        return NULL;
 937    }
 938
 939    XMEMCPY(ret->data, *src + idx, length);
 940    *src += idx + (word32)length;
 941
 942    if (out != NULL) {
 943        if (*out != NULL)
 944            wolfSSL_ASN1_BIT_STRING_free(*out);
 945        *out = ret;
 946    }
 947#else
 948    WOLFSSL_MSG("d2i_ASN1_BIT_STRING needs --enable-asn=template");
 949    (void)out;
 950    (void)src;
 951    (void)len;
 952#endif
 953    return ret;
 954}
 955
 956#endif /* OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL */
 957
 958/*******************************************************************************
 959 * ASN1_INTEGER APIs
 960 ******************************************************************************/
 961
 962#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
 963/* Create a new empty ASN.1 INTEGER object.
 964 *
 965 * @return  ASN.1 INTEGER object on success.
 966 * @return  NULL when dynamic memory allocation fails.
 967 */
 968WOLFSSL_ASN1_INTEGER* wolfSSL_ASN1_INTEGER_new(void)
 969{
 970    WOLFSSL_ASN1_INTEGER* a;
 971
 972    /* Allocate a new ASN.1 INTEGER object. */
 973    a = (WOLFSSL_ASN1_INTEGER*)XMALLOC(sizeof(WOLFSSL_ASN1_INTEGER), NULL,
 974        DYNAMIC_TYPE_OPENSSL);
 975    if (a != NULL) {
 976        XMEMSET(a, 0, sizeof(WOLFSSL_ASN1_INTEGER));
 977        /* Use fixed buffer field for data. */
 978        a->data      = a->intData;
 979        a->isDynamic = 0;
 980        /* Maximum supported by fixed buffer. */
 981        a->dataMax   = WOLFSSL_ASN1_INTEGER_MAX;
 982        /* No value set - no data. */
 983        a->length    = 0;
 984    }
 985
 986    return a;
 987}
 988
 989/* Free the ASN.1 INTEGER object and any dynamically allocated data.
 990 *
 991 * @param [in, out] in  ASN.1 INTEGER object.
 992 */
 993void wolfSSL_ASN1_INTEGER_free(WOLFSSL_ASN1_INTEGER* in)
 994{
 995    if ((in != NULL) && (in->isDynamic)) {
 996        /* Dispose of any data allocated in INTEGER. */
 997        XFREE(in->data, NULL, DYNAMIC_TYPE_OPENSSL);
 998    }
 999    /* Dispose of the ASN.1 INTEGER object. */
1000    XFREE(in, NULL, DYNAMIC_TYPE_OPENSSL);
1001}
1002
1003/* Get the length of the raw integer value bytes, stripping the DER tag/length
1004 * header if present. Required for OpenSSL compatibility where ASN1_INTEGER is
1005 * typedef'd to ASN1_STRING and callers use ASN1_STRING_length() on integers.
1006 *
1007 * @param [in] ai  ASN.1 INTEGER object.
1008 * @return  Length of the raw integer value on success.
1009 * @return  0 when ai is NULL or data is invalid.
1010 */
1011int wolfSSL_ASN1_INTEGER_get_length(const WOLFSSL_ASN1_INTEGER* ai)
1012{
1013    if (ai == NULL || ai->data == NULL || ai->length <= 0) {
1014        return 0;
1015    }
1016    if (ai->data[0] == ASN_INTEGER) {
1017        word32 idx = 1;
1018        int len = 0;
1019        if (GetLength(ai->data, &idx, &len, (word32)ai->length) >= 0 &&
1020                idx + (word32)len == (word32)ai->length) {
1021            return len;
1022        }
1023    }
1024    /* WOLFSSL_QT / WOLFSSL_HAPROXY format: raw bytes without DER header,
1025     * or data that coincidentally starts with 0x02 but whose header+value
1026     * boundaries do not span exactly ai->length. */
1027    return ai->length;
1028}
1029
1030/* Get a pointer to the raw integer value bytes, skipping the DER tag/length
1031 * header if present. Required for OpenSSL compatibility where ASN1_INTEGER is
1032 * typedef'd to ASN1_STRING and callers use ASN1_STRING_get0_data() on integers.
1033 *
1034 * @param [in] ai  ASN.1 INTEGER object.
1035 * @return  Pointer to the raw integer value bytes on success.
1036 * @return  NULL when ai is NULL or data is invalid.
1037 */
1038const unsigned char* wolfSSL_ASN1_INTEGER_get0_data(const WOLFSSL_ASN1_INTEGER* ai)
1039{
1040    if (ai == NULL || ai->data == NULL || ai->length <= 0) {
1041        return NULL;
1042    }
1043    if (ai->data[0] == ASN_INTEGER) {
1044        word32 idx = 1;
1045        int len = 0;
1046        if (GetLength(ai->data, &idx, &len, (word32)ai->length) >= 0 &&
1047                idx + (word32)len == (word32)ai->length) {
1048            return ai->data + idx;
1049        }
1050    }
1051    /* WOLFSSL_QT / WOLFSSL_HAPROXY format: raw bytes without DER header,
1052     * or data that coincidentally starts with 0x02 but whose header+value
1053     * boundaries do not span exactly ai->length. */
1054    return ai->data;
1055}
1056
1057#if defined(OPENSSL_EXTRA)
1058/* Reset the data of ASN.1 INTEGER object back to empty fixed array.
1059 *
1060 * @param [in] a  ASN.1 INTEGER object.
1061 */
1062static void wolfssl_asn1_integer_reset_data(WOLFSSL_ASN1_INTEGER* a)
1063{
1064    /* Don't use dynamic buffer anymore. */
1065    if (a->isDynamic) {
1066        /* Cache pointer to allocated data. */
1067        unsigned char* data = a->data;
1068        /* No longer dynamic. */
1069        a->isDynamic = 0;
1070        /* Point data at fixed array. */
1071        a->data = a->intData;
1072        /* Set maximum length to fixed array size. */
1073        a->dataMax = (unsigned int)sizeof(a->intData);
1074        /* Dispose of dynamically allocated data. */
1075        XFREE(data, NULL, DYNAMIC_TYPE_OPENSSL);
1076    }
1077    /* Clear out data from fixed array. */
1078    XMEMSET(a->intData, 0, sizeof(a->intData));
1079    /* No data, no length. */
1080    a->length = 0;
1081    /* No data, not negative. */
1082    a->negative = 0;
1083    /* Set type to positive INTEGER. */
1084    a->type = WOLFSSL_V_ASN1_INTEGER;
1085}
1086#endif /* OPENSSL_EXTRA */
1087
1088/* Setup ASN.1 INTEGER object to handle data of required length.
1089 *
1090 * @param [in, out] a    ASN.1 INTEGER object.
1091 * @param [in]      len  Required length in bytes.
1092 * @return  1 on success.
1093 * @return  0 on dynamic memory allocation failure.
1094 */
1095static int wolfssl_asn1_integer_require_len(WOLFSSL_ASN1_INTEGER* a, int len,
1096    int keepOldData)
1097{
1098    int ret = 1;
1099    byte* data;
1100    byte* oldData = a->intData;
1101
1102    if (a->isDynamic && (len > (int)a->dataMax)) {
1103        oldData = a->data;
1104        a->isDynamic = 0;
1105        a->data = a->intData;
1106        a->dataMax = (unsigned int)sizeof(a->intData);
1107    }
1108    if ((!a->isDynamic) && (len > (int)a->dataMax)) {
1109        /* Create a new buffer to hold large integer value. */
1110        data = (byte*)XMALLOC((size_t)len, NULL, DYNAMIC_TYPE_OPENSSL);
1111        if (data == NULL) {
1112            ret = 0;
1113        }
1114        else {
1115            /* Indicate data is dynamic and copy data over. */
1116            a->isDynamic = 1;
1117            a->data = data;
1118            a->dataMax = (word32)len;
1119        }
1120    }
1121    if (keepOldData) {
1122         if (oldData != a->data) {
1123             /* Copy old data into new buffer. */
1124             XMEMCPY(a->data, oldData, (size_t)a->length);
1125         }
1126    } else {
1127        a->length = 0;
1128    }
1129    if (oldData != a->intData) {
1130         /* Dispose of the old dynamic data. */
1131         XFREE(oldData, NULL, DYNAMIC_TYPE_OPENSSL);
1132    }
1133
1134    return ret;
1135}
1136
1137/* Duplicate the ASN.1 INTEGER object into a newly allocated one.
1138 *
1139 * @param [in] src  ASN.1 INTEGER object to copy.
1140 * @return  ASN.1 INTEGER object on success.
1141 * @return  NULL when src is NULL or dynamic memory allocation fails.
1142 */
1143WOLFSSL_ASN1_INTEGER* wolfSSL_ASN1_INTEGER_dup(const WOLFSSL_ASN1_INTEGER* src)
1144{
1145    WOLFSSL_ASN1_INTEGER* dst = NULL;
1146
1147    WOLFSSL_ENTER("wolfSSL_ASN1_INTEGER_dup");
1148
1149    /* Check for object to duplicate. */
1150    if (src != NULL) {
1151        /* Create a new ASN.1 INTEGER object to be copied into. */
1152        dst = wolfSSL_ASN1_INTEGER_new();
1153    }
1154    /* Check for object to copy into. */
1155    if (dst != NULL) {
1156        /* Copy simple fields. */
1157        dst->length   = src->length;
1158        dst->negative = src->negative;
1159        dst->type     = src->type;
1160
1161        if (!src->isDynamic) {
1162            /* Copy over data from/to fixed buffer. */
1163            XMEMCPY(dst->intData, src->intData, WOLFSSL_ASN1_INTEGER_MAX);
1164        }
1165        else if (wolfssl_asn1_integer_require_len(dst, src->length, 0) == 0) {
1166            wolfSSL_ASN1_INTEGER_free(dst);
1167            dst = NULL;
1168        }
1169        else {
1170            XMEMCPY(dst->data, src->data, (size_t)src->length);
1171        }
1172    }
1173
1174    return dst;
1175}
1176#endif /* OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL */
1177
1178#if defined(OPENSSL_EXTRA)
1179
1180/* Compare values in two ASN.1 INTEGER objects.
1181 *
1182 * @param [in] a  First ASN.1 INTEGER object.
1183 * @param [in] b  Second ASN.1 INTEGER object.
1184 * @return Negative value when a is less than b.
1185 * @return 0 when a equals b.
1186 * @return Positive value when a is greater than b.
1187 * @return WOLFSSL_FATAL_ERROR when a or b is NULL.
1188 */
1189int wolfSSL_ASN1_INTEGER_cmp(const WOLFSSL_ASN1_INTEGER* a,
1190    const WOLFSSL_ASN1_INTEGER* b)
1191{
1192    int ret = 0;
1193
1194    WOLFSSL_ENTER("wolfSSL_ASN1_INTEGER_cmp");
1195
1196    /* Validate parameters. */
1197    if ((a == NULL) || (b == NULL)) {
1198        WOLFSSL_MSG("Bad parameter.");
1199        ret = WOLFSSL_FATAL_ERROR;
1200    }
1201    /* Negative value < Positive value */
1202    else if (a->negative && !b->negative) {
1203        ret = -2; /* avoid collision with WOLFSSL_FATAL_ERROR */
1204    }
1205    /* Positive value > Negative value */
1206    else if (!a->negative && b->negative) {
1207        ret = 1;
1208    }
1209    else {
1210        /* Check for difference in length. */
1211        if (a->length != b->length) {
1212            ret = a->length - b->length;
1213        }
1214        else {
1215            /* Compare data given they are the same length. */
1216            ret = XMEMCMP(a->data, b->data, (size_t)a->length);
1217        }
1218        /* Reverse comparison result when both negative. */
1219        if (a->negative) {
1220            ret = -ret;
1221        }
1222    }
1223
1224    WOLFSSL_LEAVE("wolfSSL_ASN1_INTEGER_cmp", ret);
1225
1226    return ret;
1227}
1228
1229
1230/* Calculate 2's complement of DER encoding.
1231 *
1232 * @param [in]  data    Array that is number.
1233 * @param [in]  length  Number of bytes in array.
1234 * @return  0 on success.
1235 * @return  -1 when get length from DER header failed.
1236 */
1237static void wolfssl_twos_compl(byte* data, int length)
1238{
1239    int i;
1240
1241    /* Invert bits - 1's complement. */
1242    for (i = 0; i < length; ++i) {
1243        data[i] = ~data[i];
1244    }
1245    /* 2's complement - add 1. */
1246    for (i = length - 1; (++data[i]) == 0; --i) {
1247        /* Do nothing. */
1248    }
1249}
1250
1251/* Calculate 2's complement of DER encoding.
1252 *
1253 * @param [in|out] data Array that is number.
1254 * @param [in]  length  Number of bytes in array.
1255 * @param [out] neg     When NULL, 2's complement data.
1256 *                      When not NULL, check for negative first and return.
1257 * @return  0 on success.
1258 * @return  -1 when get length from DER header failed.
1259 */
1260static int wolfssl_asn1_int_twos_compl(byte* data, int length, byte* neg)
1261{
1262    int ret = 0;
1263    word32 idx = 1;     /* Skip tag. */
1264    int len;
1265
1266    /* Get length from DER header. */
1267    if (GetLength(data, &idx, &len, (word32)length) < 0) {
1268        ret = WOLFSSL_FATAL_ERROR;
1269    }
1270    else {
1271        if (neg != NULL) {
1272            *neg = data[idx] & 0x80;
1273        }
1274        if ((neg == NULL) || (*neg != 0)) {
1275            wolfssl_twos_compl(data + idx, length - (int)idx);
1276        }
1277    }
1278
1279    return ret;
1280}
1281
1282/* Encode ASN.1 INTEGER as DER without tag.
1283 *
1284 * When out points to NULL, a new buffer is allocated and returned.
1285 *
1286 * @param [in]      a    ASN.1 INTEGER object.
1287 * @param [in, out] out  Pointer to buffer to hold encoding. May point to NULL.
1288 * @return  Length of encoding on success.
1289 * @return  -1 when a is NULL or no data, out is NULL, dynamic memory allocation
1290 *          fails or encoding length fails.
1291 */
1292int wolfSSL_i2d_ASN1_INTEGER(const WOLFSSL_ASN1_INTEGER* a, unsigned char** pp)
1293{
1294    WOLFSSL_ENTER("wolfSSL_i2d_ASN1_INTEGER");
1295
1296    /* Validate parameters. */
1297    if (a == NULL || a->data == NULL || a->length <= 0) {
1298        WOLFSSL_MSG("Bad parameter.");
1299        return WOLFSSL_FATAL_ERROR;
1300    }
1301
1302    if (pp != NULL) {
1303        byte* buf;
1304
1305        if (*pp != NULL)
1306            buf = *pp;
1307        else {
1308            buf = (byte*)XMALLOC((size_t)a->length, NULL, DYNAMIC_TYPE_ASN1);
1309            if (buf == NULL)
1310                return WOLFSSL_FATAL_ERROR;
1311        }
1312
1313        /* Copy the data (including tag and length) into output buffer. */
1314        XMEMCPY(buf, a->data, (size_t)a->length);
1315        /* Only magnitude of the number stored (i.e. the sign isn't encoded).
1316         * The "negative" field is 1 if the value must be interpreted as
1317         * negative and we need to output the 2's complement of the value in
1318         * the DER output.
1319         */
1320        if (a->negative &&
1321                wolfssl_asn1_int_twos_compl(buf, a->length, NULL) != 0) {
1322            if (*pp == NULL)
1323                XFREE(buf, NULL, DYNAMIC_TYPE_ASN1);
1324            return WOLFSSL_FATAL_ERROR;
1325        }
1326
1327        if (*pp != NULL)
1328            *pp += a->length;
1329        else
1330            *pp = buf;
1331    }
1332
1333    return a->length;
1334}
1335
1336/* Decode DER encoding of ASN.1 INTEGER.
1337 *
1338 * @param [out]     a     ASN.1 INTEGER object. May be NULL.
1339 * @param [in, out] in    Pointer to buffer containing DER encoding.
1340 * @param [in]      inSz  Length of data in buffer.
1341 * @return  ASN.1 INTEGER object on success.
1342 * @return  NULL when in or *in is NULL, inSz is less than or equal to 2 or
1343 *          parsing DER failed.
1344 */
1345WOLFSSL_ASN1_INTEGER* wolfSSL_d2i_ASN1_INTEGER(WOLFSSL_ASN1_INTEGER** a,
1346    const unsigned char** in, long inSz)
1347{
1348    WOLFSSL_ASN1_INTEGER* ret = NULL;
1349    int err = 0;
1350    word32 idx = 1;
1351    int len = 0;
1352
1353    WOLFSSL_ENTER("wolfSSL_d2i_ASN1_INTEGER");
1354
1355    /* Validate parameters. */
1356    if ((in == NULL) || (*in == NULL) || (inSz <= 2)) {
1357        WOLFSSL_MSG("Bad parameter");
1358        err = 1;
1359    }
1360
1361    /* Check that the tag is correct. */
1362    if ((!err) && (*in)[0] != ASN_INTEGER) {
1363        WOLFSSL_MSG("Tag doesn't indicate integer type.");
1364        err = 1;
1365    }
1366    /* Check that length and use this instead of inSz. */
1367    if ((!err) && (GetLength(*in, &idx, &len, (word32)inSz) <= 0)) {
1368        WOLFSSL_MSG("ASN.1 length not valid.");
1369        err = 1;
1370    }
1371    /* Allocate a new ASN.1 INTEGER object. */
1372    if ((!err) && ((ret = wolfSSL_ASN1_INTEGER_new()) == NULL)) {
1373        err = 1;
1374    }
1375    if ((!err) && (wolfssl_asn1_integer_require_len(ret, (int)idx + len, 0) !=
1376            1)) {
1377        err = 1;
1378    }
1379    if (!err) {
1380        /* Set type. */
1381        ret->type = WOLFSSL_V_ASN1_INTEGER;
1382
1383        /* Copy DER encoding and length. */
1384        XMEMCPY(ret->data, *in, (size_t)(idx + (word32)len));
1385        ret->length = (int)idx + len;
1386        /* Do 2's complement if number is negative. */
1387        if (wolfssl_asn1_int_twos_compl(ret->data, ret->length, &ret->negative)
1388                != 0) {
1389            err = 1;
1390        }
1391    }
1392    if ((!err) && ret->negative) {
1393        /* Update type if number was negative. */
1394        ret->type |= WOLFSSL_V_ASN1_NEG_INTEGER;
1395    }
1396
1397    if (err) {
1398        /* Dispose of dynamically allocated data on error. */
1399        wolfSSL_ASN1_INTEGER_free(ret);
1400        ret = NULL;
1401    }
1402    else {
1403        if (a != NULL) {
1404            /* Return ASN.1 INTEGER through a. */
1405            *a = ret;
1406        }
1407        *in += ret->length;
1408    }
1409
1410    return ret;
1411}
1412
1413#ifndef NO_BIO
1414
1415/* Get length of leading hexadecimal characters.
1416 *
1417 * Looks for continuation character before carriage returns and line feeds.
1418 *
1419 * @param [in]  str   String with input.
1420 * @param [in]  len   Length of string.
1421 * @param [out] cont  Line continuation character at end of line before
1422 *                    carriage returns and line feeds.
1423 * @return  Number of leading hexadecimal characters in string.
1424 */
1425static int wolfssl_a2i_asn1_integer_clear_to_eol(char* str, int len, int* cont)
1426{
1427    byte num;
1428    word32 nLen;
1429    int i;
1430
1431    /* Strip off trailing carriage returns and line feeds. */
1432    while ((len > 0) && ((str[len - 1] == '\n') || (str[len - 1] == '\r'))) {
1433        len--;
1434    }
1435    /* Check for line continuation character. */
1436    if ((len > 0) && (str[len - 1] == '\\')) {
1437        *cont = 1;
1438        len--;
1439    }
1440    else {
1441        *cont = 0;
1442    }
1443
1444    /* Find end of hexadecimal characters. */
1445    nLen = 1;
1446    for (i = 0; i < len; i++) {
1447        /* Check if character is a hexadecimal character. */
1448        if (Base16_Decode((const byte*)str + i, 1, &num, &nLen) ==
1449            WC_NO_ERR_TRACE(ASN_INPUT_E))
1450        {
1451            /* Found end of hexadecimal characters, return count. */
1452            len = i;
1453            break;
1454        }
1455    }
1456
1457    return len;
1458}
1459
1460/* Read number from BIO as a string.
1461 *
1462 * Line continuation character at end of line means next line must be read.
1463 *
1464 * @param [in]      bio   BIO to read from.
1465 * @param [in]      asn1  ASN.1 INTEGER object to put number into.
1466 * @param [in, out] buf   Buffer to use when reading.
1467 * @param [in]      size  Length of buffer in bytes.
1468 * @return  1 on success.
1469 * @return  0 on failure.
1470 */
1471int wolfSSL_a2i_ASN1_INTEGER(WOLFSSL_BIO *bio, WOLFSSL_ASN1_INTEGER *asn1,
1472    char *buf, int size)
1473{
1474    int ret = 1;
1475    int readNextLine = 1;
1476    int len;
1477    word32 outLen = 0;
1478    const int hdrSz = 1 + MAX_LENGTH_SZ;
1479
1480    WOLFSSL_ENTER("wolfSSL_a2i_ASN1_INTEGER");
1481
1482    if ((bio == NULL) || (asn1 == NULL) || (buf == NULL) || (size <= 0)) {
1483        WOLFSSL_MSG("Bad parameter");
1484        ret = 0;
1485    }
1486
1487    while ((ret == 1) && readNextLine) {
1488        int lineLen;
1489
1490        /* Assume we won't be reading any more. */
1491        readNextLine = 0;
1492
1493        /* Read a line. */
1494        lineLen = wolfSSL_BIO_gets(bio, buf, size);
1495        if (lineLen <= 0) {
1496            WOLFSSL_MSG("wolfSSL_BIO_gets error");
1497            ret = 0;
1498        }
1499
1500        if (ret == 1) {
1501            /* Find length of hexadecimal digits in string. */
1502            lineLen = wolfssl_a2i_asn1_integer_clear_to_eol(buf, lineLen,
1503                &readNextLine);
1504            /* Check we have a valid hexadecimal string to process. */
1505            if ((lineLen == 0) || ((lineLen % 2) != 0)) {
1506                WOLFSSL_MSG("Invalid line length");
1507                ret = 0;
1508            }
1509        }
1510        if (ret == 1) {
1511            /* Calculate length of complete number so far. */
1512            len = asn1->length + (lineLen / 2);
1513            /* Make sure enough space for number and maximum header. */
1514            if (wolfssl_asn1_integer_require_len(asn1, len + hdrSz, outLen != 0)
1515                    != 1) {
1516                ret = 0;
1517            }
1518        }
1519        if (ret == 1) {
1520            /* Decode string and append to data. */
1521            outLen = (word32)(lineLen / 2);
1522            (void)Base16_Decode((byte*)buf, (word32)lineLen,
1523                asn1->data + asn1->length, &outLen);
1524            /* Update length of data. */
1525            asn1->length += (int)outLen;
1526        }
1527    }
1528
1529    if (ret == 1) {
1530        int idx;
1531
1532        /* Get ASN.1 header length. */
1533        idx = SetASNInt(asn1->length, asn1->data[0], NULL);
1534        /* Move data to be after ASN.1 header. */
1535        XMEMMOVE(asn1->data + idx, asn1->data, (size_t)asn1->length);
1536        /* Encode ASN.1 header. */
1537        SetASNInt(asn1->length, asn1->data[idx], asn1->data);
1538        /* Update length of data. */
1539        asn1->length += idx;
1540    }
1541
1542    return ret;
1543}
1544
1545/* Write out number in ASN.1 INTEGER object to BIO as string.
1546 *
1547 * @param [in] bp  BIO to write to.
1548 * @param [in] a   ASN.1 INTEGER object.
1549 * @return  Number of characters written on success.
1550 * @return  0 when bp or a is NULL.
1551 * @return  0 DER header in data is invalid.
1552 */
1553int wolfSSL_i2a_ASN1_INTEGER(WOLFSSL_BIO *bp, const WOLFSSL_ASN1_INTEGER *a)
1554{
1555    int err = 0;
1556    word32 idx = 1;     /* Skip ASN.1 INTEGER tag byte. */
1557    int len = 0;
1558    byte buf[WOLFSSL_ASN1_INTEGER_MAX * 2 + 1];
1559    word32 bufLen;
1560
1561    WOLFSSL_ENTER("wolfSSL_i2a_ASN1_INTEGER");
1562
1563    /* Validate parameters. */
1564    if ((bp == NULL) || (a == NULL)) {
1565         err = 1;
1566    }
1567
1568    if (!err) {
1569        /* Read DER length - must be at least 1 byte. */
1570        if (GetLength(a->data, &idx, &len, (word32)a->length) <= 0) {
1571            err = 1;
1572        }
1573    }
1574
1575    /* Keep encoding and writing while no error and bytes in data. */
1576    while ((!err) && (idx < (word32)a->length)) {
1577        /* Number of bytes left to encode. */
1578        int encLen = a->length - (int)idx;
1579        /* Reduce to maximum buffer size if necessary. */
1580        if (encLen > (int)sizeof(buf) / 2) {
1581            encLen = (int)sizeof(buf) / 2;
1582        }
1583
1584        /* Encode bytes from data into buffer. */
1585        bufLen = (int)sizeof(buf);
1586        (void)Base16_Encode(a->data + idx, (word32)encLen, buf, &bufLen);
1587        /* Update index to next bytes to encoded. */
1588        idx += (word32)encLen;
1589
1590        /* Write out characters but not NUL char. */
1591        if (wolfSSL_BIO_write(bp, buf, (int)bufLen - 1) != (int)(bufLen - 1)) {
1592            err = 1;
1593        }
1594    }
1595
1596    if (err) {
1597        /* Return 0 on error. */
1598        len = 0;
1599    }
1600    /* Return total number of characters written. */
1601    return len * 2;
1602}
1603#endif /* !NO_BIO */
1604
1605#ifndef NO_ASN
1606/* Determine if a pad byte is required and its value for a number.
1607 *
1608 * Assumes values pointed to by pad and padVal are both 0.
1609 *
1610 * @param [in]       data    Number encoded as big-endian bytes.
1611 * @param [in]       len     Length of number in bytes.
1612 * @param [in, out]  neg     Indicates number is negative.
1613 * @param [out]      pad     Number of padding bytes required.
1614 * @param [out]      padVal  Padding byte to prepend.
1615 */
1616static void wolfssl_asn1_integer_pad(unsigned char* data, int len,
1617    unsigned char* neg, char* pad, unsigned char* padVal)
1618{
1619    /* Check for empty data. */
1620    if (len == 0) {
1621        *pad = 1;
1622        *padVal = 0x00;
1623        *neg = 0;
1624    }
1625    else {
1626        /* Get first, most significant, byte of encoded number. */
1627        unsigned char firstByte = data[0];
1628
1629        /* 0 can't be negative. */
1630        if ((len == 1) && (firstByte == 0x00)) {
1631            *neg = 0;
1632        }
1633        /* Positive value must not have top bit of first byte set. */
1634        if ((!*neg) && (firstByte >= 0x80)) {
1635            *pad = 1;
1636            *padVal = 0x00;
1637        }
1638        /* Negative numbers are two's complemented.
1639         * Two's complement value must have top bit set.
1640         */
1641        else if (*neg && (firstByte > 0x80)) {
1642            *pad = 1;
1643            *padVal = 0xff;
1644        }
1645        /* Checking for: 0x80[00]*
1646         * when negative that when two's complemented will be: 0x80[00]*
1647         * and therefore doesn't require pad byte.
1648         */
1649        else if (*neg && (firstByte == 0x80)) {
1650            int i;
1651            /* Check rest of bytes. */
1652            for (i = 1; i < len; i++) {
1653                if (data[i] != 0x00) {
1654                    /* Not 0x80[00]* */
1655                    *pad = 1;
1656                    *padVal = 0xff;
1657                    break;
1658                }
1659            }
1660        }
1661    }
1662}
1663
1664/* Convert ASN.1 INTEGER object into content octets.
1665 *
1666 * TODO: compatibility with OpenSSL? OpenSSL assumes data not DER encoded.
1667 *
1668 * When pp points to a buffer, on success pp will point to after the encoded
1669 * data.
1670 *
1671 * @param [in]      a   ASN.1 INTEGER object.
1672 * @param [in, out] pp  Pointer to buffer. May be NULL. Cannot point to NULL.
1673 * @return  Length of encoding on success.
1674 * @return  0 when a is NULL, pp points to NULL or DER length encoding invalid.
1675 */
1676int wolfSSL_i2c_ASN1_INTEGER(WOLFSSL_ASN1_INTEGER *a, unsigned char **pp)
1677{
1678    int err = 0;
1679    int len = 0;
1680    char pad = 0;
1681    unsigned char padVal = 0;
1682    word32 idx = 1;
1683
1684    WOLFSSL_ENTER("wolfSSL_i2c_ASN1_INTEGER");
1685
1686    /* Validate parameters. */
1687    if ((a == NULL) || ((pp != NULL) && (*pp == NULL))) {
1688        err = 1;
1689    }
1690
1691    /* Get length from DER encoding. */
1692    if ((!err) && (GetLength_ex(a->data, &idx, &len, a->dataMax, 0) < 0)) {
1693        err = 1;
1694    }
1695
1696    if (!err) {
1697        /* Determine pad length and value. */
1698        wolfssl_asn1_integer_pad(a->data + idx, len, &a->negative, &pad,
1699            &padVal);
1700        /* Total encoded length is number length plus one when padding. */
1701        len += (int)pad;
1702    }
1703
1704    /* Check buffer supplied to write into. */
1705    if ((!err) && (pp != NULL)) {
1706        /* Put in any pad byte. */
1707        if (pad) {
1708            (*pp)[0] = padVal;
1709        }
1710        /* Copy remaining bytes into output buffer. */
1711        XMEMCPY(*pp + pad, a->data + idx, (size_t)(len - pad));
1712        /* Two's complement copied bytes when negative. */
1713        if (a->negative) {
1714            wolfssl_twos_compl(*pp + pad, len - pad);
1715        }
1716        /* Move pointer past encoded data. */
1717        *pp += len;
1718    }
1719
1720    return len;
1721}
1722
1723/* Make a big number with the value in the ASN.1 INTEGER object.
1724 *
1725 * A new big number object is allocated when bn is NULL.
1726 *
1727 * @param [in] ai  ASN.1 INTEGER object.
1728 * @param [in] bn  Big number object. May be NULL.
1729 * @return  Big number object on success.
1730 * @return  NULL when ai is NULL or converting from binary fails.
1731 */
1732WOLFSSL_BIGNUM *wolfSSL_ASN1_INTEGER_to_BN(const WOLFSSL_ASN1_INTEGER *ai,
1733    WOLFSSL_BIGNUM *bn)
1734{
1735    int err = 0;
1736    word32 idx = 1;
1737    int len = 0;
1738    WOLFSSL_BIGNUM* ret = NULL;
1739
1740    WOLFSSL_ENTER("wolfSSL_ASN1_INTEGER_to_BN");
1741
1742    /* Validate parameters. */
1743    if (ai == NULL) {
1744        err = 1;
1745    }
1746
1747    if (!err) {
1748        /* Get the length of ASN.1 INTEGER number. */
1749        if ((ai->data[0] != ASN_INTEGER) || (GetLength(ai->data, &idx, &len,
1750                (word32)ai->length) <= 0)) {
1751        #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
1752            idx = 0;
1753            len = ai->length;
1754        #else
1755            WOLFSSL_MSG("Data in WOLFSSL_ASN1_INTEGER not DER encoded");
1756            err = 1;
1757        #endif
1758        }
1759    }
1760    if (!err) {
1761        /* Convert binary to big number. */
1762        ret = wolfSSL_BN_bin2bn(ai->data + idx, len, bn);
1763        if (ret != NULL) {
1764            /* Handle negative. */
1765            (void)wolfssl_bn_set_neg(ret, ai->negative);
1766        }
1767    }
1768
1769    return ret;
1770}
1771#endif /* !NO_ASN */
1772
1773/* Create an ASN.1 INTEGER object from big number.
1774 *
1775 * Allocates a new ASN.1 INTEGER object when ai is NULL.
1776 *
1777 * @param [in] bn  Big number to encode.
1778 * @param [in] ai  ASN.1 INTEGER object. May be NULL.
1779 * @return  ASN.1 INTEGER object on success.
1780 * @return  NULL when dynamic memory allocation fails.
1781 */
1782WOLFSSL_ASN1_INTEGER* wolfSSL_BN_to_ASN1_INTEGER(const WOLFSSL_BIGNUM *bn,
1783    WOLFSSL_ASN1_INTEGER *ai)
1784{
1785    int err = 0;
1786    WOLFSSL_ASN1_INTEGER* a = NULL;
1787    int len = 0;
1788    int numBits = 0;
1789    byte firstByte = 0;
1790
1791    WOLFSSL_ENTER("wolfSSL_BN_to_ASN1_INTEGER");
1792
1793    /* Validate parameters. */
1794    if (bn == NULL) {
1795        err = 1;
1796    }
1797    /* Use ASN.1 INTEGER object if provided. */
1798    else if (ai != NULL) {
1799        a = ai;
1800    }
1801    /* Create an ASN.1 INTEGER object to return. */
1802    else {
1803        a = wolfSSL_ASN1_INTEGER_new();
1804        if (a == NULL) {
1805            err = 1;
1806        }
1807    }
1808
1809    /* Check we have an ASN.1 INTEGER object to set. */
1810    if (!err) {
1811        int length;
1812
1813        /* Set type and negative. */
1814        a->type = WOLFSSL_V_ASN1_INTEGER;
1815        if (wolfSSL_BN_is_negative(bn) && !wolfSSL_BN_is_zero(bn)) {
1816            a->negative = 1;
1817            a->type |= WOLFSSL_V_ASN1_NEG_INTEGER;
1818        }
1819
1820        /* Get length in bytes of encoded number. */
1821        len = wolfSSL_BN_num_bytes(bn);
1822        if (len == 0) {
1823            len = 1;
1824        }
1825        /* Get length in bits of encoded number. */
1826        numBits = wolfSSL_BN_num_bits(bn);
1827        /* Leading zero required if most-significant byte has top bit set. */
1828        if ((numBits > 0) && (numBits % 8) == 0) {
1829            firstByte = 0x80;
1830        }
1831        /* Get length of header based on length of number. */
1832        length = SetASNInt(len, firstByte, NULL);
1833        /* Add number of bytes to encode number. */
1834        length += len;
1835
1836        /* Update data field to handle length. */
1837        if (wolfssl_asn1_integer_require_len(a, length, 0) != 1) {
1838            err = 1;
1839        }
1840    }
1841    if (!err) {
1842        /* Write ASN.1 header. */
1843        int idx = SetASNInt(len, firstByte, a->data);
1844
1845        /* Populate data. */
1846        if (numBits == 0) {
1847            a->data[idx] = 0;
1848        }
1849        else {
1850            /* Add encoded number. */
1851            len = wolfSSL_BN_bn2bin(bn, a->data + idx);
1852            if (len < 0) {
1853                err = 1;
1854            }
1855        }
1856
1857        /* Set length to encoded length. */
1858        a->length = idx + len;
1859    }
1860
1861    if (err) {
1862        /* Can't use ASN.1 INTEGER object. */
1863        if (a != ai) {
1864            wolfSSL_ASN1_INTEGER_free(a);
1865        }
1866        a = NULL;
1867    }
1868    return a;
1869}
1870
1871/* Get the value of the ASN.1 INTEGER as a long.
1872 *
1873 * Returning 0 on NULL and -1 on error is consistent with OpenSSL.
1874 *
1875 * @param [in] a  ASN.1 INTEGER object.
1876 * @return  Value as a long.
1877 * @return  0 when a is NULL.
1878 * @return  -1 when a big number operation fails.
1879 */
1880long wolfSSL_ASN1_INTEGER_get(const WOLFSSL_ASN1_INTEGER* a)
1881{
1882    long ret = 1;
1883    WOLFSSL_BIGNUM* bn = NULL;
1884
1885    WOLFSSL_ENTER("wolfSSL_ASN1_INTEGER_get");
1886
1887    /* Validate parameter. */
1888    if (a == NULL) {
1889        ret = 0;
1890    }
1891
1892    if (ret > 0) {
1893        /* Create a big number from the DER encoding. */
1894        bn = wolfSSL_ASN1_INTEGER_to_BN(a, NULL);
1895        if (bn == NULL) {
1896            ret = WOLFSSL_FATAL_ERROR;
1897        }
1898    }
1899    if (ret > 0) {
1900        /* Get the big number as a word. */
1901        ret = (long)wolfSSL_BN_get_word(bn);
1902        /* Negate number of ASN.1 INTEGER was negative. */
1903        if (a->negative == 1) {
1904            ret = -ret;
1905        }
1906    }
1907
1908    /* Dispose of big number as no longer needed. */
1909    if (bn != NULL) {
1910        wolfSSL_BN_free(bn);
1911    }
1912
1913    WOLFSSL_LEAVE("wolfSSL_ASN1_INTEGER_get", (int)ret);
1914
1915    return ret;
1916}
1917
1918
1919/* Sets the value of the ASN.1 INTEGER object to the long value.
1920 *
1921 * @param [in, out] a  ASN.1 INTEGER object.
1922 * @param [in]      v  Value to set.
1923 * @return  1 on success.
1924 * @return  0 when a is NULL.
1925 */
1926int wolfSSL_ASN1_INTEGER_set(WOLFSSL_ASN1_INTEGER *a, long v)
1927{
1928    int ret = 1;
1929
1930    /* Validate parameters. */
1931    if (a == NULL) {
1932        ret = 0;
1933    }
1934    if (ret == 1) {
1935        byte j;
1936        unsigned int i = 0;
1937        byte tmp[sizeof(long)];
1938        byte pad = 0;
1939
1940        wolfssl_asn1_integer_reset_data(a);
1941
1942        /* Check for negative. */
1943        if (v < 0) {
1944            /* Set negative and 2's complement the value. */
1945            a->negative = 1;
1946            a->type |= WOLFSSL_V_ASN1_NEG;
1947            v = -v;
1948        }
1949
1950        /* Put value into temporary buffer - at least one byte encoded. */
1951        tmp[0] = (byte)(v & 0xff);
1952        v >>= 8;
1953        for (j = 1; j < (byte)sizeof(long); j++) {
1954            if (v == 0) {
1955                break;
1956            }
1957            tmp[j] = (byte)(v & 0xff);
1958            v >>= 8;
1959        }
1960        /* Pad with 0x00 to indicate positive number when top bit set. */
1961        if ((!a->negative) && (tmp[j-1] & 0x80)) {
1962            pad = 1;
1963        }
1964
1965        /* Set tag. */
1966        a->data[i++] = ASN_INTEGER;
1967        /* Set length of encoded value. */
1968        a->data[i++] = pad + j;
1969        /* Set length of DER encoding. +2 for tag and length */
1970        a->length = 2 + pad + j;
1971
1972        /* Add pad byte if required. */
1973        if (pad == 1) {
1974            a->data[i++] = 0;
1975        }
1976        /* Copy in data. */
1977        for (; j > 0; j--) {
1978            a->data[i++] = tmp[j-1];
1979        }
1980    }
1981
1982    return ret;
1983}
1984
1985#endif /* OPENSSL_EXTRA */
1986
1987/*******************************************************************************
1988 * ASN1_OBJECT APIs
1989 ******************************************************************************/
1990
1991#if !defined(NO_ASN)
1992#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
1993/* Create a new ASN.1 OBJECT_ID object.
1994 *
1995 * @return  ASN.1 OBJECT_ID object on success.
1996 * @return  NULL when dynamic memory allocation fails.
1997 */
1998WOLFSSL_ASN1_OBJECT* wolfSSL_ASN1_OBJECT_new(void)
1999{
2000    WOLFSSL_ASN1_OBJECT* obj;
2001
2002    /* Allocate memory for new ASN.1 OBJECT. */
2003    obj = (WOLFSSL_ASN1_OBJECT*)XMALLOC(sizeof(WOLFSSL_ASN1_OBJECT), NULL,
2004        DYNAMIC_TYPE_ASN1);
2005    if (obj != NULL) {
2006        XMEMSET(obj, 0, sizeof(WOLFSSL_ASN1_OBJECT));
2007        /* Setup pointers. */
2008        obj->d.ia5 = &(obj->d.ia5_internal);
2009    #if defined(OPENSSL_ALL)
2010        obj->d.iPAddress = &(obj->d.iPAddress_internal);
2011    #endif
2012        /* Object was allocated. */
2013        obj->dynamic |= WOLFSSL_ASN1_DYNAMIC;
2014    }
2015
2016    return obj;
2017}
2018
2019/* Dispose of any ASN.1 OBJECT_ID dynamically allocated data.
2020 *
2021 * Do not use obj after calling this function.
2022 *
2023 * @param [in, out] obj  ASN.1 OBJECT_ID object.
2024 */
2025void wolfSSL_ASN1_OBJECT_free(WOLFSSL_ASN1_OBJECT* obj)
2026{
2027    if (obj != NULL) {
2028        /* Check for dynamically allocated copy of encoded data. */
2029        if ((obj->dynamic & WOLFSSL_ASN1_DYNAMIC_DATA) != 0) {
2030        #ifdef WOLFSSL_DEBUG_OPENSSL
2031            WOLFSSL_MSG("Freeing ASN1 data");
2032        #endif
2033            XFREE((void*)obj->obj, obj->heap, DYNAMIC_TYPE_ASN1);
2034            obj->obj = NULL;
2035        }
2036    #if defined(OPENSSL_EXTRA)
2037        /* Check for path length ASN.1 INTEGER - X.509 extension. */
2038        if (obj->pathlen != NULL) {
2039            wolfSSL_ASN1_INTEGER_free(obj->pathlen);
2040            obj->pathlen = NULL;
2041        }
2042    #endif
2043        /* Check whether object was dynamically allocated. */
2044        if ((obj->dynamic & WOLFSSL_ASN1_DYNAMIC) != 0) {
2045    #ifdef WOLFSSL_DEBUG_OPENSSL
2046            WOLFSSL_MSG("Freeing ASN1 OBJECT");
2047    #endif
2048            XFREE(obj, NULL, DYNAMIC_TYPE_ASN1);
2049        }
2050    }
2051}
2052
2053/* Duplicate the ASN.1 OBJECT_ID object.
2054 *
2055 * @param [in] obj  ASN.1 OBJECT_ID object to copy.
2056 * @return  New ASN.1 OBJECT_ID object on success.
2057 * @return  NULL when obj is NULL or dynamic memory allocation fails.
2058 */
2059WOLFSSL_ASN1_OBJECT* wolfSSL_ASN1_OBJECT_dup(WOLFSSL_ASN1_OBJECT* obj)
2060{
2061    WOLFSSL_ASN1_OBJECT* dupl = NULL;
2062
2063    WOLFSSL_ENTER("wolfSSL_ASN1_OBJECT_dup");
2064
2065    /* Validate parameter. */
2066    if (obj == NULL) {
2067        WOLFSSL_MSG("Bad parameter");
2068    }
2069    /* Create a new ASN.1 OBJECT_ID object to return. */
2070    else if ((dupl = wolfSSL_ASN1_OBJECT_new()) == NULL) {
2071        WOLFSSL_MSG("wolfSSL_ASN1_OBJECT_new error");
2072    }
2073    if (dupl != NULL) {
2074        /* Copy short name. */
2075        XMEMCPY(dupl->sName, obj->sName, WOLFSSL_MAX_SNAME);
2076        /* Copy simple fields. */
2077        dupl->type  = obj->type;
2078        dupl->grp   = obj->grp;
2079        dupl->nid   = obj->nid;
2080        dupl->objSz = obj->objSz;
2081    #ifdef OPENSSL_EXTRA
2082        dupl->ca    = obj->ca;
2083        if (obj->pathlen != NULL) {
2084            dupl->pathlen = wolfSSL_ASN1_INTEGER_dup(obj->pathlen);
2085            if (dupl->pathlen == NULL) {
2086                WOLFSSL_MSG("ASN1 pathlen alloc error");
2087                wolfSSL_ASN1_OBJECT_free(dupl);
2088                dupl = NULL;
2089            }
2090        }
2091    #endif
2092        /* Check for encoding. */
2093        if (dupl != NULL && obj->obj) {
2094            /* Allocate memory for ASN.1 OBJECT_ID DER encoding. */
2095            dupl->obj = (const unsigned char*)XMALLOC(obj->objSz, NULL,
2096                DYNAMIC_TYPE_ASN1);
2097            if (dupl->obj == NULL) {
2098                WOLFSSL_MSG("ASN1 obj malloc error");
2099                wolfSSL_ASN1_OBJECT_free(dupl);
2100                dupl = NULL;
2101            }
2102            else {
2103                /* Encoding buffer was dynamically allocated. */
2104                dupl->dynamic |= WOLFSSL_ASN1_DYNAMIC_DATA;
2105                /* Copy DER encoding. */
2106                XMEMCPY((byte*)dupl->obj, obj->obj, obj->objSz);
2107            }
2108        }
2109    }
2110
2111    return dupl;
2112}
2113#endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
2114#endif /* !NO_ASN */
2115
2116#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
2117
2118/**
2119 * Parse DER encoding and return header information.
2120 *
2121 * *in is moved to the value of the ASN1 object
2122 *
2123 * @param [in, out] in     Pointer to BER encoded data.
2124 * @param [out]     len    Length of parsed ASN1 object
2125 * @param [out]     tag    Tag value of parsed ASN1 object
2126 * @param [out]     cls    Class of parsed ASN1 object
2127 * @param [in]      inLen  Length of *in buffer
2128 * @return int  Depends on which bits are set in the returned int:
2129 *              0x80 an error occurred during parsing.
2130 *              0x20 parsed object is constructed.
2131 *              0x01 the parsed object length is indefinite.
2132 */
2133int wolfSSL_ASN1_get_object(const unsigned char **in, long *len, int *tag,
2134    int *cls, long inLen)
2135{
2136    int err = 0;
2137    word32 inOutIdx = 0;
2138    int l = 0;
2139    byte t = 0;
2140    int ret = 0x80;
2141
2142    WOLFSSL_ENTER("wolfSSL_ASN1_get_object");
2143
2144    if ((in == NULL) || (*in == NULL) || (len == NULL) || (tag == NULL) ||
2145            (cls == NULL) || (inLen <= 0)) {
2146        WOLFSSL_MSG("Bad parameter");
2147        err = 1;
2148    }
2149    if (!err) {
2150        /* Length at least 1, parameters valid - cannot fail to get tag. */
2151        err = GetASNTag(*in, &inOutIdx, &t, (word32)inLen);
2152        if (!err){
2153            /* Get length in DER encoding. */
2154            if (GetLength_ex(*in, &inOutIdx, &l, (word32)inLen, 0) < 0) {
2155                WOLFSSL_MSG("GetLength error");
2156                err = 1;
2157            }
2158        }
2159    }
2160    if (!err) {
2161        /* Return header information. */
2162        *tag = t & ASN_TYPE_MASK;  /* Tag number is 5 lsb */
2163        *cls = t & ASN_CLASS_MASK; /* Class is 2 msb */
2164        *len = l;
2165        ret = t & ASN_CONSTRUCTED;
2166
2167        if (l > (int)(inLen - inOutIdx)) {
2168            /* Still return other values but indicate error in msb */
2169            ret |= 0x80;
2170        }
2171
2172        /* Move pointer to after DER header. */
2173        *in += inOutIdx;
2174    }
2175
2176    return ret;
2177}
2178
2179int wolfssl_asn1_obj_set(WOLFSSL_ASN1_OBJECT* obj, const byte* der, word32 len,
2180        int addHdr)
2181{
2182    word32 idx = 0;
2183
2184    if (obj == NULL || der == NULL || len == 0)
2185        return WOLFSSL_FAILURE;
2186
2187    if (addHdr)
2188        idx = SetHeader(ASN_OBJECT_ID, (word32)len, NULL, 0);
2189
2190    if (obj->obj != NULL) {
2191        XFREE((void*)obj->obj, obj->heap, DYNAMIC_TYPE_ASN1);
2192        obj->obj = NULL;
2193        obj->dynamic &= ~WOLFSSL_ASN1_DYNAMIC_DATA;
2194    }
2195
2196    obj->obj =(unsigned char*)XMALLOC(idx + len, obj->heap, DYNAMIC_TYPE_ASN1);
2197    if (obj->obj == NULL)
2198        return WOLFSSL_FAILURE;
2199
2200    if (addHdr)
2201        SetHeader(ASN_OBJECT_ID, (word32)len, (byte*)obj->obj, 0);
2202
2203    XMEMCPY((byte*)obj->obj + idx, der, len);
2204    obj->objSz = (unsigned int)(idx + len);
2205    obj->dynamic |= WOLFSSL_ASN1_DYNAMIC_DATA;
2206    return WOLFSSL_SUCCESS;
2207}
2208
2209/* Creates and ASN.1 OBJECT_ID object from DER encoding.
2210 *
2211 * @param [out]     a       Pointer to return new ASN.1 OBJECT_ID through.
2212 * @param [in, out] der     Pointer to buffer holding DER encoding.
2213 * @param [in]      length  Length of DER encoding in bytes.
2214 * @return  New ASN.1 OBJECT_ID object on success.
2215 * @return  NULL when der or *der is NULL or length is less than or equal zero.
2216 * @return  NULL when not an OBJECT_ID or decoding fails.
2217 * @return  NULL when dynamic memory allocation fails.
2218 */
2219WOLFSSL_ASN1_OBJECT *wolfSSL_d2i_ASN1_OBJECT(WOLFSSL_ASN1_OBJECT **a,
2220    const unsigned char **der, long length)
2221{
2222    WOLFSSL_ASN1_OBJECT* ret = NULL;
2223    int len = 0;
2224    word32 idx = 0;
2225
2226    WOLFSSL_ENTER("wolfSSL_d2i_ASN1_OBJECT");
2227
2228    /* Validate parameters. */
2229    if ((der == NULL) || (*der == NULL) || (length <= 0)) {
2230        WOLFSSL_MSG("Bad parameter");
2231        return NULL;
2232    }
2233
2234    if (GetASNHeader(*der, ASN_OBJECT_ID, &idx, &len, (word32)length) < 0) {
2235        WOLFSSL_MSG("error getting tag");
2236        return NULL;
2237    }
2238
2239    if (len <= 0) {
2240        WOLFSSL_MSG("zero length");
2241        return NULL;
2242    }
2243
2244    ret = wolfSSL_ASN1_OBJECT_new();
2245    if (ret == NULL) {
2246        WOLFSSL_MSG("wolfSSL_ASN1_OBJECT_new error");
2247        return NULL;
2248    }
2249
2250    if (wolfssl_asn1_obj_set(ret, *der, idx + len, 0) != WOLFSSL_SUCCESS) {
2251        wolfSSL_ASN1_OBJECT_free(ret);
2252        return NULL;
2253    }
2254
2255    *der += idx + len;
2256    if (a != NULL) {
2257        if (*a != NULL)
2258            wolfSSL_ASN1_OBJECT_free(*a);
2259        *a = ret;
2260    }
2261
2262    return ret;
2263}
2264
2265/* Write out DER encoding of ASN.1 OBJECT_ID.
2266 *
2267 * When pp is NULL, length is returned.
2268 * When pp points to NULL, a new buffer is allocated and returned through pp.
2269 * When pp points to a buffer, it is moved on past encoded data on success.
2270 *
2271 * @param [in]      a   ASN.1 OBJECT_ID object.
2272 * @param [in, out] pp  Pointer to buffer to write to. May be NULL.
2273 * @return  Length of encoding on success.
2274 * @return  0 when a or encoding buffer is NULL.
2275 * @return  0 when dynamic memory allocation fails.
2276 */
2277int wolfSSL_i2d_ASN1_OBJECT(WOLFSSL_ASN1_OBJECT *a, unsigned char **pp)
2278{
2279    int len = 0;
2280
2281    WOLFSSL_ENTER("wolfSSL_i2d_ASN1_OBJECT");
2282
2283    /* Validate parameters */
2284    if ((a == NULL) || (a->obj == NULL)) {
2285        WOLFSSL_MSG("Bad parameters");
2286    }
2287    /* Only return length when no pointer supplied. */
2288    else if (pp == NULL) {
2289        len = (int)a->objSz;
2290    }
2291    else {
2292        byte *p = NULL;
2293
2294        /* Check if we have a buffer to encode into. */
2295        if (*pp == NULL) {
2296            /* Allocate a new buffer to return. */
2297            p = (byte*)XMALLOC(a->objSz, NULL, DYNAMIC_TYPE_OPENSSL);
2298            if (p == NULL) {
2299                WOLFSSL_MSG("Bad malloc");
2300            }
2301            else {
2302                /* Return allocated buffer. */
2303                *pp = p;
2304            }
2305        }
2306
2307        /* Check we have a buffer to encode into. */
2308        if (*pp != NULL) {
2309            /* Copy in DER encoding. */
2310            XMEMCPY(*pp, a->obj, a->objSz);
2311            /* Move on pointer if user supplied. */
2312            if (p == NULL) {
2313                *pp += a->objSz;
2314            }
2315            /* Return length of DER encoding. */
2316            len = (int)a->objSz;
2317        }
2318    }
2319
2320    return len;
2321}
2322
2323/* Create an ASN.1 OBJECT_ID object from the content octets.
2324 *
2325 * @param [out]     a    Pointer to return ASN.1 OBJECT_ID object.
2326 * @param [in, out] pp   Pointer to buffer holding content octets.
2327 * @param [in]      len  Length of content octets in bytes.
2328 * @return  New ASN.1 OBJECT_ID object on success.
2329 * @return  NULL when pp or *pp is NULL or length is less than or equal zero.
2330 * @return  NULL when dynamic memory allocation fails.
2331 */
2332WOLFSSL_ASN1_OBJECT *wolfSSL_c2i_ASN1_OBJECT(WOLFSSL_ASN1_OBJECT **a,
2333        const unsigned char **pp, long len)
2334{
2335    WOLFSSL_ASN1_OBJECT* ret = NULL;
2336
2337    WOLFSSL_ENTER("wolfSSL_c2i_ASN1_OBJECT");
2338
2339    /* Validate parameters. */
2340    if ((pp == NULL) || (*pp == NULL) || (len <= 0)) {
2341        WOLFSSL_MSG("Bad parameter");
2342        return NULL;
2343    }
2344
2345    /* Create a new ASN.1 OBJECT_ID object. */
2346    ret = wolfSSL_ASN1_OBJECT_new();
2347    if (ret == NULL) {
2348        WOLFSSL_MSG("wolfSSL_ASN1_OBJECT_new error");
2349        return NULL;
2350    }
2351
2352    if (wolfssl_asn1_obj_set(ret, *pp, (word32)len, 1) != WOLFSSL_SUCCESS) {
2353        WOLFSSL_MSG("wolfssl_asn1_obj_set error");
2354        wolfSSL_ASN1_OBJECT_free(ret);
2355        return NULL;
2356    }
2357
2358    /* Move pointer to after data copied out. */
2359    *pp += len;
2360    /* Return ASN.1 OBJECT_ID object through a if required. */
2361    if (a != NULL) {
2362        if (*a != NULL)
2363            wolfSSL_ASN1_OBJECT_free(*a);
2364        *a = ret;
2365    }
2366
2367    return ret;
2368}
2369
2370#endif /* OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL */
2371
2372#ifdef OPENSSL_EXTRA
2373
2374/* Write at most buf_len bytes of textual representation of ASN.1 OBJECT_ID.
2375 *
2376 * @param [in, out] buf      Buffer to write to.
2377 * @param [in]      buf_len  Length of buffer in bytes.
2378 * @param [in]      a        ASN.1 OBJECT_ID object.
2379 * @return  Number of bytes written on success.
2380 * @return  0 on failure.
2381 */
2382int wolfSSL_i2t_ASN1_OBJECT(char *buf, int buf_len, WOLFSSL_ASN1_OBJECT *a)
2383{
2384    WOLFSSL_ENTER("wolfSSL_i2t_ASN1_OBJECT");
2385
2386    return wolfSSL_OBJ_obj2txt(buf, buf_len, a, 0);
2387}
2388
2389#ifndef NO_BIO
2390/* Write out the text encoding of the ASN.1 OBJECT_ID.
2391 *
2392 * @param [in] bp  BIO to write to.
2393 * @param [in] a   ASN.1 OBJECT_ID object.
2394 * @return  Number of bytes written on success.
2395 * @return  0 on failure.
2396 */
2397int wolfSSL_i2a_ASN1_OBJECT(WOLFSSL_BIO *bp, WOLFSSL_ASN1_OBJECT *a)
2398{
2399    int length = 0;
2400    int cLen = 0;
2401    word32 idx = 0;
2402    const char null_str[] = "NULL";
2403    const char invalid_str[] = "<INVALID>";
2404    char buf[80];
2405
2406    WOLFSSL_ENTER("wolfSSL_i2a_ASN1_OBJECT");
2407
2408    /* Validate parameters. */
2409    if (bp == NULL) {
2410        /* Do nothing. */
2411    }
2412    /* NULL object is written as "NULL". */
2413    else if (a == NULL) {
2414        /* Write "NULL" - as done in OpenSSL. */
2415        length = wolfSSL_BIO_write(bp, null_str, (int)XSTRLEN(null_str));
2416    }
2417    /* Try getting text version and write it out. */
2418    else if ((length = wolfSSL_i2t_ASN1_OBJECT(buf, sizeof(buf), a)) > 0) {
2419        length = wolfSSL_BIO_write(bp, buf, length);
2420    }
2421    /* Look for DER header. */
2422    else if ((a->obj == NULL) || (a->obj[idx++] != ASN_OBJECT_ID)) {
2423        WOLFSSL_MSG("Bad ASN1 Object");
2424    }
2425    /* Get length from DER header. */
2426    else if (GetLength((const byte*)a->obj, &idx, &cLen, a->objSz) < 0) {
2427        length = 0;
2428    }
2429    else {
2430        /* Write out "<INVALID>" and dump content. */
2431        length = wolfSSL_BIO_write(bp, invalid_str, (int)XSTRLEN(invalid_str));
2432        length += wolfSSL_BIO_dump(bp, (const char*)(a->obj + idx), cLen);
2433    }
2434
2435    return length;
2436}
2437#endif /* !NO_BIO */
2438
2439#endif /* OPENSSL_EXTRA */
2440
2441/*******************************************************************************
2442 * ASN1_SK_OBJECT APIs
2443 ******************************************************************************/
2444
2445#if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && !defined(NO_ASN)
2446/* Create a new WOLFSSL_ASN1_OBJECT stack.
2447 *
2448 * @return  New WOLFSSL_ASN1_OBJECT stack on success.
2449 * @return  NULL when dynamic memory allocation fails.
2450 */
2451WOLFSSL_STACK* wolfSSL_sk_new_asn1_obj(void)
2452{
2453    WOLFSSL_ENTER("wolfSSL_sk_new_asn1_obj");
2454
2455    return wolfssl_sk_new_type(STACK_TYPE_OBJ);
2456}
2457
2458/* Dispose of WOLFSL_ASN1_OBJECT stack.
2459 *
2460 * @param [in, out] sk  Stack to free nodes in.
2461 */
2462void wolfSSL_sk_ASN1_OBJECT_free(WOLF_STACK_OF(WOLFSSL_ASN1_OBJECT)* sk)
2463{
2464    /* Dispose of stack. */
2465    wolfSSL_sk_free(sk);
2466}
2467
2468/* Dispose of all ASN.1 OBJECT_ID objects in ASN1_OBJECT stack.
2469 *
2470 * This is different then wolfSSL_ASN1_OBJECT_free in that it allows for
2471 * choosing the function to use when freeing an ASN1_OBJECT stack.
2472 *
2473 * @param [in, out] sk  ASN.1 OBJECT_ID stack to free.
2474 * @param [in]      f   Free function to apply to each ASN.1 OBJECT_ID object.
2475 */
2476void wolfSSL_sk_ASN1_OBJECT_pop_free(WOLF_STACK_OF(WOLFSSL_ASN1_OBJECT)* sk,
2477    void (*f) (WOLFSSL_ASN1_OBJECT*))
2478{
2479    WOLFSSL_ENTER("wolfSSL_sk_ASN1_OBJECT_pop_free");
2480    wolfSSL_sk_pop_free(sk, (wolfSSL_sk_freefunc)f);
2481}
2482
2483/* Push a WOLFSSL_ASN1_OBJECT onto stack.
2484 *
2485 * @param [in, out] sk   ASN.1 OBJECT_ID stack.
2486 * @param [in]      obj  ASN.1 OBJECT_ID object to push on. Cannot be NULL.
2487 * @return  1 on success.
2488 * @return  0 when sk or obj is NULL.
2489 * @return  0 when dynamic memory allocation fails.
2490 */
2491int wolfSSL_sk_ASN1_OBJECT_push(WOLF_STACK_OF(WOLFSSL_ASN1_OBJECT)* sk,
2492    WOLFSSL_ASN1_OBJECT* obj)
2493{
2494    WOLFSSL_ENTER("wolfSSL_sk_ASN1_OBJECT_push");
2495
2496    return wolfSSL_sk_push(sk, obj);
2497}
2498
2499/* Pop off a WOLFSSL_ASN1_OBJECT from the stack.
2500 *
2501 * @param [in, out] sk  ASN.1 OBJECT_ID stack.
2502 * @return  ASN.1 OBJECT_ID object on success.
2503 * @return  NULL when stack is NULL or no nodes left in stack.
2504 */
2505WOLFSSL_ASN1_OBJECT* wolfSSL_sk_ASN1_OBJECT_pop(
2506    WOLF_STACK_OF(WOLFSSL_ASN1_OBJECT)* sk)
2507{
2508    return (WOLFSSL_ASN1_OBJECT*)wolfssl_sk_pop_type(sk, STACK_TYPE_OBJ);
2509}
2510
2511#endif /* (OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL) && !NO_ASN */
2512
2513/*******************************************************************************
2514 * ASN1_STRING APIs
2515 ******************************************************************************/
2516
2517#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
2518
2519/* Create a new ASN.1 STRING object.
2520 *
2521 * @return  New ASN.1 STRING object on success.
2522 * @return  NULL when dynamic memory allocation fails.
2523 */
2524WOLFSSL_ASN1_STRING* wolfSSL_ASN1_STRING_new(void)
2525{
2526    WOLFSSL_ASN1_STRING* asn1;
2527
2528#ifdef WOLFSSL_DEBUG_OPENSSL
2529    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_new");
2530#endif
2531
2532    asn1 = (WOLFSSL_ASN1_STRING*)XMALLOC(sizeof(WOLFSSL_ASN1_STRING), NULL,
2533        DYNAMIC_TYPE_OPENSSL);
2534    if (asn1 != NULL) {
2535        XMEMSET(asn1, 0, sizeof(WOLFSSL_ASN1_STRING));
2536    }
2537
2538    return asn1;
2539}
2540
2541/* Create a new ASN.1 STRING object.
2542 *
2543 * @param [in] type  Encoding type.
2544 * @return  New ASN.1 STRING object on success.
2545 * @return  NULL when dynamic memory allocation fails.
2546 */
2547WOLFSSL_ASN1_STRING* wolfSSL_ASN1_STRING_type_new(int type)
2548{
2549    WOLFSSL_ASN1_STRING* asn1;
2550
2551#ifdef WOLFSSL_DEBUG_OPENSSL
2552    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_type_new");
2553#endif
2554
2555    asn1 = wolfSSL_ASN1_STRING_new();
2556    if (asn1 != NULL) {
2557        asn1->type = type;
2558    }
2559
2560    return asn1;
2561}
2562
2563/* Dispose of ASN.1 STRING object.
2564 *
2565 * @param [in, out] asn1  ASN.1 STRING object.
2566 */
2567void wolfSSL_ASN1_STRING_free(WOLFSSL_ASN1_STRING* asn1)
2568{
2569#ifdef WOLFSSL_DEBUG_OPENSSL
2570    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_free");
2571#endif
2572
2573    /* Check we have an object to free. */
2574    if (asn1 != NULL) {
2575        /* Dispose of dynamic data. */
2576        if ((asn1->length > 0) && asn1->isDynamic) {
2577            XFREE(asn1->data, NULL, DYNAMIC_TYPE_OPENSSL);
2578        }
2579    }
2580    /* Dispose of ASN.1 STRING object. */
2581    XFREE(asn1, NULL, DYNAMIC_TYPE_OPENSSL);
2582}
2583
2584/* Copy an ASN.1 STRING object from src into dest.
2585 *
2586 * @param [in, out] dest  ASN.1 STRING object to copy into.
2587 * @param [in]      src   ASN.1 STRING object to copy from.
2588 */
2589int wolfSSL_ASN1_STRING_copy(WOLFSSL_ASN1_STRING* dest,
2590    const WOLFSSL_ASN1_STRING* src)
2591{
2592    int ret = 1;
2593
2594    /* Validate parameters. */
2595    if ((src == NULL) || (dest == NULL)) {
2596        ret = 0;
2597    }
2598    /* Set the DER encoding. */
2599    if ((ret == 1) && (wolfSSL_ASN1_STRING_set(dest, src->data, src->length) !=
2600            1)) {
2601        ret = 0;
2602    }
2603    if (ret == 1) {
2604        /* Copy simple fields. */
2605        dest->type  = src->type;
2606        dest->flags = src->flags;
2607    }
2608
2609    return ret;
2610}
2611
2612/* Duplicate an ASN.1 STRING object.
2613 *
2614 * @param [in] asn1  ASN.1 STRING object to duplicate.
2615 * @return  New ASN.1 STRING object on success.
2616 * @return  NULL when asn1 is NULL or dynamic memory allocation fails.
2617 */
2618WOLFSSL_ASN1_STRING* wolfSSL_ASN1_STRING_dup(WOLFSSL_ASN1_STRING* asn1)
2619{
2620    WOLFSSL_ASN1_STRING* dupl = NULL;
2621
2622    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_dup");
2623
2624    /* Check we have an object to duplicate. */
2625    if (asn1 == NULL) {
2626        WOLFSSL_MSG("Bad parameter");
2627    }
2628    else {
2629        /* Create a new ASN.1 STRING object. */
2630        dupl = wolfSSL_ASN1_STRING_new();
2631        if (dupl == NULL) {
2632            WOLFSSL_MSG("wolfSSL_ASN1_STRING_new error");
2633        }
2634    }
2635
2636    if (dupl != NULL) {
2637        /* Copy the contents. */
2638        if (wolfSSL_ASN1_STRING_copy(dupl, asn1) != 1) {
2639            WOLFSSL_MSG("wolfSSL_ASN1_STRING_copy error");
2640            /* Dispose of duplicate and return NULL. */
2641            wolfSSL_ASN1_STRING_free(dupl);
2642            dupl = NULL;
2643        }
2644    }
2645
2646    return dupl;
2647}
2648
2649/* Compare two ASN.1 STRING objects.
2650 *
2651 * Compares type when data the same.
2652 *
2653 * @param [in] a  First ASN.1 STRING object.
2654 * @param [in] b  Second ASN.1 STRING object.
2655 * @return Negative value when a is less than b.
2656 * @return 0 when a equals b.
2657 * @return Positive value when a is greater than b.
2658 * @return WOLFSSL_FATAL_ERROR when a or b is NULL.
2659 */
2660int wolfSSL_ASN1_STRING_cmp(const WOLFSSL_ASN1_STRING *a,
2661    const WOLFSSL_ASN1_STRING *b)
2662{
2663    int ret;
2664    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_cmp");
2665
2666    /* Validate parameters. */
2667    if ((a == NULL) || (b == NULL)) {
2668        ret = WOLFSSL_FATAL_ERROR;
2669    }
2670    /* Compare length of data. */
2671    else if (a->length != b->length) {
2672        ret = a->length - b->length;
2673    }
2674    /* Compare data. */
2675    else if ((ret = XMEMCMP(a->data, b->data, (size_t)a->length)) == 0) {
2676        /* Compare ASN.1 types - wolfSSL_ASN1_STRING_type_new(). */
2677        ret = a->type - b->type;
2678    }
2679
2680    return ret;
2681}
2682
2683#endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
2684
2685#if defined(OPENSSL_EXTRA)
2686#if !defined(NO_CERTS)
2687#ifndef NO_WOLFSSL_STUB
2688WOLFSSL_ASN1_STRING* wolfSSL_d2i_DISPLAYTEXT(WOLFSSL_ASN1_STRING **asn,
2689    const unsigned char **in, long len)
2690{
2691    WOLFSSL_STUB("d2i_DISPLAYTEXT");
2692    (void)asn;
2693    (void)in;
2694    (void)len;
2695    return NULL;
2696}
2697#endif
2698#endif /* !NO_CERTS */
2699#endif /* OPENSSL_EXTRA */
2700
2701#ifndef NO_ASN
2702#if defined(OPENSSL_EXTRA)
2703/* Convert ASN.1 STRING that is UniversalString type to PrintableString type.
2704 *
2705 * @param [in, out] s  ASN.1 STRING object to convert.
2706 * @return  1 on success.
2707 * @return  0 when s is NULL.
2708 * @return  0 when type is not UniversalString or string is not of that format.
2709 */
2710int wolfSSL_ASN1_UNIVERSALSTRING_to_string(WOLFSSL_ASN1_STRING *s)
2711{
2712    int ret = 1;
2713    char* p;
2714
2715    WOLFSSL_ENTER("wolfSSL_ASN1_UNIVERSALSTRING_to_string");
2716
2717    /* Validate parameter. */
2718    if (s == NULL) {
2719        WOLFSSL_MSG("Bad parameter");
2720        ret = 0;
2721    }
2722
2723    /* Check type of ASN.1 STRING. */
2724    if ((ret == 1) && (s->type != WOLFSSL_V_ASN1_UNIVERSALSTRING)) {
2725        WOLFSSL_MSG("Input is not a universal string");
2726        ret = 0;
2727    }
2728
2729    /* Check length is indicative of UNIVERSAL_STRING. */
2730    if ((ret == 1) && ((s->length % 4) != 0)) {
2731        WOLFSSL_MSG("Input string must be divisible by 4");
2732        ret = 0;
2733    }
2734
2735    if (ret == 1) {
2736        /* Ensure each UniversalString character looks right. */
2737        for (p = s->data; p < s->data + s->length; p += 4)
2738            if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
2739                break;
2740        /* Check whether we failed loop early. */
2741        if (p != s->data + s->length) {
2742            WOLFSSL_MSG("Wrong string format");
2743            ret = 0;
2744        }
2745    }
2746
2747    if (ret == 1) {
2748        char* copy;
2749
2750        /* Strip first three bytes of each four byte character. */
2751        for (copy = p = s->data; p < s->data + s->length; p += 4) {
2752            *copy++ = p[3];
2753        }
2754        /* Place NUL on end. */
2755        *copy = '\0';
2756        /* Update length and type. */
2757        s->length /= 4;
2758        s->type = WOLFSSL_V_ASN1_PRINTABLESTRING;
2759    }
2760
2761    return ret;
2762}
2763#endif /* OPENSSL_EXTRA */
2764
2765#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
2766/* Convert ASN.1 STRING to UTF8 encoding.
2767 *
2768 * Assumes stored encoding is UTF8.
2769 * Returned buffer should be freed using OPENSSL_free().
2770 *
2771 * @param [out] out   Pointer to return allocated string.
2772 * @param [in]  asn1  ASN.1 STRING object.
2773 * @return  Length of string, excluding NUL, on success.
2774 * @return  -1 when out or asn1 is NULL.
2775 * @return  -1 when no data to return.
2776 * @return  -1 dynamic memory allocation fails.
2777 */
2778int wolfSSL_ASN1_STRING_to_UTF8(unsigned char **out, WOLFSSL_ASN1_STRING *asn1)
2779{
2780    unsigned char* buf = NULL;
2781    unsigned char* data = NULL;
2782    int len = -1;
2783
2784    /* Validate parameters. */
2785    if ((out != NULL) && (asn1 != NULL)) {
2786        /* Get data and length. */
2787        data = wolfSSL_ASN1_STRING_data(asn1);
2788        len = wolfSSL_ASN1_STRING_length(asn1);
2789        /* Check data and length are usable. */
2790        if ((data == NULL) || (len < 0)) {
2791            len = WOLFSSL_FATAL_ERROR;
2792        }
2793    }
2794    if (len != -1) {
2795        /* Allocate buffer to hold string and NUL. */
2796        buf = (unsigned char*)XMALLOC((size_t)(len + 1), NULL,
2797            DYNAMIC_TYPE_OPENSSL);
2798        if (buf == NULL) {
2799            len = WOLFSSL_FATAL_ERROR;
2800        }
2801    }
2802    if (len != -1) {
2803        /* Copy in string - NUL always put on end of stored string. */
2804        XMEMCPY(buf, data, (size_t)(len + 1));
2805        /* Return buffer. */
2806        *out = buf;
2807    }
2808
2809    return len;
2810}
2811#endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
2812
2813#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
2814
2815/* Encode ASN.1 STRING data as hex digits separated by colon.
2816 *
2817 * Assumes length is greater than 0.
2818 *
2819 * @param [in] s  ASN.1 STRING object.
2820 * @return  Buffer containing string representation on success.
2821 * @return  NULL when dynamic memory allocation fails.
2822 * @return  NULL when encoding a character as hex fails.
2823 */
2824static char* wolfssl_asn1_string_to_hex_chars(const WOLFSSL_ASN1_STRING *s)
2825{
2826    char* tmp;
2827    int tmpSz = s->length * 3;
2828
2829    tmp = (char*)XMALLOC((size_t)tmpSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2830    if (tmp == NULL) {
2831        WOLFSSL_MSG("Memory Error");
2832    }
2833    else {
2834        int i;
2835        unsigned char* str = (unsigned char*)s->data;
2836
2837        /* Put out all but last character as a hex digit with ':'. */
2838        for (i = 0; i < s->length; i++) {
2839            /* Put in hex digit string at end of tmp. */
2840            ByteToHexStr(str[i], tmp + i * 3);
2841            /* Check not last character. */
2842            if (i < s->length - 1) {
2843                /* Put in separator: ':'. */
2844                tmp[i * 3 + 2] = ':';
2845            }
2846            /* Last character. */
2847            else {
2848                /* Put in NUL to terminate string. */
2849                tmp[i * 3 + 2] = '\0';
2850            }
2851        }
2852    }
2853
2854    return tmp;
2855}
2856
2857/* Create a string encoding of ASN.1 STRING object.
2858 *
2859 * @param [in] method  Method table. Unused.
2860 * @param [in] s       ASN.1 STRING object.
2861 * @return  Buffer containing string representation on success.
2862 * @return  NULL when s or data is NULL.
2863 * @return  NULL when dynamic memory allocation fails.
2864 * @return  NULL when encoding a character as hex fails.
2865 */
2866char* wolfSSL_i2s_ASN1_STRING(WOLFSSL_v3_ext_method *method,
2867    const WOLFSSL_ASN1_STRING *s)
2868{
2869    char* ret = NULL;
2870
2871    WOLFSSL_ENTER("wolfSSL_i2s_ASN1_STRING");
2872    (void)method;
2873
2874    /* Validate parameters. */
2875    if ((s == NULL) || (s->data == NULL)) {
2876        WOLFSSL_MSG("Bad Function Argument");
2877    }
2878    /* Handle 0 length data separately. */
2879    else if (s->length == 0) {
2880        ret = (char *)XMALLOC(1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2881        if (ret != NULL) {
2882            ret[0] = '\0';
2883        }
2884    }
2885    else {
2886        /* Convert unreadable strings to hexadecimal. */
2887        ret = wolfssl_asn1_string_to_hex_chars(s);
2888    }
2889
2890    return ret;
2891}
2892
2893static int i2d_ASN1_STRING(WOLFSSL_ASN1_STRING* s,
2894        unsigned char **pp, byte tag)
2895{
2896    int idx;
2897    int len;
2898    unsigned char* out;
2899
2900    if (s == NULL || s->data == NULL || s->length == 0)
2901        return WOLFSSL_FATAL_ERROR;
2902
2903    len = SetHeader(tag, s->length, NULL, 0) + s->length;
2904
2905    if (pp == NULL)
2906        return len;
2907
2908    if (*pp == NULL) {
2909        out = (unsigned char*)XMALLOC(len, NULL, DYNAMIC_TYPE_ASN1);
2910        if (out == NULL)
2911            return WOLFSSL_FATAL_ERROR;
2912    }
2913    else {
2914        out = *pp;
2915    }
2916
2917    idx = (int)SetHeader(tag, s->length, out, 0);
2918    XMEMCPY(out + idx, s->data, s->length);
2919    if (*pp == NULL)
2920        *pp = out;
2921    else
2922        *pp += len;
2923
2924    return len;
2925}
2926
2927int wolfSSL_i2d_ASN1_GENERALSTRING(WOLFSSL_ASN1_STRING* s, unsigned char **pp)
2928{
2929    WOLFSSL_ENTER("wolfSSL_i2d_ASN1_GENERALSTRING");
2930
2931    return i2d_ASN1_STRING(s, pp, ASN_GENERALSTRING);
2932}
2933
2934int wolfSSL_i2d_ASN1_OCTET_STRING(WOLFSSL_ASN1_STRING* s, unsigned char **pp)
2935{
2936    WOLFSSL_ENTER("wolfSSL_i2d_ASN1_OCTET_STRING");
2937
2938    return i2d_ASN1_STRING(s, pp, ASN_OCTET_STRING);
2939}
2940
2941int wolfSSL_i2d_ASN1_UTF8STRING(WOLFSSL_ASN1_STRING* s, unsigned char **pp)
2942{
2943    WOLFSSL_ENTER("wolfSSL_i2d_ASN1_UTF8STRING");
2944
2945    return i2d_ASN1_STRING(s, pp, ASN_UTF8STRING);
2946}
2947
2948int wolfSSL_i2d_ASN1_SEQUENCE(WOLFSSL_ASN1_STRING* s,
2949        unsigned char **pp)
2950{
2951    unsigned char* out;
2952
2953    if (s == NULL || s->data == NULL || s->length == 0)
2954        return WOLFSSL_FATAL_ERROR;
2955
2956    if (pp == NULL)
2957        return s->length;
2958
2959    if (*pp == NULL) {
2960        out = (unsigned char*)XMALLOC(s->length, NULL, DYNAMIC_TYPE_ASN1);
2961        if (out == NULL)
2962            return WOLFSSL_FATAL_ERROR;
2963    }
2964    else {
2965        out = *pp;
2966    }
2967
2968    XMEMCPY(out, s->data, s->length);
2969    if (*pp == NULL)
2970        *pp = out;
2971    else
2972        *pp += s->length;
2973
2974    return s->length;
2975}
2976
2977static WOLFSSL_ASN1_STRING* d2i_ASN1_STRING(WOLFSSL_ASN1_STRING** out,
2978        const byte** src, long len, byte expTag)
2979{
2980    WOLFSSL_ASN1_STRING* ret = NULL;
2981    word32 idx = 0;
2982    byte tag = 0;
2983    int length = 0;
2984
2985    WOLFSSL_ENTER("d2i_ASN1_STRING");
2986
2987    if (src == NULL || *src == NULL || len == 0)
2988        return NULL;
2989
2990    if (GetASNTag(*src, &idx, &tag, (word32)len) < 0)
2991        return NULL;
2992    if (tag != expTag)
2993        return NULL;
2994    if (GetLength(*src, &idx, &length, (word32)len) < 0)
2995        return NULL;
2996
2997    ret = wolfSSL_ASN1_STRING_new();
2998    if (ret == NULL)
2999        return NULL;
3000
3001    if (wolfSSL_ASN1_STRING_set(ret, *src + idx, length) != 1) {
3002        wolfSSL_ASN1_STRING_free(ret);
3003        return NULL;
3004    }
3005
3006    if (out != NULL) {
3007        if (*out != NULL)
3008            wolfSSL_ASN1_STRING_free(*out);
3009        *out = ret;
3010    }
3011    *src += idx + length;
3012
3013    return ret;
3014}
3015
3016WOLFSSL_ASN1_STRING* wolfSSL_d2i_ASN1_GENERALSTRING(WOLFSSL_ASN1_STRING** out,
3017        const byte** src, long len)
3018{
3019    WOLFSSL_ENTER("wolfSSL_d2i_ASN1_GENERALSTRING");
3020
3021    return d2i_ASN1_STRING(out, src, len, ASN_GENERALSTRING);
3022}
3023
3024WOLFSSL_ASN1_STRING* wolfSSL_d2i_ASN1_OCTET_STRING(WOLFSSL_ASN1_STRING** out,
3025        const byte** src, long len)
3026{
3027    WOLFSSL_ENTER("wolfSSL_d2i_ASN1_OCTET_STRING");
3028
3029    return d2i_ASN1_STRING(out, src, len, ASN_OCTET_STRING);
3030}
3031
3032WOLFSSL_ASN1_STRING* wolfSSL_d2i_ASN1_UTF8STRING(WOLFSSL_ASN1_STRING** out,
3033        const byte** src, long len)
3034{
3035    WOLFSSL_ENTER("wolfSSL_d2i_ASN1_UTF8STRING");
3036
3037    return d2i_ASN1_STRING(out, src, len, ASN_UTF8STRING);
3038}
3039
3040#endif /* OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL */
3041#endif /* NO_ASN */
3042
3043#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
3044/* Get the type of encoding.
3045 *
3046 * @param [in] asn1  ASN.1 STRING object.
3047 * @return  Encoding type on success.
3048 * @return  0 when asn1 is NULL or no encoding set.
3049 */
3050int wolfSSL_ASN1_STRING_type(const WOLFSSL_ASN1_STRING* asn1)
3051{
3052    int type = 0;
3053
3054#ifdef WOLFSSL_DEBUG_OPENSSL
3055    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_type");
3056#endif
3057
3058    if (asn1 != NULL) {
3059        type = asn1->type;
3060    }
3061
3062    return type;
3063}
3064
3065#ifndef NO_CERTS
3066/* Get the pointer that is the data.
3067 *
3068 * @param [in] asn  ASN.1 STRING object.
3069 * @return  Buffer with string on success.
3070 * @return  NULL when asn is NULL or no data set.
3071 */
3072const unsigned char* wolfSSL_ASN1_STRING_get0_data(
3073    const WOLFSSL_ASN1_STRING* asn)
3074{
3075    char* data = NULL;
3076
3077    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_get0_data");
3078
3079    if (asn != NULL) {
3080        data = asn->data;
3081    }
3082
3083    return (const unsigned char*)data;
3084}
3085
3086/* Get the pointer that is the data.
3087 *
3088 * @param [in] asn  ASN.1 STRING object.
3089 * @return  Buffer with string on success.
3090 * @return  NULL when asn is NULL or no data set.
3091 */
3092unsigned char* wolfSSL_ASN1_STRING_data(WOLFSSL_ASN1_STRING* asn)
3093{
3094    char* data = NULL;
3095
3096#ifdef WOLFSSL_DEBUG_OPENSSL
3097    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_data");
3098#endif
3099
3100    if (asn != NULL) {
3101        data = asn->data;
3102    }
3103
3104    return (unsigned char*)data;
3105}
3106
3107/* Get the length of the data.
3108 *
3109 * @param [in] asn  ASN.1 STRING object.
3110 * @return  String length on success.
3111 * @return  0 when asn is NULL or no data set.
3112 */
3113int wolfSSL_ASN1_STRING_length(const WOLFSSL_ASN1_STRING* asn)
3114{
3115    int len = 0;
3116
3117#ifdef WOLFSSL_DEBUG_OPENSSL
3118    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_length");
3119#endif
3120
3121    if (asn) {
3122        len = asn->length;
3123    }
3124
3125    return len;
3126}
3127#endif /* !NO_CERTS */
3128
3129/* Set the string data.
3130 *
3131 * When sz is less than 0, the string length will be calculated using XSTRLEN.
3132 *
3133 * @param [in, out] asn1    ASN.1 STRING object.
3134 * @param [in]      data    String data to set.
3135 * @param [in]      sz      Length of data to set in bytes.
3136 * @return  1 on success.
3137 * @return  0 when asn1 is NULL or data is NULL and sz is not zero.
3138 * @return  0 when dynamic memory allocation fails.
3139 */
3140int wolfSSL_ASN1_STRING_set(WOLFSSL_ASN1_STRING* asn1, const void* data, int sz)
3141{
3142    int ret = 1;
3143
3144#ifdef WOLFSSL_DEBUG_OPENSSL
3145    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_set");
3146#endif
3147
3148    /* Validate parameters. */
3149    if ((asn1 == NULL) || ((data == NULL) && (sz != 0))) {
3150        ret = 0;
3151    }
3152
3153    /* Calculate size from data if not passed in. */
3154    if ((ret == 1) && (sz < 0)) {
3155        sz = (int)XSTRLEN((const char*)data);
3156        if (sz < 0) {
3157            ret = 0;
3158        }
3159    }
3160
3161    if (ret == 1) {
3162        /* Dispose of any existing dynamic data. */
3163        if (asn1->isDynamic) {
3164            XFREE(asn1->data, NULL, DYNAMIC_TYPE_OPENSSL);
3165            asn1->data = NULL;
3166        }
3167
3168        /* Check string will fit - including NUL. */
3169        if (sz + 1 > CTC_NAME_SIZE) {
3170            /* Allocate new buffer. */
3171            asn1->data = (char*)XMALLOC((size_t)(sz + 1), NULL,
3172                DYNAMIC_TYPE_OPENSSL);
3173            if (asn1->data == NULL) {
3174                ret = 0;
3175            }
3176            else {
3177                /* Ensure buffer will be freed. */
3178                asn1->isDynamic = 1;
3179            }
3180        }
3181        else {
3182            /* Clear out fixed array and use it for data. */
3183            XMEMSET(asn1->strData, 0, CTC_NAME_SIZE);
3184            asn1->data = asn1->strData;
3185            asn1->isDynamic = 0;
3186        }
3187    }
3188    if (ret == 1) {
3189        /* Check if there is a string to copy. */
3190        if (data != NULL) {
3191            /* Copy string and append NUL. */
3192            XMEMCPY(asn1->data, data, (size_t)sz);
3193            asn1->data[sz] = '\0';
3194        }
3195        /* Set size of string. */
3196        asn1->length = sz;
3197    }
3198
3199    return ret;
3200}
3201#endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
3202
3203#if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
3204    !defined(WOLFCRYPT_ONLY)
3205#ifndef NO_CERTS
3206
3207/* Make a UTF8 canonical version of ASN.1 STRING object's data.
3208 *
3209 * @param [in, out] asn  ASN.1 STRING to set.
3210 */
3211static void wolfssl_asn1_string_canonicalize(WOLFSSL_ASN1_STRING* asn)
3212{
3213    char* src = asn->data;
3214    char* p = asn->data + asn->length - 1;
3215    int len = asn->length;
3216    int i;
3217
3218    /* Trim whitespace from the tail. */
3219    for (; (len > 0) && (XISSPACE((unsigned char)*p)); len--) {
3220        p--;
3221    }
3222    if (len > 0) {
3223        /* Trim whitespace from the head. */
3224        for (; XISSPACE((unsigned char)*src); len--) {
3225            src++;
3226        }
3227    }
3228
3229    /* Output at the start. */
3230    p = asn->data;
3231    /* Process each character in string after trim. */
3232    for (i = 0; i < len; p++, i++) {
3233        /* Check for non-ascii character. */
3234        if (!XISASCII(*src)) {
3235            /* Keep non-ascii character as-is. */
3236            *p = *src++;
3237        }
3238        /* Check for whitespace. */
3239        else if (XISSPACE((unsigned char)*src)) {
3240            /* Only use space character for whitespace. */
3241            *p = 0x20;
3242            /* Skip any succeeding whitespace characters. */
3243            while (XISSPACE((unsigned char)*++src)) {
3244                i++;
3245            }
3246        }
3247        else {
3248            /* Convert to lower case. */
3249            *p = (char)XTOLOWER((unsigned char)*src++);
3250        }
3251    }
3252    /* Set actual length after canonicalization. */
3253    asn->length = (int)(p - asn->data);
3254}
3255
3256/* Make a canonical version of ASN.1 STRING object in ASN.1 STRING object.
3257 *
3258 * @param [in, out] asn_out  ASN.1 STRING object to set.
3259 * @param [in]      asn_in   ASN.1 STRING object to get data from.
3260 * @return  1 on success.
3261 * @return  BAD_FUNC_ARG when asn_out or asn_in is NULL.
3262 * @return  0 when no data.
3263 * @return  0 when dynamic memory allocation fails.
3264 */
3265int wolfSSL_ASN1_STRING_canon(WOLFSSL_ASN1_STRING* asn_out,
3266    const WOLFSSL_ASN1_STRING* asn_in)
3267{
3268    int ret = 1;
3269
3270    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_canon");
3271
3272    /* Validate parameters. */
3273    if ((asn_out == NULL) || (asn_in == NULL)) {
3274        WOLFSSL_MSG("invalid function arguments");
3275        ret = BAD_FUNC_ARG;
3276    }
3277
3278    if (ret == 1) {
3279        switch (asn_in->type) {
3280            case WOLFSSL_MBSTRING_UTF8:
3281            case WOLFSSL_V_ASN1_PRINTABLESTRING:
3282                /* Set type to UTF8. */
3283                asn_out->type = WOLFSSL_MBSTRING_UTF8;
3284                /* Dispose of any dynamic data already in asn_out. */
3285                if (asn_out->isDynamic) {
3286                    XFREE(asn_out->data, NULL, DYNAMIC_TYPE_OPENSSL);
3287                    asn_out->data = NULL;
3288                }
3289                /* Make ASN.1 STRING into UTF8 buffer. */
3290                asn_out->length = wolfSSL_ASN1_STRING_to_UTF8(
3291                    (unsigned char**)&asn_out->data,
3292                    (WOLFSSL_ASN1_STRING*)asn_in);
3293                /* Check for error from creating UTF8 string. */
3294                if (asn_out->length < 0) {
3295                    ret = 0;
3296                }
3297                else {
3298                    /* Data now dynamic after converting to UTF8. */
3299                    asn_out->isDynamic = 1;
3300                    /* Canonicalize the data. */
3301                    wolfssl_asn1_string_canonicalize(asn_out);
3302                    if (asn_out->length == 0) {
3303                        /* Dispose of data if canonicalization removes all
3304                         * characters. */
3305                        XFREE(asn_out->data, NULL, DYNAMIC_TYPE_OPENSSL);
3306                        asn_out->data = NULL;
3307                        asn_out->isDynamic = 0;
3308                    }
3309                }
3310                break;
3311            default:
3312                /* Unrecognized format - just copy. */
3313                WOLFSSL_MSG("just copy string");
3314                ret = wolfSSL_ASN1_STRING_copy(asn_out, asn_in);
3315        }
3316    }
3317
3318    return ret;
3319}
3320
3321#endif /* !NO_CERTS */
3322#endif /* (OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL) && !WOLFCRYPT_ONLY */
3323
3324#if defined(OPENSSL_EXTRA)
3325
3326#if !defined(NO_ASN)
3327#ifndef NO_BIO
3328/* Returns boolean indicating character is unprintable.
3329 *
3330 * @param [in] c  ASCII character.
3331 * @return  1 when character is unprintable.
3332 * @return  0 when character is printable.
3333 */
3334static int wolfssl_unprintable_char(char c)
3335{
3336    const unsigned char last_unprintable = 31;
3337    const unsigned char LF = 10;               /* Line Feed */
3338    const unsigned char CR = 13;               /* Carriage Return */
3339
3340    return (c <= last_unprintable) && (c != LF) && (c != CR);
3341}
3342
3343/* Print ASN.1 STRING to BIO.
3344 *
3345 * TODO: Unprintable characters conversion is destructive.
3346 *
3347 * @param [in] bio  BIO to print to.
3348 * @param [in] str  ASN.1 STRING to print.
3349 * @return  Length of string written on success.
3350 * @return  0 when bio or str is NULL.
3351 * @return  0 when writing to BIO fails.
3352 */
3353int wolfSSL_ASN1_STRING_print(WOLFSSL_BIO *bio, WOLFSSL_ASN1_STRING *str)
3354{
3355    int len = 0;
3356
3357    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_print");
3358
3359    /* Validate parameters. */
3360    if ((bio != NULL) && (str != NULL)) {
3361        int i;
3362
3363        len = str->length;
3364        /* Convert all unprintable characters to '.'. */
3365        for (i = 0; i < len; i++) {
3366            if (wolfssl_unprintable_char(str->data[i])) {
3367                str->data[i] = '.';
3368            }
3369        }
3370        /* Write string to BIO. */
3371        if (wolfSSL_BIO_write(bio, str->data, len) != len) {
3372            len = 0;
3373        }
3374    }
3375
3376    return len;
3377}
3378#endif /* !NO_BIO */
3379#endif /* !NO_ASN */
3380
3381/* Get a string for the ASN.1 tag.
3382 *
3383 * @param [in] tag  ASN.1 tag.
3384 * @return  A string.
3385 */
3386const char* wolfSSL_ASN1_tag2str(int tag)
3387{
3388    static const char *const tag_label[31] = {
3389        "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", "NULL",
3390        "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", "ENUMERATED",
3391        "<ASN1 11>", "UTF8STRING", "<ASN1 13>", "<ASN1 14>", "<ASN1 15>",
3392        "SEQUENCE", "SET", "NUMERICSTRING", "PRINTABLESTRING", "T61STRING",
3393        "VIDEOTEXTSTRING", "IA5STRING", "UTCTIME", "GENERALIZEDTIME",
3394        "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", "UNIVERSALSTRING",
3395        "<ASN1 29>", "BMPSTRING"
3396    };
3397    const char* str = "(unknown)";
3398
3399    /* Clear negative flag. */
3400    if ((tag == WOLFSSL_V_ASN1_NEG_INTEGER) ||
3401            (tag == WOLFSSL_V_ASN1_NEG_ENUMERATED)) {
3402        tag &= ~WOLFSSL_V_ASN1_NEG;
3403    }
3404    /* Check for known basic types. */
3405    if ((tag >= 0) && (tag <= 30)) {
3406        str = tag_label[tag];
3407    }
3408
3409    return str;
3410}
3411
3412#ifndef NO_BIO
3413
3414/* Print out ASN.1 tag for the ASN.1 STRING to the BIO.
3415 *
3416 * @param [in] bio  BIO to write to.
3417 * @param [in] str  ASN.1 STRING object.
3418 * @return  Number of characters written on success.
3419 * @return  0 when BIO write fails.
3420 */
3421static int wolfssl_string_print_type(WOLFSSL_BIO *bio, WOLFSSL_ASN1_STRING *str)
3422{
3423    int type_len;
3424    const char *tag;
3425
3426    /* Get tag and string length. */
3427    tag = wolfSSL_ASN1_tag2str(str->type);
3428    type_len = (int)XSTRLEN(tag);
3429    /* Write tag to BIO. */
3430    if (wolfSSL_BIO_write(bio, tag, type_len) != type_len){
3431        type_len = 0;
3432    }
3433    /* Write colon after tag string. */
3434    else if (wolfSSL_BIO_write(bio, ":", 1) != 1) {
3435        type_len = 0;
3436    }
3437    else {
3438        /* Written colon - update count. */
3439        type_len++;
3440    }
3441
3442    return type_len;
3443}
3444
3445/* Dump hex digit representation of each string character to BIO.
3446 *
3447 * TODO: Assumes length is only one byte ie less than 128 characters long.
3448 *
3449 * @param [in] bio    BIO to write to.
3450 * @param [in] str    ASN.1 STRING object.
3451 * @param [in] asDer  Whether to write out as a DER encoding.
3452 * @return  Number of characters written to BIO on success.
3453 * @return  -1 when writing to BIO fails.
3454 */
3455static int wolfssl_asn1_string_dump_hex(WOLFSSL_BIO *bio,
3456    WOLFSSL_ASN1_STRING *str, int asDer)
3457{
3458    const char* hash="#";
3459    char hex_tmp[4];
3460    int str_len = 1;
3461
3462    /* Write out hash character to indicate hex string. */
3463    if (wolfSSL_BIO_write(bio, hash, 1) != 1) {
3464        str_len = WOLFSSL_FATAL_ERROR;
3465    }
3466    else {
3467        /* Check if we are to write out DER header. */
3468        if (asDer) {
3469            /* Encode tag and length as hex into temporary. */
3470            ByteToHexStr((byte)str->type, &hex_tmp[0]);
3471            ByteToHexStr((byte)str->length, &hex_tmp[2]);
3472            /* Update count of written characters: tag and length. */
3473            str_len += 4;
3474            /* Write out tag and length as hex digits. */
3475            if (wolfSSL_BIO_write(bio, hex_tmp, 4) != 4) {
3476                str_len = WOLFSSL_FATAL_ERROR;
3477            }
3478        }
3479    }
3480
3481    if (str_len != -1) {
3482        char* p;
3483        char* end;
3484
3485        /* Calculate end of string. */
3486        end = str->data + str->length - 1;
3487        for (p = str->data; p <= end; p++) {
3488            /* Encode string character as hex into temporary. */
3489            ByteToHexStr((byte)*p, hex_tmp);
3490            /* Update count of written characters. */
3491            str_len += 2;
3492            /* Write out character as hex digites. */
3493            if (wolfSSL_BIO_write(bio, hex_tmp, 2) != 2) {
3494                str_len = WOLFSSL_FATAL_ERROR;
3495                break;
3496            }
3497        }
3498    }
3499
3500    return str_len;
3501}
3502
3503/* Check whether character needs to be escaped.
3504 *
3505 * @param [in] c    Character to check for.
3506 * @param [in] str  String to check.
3507 * @return  1 when character found.
3508 * @return  0 when character not found.
3509 */
3510static int wolfssl_check_esc_char(char c)
3511{
3512    int ret = 0;
3513    const char esc_ch[] = "+;<>\\";
3514    const char* p = esc_ch;
3515
3516    /* Check if character matches any of those needing escaping. */
3517    for (; (*p) != '\0'; p++) {
3518        /* Check if character matches escape character. */
3519        if (c == (*p)) {
3520            ret = 1;
3521            break;
3522        }
3523    }
3524
3525    return ret;
3526}
3527
3528/* Print out string, with escaping for special characters, to BIO.
3529 *
3530 * @param [in] bio  BIO to write to.
3531 * @param [in] str  ASN.1 STRING object.
3532 * @return  Number of characters written to BIO on success.
3533 * @return  -1 when writing to BIO fails.
3534 */
3535static int wolfssl_asn1_string_print_esc_2253(WOLFSSL_BIO *bio,
3536    WOLFSSL_ASN1_STRING *str)
3537{
3538    char* p;
3539    int str_len = 0;
3540
3541    /* Write all of string character by character. */
3542    for (p = str->data; (*p) != '\0'; p++) {
3543        /* Check if character needs escaping. */
3544        if (wolfssl_check_esc_char(*p)){
3545            /* Update count of written characters. */
3546            str_len++;
3547            /* Write out escaping character. */
3548            if (wolfSSL_BIO_write(bio,"\\", 1) != 1) {
3549                str_len = WOLFSSL_FATAL_ERROR;
3550                break;
3551            }
3552        }
3553        /* Update count of written characters. */
3554        str_len++;
3555        /* Write out character. */
3556        if (wolfSSL_BIO_write(bio, p, 1) != 1) {
3557            str_len = WOLFSSL_FATAL_ERROR;
3558            break;
3559        }
3560    }
3561
3562    return str_len;
3563}
3564
3565/* Extended print ASN.1 STRING to BIO.
3566 *
3567 * @param [in] bio    BIO to print to.
3568 * @param [in] str    ASN.1 STRING to print.
3569 * @param [in] flags  Flags describing output format.
3570 * @return  Length of string written on success.
3571 * @return  0 when bio or str is NULL.
3572 * @return  0 when writing to BIO fails.
3573 */
3574int wolfSSL_ASN1_STRING_print_ex(WOLFSSL_BIO *bio, WOLFSSL_ASN1_STRING *str,
3575    unsigned long flags)
3576{
3577    int err = 0;
3578    int str_len = -1;
3579    int type_len = 0;
3580
3581    WOLFSSL_ENTER("wolfSSL_ASN1_STRING_PRINT_ex");
3582
3583    /* Validate parameters. */
3584    if ((bio == NULL) || (str == NULL)) {
3585        err = 1;
3586    }
3587    /* Check if ASN.1 type is to be printed. */
3588    if ((!err) && (flags & WOLFSSL_ASN1_STRFLGS_SHOW_TYPE)) {
3589        /* Print type and colon to BIO. */
3590        type_len = wolfssl_string_print_type(bio, str);
3591        if (type_len == 0) {
3592            err = 1;
3593        }
3594    }
3595
3596    if (!err) {
3597        if (flags & WOLFSSL_ASN1_STRFLGS_DUMP_ALL) {
3598            /* Dump hex. */
3599            str_len = wolfssl_asn1_string_dump_hex(bio, str,
3600                flags & WOLFSSL_ASN1_STRFLGS_DUMP_DER);
3601        }
3602        else if (flags & WOLFSSL_ASN1_STRFLGS_ESC_2253) {
3603            /* Print out string with escaping. */
3604            str_len = wolfssl_asn1_string_print_esc_2253(bio, str);
3605        }
3606        else {
3607            /* Get number of characters to write. */
3608            str_len = str->length;
3609            /* Print out string as is. */
3610            if (wolfSSL_BIO_write(bio, str->data, str_len) != str_len) {
3611                err = 1;
3612            }
3613        }
3614    }
3615
3616    if ((!err) && (str_len >= 0)) {
3617        /* Include any characters written for type. */
3618        str_len += type_len;
3619    }
3620    else {
3621        str_len = 0;
3622    }
3623
3624    return str_len;
3625}
3626
3627#endif /* !NO_BIO */
3628
3629#endif /* OPENSSL_EXTRA */
3630
3631/*******************************************************************************
3632 * ASN1_GENERALIZEDTIME APIs
3633 ******************************************************************************/
3634
3635#ifdef OPENSSL_EXTRA
3636
3637/* Free the static ASN.1 GENERALIZED TIME object.
3638 *
3639 * Not an OpenSSL compatibility API.
3640 *
3641 * @param [in] asn1Time  ASN.1 GENERALIZED TIME object.
3642 */
3643void wolfSSL_ASN1_GENERALIZEDTIME_free(WOLFSSL_ASN1_TIME* asn1Time)
3644{
3645    WOLFSSL_ENTER("wolfSSL_ASN1_GENERALIZEDTIME_free");
3646    XFREE(asn1Time, NULL, DYNAMIC_TYPE_OPENSSL);
3647}
3648
3649#ifndef NO_BIO
3650/* Return the month as a string.
3651 *
3652 * Assumes n is '01'-'12'.
3653 *
3654 * @param [in] n  The number of the month as a two characters (1 based).
3655 * @return  Month as a string.
3656 */
3657static WC_INLINE const char* MonthStr(const char* n)
3658{
3659    static const char monthStr[12][4] = {
3660            "Jan", "Feb", "Mar", "Apr", "May", "Jun",
3661            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
3662    const char* month = "BAD";
3663    int i;
3664
3665    i = (n[0] - '0') * 10 + (n[1] - '0') - 1;
3666    /* Convert string to number and index table. */
3667    if ((i >= 0) && (i < 12)) {
3668        month = monthStr[i];
3669    }
3670
3671    return month;
3672}
3673
3674/* Print an ASN.1 GENERALIZED TIME to a BIO.
3675 *
3676 * @param [in] bio      BIO to write to.
3677 * @param [in] asnTime  ASN.1 GENERALIZED TIME object.
3678 * @return  1 on success.
3679 * @return  0 when ASN.1 GENERALIZED TIME type is invalid.
3680 * @return  0 when writing to BIO fails.
3681 * @return  BAD_FUNC_ARG when bio or asnTime is NULL.
3682 */
3683int wolfSSL_ASN1_GENERALIZEDTIME_print(WOLFSSL_BIO* bio,
3684    const WOLFSSL_ASN1_GENERALIZEDTIME* asnTime)
3685{
3686    int ret = 1;
3687    const char* p = NULL;
3688    WOLFSSL_ENTER("wolfSSL_ASN1_GENERALIZEDTIME_print");
3689
3690    /* Validate parameters. */
3691    if ((bio == NULL) || (asnTime == NULL)) {
3692        ret = BAD_FUNC_ARG;
3693    }
3694    /* Check type is GENERALIZED TIME. */
3695    if ((ret == 1) && (asnTime->type != WOLFSSL_V_ASN1_GENERALIZEDTIME)) {
3696        WOLFSSL_MSG("Error, not GENERALIZED_TIME");
3697        ret = 0;
3698    }
3699    if (ret == 1) {
3700        /* Get the string. */
3701        p = (const char *)(asnTime->data);
3702
3703        /* Print month as a 3 letter string. */
3704        if (wolfSSL_BIO_write(bio, MonthStr(p + 4), 3) != 3) {
3705            ret = 0;
3706        }
3707    }
3708    /* Print space separator. */
3709    if ((ret == 1) && (wolfSSL_BIO_write(bio, " ", 1) != 1)) {
3710        ret = 0;
3711    }
3712
3713    /* Print day. */
3714    if ((ret == 1) && (wolfSSL_BIO_write(bio, p + 6, 2) != 2)) {
3715        ret = 0;
3716    }
3717    /* Print space separator. */
3718    if ((ret == 1) && (wolfSSL_BIO_write(bio, " ", 1) != 1)) {
3719        ret = 0;
3720    }
3721
3722    /* Print hour. */
3723    if ((ret == 1) && (wolfSSL_BIO_write(bio, p + 8, 2) != 2)) {
3724        ret = 0;
3725    }
3726    /* Print time separator - colon. */
3727    if ((ret == 1) && (wolfSSL_BIO_write(bio, ":", 1) != 1)) {
3728        ret = 0;
3729    }
3730
3731    /* Print minutes. */
3732    if ((ret == 1) && (wolfSSL_BIO_write(bio, p + 10, 2) != 2)) {
3733        ret = 0;
3734    }
3735    /* Print time separator - colon. */
3736    if ((ret == 1) && (wolfSSL_BIO_write(bio, ":", 1) != 1)) {
3737        ret = 0;
3738    }
3739
3740    /* Print seconds. */
3741    if ((ret == 1) && (wolfSSL_BIO_write(bio, p + 12, 2) != 2)) {
3742        ret = 0;
3743    }
3744    /* Print space separator. */
3745    if ((ret == 1) && (wolfSSL_BIO_write(bio, " ", 1) != 1)) {
3746        ret = 0;
3747    }
3748    /* Print year. */
3749    if ((ret == 1) && (wolfSSL_BIO_write(bio, p, 4) != 4)) {
3750        ret = 0;
3751    }
3752
3753    return ret;
3754}
3755#endif /* !NO_BIO */
3756
3757#endif /* OPENSSL_EXTRA */
3758
3759/*******************************************************************************
3760 * ASN1_TIME APIs
3761 ******************************************************************************/
3762
3763#ifndef NO_ASN_TIME
3764
3765#ifdef OPENSSL_EXTRA
3766/* Allocate a new ASN.1 TIME object.
3767 *
3768 * @return  New empty ASN.1 TIME object on success.
3769 * @return  NULL when dynamic memory allocation fails.
3770 */
3771WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_new(void)
3772{
3773    WOLFSSL_ASN1_TIME* ret;
3774
3775    /* Allocate a new ASN.1 TYPE object. */
3776    ret = (WOLFSSL_ASN1_TIME*)XMALLOC(sizeof(WOLFSSL_ASN1_TIME), NULL,
3777        DYNAMIC_TYPE_OPENSSL);
3778    if (ret != NULL) {
3779        /* Clear out fields. */
3780        XMEMSET(ret, 0, sizeof(WOLFSSL_ASN1_TIME));
3781    }
3782
3783    return ret;
3784}
3785
3786/* Dispose of ASN.1 TIME object.
3787 *
3788 * @param [in, out] t  ASN.1 TIME object.
3789 */
3790void wolfSSL_ASN1_TIME_free(WOLFSSL_ASN1_TIME* t)
3791{
3792    /* Dispose of ASN.1 TIME object. */
3793    XFREE(t, NULL, DYNAMIC_TYPE_OPENSSL);
3794}
3795
3796#ifndef NO_WOLFSSL_STUB
3797/* Set the Unix time GMT into ASN.1 TIME object.
3798 *
3799 * Not implemented.
3800 *
3801 * @param [in, out] a   ASN.1 TIME object.
3802 * @param [in]      t   Unix time GMT.
3803 * @return  An ASN.1 TIME object.
3804 */
3805WOLFSSL_ASN1_TIME *wolfSSL_ASN1_TIME_set(WOLFSSL_ASN1_TIME *a, time_t t)
3806{
3807    WOLFSSL_STUB("wolfSSL_ASN1_TIME_set");
3808    (void)a;
3809    (void)t;
3810    return a;
3811}
3812#endif /* !NO_WOLFSSL_STUB */
3813
3814/* Convert time to Unix time (GMT).
3815 *
3816 * @param [in] sec     Second in minute. 0-59.
3817 * @param [in] minute  Minute in hour. 0-59.
3818 * @param [in] hour    Hour in day. 0-23.
3819 * @param [in] mday    Day of month. 1-31.
3820 * @param [in] mon     Month of year. 0-11
3821 * @param [in] year    Year including century. ie: 1991, 2023, 2048.
3822 * @return  Seconds since 00:00:00 01/01/1970 for the time passed in.
3823 */
3824static long long wolfssl_time_to_unix_time(int sec, int minute, int hour,
3825    int mday, int mon, int year)
3826{
3827    /* Number of cumulative days from the previous months, starting from
3828     * beginning of January. */
3829    static const int monthDaysCumulative [12] = {
3830        0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
3831    };
3832    int leapDays = year;
3833
3834    /* Leap day at end of February. */
3835    if (mon <= 1) {
3836        --leapDays;
3837    }
3838    /* Calculate leap days. */
3839    leapDays = leapDays / 4 - leapDays / 100 + leapDays / 400 - 1969 / 4 +
3840               1969 / 100 - 1969 / 400;
3841
3842    /* Calculate number of seconds. */
3843    return ((((long long) (year - 1970) * 365 + leapDays +
3844           monthDaysCumulative[mon] + mday - 1) * 24 + hour) * 60 + minute) *
3845           60 + sec;
3846}
3847
3848/* Convert ASN.1 TIME object to Unix time (GMT).
3849 *
3850 * @param [in]  t     ASN.1 TIME object.
3851 * @param [out] secs  Number of seconds since 00:00:00 01/01/1970.
3852 * @return  1 on success.
3853 * @return  0 when conversion of time fails.
3854 */
3855static int wolfssl_asn1_time_to_secs(const WOLFSSL_ASN1_TIME* t,
3856    long long* secs)
3857{
3858    int ret = 1;
3859    struct tm tm_s;
3860    struct tm *tmGmt = &tm_s;
3861
3862    /* Convert ASN.1 TIME to broken-down time. NULL treated as current time. */
3863    ret = wolfSSL_ASN1_TIME_to_tm(t, tmGmt);
3864    if (ret != 1) {
3865        WOLFSSL_MSG("Failed to convert from time to struct tm.");
3866    }
3867    else {
3868        /* We use wolfssl_time_to_unix_time here instead of XMKTIME to avoid the
3869         * Year 2038 problem on platforms where time_t is 32 bits. struct tm
3870         * stores the year as years since 1900, so we add 1900 to the year. */
3871        *secs = wolfssl_time_to_unix_time(tmGmt->tm_sec, tmGmt->tm_min,
3872            tmGmt->tm_hour, tmGmt->tm_mday, tmGmt->tm_mon,
3873            tmGmt->tm_year + 1900);
3874    }
3875
3876    return ret;
3877}
3878
3879/* Calculate difference in time of two ASN.1 TIME objects.
3880 *
3881 * @param [out] days  Number of whole days between from and to.
3882 * @param [out] secs  Number of seconds less than a day between from and to.
3883 * @param [in]  from  ASN.1 TIME object as start time.
3884 * @param [in]  to    ASN.1 TIME object as end time.
3885 * @return  1 on success.
3886 * @return  0 when conversion of time fails.
3887 */
3888int wolfSSL_ASN1_TIME_diff(int *days, int *secs, const WOLFSSL_ASN1_TIME *from,
3889    const WOLFSSL_ASN1_TIME *to)
3890{
3891    int ret = 1;
3892
3893    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_diff");
3894
3895    if ((from == NULL) && (to == NULL)) {
3896        if (days != NULL) {
3897            *days = 0;
3898        }
3899        if (secs != NULL) {
3900            *secs = 0;
3901        }
3902    }
3903    else {
3904        const long long SECS_PER_DAY = 24 * 60 * 60;
3905        long long fromSecs;
3906        long long toSecs = 0;
3907
3908        ret = wolfssl_asn1_time_to_secs(from, &fromSecs);
3909        if (ret == 1) {
3910            ret = wolfssl_asn1_time_to_secs(to, &toSecs);
3911        }
3912        if (ret == 1) {
3913            long long diffSecs = toSecs - fromSecs;
3914            if (days != NULL) {
3915                *days = (int) (diffSecs / SECS_PER_DAY);
3916            }
3917            if (secs != NULL) {
3918                *secs = (int) (diffSecs -
3919                        ((long long)(diffSecs / SECS_PER_DAY) * SECS_PER_DAY));
3920            }
3921        }
3922    }
3923
3924    return ret;
3925}
3926
3927/* Compare two ASN.1 TIME objects by comparing time value.
3928 *
3929 * @param [in] a  First ASN.1 TIME object.
3930 * @param [in] b  Second ASN.1 TIME object.
3931 * @return Negative value when a is less than b.
3932 * @return 0 when a equals b.
3933 * @return Positive value when a is greater than b.
3934 * @return -2 when a or b is invalid.
3935 */
3936int wolfSSL_ASN1_TIME_compare(const WOLFSSL_ASN1_TIME *a,
3937    const WOLFSSL_ASN1_TIME *b)
3938{
3939    int ret;
3940    int days;
3941    int secs;
3942
3943    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_compare");
3944
3945    /* Calculate difference in time between a and b. */
3946    if (wolfSSL_ASN1_TIME_diff(&days, &secs, a, b) != 1) {
3947        WOLFSSL_MSG("Failed to get time difference.");
3948        ret = -2;
3949    }
3950    else if (days == 0 && secs == 0) {
3951        /* a and b are the same time. */
3952        ret = 0;
3953    }
3954    else if (days >= 0 && secs >= 0) {
3955        /* a is before b. */
3956        ret = -1;
3957    }
3958    /* Assume wolfSSL_ASN1_TIME_diff creates coherent values. */
3959    else {
3960        ret = 1;
3961    }
3962
3963    WOLFSSL_LEAVE("wolfSSL_ASN1_TIME_compare", ret);
3964
3965    return ret;
3966}
3967
3968#if !defined(USER_TIME) && !defined(TIME_OVERRIDES)
3969/* Adjust the time into an ASN.1 TIME object.
3970 *
3971 * @param [in] a           ASN.1 TIME object. May be NULL.
3972 * @param [in] t           Time to offset.
3973 * @param [in] offset_day  Number of days to offset. May be negative.
3974 * @param [in] offset_sec  Number of seconds to offset. May be negative.
3975 * @return  ASN.1 TIME object on success.
3976 * @return  NULL when formatting time fails.
3977 * @return  NULL when dynamic memory allocation fails.
3978 */
3979WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_adj(WOLFSSL_ASN1_TIME* a, time_t t,
3980    int offset_day, long offset_sec)
3981{
3982    WOLFSSL_ASN1_TIME* ret = NULL;
3983    const time_t sec_per_day = 24*60*60;
3984    int time_get;
3985    char time_str[MAX_TIME_STRING_SZ];
3986    time_t offset_day_sec = offset_day * sec_per_day;
3987    time_t t_adj          = t + offset_day_sec + offset_sec;
3988
3989    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_adj");
3990
3991    /* Get time string as either UTC or GeneralizedTime. */
3992    time_get = GetFormattedTime(&t_adj, (byte*)time_str, MAX_TIME_STRING_SZ);
3993    if (time_get > 0) {
3994        ret = a;
3995        if (ret == NULL) {
3996            ret = wolfSSL_ASN1_TIME_new();
3997        }
3998        /* Set the string into the ASN.1 TIME object. */
3999        if ((wolfSSL_ASN1_TIME_set_string(ret, time_str) != 1) && (ret != a)) {
4000            wolfSSL_ASN1_TIME_free(ret);
4001            ret = NULL;
4002        }
4003    }
4004
4005    return ret;
4006}
4007#endif /* !USER_TIME && !TIME_OVERRIDES */
4008
4009/* Get the length of the ASN.1 TIME data.
4010 *
4011 * Not an OpenSSL function - ASN1_TIME is not opaque.
4012 *
4013 * @param [in] t  ASN.1 TIME object.
4014 * @return  Length of data on success.
4015 * @return  0 when t is NULL or no time set.
4016 */
4017int wolfSSL_ASN1_TIME_get_length(const WOLFSSL_ASN1_TIME *t)
4018{
4019    int len = 0;
4020
4021    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_get_length");
4022
4023    if (t != NULL) {
4024        len = t->length;
4025    }
4026
4027    return len;
4028}
4029
4030/* Get the data from the ASN.1 TIME object.
4031 *
4032 * Not an OpenSSL function - ASN1_TIME is not opaque.
4033 *
4034 * @param [in] t  ASN.1 TIME object.
4035 * @return  Data buffer on success.
4036 * @return  NULL when t is NULL.
4037 */
4038unsigned char* wolfSSL_ASN1_TIME_get_data(const WOLFSSL_ASN1_TIME *t)
4039{
4040    unsigned char* data = NULL;
4041
4042    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_get_data");
4043
4044    if (t != NULL) {
4045        data = (unsigned char*)t->data;
4046    }
4047
4048    return data;
4049}
4050
4051/* Check format of string in ASN.1 TIME object.
4052 *
4053 * @param [in] a  ASN.1 TIME object.
4054 * @return  1 on success.
4055 * @return  0 when format invalid.
4056 */
4057int wolfSSL_ASN1_TIME_check(const WOLFSSL_ASN1_TIME* a)
4058{
4059    int ret = WOLFSSL_SUCCESS;
4060    char buf[MAX_TIME_STRING_SZ];
4061
4062    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_check");
4063
4064    /* If can convert to human readable then format good. */
4065    if (wolfSSL_ASN1_TIME_to_string((WOLFSSL_ASN1_TIME*)a, buf,
4066            MAX_TIME_STRING_SZ) == NULL) {
4067        ret = WOLFSSL_FAILURE;
4068    }
4069
4070    return ret;
4071}
4072
4073/* Set the time as a string into ASN.1 TIME object.
4074 *
4075 * When t is NULL, str is checked only.
4076 *
4077 * @param [in, out] t    ASN.1 TIME object.
4078 * @param [in]      str  Time as a string.
4079 * @return  1 on success.
4080 * @return  0 when str is NULL.
4081 * @return  0 when str is not formatted correctly.
4082 */
4083int wolfSSL_ASN1_TIME_set_string(WOLFSSL_ASN1_TIME *t, const char *str)
4084{
4085    int ret = WOLFSSL_SUCCESS;
4086    int slen = 0;
4087
4088    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_set_string");
4089
4090    if (str == NULL) {
4091        WOLFSSL_MSG("Bad parameter");
4092        ret = 0;
4093    }
4094    if (ret == WOLFSSL_SUCCESS) {
4095        /* Get length of string including NUL terminator. */
4096        slen = (int)XSTRLEN(str) + 1;
4097        if (slen > CTC_DATE_SIZE) {
4098            WOLFSSL_MSG("Date string too long");
4099            ret = WOLFSSL_FAILURE;
4100        }
4101    }
4102    if ((ret == WOLFSSL_SUCCESS) && (t != NULL)) {
4103        /* Copy in string including NUL terminator. */
4104        XMEMCPY(t->data, str, (size_t)slen);
4105        /* Do not include NUL terminator in length. */
4106        t->length = slen - 1;
4107        /* Set ASN.1 type based on string length. */
4108        t->type = ((slen == ASN_UTC_TIME_SIZE) ? WOLFSSL_V_ASN1_UTCTIME :
4109            WOLFSSL_V_ASN1_GENERALIZEDTIME);
4110    }
4111
4112    return ret;
4113}
4114
4115int wolfSSL_ASN1_TIME_set_string_X509(WOLFSSL_ASN1_TIME *t, const char *str)
4116{
4117    int ret = WOLFSSL_SUCCESS;
4118
4119    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_set_string_X509");
4120
4121    if (t == NULL)
4122        ret = WOLFSSL_FAILURE;
4123    if (ret == WOLFSSL_SUCCESS)
4124        ret = wolfSSL_ASN1_TIME_set_string(t, str);
4125    if (ret == WOLFSSL_SUCCESS)
4126        ret = wolfSSL_ASN1_TIME_check(t);
4127    return ret;
4128}
4129
4130/* Convert ASN.1 TIME object to ASN.1 GENERALIZED TIME object.
4131 *
4132 * @param [in]      t    ASN.1 TIME object.
4133 * @param [in, out] out  ASN.1 GENERALIZED TIME object.
4134 * @return  ASN.1 GENERALIZED TIME object on success.
4135 * @return  NULL when t is NULL or t has wrong ASN.1 type.
4136 * @return  NULL when dynamic memory allocation fails.
4137 */
4138WOLFSSL_ASN1_TIME* wolfSSL_ASN1_TIME_to_generalizedtime(WOLFSSL_ASN1_TIME *t,
4139    WOLFSSL_ASN1_TIME **out)
4140{
4141    WOLFSSL_ASN1_TIME *ret = NULL;
4142
4143    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_to_generalizedtime");
4144
4145    /* Validate parameters. */
4146    if (t == NULL) {
4147        WOLFSSL_MSG("Invalid ASN_TIME value");
4148    }
4149    /* Ensure ASN.1 type is one that is supported. */
4150    else if ((t->type != WOLFSSL_V_ASN1_UTCTIME) &&
4151             (t->type != WOLFSSL_V_ASN1_GENERALIZEDTIME)) {
4152        WOLFSSL_MSG("Invalid ASN_TIME type.");
4153    }
4154    /* Check for ASN.1 GENERALIZED TIME object being passed in. */
4155    else if ((out != NULL) && (*out != NULL)) {
4156        /* Copy into the passed in object. */
4157        ret = *out;
4158    }
4159    else {
4160        /* Create a new ASN.1 GENERALIZED TIME object. */
4161        ret = wolfSSL_ASN1_TIME_new();
4162        if (ret == NULL) {
4163            WOLFSSL_MSG("memory alloc failed.");
4164        }
4165    }
4166
4167    if (ret != NULL) {
4168        /* Set the ASN.1 type and length of string. */
4169        ret->type = WOLFSSL_V_ASN1_GENERALIZEDTIME;
4170
4171        if (t->type == WOLFSSL_V_ASN1_GENERALIZEDTIME) {
4172            ret->length = ASN_GENERALIZED_TIME_SIZE;
4173
4174            /* Just copy as data already appropriately formatted. */
4175            XMEMCPY(ret->data, t->data, ASN_GENERALIZED_TIME_SIZE);
4176        }
4177        else {
4178            /* Convert UTC TIME to GENERALIZED TIME. */
4179            ret->length = t->length + 2; /* Add two extra year digits */
4180
4181            if (t->data[0] >= '5') {
4182                /* >= 50 is 1900s.  */
4183                ret->data[0] = '1'; ret->data[1] = '9';
4184            }
4185            else {
4186                /* < 50 is 2000s.  */
4187                ret->data[0] = '2'; ret->data[1] = '0';
4188            }
4189            /* Append rest of the data as it is the same. */
4190            XMEMCPY(&ret->data[2], t->data, t->length);
4191        }
4192
4193        /* Check for pointer to return result through. */
4194        if (out != NULL) {
4195            *out = ret;
4196        }
4197    }
4198
4199    return ret;
4200}
4201
4202#if !defined(USER_TIME) && !defined(TIME_OVERRIDES)
4203WOLFSSL_ASN1_TIME* wolfSSL_ASN1_UTCTIME_set(WOLFSSL_ASN1_TIME *s, time_t t)
4204{
4205    WOLFSSL_ASN1_TIME* ret = s;
4206
4207    WOLFSSL_ENTER("wolfSSL_ASN1_UTCTIME_set");
4208
4209    if (ret == NULL) {
4210        ret = wolfSSL_ASN1_TIME_new();
4211        if (ret == NULL)
4212            return NULL;
4213    }
4214
4215    ret->length = GetFormattedTime(&t, ret->data, sizeof(ret->data));
4216    if (ret->length + 1 != ASN_UTC_TIME_SIZE) {
4217        /* Either snprintf error or t can't be represented in UTC format */
4218        if (ret != s)
4219            wolfSSL_ASN1_TIME_free(ret);
4220        ret = NULL;
4221    }
4222    else {
4223        ret->type = WOLFSSL_V_ASN1_UTCTIME;
4224    }
4225
4226    return ret;
4227}
4228#endif /* !USER_TIME && !TIME_OVERRIDES */
4229#endif /* OPENSSL_EXTRA */
4230
4231#if defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(OPENSSL_EXTRA)
4232/* Get string from ASN.1 TIME object.
4233 *
4234 * Not an OpenSSL compatibility API.
4235 *
4236 * @param [in]      t    ASN.1 TIME object.
4237 * @param [in, out] buf  Buffer to put string in.
4238 * @param [in]      len  Length of buffer in bytes.
4239 * @return  buf on success.
4240 * @return  NULL when t or buf is NULL, or len is less than 5.
4241 * @return  NULL when ASN.1 TIME length is larger than len.
4242 * @return  NULL when internal time format not valid.
4243 */
4244char* wolfSSL_ASN1_TIME_to_string(WOLFSSL_ASN1_TIME* t, char* buf, int len)
4245{
4246    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_to_string");
4247
4248    /* Validate parameters. */
4249    if ((t == NULL) || (buf == NULL) || (len < 5)) {
4250        WOLFSSL_MSG("Bad argument");
4251        buf = NULL;
4252    }
4253
4254    /* Check internal length against passed in length. */
4255    if ((buf != NULL) && (t->length > len)) {
4256        WOLFSSL_MSG("Length of date is longer then buffer");
4257        buf = NULL;
4258    }
4259
4260    /* Get time as human readable string. */
4261    if ((buf != NULL) && !GetTimeString(t->data, t->type, buf, len,
4262           t->length)) {
4263        buf = NULL;
4264    }
4265
4266    return buf;
4267}
4268
4269/* Number of characters in a UTC TIME string. */
4270#define UTCTIME_LEN     13
4271
4272/* Get year from UTC TIME string.
4273 *
4274 * @param [in]  str   UTC TIME string.
4275 * @param [in]  len   Length of string in bytes.
4276 * @param [out] year  Year as extracted from string.
4277 * @return  1 on success.
4278 * @return  0 when length is too short for a UTC TIME.
4279 * @return  0 when not ZULU time.
4280 */
4281static int wolfssl_utctime_year(const unsigned char* str, int len, int* year)
4282{
4283    int ret = 1;
4284
4285    /* Check minimal length for UTC TIME. */
4286    if (len < UTCTIME_LEN) {
4287        WOLFSSL_MSG("WOLFSSL_ASN1_TIME buffer length is invalid.");
4288        ret = 0;
4289    }
4290    /* Only support ZULU time. */
4291    if ((ret == 1) && (str[UTCTIME_LEN - 1] != 'Z')) {
4292        WOLFSSL_MSG("Expecting UTC time.");
4293        ret = 0;
4294    }
4295
4296    if (ret == 1) {
4297        if ((str[0] < '0') || (str[0] > '9') ||
4298            (str[1] < '0') || (str[1] > '9')) {
4299            WOLFSSL_MSG("Invalid characters in UTC year.");
4300            ret = 0;
4301        }
4302    }
4303
4304    if (ret == 1) {
4305        int tm_year;
4306        /* 2-digit year. */
4307        tm_year =  (str[0] - '0') * 10;
4308        tm_year +=  str[1] - '0';
4309        /* Check for year being in the 2000s. */
4310        if (tm_year < 50) {
4311            tm_year += 100;
4312        }
4313        *year = tm_year;
4314    }
4315
4316    return ret;
4317}
4318
4319/* Number of characters in a GENERALIZED TIME string. */
4320#define GENTIME_LEN     15
4321
4322/* Get year from GENERALIZED TIME string.
4323 *
4324 * @param [in]  str   GENERALIZED TIME string.
4325 * @param [in]  len   Length of string in bytes.
4326 * @param [out] year  Year as extracted from string.
4327 * @return  1 on success.
4328 * @return  0 when length is too short for a GENERALIZED TIME.
4329 * @return  0 when not ZULU time.
4330 */
4331static int wolfssl_gentime_year(const unsigned char* str, int len, int* year)
4332{
4333    int ret = 1;
4334
4335    /* Check minimal length for GENERALIZED TIME. */
4336    if (len < GENTIME_LEN) {
4337        WOLFSSL_MSG("WOLFSSL_ASN1_TIME buffer length is invalid.");
4338        ret = 0;
4339    }
4340    if ((ret == 1) && (str[GENTIME_LEN - 1] != 'Z')) {
4341        WOLFSSL_MSG("Expecting Generalized time.");
4342        ret = 0;
4343    }
4344
4345    if (ret == 1) {
4346        if ((str[0] < '0') || (str[0] > '9') ||
4347            (str[1] < '0') || (str[1] > '9') ||
4348            (str[2] < '0') || (str[2] > '9') ||
4349            (str[3] < '0') || (str[3] > '9')) {
4350            WOLFSSL_MSG("Invalid characters in generalized year.");
4351            ret = 0;
4352        }
4353    }
4354
4355    if (ret == 1) {
4356        int tm_year;
4357        /* 4-digit year. */
4358        tm_year =  (str[0] - '0') * 1000;
4359        tm_year += (str[1] - '0') * 100;
4360        tm_year += (str[2] - '0') * 10;
4361        tm_year +=  str[3] - '0';
4362        /* Only need value to be years since 1900. */
4363        tm_year -= 1900;
4364        *year = tm_year;
4365    }
4366
4367    return ret;
4368}
4369
4370/* Convert an ASN.1 TIME to a struct tm.
4371 *
4372 * @param [in] asnTime  ASN.1 TIME object.
4373 * @param [in] tm       Broken-down time. Must be non-NULL.
4374 * @return  1 on success.
4375 * @return  0 when string format is invalid.
4376 */
4377static int wolfssl_asn1_time_to_tm(const WOLFSSL_ASN1_TIME* asnTime,
4378    struct tm* tm)
4379{
4380    int ret = 1;
4381    const unsigned char* asn1TimeBuf;
4382    int asn1TimeBufLen;
4383    int i = 0;
4384    /* Parse into a local struct so the caller's tm is only written on
4385     * success. Avoids leaving a partially-populated struct behind when
4386     * the input fails validation. */
4387    struct tm localTm;
4388
4389    XMEMSET(&localTm, 0, sizeof(localTm));
4390
4391    /* Get the string buffer - fixed array, can't fail. */
4392    asn1TimeBuf = wolfSSL_ASN1_TIME_get_data(asnTime);
4393    /* Get the length of the string. */
4394    asn1TimeBufLen = wolfSSL_ASN1_TIME_get_length(asnTime);
4395    if (asn1TimeBufLen <= 0) {
4396        WOLFSSL_MSG("Failed to get WOLFSSL_ASN1_TIME buffer length.");
4397        ret = 0;
4398    }
4399    if (ret == 1) {
4400        if (asnTime->type == WOLFSSL_V_ASN1_UTCTIME) {
4401            /* Get year from UTC TIME string. */
4402            int tm_year;
4403            if ((ret = wolfssl_utctime_year(asn1TimeBuf, asn1TimeBufLen,
4404                    &tm_year)) == 1) {
4405                localTm.tm_year = tm_year;
4406                /* Month starts after year - 2 characters. */
4407                i = 2;
4408            }
4409        }
4410        else if (asnTime->type == WOLFSSL_V_ASN1_GENERALIZEDTIME) {
4411            /* Get year from GENERALIZED TIME string. */
4412            int tm_year;
4413            if ((ret = wolfssl_gentime_year(asn1TimeBuf, asn1TimeBufLen,
4414                    &tm_year)) == 1) {
4415                localTm.tm_year = tm_year;
4416                /* Month starts after year - 4 characters. */
4417                i = 4;
4418            }
4419        }
4420        else {
4421            /* No other time formats known. */
4422            WOLFSSL_MSG("asnTime->type is invalid.");
4423            ret = 0;
4424        }
4425    }
4426
4427    if (ret == 1) {
4428        int j;
4429        /* Validate 10 digits: MMDDHHMMSS. Length was already checked
4430         * (>= UTCTIME_LEN or >= GENTIME_LEN), so i+10 is in range. */
4431        for (j = i; j < i + 10; j++) {
4432            if (asn1TimeBuf[j] < '0' || asn1TimeBuf[j] > '9') {
4433                WOLFSSL_MSG("Non-digit in ASN.1 TIME.");
4434                ret = 0;
4435                break;
4436            }
4437        }
4438    }
4439
4440    if (ret == 1) {
4441        /* Fill in rest of broken-down time from string. */
4442        /* January is 0 not 1 */
4443        localTm.tm_mon   = (asn1TimeBuf[i] - '0') * 10; i++;
4444        localTm.tm_mon  += (asn1TimeBuf[i] - '0') - 1;  i++;
4445        localTm.tm_mday  = (asn1TimeBuf[i] - '0') * 10; i++;
4446        localTm.tm_mday += (asn1TimeBuf[i] - '0');      i++;
4447        localTm.tm_hour  = (asn1TimeBuf[i] - '0') * 10; i++;
4448        localTm.tm_hour += (asn1TimeBuf[i] - '0');      i++;
4449        localTm.tm_min   = (asn1TimeBuf[i] - '0') * 10; i++;
4450        localTm.tm_min  += (asn1TimeBuf[i] - '0');      i++;
4451        localTm.tm_sec   = (asn1TimeBuf[i] - '0') * 10; i++;
4452        localTm.tm_sec  += (asn1TimeBuf[i] - '0');
4453    }
4454
4455    if (ret == 1) {
4456        /* Range-check broken-down fields. ValidateGmtime returns 0 on
4457         * success. */
4458        if (ValidateGmtime(&localTm)) {
4459            WOLFSSL_MSG("Out-of-range field in ASN.1 TIME.");
4460            ret = 0;
4461        }
4462    }
4463
4464    if (ret == 1) {
4465        /* Publish to caller. */
4466        XMEMCPY(tm, &localTm, sizeof(*tm));
4467    #ifdef XMKTIME
4468        /* XMKTIME may set tm_isdst/tm_gmtoff on localTm; call after the
4469         * copy so those fields stay zero in the caller's tm. */
4470        XMKTIME(&localTm);
4471        tm->tm_wday = localTm.tm_wday;
4472        tm->tm_yday = localTm.tm_yday;
4473    #endif
4474    }
4475
4476    return ret;
4477}
4478
4479/* Get the current time into a broken-down time.
4480 *
4481 * @param [out] tm  Broken-time time.
4482 * @return  1 on success.
4483 * @return  0 when tm is NULL.
4484 * @return  0 when get current time fails.
4485 * @return  0 when converting Unix time to broken-down time fails.
4486 */
4487static int wolfssl_get_current_time_tm(struct tm* tm)
4488{
4489    int ret = 1;
4490    time_t currentTime;
4491    struct tm *tmpTs;
4492#if defined(NEED_TMP_TIME)
4493    /* for use with gmtime_r */
4494    struct tm tmpTimeStorage;
4495    tmpTs = &tmpTimeStorage;
4496#else
4497    tmpTs = NULL;
4498#endif
4499    (void)tmpTs;
4500
4501    /* Must have a pointer to return result into. */
4502    if (tm == NULL) {
4503        WOLFSSL_MSG("asnTime and tm are both NULL");
4504        ret = 0;
4505    }
4506    if (ret == 1) {
4507        /* Get current Unix Time GMT. */
4508        currentTime = wc_Time(0);
4509        if (currentTime <= 0) {
4510            WOLFSSL_MSG("Failed to get current time.");
4511            ret = 0;
4512        }
4513    }
4514    if (ret == 1) {
4515        /* Convert Unix Time GMT into broken-down time. */
4516        tmpTs = XGMTIME(&currentTime, tmpTs);
4517        if (tmpTs == NULL) {
4518            WOLFSSL_MSG("Failed to convert current time to UTC.");
4519            ret = 0;
4520        }
4521    }
4522    if (ret == 1) {
4523        /* Copy from the structure returned into parameter. */
4524        XMEMCPY(tm, tmpTs, sizeof(*tm));
4525    }
4526
4527    return ret;
4528}
4529
4530/* Convert ASN.1 TIME object's time into broken-down representation.
4531 *
4532 * Internal time string is checked when tm is NULL.
4533 *
4534 * @param [in]  asnTime  ASN.1 TIME object.
4535 * @param [out] tm       Broken-down time.
4536 * @return  1 on success.
4537 * @return  0 when asnTime is NULL and tm is NULL.
4538 * @return  0 getting current time fails.
4539 * @return  0 when internal time string is invalid.
4540 */
4541int wolfSSL_ASN1_TIME_to_tm(const WOLFSSL_ASN1_TIME* asnTime, struct tm* tm)
4542{
4543    int ret = 1;
4544
4545    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_to_tm");
4546
4547    /* If asnTime is NULL, then the current time is converted. */
4548    if (asnTime == NULL) {
4549        ret = wolfssl_get_current_time_tm(tm);
4550    }
4551    /* If tm is NULL this function performs a format check on asnTime only. */
4552    else if (tm == NULL) {
4553        ret = wolfSSL_ASN1_TIME_check(asnTime);
4554    }
4555    else {
4556        /* Convert ASN.1 TIME to broken-down time. */
4557        ret = wolfssl_asn1_time_to_tm(asnTime, tm);
4558    }
4559
4560    return ret;
4561}
4562
4563#ifndef NO_BIO
4564/* Print the ASN.1 TIME object as a string to BIO.
4565 *
4566 * @param [in] bio      BIO to write to.
4567 * @param [in] asnTime  ASN.1 TIME object.
4568 * @return  1 on success.
4569 * @return  0 when bio or asnTime is NULL.
4570 * @return  0 when creating human readable string fails.
4571 * @return  0 when writing to BIO fails.
4572 */
4573int wolfSSL_ASN1_TIME_print(WOLFSSL_BIO* bio, const WOLFSSL_ASN1_TIME* asnTime)
4574{
4575    int  ret = 1;
4576
4577    WOLFSSL_ENTER("wolfSSL_ASN1_TIME_print");
4578
4579    /* Validate parameters. */
4580    if ((bio == NULL) || (asnTime == NULL)) {
4581        WOLFSSL_MSG("NULL function argument");
4582        ret = 0;
4583    }
4584
4585    if (ret == 1) {
4586        char buf[MAX_TIME_STRING_SZ];
4587        int len;
4588
4589        /* Create human readable string. */
4590        if (wolfSSL_ASN1_TIME_to_string((WOLFSSL_ASN1_TIME*)asnTime, buf,
4591                sizeof(buf)) == NULL) {
4592            /* Write out something anyway but return error. */
4593            XMEMSET(buf, 0, MAX_TIME_STRING_SZ);
4594            XSTRNCPY(buf, "Bad time value", sizeof(buf)-1);
4595            ret = 0;
4596        }
4597
4598        /* Write out string. */
4599        len = (int)XSTRLEN(buf);
4600        if (wolfSSL_BIO_write(bio, buf, len) != len) {
4601            WOLFSSL_MSG("Unable to write to bio");
4602            ret = 0;
4603        }
4604    }
4605
4606    return ret;
4607}
4608#endif /* !NO_BIO */
4609
4610#endif /* WOLFSSL_MYSQL_COMPATIBLE || OPENSSL_EXTRA */
4611
4612#ifdef OPENSSL_EXTRA
4613
4614#ifndef NO_BIO
4615/* Print the ASN.1 UTC TIME object as a string to BIO.
4616 *
4617 * @param [in] bio      BIO to write to.
4618 * @param [in] asnTime  ASN.1 UTC TIME object.
4619 * @return  1 on success.
4620 * @return  0 when bio or asnTime is NULL.
4621 * @return  0 when ASN.1 type is not UTC TIME.
4622 * @return  0 when creating human readable string fails.
4623 * @return  0 when writing to BIO fails.
4624 */
4625int wolfSSL_ASN1_UTCTIME_print(WOLFSSL_BIO* bio, const WOLFSSL_ASN1_UTCTIME* a)
4626{
4627    int ret = 1;
4628
4629    WOLFSSL_ENTER("wolfSSL_ASN1_UTCTIME_print");
4630
4631    /* Validate parameters. */
4632    if ((bio == NULL) || (a == NULL)) {
4633        ret = 0;
4634    }
4635    /* Validate ASN.1 UTC TIME object is of type UTC_TIME. */
4636    if ((ret == 1) && (a->type != WOLFSSL_V_ASN1_UTCTIME)) {
4637        WOLFSSL_MSG("Error, not UTC_TIME");
4638        ret = 0;
4639    }
4640
4641    if (ret == 1) {
4642        /* Use generic time printing function to do work. */
4643        ret = wolfSSL_ASN1_TIME_print(bio, a);
4644    }
4645
4646    return ret;
4647}
4648#endif /* !NO_BIO */
4649
4650#endif /* OPENSSL_EXTRA */
4651
4652#endif /* !NO_ASN_TIME */
4653
4654/*******************************************************************************
4655 * ASN1_TYPE APIs
4656 ******************************************************************************/
4657
4658#if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
4659    defined(OPENSSL_EXTRA_X509_SMALL) || defined(WOLFSSL_WPAS_SMALL)
4660
4661/**
4662 * Allocate a new ASN.1 TYPE object.
4663 *
4664 * @return  New empty ASN.1 TYPE object on success.
4665 * @return  NULL when dynamic memory allocation fails.
4666 */
4667WOLFSSL_ASN1_TYPE* wolfSSL_ASN1_TYPE_new(void)
4668{
4669    WOLFSSL_ASN1_TYPE* ret;
4670
4671    /* Allocate a new ASN.1 TYPE object. */
4672    ret = (WOLFSSL_ASN1_TYPE*)XMALLOC(sizeof(WOLFSSL_ASN1_TYPE), NULL,
4673        DYNAMIC_TYPE_OPENSSL);
4674    if (ret != NULL) {
4675        /* Clear out fields. */
4676        XMEMSET(ret, 0, sizeof(WOLFSSL_ASN1_TYPE));
4677    }
4678
4679    return ret;
4680}
4681
4682/* Free the ASN.1 TYPE object's value field.
4683 *
4684 * @param [in, out] at  ASN.1 TYPE object.
4685 */
4686static void wolfssl_asn1_type_free_value(WOLFSSL_ASN1_TYPE* at)
4687{
4688    switch (at->type) {
4689        case WOLFSSL_V_ASN1_NULL:
4690            break;
4691        case WOLFSSL_V_ASN1_OBJECT:
4692            wolfSSL_ASN1_OBJECT_free(at->value.object);
4693            break;
4694        case WOLFSSL_V_ASN1_UTCTIME:
4695        #if !defined(NO_ASN_TIME) && defined(OPENSSL_EXTRA)
4696            wolfSSL_ASN1_TIME_free(at->value.utctime);
4697        #endif
4698            break;
4699        case WOLFSSL_V_ASN1_GENERALIZEDTIME:
4700        #if !defined(NO_ASN_TIME) && defined(OPENSSL_EXTRA)
4701            wolfSSL_ASN1_TIME_free(at->value.generalizedtime);
4702        #endif
4703            break;
4704        case WOLFSSL_V_ASN1_UTF8STRING:
4705        case WOLFSSL_V_ASN1_OCTET_STRING:
4706        case WOLFSSL_V_ASN1_PRINTABLESTRING:
4707        case WOLFSSL_V_ASN1_T61STRING:
4708        case WOLFSSL_V_ASN1_IA5STRING:
4709        case WOLFSSL_V_ASN1_UNIVERSALSTRING:
4710        case WOLFSSL_V_ASN1_SEQUENCE:
4711            wolfSSL_ASN1_STRING_free(at->value.asn1_string);
4712            break;
4713        default:
4714            break;
4715    }
4716}
4717
4718/**
4719 * Free ASN.1 TYPE object and its value.
4720 *
4721 * @param [in, out] at  ASN.1 TYPE object.
4722 */
4723void wolfSSL_ASN1_TYPE_free(WOLFSSL_ASN1_TYPE* at)
4724{
4725    if (at != NULL) {
4726        /* Dispose of value in ASN.1 TYPE object. */
4727        wolfssl_asn1_type_free_value(at);
4728    }
4729    /* Dispose of ASN.1 TYPE object. */
4730    XFREE(at, NULL, DYNAMIC_TYPE_OPENSSL);
4731}
4732
4733#endif /* OPENSSL_ALL || OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL ||
4734          WOLFSSL_WPAS_SMALL */
4735
4736#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
4737
4738int wolfSSL_i2d_ASN1_TYPE(WOLFSSL_ASN1_TYPE* at, unsigned char** pp)
4739{
4740    int ret = WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR);
4741
4742    if (at == NULL)
4743        return WOLFSSL_FATAL_ERROR;
4744
4745    switch (at->type) {
4746        case WOLFSSL_V_ASN1_NULL:
4747            break;
4748        case WOLFSSL_V_ASN1_OBJECT:
4749            ret = wolfSSL_i2d_ASN1_OBJECT(at->value.object, pp);
4750            break;
4751        case WOLFSSL_V_ASN1_UTF8STRING:
4752            ret = wolfSSL_i2d_ASN1_UTF8STRING(at->value.utf8string, pp);
4753            break;
4754        case WOLFSSL_V_ASN1_GENERALIZEDTIME:
4755            ret = wolfSSL_i2d_ASN1_GENERALSTRING(at->value.utf8string, pp);
4756            break;
4757        case WOLFSSL_V_ASN1_SEQUENCE:
4758            ret = wolfSSL_i2d_ASN1_SEQUENCE(at->value.sequence, pp);
4759            break;
4760        case WOLFSSL_V_ASN1_UTCTIME:
4761        case WOLFSSL_V_ASN1_PRINTABLESTRING:
4762        case WOLFSSL_V_ASN1_T61STRING:
4763        case WOLFSSL_V_ASN1_IA5STRING:
4764        case WOLFSSL_V_ASN1_UNIVERSALSTRING:
4765        default:
4766            WOLFSSL_MSG("asn1 i2d type not supported");
4767            break;
4768    }
4769
4770    return ret;
4771}
4772
4773#endif /* OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL */
4774
4775#if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
4776    defined(OPENSSL_EXTRA_X509_SMALL) || defined(WOLFSSL_WPAS_SMALL)
4777/**
4778 * Set ASN.1 TYPE object with a type and value.
4779 *
4780 * Type of value for different types:
4781 *   WOLFSSL_V_ASN1_NULL            : Value should be NULL.
4782 *   WOLFSSL_V_ASN1_OBJECT          : WOLFSSL_ASN1_OBJECT.
4783 *   WOLFSSL_V_ASN1_UTCTIME         : WOLFSSL_ASN1_TIME.
4784 *   WOLFSSL_V_ASN1_GENERALIZEDTIME : WOLFSSL_ASN1_TIME.
4785 *   WOLFSSL_V_ASN1_UTF8STRING      : WOLFSSL_ASN1_STRING.
4786 *   WOLFSSL_V_ASN1_PRINTABLESTRING : WOLFSSL_ASN1_STRING.
4787 *   WOLFSSL_V_ASN1_T61STRING       : WOLFSSL_ASN1_STRING.
4788 *   WOLFSSL_V_ASN1_IA5STRING       : WOLFSSL_ASN1_STRING.
4789 *   WOLFSSL_V_ASN1_UNINVERSALSTRING: WOLFSSL_ASN1_STRING.
4790 *   WOLFSSL_V_ASN1_SEQUENCE        : WOLFSSL_ASN1_STRING.
4791 *
4792 * @param [in, out] a      ASN.1 TYPE object to set.
4793 * @param [in]      type   ASN.1 type of value.
4794 * @param [in]      value  Value to store.
4795 */
4796void wolfSSL_ASN1_TYPE_set(WOLFSSL_ASN1_TYPE *a, int type, void *value)
4797{
4798    if (a != NULL) {
4799        switch (type) {
4800            case WOLFSSL_V_ASN1_NULL:
4801                if (value != NULL) {
4802                    WOLFSSL_MSG("NULL tag meant to be always empty!");
4803                    /* No way to return error - value will not be used. */
4804                }
4805                FALL_THROUGH;
4806            case WOLFSSL_V_ASN1_OBJECT:
4807            case WOLFSSL_V_ASN1_UTCTIME:
4808            case WOLFSSL_V_ASN1_GENERALIZEDTIME:
4809            case WOLFSSL_V_ASN1_UTF8STRING:
4810            case WOLFSSL_V_ASN1_OCTET_STRING:
4811            case WOLFSSL_V_ASN1_PRINTABLESTRING:
4812            case WOLFSSL_V_ASN1_T61STRING:
4813            case WOLFSSL_V_ASN1_IA5STRING:
4814            case WOLFSSL_V_ASN1_UNIVERSALSTRING:
4815            case WOLFSSL_V_ASN1_SEQUENCE:
4816                /* Dispose of any value currently set. */
4817                wolfssl_asn1_type_free_value(a);
4818                /* Assign anonymously typed input to anonymously typed field. */
4819                a->value.ptr = (char *)value;
4820                /* Set the type required. */
4821                a->type = type;
4822                break;
4823            default:
4824                WOLFSSL_MSG("Unknown or unsupported ASN1_TYPE");
4825                /* No way to return error. */
4826        }
4827    }
4828}
4829
4830int wolfSSL_ASN1_TYPE_get(const WOLFSSL_ASN1_TYPE *a)
4831{
4832    if (a != NULL && (a->type == WOLFSSL_V_ASN1_BOOLEAN ||
4833                      a->type == WOLFSSL_V_ASN1_NULL    ||
4834                      a->value.ptr != NULL)) {
4835        return a->type;
4836    }
4837    return 0;
4838}
4839
4840#endif /* OPENSSL_ALL || OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL ||
4841          WOLFSSL_WPAS_SMALL */
4842
4843#endif /* !NO_ASN */
4844
4845#endif /* !WOLFSSL_SSL_ASN1_INCLUDED */