Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quellcode-Bibliothek arm_smccc_trng.c

  Sprache: C
 

// SPDX-License-Identifier: GPL-2.0
/*
 * Randomness driver for the ARM SMCCC TRNG Firmware Interface
 * https://developer.arm.com/documentation/den0098/latest/
 *
 *  Copyright (C) 2020 Arm Ltd.
 *
 * The ARM TRNG firmware interface specifies a protocol to read entropy
 * from a higher exception level, to abstract from any machine specific
 * implemenations and allow easier use in hypervisors.
 *
 * The firmware interface is realised using the SMCCC specification.
 */


#include <linux/bits.h>
#include <linux/device.h>
#include <linux/hw_random.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/arm-smccc.h>

#ifdef CONFIG_ARM64
#define ARM_SMCCC_TRNG_RND ARM_SMCCC_TRNG_RND64
#define MAX_BITS_PER_CALL (3 * 64UL)
#else
#define ARM_SMCCC_TRNG_RND ARM_SMCCC_TRNG_RND32
#define MAX_BITS_PER_CALL (3 * 32UL)
#endif

/* We don't want to allow the firmware to stall us forever. */
#define SMCCC_TRNG_MAX_TRIES 20

#define SMCCC_RET_TRNG_INVALID_PARAMETER -2
#define SMCCC_RET_TRNG_NO_ENTROPY  -3

static int copy_from_registers(char *buf, struct arm_smccc_res *res,
          size_t bytes)
{
 unsigned int chunk, copied;

 if (bytes == 0)
  return 0;

 chunk = min(bytes, sizeof(long));
 memcpy(buf, &res->a3, chunk);
 copied = chunk;
 if (copied >= bytes)
  return copied;

 chunk = min((bytes - copied), sizeof(long));
 memcpy(&buf[copied], &res->a2, chunk);
 copied += chunk;
 if (copied >= bytes)
  return copied;

 chunk = min((bytes - copied), sizeof(long));
 memcpy(&buf[copied], &res->a1, chunk);

 return copied + chunk;
}

static int smccc_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
{
 struct arm_smccc_res res;
 u8 *buf = data;
 unsigned int copied = 0;
 int tries = 0;

 while (copied < max) {
  size_t bits = min_t(size_t, (max - copied) * BITS_PER_BYTE,
      MAX_BITS_PER_CALL);

  arm_smccc_1_1_invoke(ARM_SMCCC_TRNG_RND, bits, &res);

  switch ((int)res.a0) {
  case SMCCC_RET_SUCCESS:
   copied += copy_from_registers(buf + copied, &res,
            bits / BITS_PER_BYTE);
   tries = 0;
   break;
  case SMCCC_RET_TRNG_NO_ENTROPY:
   if (!wait)
    return copied;
   tries++;
   if (tries >= SMCCC_TRNG_MAX_TRIES)
    return copied;
   cond_resched();
   break;
  default:
   return -EIO;
  }
 }

 return copied;
}

static int smccc_trng_probe(struct platform_device *pdev)
{
 struct hwrng *trng;

 trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL);
 if (!trng)
  return -ENOMEM;

 trng->name = "smccc_trng";
 trng->read = smccc_trng_read;

 return devm_hwrng_register(&pdev->dev, trng);
}

static struct platform_driver smccc_trng_driver = {
 .driver = {
  .name  = "smccc_trng",
 },
 .probe  = smccc_trng_probe,
};
module_platform_driver(smccc_trng_driver);

MODULE_ALIAS("platform:smccc_trng");
MODULE_AUTHOR("Andre Przywara");
MODULE_DESCRIPTION("Arm SMCCC TRNG firmware interface support");
MODULE_LICENSE("GPL");

Messung V0.5 in Prozent
C=95 H=92 G=93

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.0Bemerkung:  (vorverarbeitet am  2026-06-07) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik