Path: blob/main/crypto/openssl/engines/e_padlock.c
105977 views
/*1* Copyright 2004-2023 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89/*10* This file uses the low level AES and engine functions (which are deprecated11* for non-internal use) in order to implement the padlock engine AES ciphers.12*/13#define OPENSSL_SUPPRESS_DEPRECATED1415#include <stdio.h>16#include <string.h>1718#include <openssl/opensslconf.h>19#include <openssl/crypto.h>20#include <openssl/engine.h>21#include <openssl/evp.h>22#include <openssl/aes.h>23#include <openssl/rand.h>24#include <openssl/err.h>25#include <openssl/modes.h>2627#ifndef OPENSSL_NO_PADLOCKENG2829/*30* VIA PadLock AES is available *ONLY* on some x86 CPUs. Not only that it31* doesn't exist elsewhere, but it even can't be compiled on other platforms!32*/3334#undef COMPILE_PADLOCKENG35#if defined(PADLOCK_ASM)36#define COMPILE_PADLOCKENG37#ifdef OPENSSL_NO_DYNAMIC_ENGINE38static ENGINE *ENGINE_padlock(void);39#endif40#endif4142#ifdef OPENSSL_NO_DYNAMIC_ENGINE43void engine_load_padlock_int(void);44void engine_load_padlock_int(void)45{46/* On non-x86 CPUs it just returns. */47#ifdef COMPILE_PADLOCKENG48ENGINE *toadd = ENGINE_padlock();49if (!toadd)50return;51ERR_set_mark();52ENGINE_add(toadd);53/*54* If the "add" worked, it gets a structural reference. So either way, we55* release our just-created reference.56*/57ENGINE_free(toadd);58/*59* If the "add" didn't work, it was probably a conflict because it was60* already added (eg. someone calling ENGINE_load_blah then calling61* ENGINE_load_builtin_engines() perhaps).62*/63ERR_pop_to_mark();64#endif65}6667#endif6869#ifdef COMPILE_PADLOCKENG7071/* Function for ENGINE detection and control */72static int padlock_available(void);73static int padlock_init(ENGINE *e);7475/* RNG Stuff */76static RAND_METHOD padlock_rand;7778/* Cipher Stuff */79static int padlock_ciphers(ENGINE *e, const EVP_CIPHER **cipher,80const int **nids, int nid);8182/* Engine names */83static const char *padlock_id = "padlock";84static char padlock_name[100];8586/* Available features */87static int padlock_use_ace = 0; /* Advanced Cryptography Engine */88static int padlock_use_rng = 0; /* Random Number Generator */8990/* ===== Engine "management" functions ===== */9192/* Prepare the ENGINE structure for registration */93static int padlock_bind_helper(ENGINE *e)94{95/* Check available features */96padlock_available();9798/*99* RNG is currently disabled for reasons discussed in commentary just100* before padlock_rand_bytes function.101*/102padlock_use_rng = 0;103104/* Generate a nice engine name with available features */105BIO_snprintf(padlock_name, sizeof(padlock_name),106"VIA PadLock (%s, %s)",107padlock_use_rng ? "RNG" : "no-RNG",108padlock_use_ace ? "ACE" : "no-ACE");109110/* Register everything or return with an error */111if (!ENGINE_set_id(e, padlock_id) || !ENGINE_set_name(e, padlock_name) || !ENGINE_set_init_function(e, padlock_init) || (padlock_use_ace && !ENGINE_set_ciphers(e, padlock_ciphers)) || (padlock_use_rng && !ENGINE_set_RAND(e, &padlock_rand))) {112return 0;113}114115/* Everything looks good */116return 1;117}118119#ifdef OPENSSL_NO_DYNAMIC_ENGINE120/* Constructor */121static ENGINE *ENGINE_padlock(void)122{123ENGINE *eng = ENGINE_new();124125if (eng == NULL) {126return NULL;127}128129if (!padlock_bind_helper(eng)) {130ENGINE_free(eng);131return NULL;132}133134return eng;135}136#endif137138/* Check availability of the engine */139static int padlock_init(ENGINE *e)140{141return (padlock_use_rng || padlock_use_ace);142}143144#ifndef AES_ASM145static int padlock_aes_set_encrypt_key(const unsigned char *userKey,146const int bits,147AES_KEY *key);148static int padlock_aes_set_decrypt_key(const unsigned char *userKey,149const int bits,150AES_KEY *key);151#define AES_ASM152#define AES_set_encrypt_key padlock_aes_set_encrypt_key153#define AES_set_decrypt_key padlock_aes_set_decrypt_key154/* clang-format off */155# include "../crypto/aes/aes_core.c"156/* clang-format on */157#endif158159/*160* This stuff is needed if this ENGINE is being compiled into a161* self-contained shared-library.162*/163#ifndef OPENSSL_NO_DYNAMIC_ENGINE164static int padlock_bind_fn(ENGINE *e, const char *id)165{166if (id && (strcmp(id, padlock_id) != 0)) {167return 0;168}169170if (!padlock_bind_helper(e)) {171return 0;172}173174return 1;175}176177IMPLEMENT_DYNAMIC_CHECK_FN()178IMPLEMENT_DYNAMIC_BIND_FN(padlock_bind_fn)179#endif /* !OPENSSL_NO_DYNAMIC_ENGINE */180/* ===== Here comes the "real" engine ===== */181182/* Some AES-related constants */183#define AES_BLOCK_SIZE 16184#define AES_KEY_SIZE_128 16185#define AES_KEY_SIZE_192 24186#define AES_KEY_SIZE_256 32187/*188* Here we store the status information relevant to the current context.189*/190/*191* BIG FAT WARNING: Inline assembler in PADLOCK_XCRYPT_ASM() depends on192* the order of items in this structure. Don't blindly modify, reorder,193* etc!194*/195struct padlock_cipher_data {196unsigned char iv[AES_BLOCK_SIZE]; /* Initialization vector */197union {198unsigned int pad[4];199struct {200int rounds : 4;201int dgst : 1; /* n/a in C3 */202int align : 1; /* n/a in C3 */203int ciphr : 1; /* n/a in C3 */ /* codespell:ignore */204unsigned int keygen : 1;205int interm : 1; /* codespell:ignore */206unsigned int encdec : 1;207int ksize : 2;208} b;209} cword; /* Control word */210AES_KEY ks; /* Encryption key */211};212213/* Interface to assembler module */214unsigned int padlock_capability(void);215void padlock_key_bswap(AES_KEY *key);216void padlock_verify_context(struct padlock_cipher_data *ctx);217void padlock_reload_key(void);218void padlock_aes_block(void *out, const void *inp,219struct padlock_cipher_data *ctx);220int padlock_ecb_encrypt(void *out, const void *inp,221struct padlock_cipher_data *ctx, size_t len);222int padlock_cbc_encrypt(void *out, const void *inp,223struct padlock_cipher_data *ctx, size_t len);224int padlock_cfb_encrypt(void *out, const void *inp,225struct padlock_cipher_data *ctx, size_t len);226int padlock_ofb_encrypt(void *out, const void *inp,227struct padlock_cipher_data *ctx, size_t len);228int padlock_ctr32_encrypt(void *out, const void *inp,229struct padlock_cipher_data *ctx, size_t len);230int padlock_xstore(void *out, int edx);231void padlock_sha1_oneshot(void *ctx, const void *inp, size_t len);232void padlock_sha1(void *ctx, const void *inp, size_t len);233void padlock_sha256_oneshot(void *ctx, const void *inp, size_t len);234void padlock_sha256(void *ctx, const void *inp, size_t len);235236/*237* Load supported features of the CPU to see if the PadLock is available.238*/239static int padlock_available(void)240{241unsigned int edx = padlock_capability();242243/* Fill up some flags */244padlock_use_ace = ((edx & (0x3 << 6)) == (0x3 << 6));245padlock_use_rng = ((edx & (0x3 << 2)) == (0x3 << 2));246247return padlock_use_ace + padlock_use_rng;248}249250/* ===== AES encryption/decryption ===== */251252#if defined(NID_aes_128_cfb128) && !defined(NID_aes_128_cfb)253#define NID_aes_128_cfb NID_aes_128_cfb128254#endif255256#if defined(NID_aes_128_ofb128) && !defined(NID_aes_128_ofb)257#define NID_aes_128_ofb NID_aes_128_ofb128258#endif259260#if defined(NID_aes_192_cfb128) && !defined(NID_aes_192_cfb)261#define NID_aes_192_cfb NID_aes_192_cfb128262#endif263264#if defined(NID_aes_192_ofb128) && !defined(NID_aes_192_ofb)265#define NID_aes_192_ofb NID_aes_192_ofb128266#endif267268#if defined(NID_aes_256_cfb128) && !defined(NID_aes_256_cfb)269#define NID_aes_256_cfb NID_aes_256_cfb128270#endif271272#if defined(NID_aes_256_ofb128) && !defined(NID_aes_256_ofb)273#define NID_aes_256_ofb NID_aes_256_ofb128274#endif275276/* List of supported ciphers. */277static const int padlock_cipher_nids[] = {278NID_aes_128_ecb,279NID_aes_128_cbc,280NID_aes_128_cfb,281NID_aes_128_ofb,282NID_aes_128_ctr,283284NID_aes_192_ecb,285NID_aes_192_cbc,286NID_aes_192_cfb,287NID_aes_192_ofb,288NID_aes_192_ctr,289290NID_aes_256_ecb,291NID_aes_256_cbc,292NID_aes_256_cfb,293NID_aes_256_ofb,294NID_aes_256_ctr295};296297static int padlock_cipher_nids_num = (sizeof(padlock_cipher_nids) / sizeof(padlock_cipher_nids[0]));298299/* Function prototypes ... */300static int padlock_aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,301const unsigned char *iv, int enc);302303#define NEAREST_ALIGNED(ptr) ((unsigned char *)(ptr) + ((0x10 - ((size_t)(ptr) & 0x0F)) & 0x0F))304#define ALIGNED_CIPHER_DATA(ctx) ((struct padlock_cipher_data *) \305NEAREST_ALIGNED(EVP_CIPHER_CTX_get_cipher_data(ctx)))306307static int308padlock_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg,309const unsigned char *in_arg, size_t nbytes)310{311return padlock_ecb_encrypt(out_arg, in_arg,312ALIGNED_CIPHER_DATA(ctx), nbytes);313}314315static int316padlock_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg,317const unsigned char *in_arg, size_t nbytes)318{319struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx);320int ret;321322memcpy(cdata->iv, EVP_CIPHER_CTX_iv(ctx), AES_BLOCK_SIZE);323if ((ret = padlock_cbc_encrypt(out_arg, in_arg, cdata, nbytes)))324memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), cdata->iv, AES_BLOCK_SIZE);325return ret;326}327328static int329padlock_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg,330const unsigned char *in_arg, size_t nbytes)331{332struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx);333size_t chunk;334335if ((chunk = EVP_CIPHER_CTX_get_num(ctx))) { /* borrow chunk variable */336unsigned char *ivp = EVP_CIPHER_CTX_iv_noconst(ctx);337338if (chunk >= AES_BLOCK_SIZE)339return 0; /* bogus value */340341if (EVP_CIPHER_CTX_is_encrypting(ctx))342while (chunk < AES_BLOCK_SIZE && nbytes != 0) {343ivp[chunk] = *(out_arg++) = *(in_arg++) ^ ivp[chunk];344chunk++, nbytes--;345}346else347while (chunk < AES_BLOCK_SIZE && nbytes != 0) {348unsigned char c = *(in_arg++);349*(out_arg++) = c ^ ivp[chunk];350ivp[chunk++] = c, nbytes--;351}352353EVP_CIPHER_CTX_set_num(ctx, chunk % AES_BLOCK_SIZE);354}355356if (nbytes == 0)357return 1;358359memcpy(cdata->iv, EVP_CIPHER_CTX_iv(ctx), AES_BLOCK_SIZE);360361if ((chunk = nbytes & ~(AES_BLOCK_SIZE - 1))) {362if (!padlock_cfb_encrypt(out_arg, in_arg, cdata, chunk))363return 0;364nbytes -= chunk;365}366367if (nbytes) {368unsigned char *ivp = cdata->iv;369370out_arg += chunk;371in_arg += chunk;372EVP_CIPHER_CTX_set_num(ctx, nbytes);373if (cdata->cword.b.encdec) {374cdata->cword.b.encdec = 0;375padlock_reload_key();376padlock_aes_block(ivp, ivp, cdata);377cdata->cword.b.encdec = 1;378padlock_reload_key();379while (nbytes) {380unsigned char c = *(in_arg++);381*(out_arg++) = c ^ *ivp;382*(ivp++) = c, nbytes--;383}384} else {385padlock_reload_key();386padlock_aes_block(ivp, ivp, cdata);387padlock_reload_key();388while (nbytes) {389*ivp = *(out_arg++) = *(in_arg++) ^ *ivp;390ivp++, nbytes--;391}392}393}394395memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), cdata->iv, AES_BLOCK_SIZE);396397return 1;398}399400static int401padlock_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg,402const unsigned char *in_arg, size_t nbytes)403{404struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx);405size_t chunk;406407/*408* ctx->num is maintained in byte-oriented modes, such as CFB and OFB...409*/410if ((chunk = EVP_CIPHER_CTX_get_num(ctx))) { /* borrow chunk variable */411unsigned char *ivp = EVP_CIPHER_CTX_iv_noconst(ctx);412413if (chunk >= AES_BLOCK_SIZE)414return 0; /* bogus value */415416while (chunk < AES_BLOCK_SIZE && nbytes != 0) {417*(out_arg++) = *(in_arg++) ^ ivp[chunk];418chunk++, nbytes--;419}420421EVP_CIPHER_CTX_set_num(ctx, chunk % AES_BLOCK_SIZE);422}423424if (nbytes == 0)425return 1;426427memcpy(cdata->iv, EVP_CIPHER_CTX_iv(ctx), AES_BLOCK_SIZE);428429if ((chunk = nbytes & ~(AES_BLOCK_SIZE - 1))) {430if (!padlock_ofb_encrypt(out_arg, in_arg, cdata, chunk))431return 0;432nbytes -= chunk;433}434435if (nbytes) {436unsigned char *ivp = cdata->iv;437438out_arg += chunk;439in_arg += chunk;440EVP_CIPHER_CTX_set_num(ctx, nbytes);441padlock_reload_key(); /* empirically found */442padlock_aes_block(ivp, ivp, cdata);443padlock_reload_key(); /* empirically found */444while (nbytes) {445*(out_arg++) = *(in_arg++) ^ *ivp;446ivp++, nbytes--;447}448}449450memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), cdata->iv, AES_BLOCK_SIZE);451452return 1;453}454455static void padlock_ctr32_encrypt_glue(const unsigned char *in,456unsigned char *out, size_t blocks,457struct padlock_cipher_data *ctx,458const unsigned char *ivec)459{460memcpy(ctx->iv, ivec, AES_BLOCK_SIZE);461padlock_ctr32_encrypt(out, in, ctx, AES_BLOCK_SIZE * blocks);462}463464static int465padlock_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg,466const unsigned char *in_arg, size_t nbytes)467{468struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx);469int n = EVP_CIPHER_CTX_get_num(ctx);470unsigned int num;471472if (n < 0)473return 0;474num = (unsigned int)n;475476CRYPTO_ctr128_encrypt_ctr32(in_arg, out_arg, nbytes,477cdata, EVP_CIPHER_CTX_iv_noconst(ctx),478EVP_CIPHER_CTX_buf_noconst(ctx), &num,479(ctr128_f)padlock_ctr32_encrypt_glue);480481EVP_CIPHER_CTX_set_num(ctx, (size_t)num);482return 1;483}484485#define EVP_CIPHER_block_size_ECB AES_BLOCK_SIZE486#define EVP_CIPHER_block_size_CBC AES_BLOCK_SIZE487#define EVP_CIPHER_block_size_OFB 1488#define EVP_CIPHER_block_size_CFB 1489#define EVP_CIPHER_block_size_CTR 1490491/*492* Declaring so many ciphers by hand would be a pain. Instead introduce a bit493* of preprocessor magic :-)494*/495#define DECLARE_AES_EVP(ksize, lmode, umode) \496static EVP_CIPHER *_hidden_aes_##ksize##_##lmode = NULL; \497static const EVP_CIPHER *padlock_aes_##ksize##_##lmode(void) \498{ \499if (_hidden_aes_##ksize##_##lmode == NULL \500&& ((_hidden_aes_##ksize##_##lmode = EVP_CIPHER_meth_new(NID_aes_##ksize##_##lmode, \501EVP_CIPHER_block_size_##umode, \502AES_KEY_SIZE_##ksize)) \503== NULL \504|| !EVP_CIPHER_meth_set_iv_length(_hidden_aes_##ksize##_##lmode, \505AES_BLOCK_SIZE) \506|| !EVP_CIPHER_meth_set_flags(_hidden_aes_##ksize##_##lmode, \5070 | EVP_CIPH_##umode##_MODE) \508|| !EVP_CIPHER_meth_set_init(_hidden_aes_##ksize##_##lmode, \509padlock_aes_init_key) \510|| !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_##ksize##_##lmode, \511padlock_##lmode##_cipher) \512|| !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_##ksize##_##lmode, \513sizeof(struct padlock_cipher_data) + 16) \514|| !EVP_CIPHER_meth_set_set_asn1_params(_hidden_aes_##ksize##_##lmode, \515EVP_CIPHER_set_asn1_iv) \516|| !EVP_CIPHER_meth_set_get_asn1_params(_hidden_aes_##ksize##_##lmode, \517EVP_CIPHER_get_asn1_iv))) { \518EVP_CIPHER_meth_free(_hidden_aes_##ksize##_##lmode); \519_hidden_aes_##ksize##_##lmode = NULL; \520} \521return _hidden_aes_##ksize##_##lmode; \522}523524DECLARE_AES_EVP(128, ecb, ECB)525DECLARE_AES_EVP(128, cbc, CBC)526DECLARE_AES_EVP(128, cfb, CFB)527DECLARE_AES_EVP(128, ofb, OFB)528DECLARE_AES_EVP(128, ctr, CTR)529530DECLARE_AES_EVP(192, ecb, ECB)531DECLARE_AES_EVP(192, cbc, CBC)532DECLARE_AES_EVP(192, cfb, CFB)533DECLARE_AES_EVP(192, ofb, OFB)534DECLARE_AES_EVP(192, ctr, CTR)535536DECLARE_AES_EVP(256, ecb, ECB)537DECLARE_AES_EVP(256, cbc, CBC)538DECLARE_AES_EVP(256, cfb, CFB)539DECLARE_AES_EVP(256, ofb, OFB)540DECLARE_AES_EVP(256, ctr, CTR)541542static int543padlock_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids,544int nid)545{546/* No specific cipher => return a list of supported nids ... */547if (!cipher) {548*nids = padlock_cipher_nids;549return padlock_cipher_nids_num;550}551552/* ... or the requested "cipher" otherwise */553switch (nid) {554case NID_aes_128_ecb:555*cipher = padlock_aes_128_ecb();556break;557case NID_aes_128_cbc:558*cipher = padlock_aes_128_cbc();559break;560case NID_aes_128_cfb:561*cipher = padlock_aes_128_cfb();562break;563case NID_aes_128_ofb:564*cipher = padlock_aes_128_ofb();565break;566case NID_aes_128_ctr:567*cipher = padlock_aes_128_ctr();568break;569570case NID_aes_192_ecb:571*cipher = padlock_aes_192_ecb();572break;573case NID_aes_192_cbc:574*cipher = padlock_aes_192_cbc();575break;576case NID_aes_192_cfb:577*cipher = padlock_aes_192_cfb();578break;579case NID_aes_192_ofb:580*cipher = padlock_aes_192_ofb();581break;582case NID_aes_192_ctr:583*cipher = padlock_aes_192_ctr();584break;585586case NID_aes_256_ecb:587*cipher = padlock_aes_256_ecb();588break;589case NID_aes_256_cbc:590*cipher = padlock_aes_256_cbc();591break;592case NID_aes_256_cfb:593*cipher = padlock_aes_256_cfb();594break;595case NID_aes_256_ofb:596*cipher = padlock_aes_256_ofb();597break;598case NID_aes_256_ctr:599*cipher = padlock_aes_256_ctr();600break;601602default:603/* Sorry, we don't support this NID */604*cipher = NULL;605return 0;606}607608return 1;609}610611/* Prepare the encryption key for PadLock usage */612static int613padlock_aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,614const unsigned char *iv, int enc)615{616struct padlock_cipher_data *cdata;617int key_len = EVP_CIPHER_CTX_get_key_length(ctx) * 8;618unsigned long mode = EVP_CIPHER_CTX_get_mode(ctx);619620if (key == NULL)621return 0; /* ERROR */622623cdata = ALIGNED_CIPHER_DATA(ctx);624memset(cdata, 0, sizeof(*cdata));625626/* Prepare Control word. */627if (mode == EVP_CIPH_OFB_MODE || mode == EVP_CIPH_CTR_MODE)628cdata->cword.b.encdec = 0;629else630cdata->cword.b.encdec = (EVP_CIPHER_CTX_is_encrypting(ctx) == 0);631cdata->cword.b.rounds = 10 + (key_len - 128) / 32;632cdata->cword.b.ksize = (key_len - 128) / 64;633634switch (key_len) {635case 128:636/*637* PadLock can generate an extended key for AES128 in hardware638*/639memcpy(cdata->ks.rd_key, key, AES_KEY_SIZE_128);640cdata->cword.b.keygen = 0;641break;642643case 192:644case 256:645/*646* Generate an extended AES key in software. Needed for AES192/AES256647*/648/*649* Well, the above applies to Stepping 8 CPUs and is listed as650* hardware errata. They most likely will fix it at some point and651* then a check for stepping would be due here.652*/653if ((mode == EVP_CIPH_ECB_MODE || mode == EVP_CIPH_CBC_MODE)654&& !enc)655AES_set_decrypt_key(key, key_len, &cdata->ks);656else657AES_set_encrypt_key(key, key_len, &cdata->ks);658/*659* OpenSSL C functions use byte-swapped extended key.660*/661padlock_key_bswap(&cdata->ks);662cdata->cword.b.keygen = 1;663break;664665default:666/* ERROR */667return 0;668}669670/*671* This is done to cover for cases when user reuses the672* context for new key. The catch is that if we don't do673* this, padlock_eas_cipher might proceed with old key...674*/675padlock_reload_key();676677return 1;678}679680/* ===== Random Number Generator ===== */681/*682* This code is not engaged. The reason is that it does not comply683* with recommendations for VIA RNG usage for secure applications684* (posted at http://www.via.com.tw/en/viac3/c3.jsp) nor does it685* provide meaningful error control...686*/687/*688* Wrapper that provides an interface between the API and the raw PadLock689* RNG690*/691static int padlock_rand_bytes(unsigned char *output, int count)692{693unsigned int eax, buf;694695while (count >= 8) {696eax = padlock_xstore(output, 0);697if (!(eax & (1 << 6)))698return 0; /* RNG disabled */699/* this ---vv--- covers DC bias, Raw Bits and String Filter */700if (eax & (0x1F << 10))701return 0;702if ((eax & 0x1F) == 0)703continue; /* no data, retry... */704if ((eax & 0x1F) != 8)705return 0; /* fatal failure... */706output += 8;707count -= 8;708}709while (count > 0) {710eax = padlock_xstore(&buf, 3);711if (!(eax & (1 << 6)))712return 0; /* RNG disabled */713/* this ---vv--- covers DC bias, Raw Bits and String Filter */714if (eax & (0x1F << 10))715return 0;716if ((eax & 0x1F) == 0)717continue; /* no data, retry... */718if ((eax & 0x1F) != 1)719return 0; /* fatal failure... */720*output++ = (unsigned char)buf;721count--;722}723OPENSSL_cleanse(&buf, sizeof(buf));724725return 1;726}727728/* Dummy but necessary function */729static int padlock_rand_status(void)730{731return 1;732}733734/* Prepare structure for registration */735static RAND_METHOD padlock_rand = {736NULL, /* seed */737padlock_rand_bytes, /* bytes */738NULL, /* cleanup */739NULL, /* add */740padlock_rand_bytes, /* pseudorand */741padlock_rand_status, /* rand status */742};743744#endif /* COMPILE_PADLOCKENG */745#endif /* !OPENSSL_NO_PADLOCKENG */746747#if defined(OPENSSL_NO_PADLOCKENG) || !defined(COMPILE_PADLOCKENG)748#ifndef OPENSSL_NO_DYNAMIC_ENGINE749OPENSSL_EXPORT750int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns);751OPENSSL_EXPORT752int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns)753{754return 0;755}756757IMPLEMENT_DYNAMIC_CHECK_FN()758#endif759#endif760761762