\begin{document}

\preprint{AIP/123-QED}

\title[]{Practical Semi-Device Independent Randomness Generation Based on Quantum State's Indistinguishability}

\author{Hamid Tebyanian}
\thanks{These authors contributed equally to this work.}
\affiliation{Dipartimento di Ingegneria dell'Informazione, Universit\`a degli Studi di Padova, via Gradenigo 6B, IT-35131 Padova, Italy}

\author{Mujtaba Zahidy}
\thanks{These authors contributed equally to this work.}
\affiliation{Dipartimento di Ingegneria dell'Informazione, Universit\`a degli Studi di Padova, via Gradenigo 6B, IT-35131 Padova, Italy}

\author{Marco Avesani}
\affiliation{Dipartimento di Ingegneria dell'Informazione, Universit\`a degli Studi di Padova, via Gradenigo 6B, IT-35131 Padova, Italy}

\author{Andrea Stanco}
\affiliation{Dipartimento di Ingegneria dell'Informazione, Universit\`a degli Studi di Padova, via Gradenigo 6B, IT-35131 Padova, Italy}

\author{Paolo Villoresi}
\affiliation{Dipartimento di Ingegneria dell'Informazione, Universit\`a degli Studi di Padova, via Gradenigo 6B, IT-35131 Padova, Italy}
\affiliation{Padua Quantum Technologies Research Center, Universit\`a degli Studi di Padova, via Gradenigo 6B, IT-35131 Padova, Italy}
\affiliation{Istituto di Fotonica e Nanotecnologie, CNR, via Trasea 7, IT-35131 Padova, Italy}

\author{Giuseppe Vallone}
\affiliation{Dipartimento di Ingegneria dell'Informazione, Universit\`a degli Studi di Padova, via Gradenigo 6B, IT-35131 Padova, Italy}
\affiliation{Padua Quantum Technologies Research Center, Universit\`a degli Studi di Padova, via Gradenigo 6B, IT-35131 Padova, Italy}
\affiliation{Dipartimento di Fisica e Astronomia, Universit\`a degli Studi di Padova, via Marzolo 8, IT-35131 Padova, Italy}

\begin{abstract}
Semi-device independent (Semi-DI)
quantum random number generators (QRNG) gained attention 
{for security applications}, offering an excellent trade-off between security and generation rate. 
This paper presents a proof-of-principle time-bin encoding semi-DI QRNG experiments based on a prepare-and-measure scheme. 
The protocol requires two simple assumptions and a measurable condition: an upper-bound on the prepared pulses' energy. 
We lower-bound the conditional min-entropy from the energy-bound and the input-output correlation, determining the amount of genuine randomness that can be certified.
Moreover, we present a generalized optimization problem for bounding the min-entropy in the case of multiple input and outcomes, in the form of a semidefinite program (SDP).
The protocol is tested with a simple experimental setup, 
capable of realizing two configurations for the ternary time-bin encoding 
scheme. The experimental setup is easy-to-implement and comprises commercially available off-the-shelf (COTS) components at the telecom wavelength, granting a secure and certifiable entropy source. 
The combination of ease-of-implementation,
scalability, high security level and output-entropy, make our system a promising candidate for commercial QRNGs. 
\end{abstract}
\maketitle

\section{Introduction}
The world of cybersecurity is developing exceedingly fast, and the data encrypted by the traditional encryption methods are facing the danger of being revealed. 
Producing unpredictable and certified random numbers is a critical part of every cryptographic operation. There are many simple techniques to generate random numbers that rely on a deterministic phenomenon, however, these generators' security cannot be guaranteed since, in principle, they can always be predicted. On the contrary, quantum mechanics provides randomness based on its intrinsic behavior, which theoretically is an unpredictable source of secure random numbers \cite{Ma2016,Acin2016}. 

The most common approach to generate random numbers through a quantum process is by trusting the experiment's apparatus: these protocols are called trusted-device QRNGs. Trusted-device QRNGs are cheap, high-rate, and easy-to-implement \cite{Stanco2020,Regazzoni2021}, although the random numbers' security and privacy could be threatened \cite{QRNG_attack,QRNG_attack2}.
In fact, the behaviour of the trusted devices could deviate from the model and classical or quantum side-information could be leaked to the adversary's system, compromising the privacy of the numbers. Therefore, trust in the generator's devices can compromise the security of the system.
The highest level of security is offered by an approach called device-independent (DI) \cite{DI_Pironio_2010,DI_roger}. Considering there is no hypothesis on the devices' internal-working regularity, it is highly protected. However, this protocol's drawbacks are the low generation-rate and experimental complexity, making it less practical~\cite{Liu2021,Liu2018a,Zhang2020,DI_new,foletto2021experimental}. 

By introducing few assumptions on the working principles of the devices, it is possible to reduce the experimental complexity while increasing the generation rate; these protocols are called semi-DI \cite{Ma2016,Supic2020,tavakoli2021semideviceindependent}. The semi-DI scheme's assumptions can vary depending on users' needs, e.g.  source-DI~\cite{Ma_new1,avesani2020unbounded,Avesani2018, PhysRevX_SDI} have trusted measurement devices, or measurement-DI~\cite{MDI,MDI2}, where the
source device is 
trusted.
At the same time, there are protocols with weaker assumptions, e.g., bounding the state's overlap or  energy~\cite{tebyanian2020semidevice,Brask2017,Rusca2020,avesani2020}, granting a higher level of security.

In this work, by extending the approach proposed in~\cite{Brask2017} we demonstrate a semi-DI QRNG based on the ambiguity in discriminating non-orthogonal quantum states \cite{state_dis}.
Non-orthogonal quantum states can not be perfectly distinguished due to the inevitable uncertainty imposed by the quantum theory. This uncertainty can be exploited, as in this protocol, to generate secure and private random numbers.
A security estimation based on state overlap and unambiguous state discrimination was first derived in \cite{Brask2017, VanHimbeeck2017semidevice} and later implemented for coherent detection schemes in \cite{avesani2020,Rusca2020,tebyanian2020semidevice}.

We generalized the security framework initially presented in \cite{Brask2017}
in the case of a larger number of inputs and outputs (for more details and comparison, see Appendix \ref{app:c}).
We implement the protocol with a photonic setup based on a time-bin encoding with two configurations. In both configurations, we consider three inputs, while four and seven outcomes are tested in the respective structures.

The experimental setup is based on a prepare-and-measure scheme that features all-in-fiber commercially off-the-shelf (COTS) components at the telecom wavelength (1550 nm). The output entropy is evaluated given the correlation of the input-output data $p(b|x)$ along with the bound on the input states' energy that is the single measurable condition of this semi-DI QRNG. Furthermore, the user is capable of {monitoring} on-the-fly that the bound on the energy used to calculate the randomness rate is indeed verified by the given devices.
Note that we assume that the inputs are identically and independently distributed (I.I.D. hypothesis).

The reduced number of assumptions with respect to other types of semi-DI QRNG allows to reduce the trust in the employed devices, thus increasing its security, while keeping its performance on par with the commercial QRNGs \cite{gras2020quantum}. 
Finally, this implementation can be further miniaturized by integrating it directly on a chip as shown in \cite{QRNG_chip}. 

\section{ Framework }
\subsection{Protocol}
The experimental setup is based on a prepare-and-measure scheme, see Fig. \ref{fig:general}. A ternary input $x\in \{0,1,2\}$ is fed into the preparation device,
which prepares, accordingly,  a quantum state $\hat\rho_x$, that is sent to the measurement station. Here, after the measurement of the quantum state, the station returns an output $b\in 0,1,\cdots,d-1$.
The preparation and measurement devices are considered black boxes, with two simple assumptions 
on the preparation device: 
the prepared states are identically and independently distributed (I.I.D. hypothesis) and
no correlations between the preparation device and any external device are present. Randomness can be certified if the following  bound, 
easy-to-verify experimentally, holds on the energy of the prepared states:
\begin{equation}
\langle \hat N\rangle_{\rho_x}\leq \mu\,, \quad \forall x,
\label{energy_bound1}
\end{equation}
where $\hat N$ is the photon number operator 
(i.e. the energy of the state) and $\mu$ is its upper-bound.

\begin{figure}
\caption{ General schematic of the protocol; depending on the input $x$, the preparation device emits a quantum state $\rho_x$, with a single condition on the states' energy. The measurement site outputs $b$ after detecting the received states, as there is no assumption on the receiver side, it can be regarded as a black box.}
\label{fig:general}
\end{figure}
If $\mu$ is below a certain threshold, the emitted states must be close to the vacuum, and so they must share some unavoidable overlap.
According to quantum mechanics,
non-orthogonal quantum states can not be deterministically distinguished
meaning that outcomes of any measurement cannot be predicted with certainty. 

From this simple idea it is possible to show that the amount of extractable randomness can be evaluated only by knowing the energy bound and the input-output correlations $P(b|x)$,
in a semi-DI way.
Indeed, the observation of certain correlations certifies that no pre-established strategies can fully reproduce the measured outcomes.
The values of the correlations allow to certify their quantum nature and allows to bound the amount of entropy in the outcomes. 

The scheme can be described as follows: the preparation device produces quantum states $\hat\rho_x$ while the measurement device performs a 
positive-operator valued measurement (POVM) $\hat \Pi_b^\lambda$. The classical variable $\lambda$, known to the adversary (e.g. the producer of the devices), represents the correlations between the measurement devices
and the adversary. Each different realization $\hat \Pi_b^\lambda$ labeled by $\lambda$ can be implemented with probability $p_\lambda$.
The input-output correlations $P(b|x)$ can then be written as
\begin{equation}
p(b|x) = \sum\limits_\lambda  {p_\lambda} 
\text{Tr}[\hat\rho_x \hat\Pi_b^\lambda],
\label{eq:constraints}
\end{equation}
In order to bound the amount of private randomness that can be certified we need to bound, the guessing probability $P_{\rm guess}$: the latter represents the maximum probability of guessing the outcome of the measurement device $b$ from the adversary point of view which
has full knowledge of the fundamental working principle of the experiment apparatus and the input $x$. $P_{\rm guess}$ can be evaluated as follows:
\begin{equation}
P_{\rm guess} =  \max \limits_{\{ p_\lambda ,\hat\rho_x,\hat\Pi _b^\lambda\}}
\left(\sum_{x} p_x \sum_{\lambda} p_\lambda 
\max_b \bigg\{ \Tr[\hat\rho_x \hat\Pi^\lambda_b] \bigg\}\right),
\label{eq:P_g}
\end{equation}
where $p_x$ is the probability of transmitting $x$.
We assume that the probability of sending different inputs ($x$) is balanced $p_x=\frac13$.
The overall maximization is performed on the states and operators $\{ p_\lambda ,\hat\rho_x,\hat\Pi _b^\lambda\}$ that are compatible with the observed correlations and thus satisfy the constraint of Eq. ~\eqref{eq:constraints}.

Following the same approach shown in \cite{Brask2017},
since
the preparation device shares no correlation with the environment, the maximum  $P_{\rm guess}$ is achieved when the states $\hat\rho_x$ are pure states, $\hat\rho_x=\ket{\psi_x}\bra{\psi_x}$.
Since the energy bound~\eqref{energy_bound1} implies on pure states a bound on their overlap (see~\cite{Himbeeck2019CorrelationsConstraints,avesani2020}) $|\braket{\psi_x}{\psi_y}|\geq1-2\mu\equiv\delta$, the choice that maximize  $P_{\rm guess}$ is obtained when the bound is saturated, namely $|\braket{\psi_x}{\psi_y}|=\delta$, $\forall x,y$.
Then, without losing generalities, the three states $\ket{\psi_x}$ can be then written as a linear combination of three orthonormal states $\ket{0}$,
$\ket{1}$, $\ket{2}$ as follows:
\begin{equation}
\begin{aligned}
    \ket{\psi_0}&=\ket0\,,
    \\
    \ket{\psi_1}&=\delta \ket0+
    \sqrt{1-\delta^2}\ket1\,,
    \\
    \ket{\psi_2}&=\delta \ket0+
    \delta \sqrt{\frac{1-\delta}{1+\delta}}\ket1 +
    \sqrt{\frac{1+\delta-2\delta^2}{1+\delta}}
    \ket2 
\end{aligned}
\label{state:ternary}
\end{equation}
while  $P_{\rm guess}$ can be written as
\begin{equation}
 P_{\rm guess} = \frac{1}{3} \max \limits_{\{ p_\lambda ,\Pi _b^\lambda\}} 
\left( \sum\limits_{x = 0}^{2} \sum\limits_{\lambda}^{d-1} {p_\lambda } \max\limits_{b}  \bigg[ \bra{\psi_x}\Pi^\lambda_b\ket{\psi_x} \bigg] \right)
\label{eq:P_g2}
\end{equation}
It is possible to cast Eq. (\ref{eq:P_g2}) into an semi-definite programming (SDP) problem, which can be efficiently solved (see appendix \ref{app:a}).
By inserting the input-output correlations $p(b|x)$ into the SDP, we can obtain a bound $P_{\rm g}$ on the guessing probability  and the conditional min-entropy\cite{entropy}
that quantifies the amount of private randomness 
\begin{equation}
\label{eq:Hmin}
{
H_{\rm min}=-\log_2 \{ P_{g}\}.
}
\end{equation}
\begin{figure}
\caption{ \textit{Blue-box:}
\label{fig:conf1}
\end{figure}
Finally, after obtaining a bound on the min-entropy, secure and private random numbers can be obtained thanks to the Leftover Hashing Lemma, using a Toeplitz  randomness extractor~\cite{Tomamichel2011}.
\subsection{Implementation}
{The semi-DI protocol with ternary inputs and multiple outcomes described in the previous section can be implemented in different ways. In this work we present}
 two configurations based on the ternary time-bin encoding 
 {shown in the top box of Fig. \ref{fig:conf1}}. In the first configuration (Config. I), the transmitter emits a coherent state $\ket{\alpha}$ once every three bins,
 {while in the other two time-bins} the vacuum state is present. In contrast, in the second configuration (Config. II), the vacuum state and weak coherent pules are reversed. 
 For both configurations
we choose $\mu=|\alpha|^2$ such that the condition written in eq. \eqref{energy_bound1}
is satisfied.

The main advantage of such implementations is the low experimental complexity of the state's preparation and the possibility to easily monitor the energy of the prepared states.
{For the first configuration (Config. I), shown in Fig. \ref{fig:conf1} (lower box),} four possible outcomes $b \in \{0,1,2,3\}$ are considered, where $b=0$, $b=1$, and $b=2$ occur when a detection is registered in the early ($bin_0$), middle ($bin_1$), and late ($bin_2$) time-interval, respectively,  and if no click or more than one click
is recorded, then the outcome is $b=3$.
\begin{figure*}
\caption{Experimental setup: A pulsed laser emits pulses at 1550 nm to a polarization controller (PC) and then a
Sagnac interferometer (SI).
One path in
the SI is experiencing either an extra $0$ or $\pi$-phase shift with respect to the other one. The two parts interfere and recombine at the beam-splitter (BS). Depending on the phase shift, light is redirected to either output or back to the input. Later the single photons are detected with a single-photon detector, in this case, an SNSPD. A time to digital converter (TDC) converts the SNSPD detection event to time-stamps which are analyzed in post-processing. A field-programmable gate array (FPGA) provides the electrical signal to drive the laser driver (LD), phase modulator, and synchronization clock.}
\label{fig:setup}
\end{figure*}
On the other hand, for the second configuration (Config. II), 
a larger number of outcomes are possible. 
Let's for instance consider the case where $x=0$ is chosen for Config. II (see Fig. \ref{fig:general}).
Due to the low values of $\alpha$ imposed by the energy bound and the non-unity efficiency of the detectors, it is possible that only one of the two pulses is detected ($b=3$ or $b=4$ in Fig. \ref{fig:conf1}), or no pulses at all ($b=6$ in Fig. \ref{fig:conf1}). Thus, the total number of outcomes is increased from four to seven, with respect to the previous configuration.

\subsection{Input-output Correlation}
Depending on the input $x$, the transmitter sends one of the ternary states represented in Fig. \ref{fig:general}. We underline that the input $x$ are identically distributed and independent from the devices.
The states are measured at the receiver through a single-photon detector, in this case, a superconducting nanowire single-photon detector (SNSPD) \cite{SNSPD}. Based on the detection events and their
{arrival times}, the receiver outputs $b \in \{0,1,2,3\}$, or $\{0,1,2,3,4,5,6\}$.
{Given} the inputs $x$, and outputs $b$, we can compute the input-output correlation of the measurement and preparation devices $p(b|x)$, namely the probability of obtaining outcome $b$ given the input $x$.

In practice, the experimental setup is always combined with imperfections, mainly originated from the experimental apparatus; therefore, considering an
ideal measurement
would over-simplify our detection model. For example, the detector's dark count, background noise or imperfections in the state preparation, could lead to a theoretically impossible detection event. 
Therefore, we take these effects into account by introducing a value $\epsilon$ associated with the noise. We point out that the parameter $\epsilon$ is only useful for a correct modeling of the expected experimental probabilities, but it is not used in the $P_{\rm guess}$ evaluation and it has no impact on the security and performances of the protocol. 

The models used to describe the conditional probabilities $p(b|x)$ are the following:

\uline{Config. I}, $\forall x \in \{0,1,2\}$
\begin{equation}
\begin{aligned}
& p(b=x|x)= (1-\xi+\xi\epsilon)(1-\epsilon)^2\,, \\
& p(b \neq x\wedge b\neq 3|x)= \xi\epsilon (1-\epsilon)^2\,,
\\
& p(b=3|x)=  1-p(b\neq 3|x)\,, \\
\end{aligned}
\label{prob:congig 1}
\end{equation}
where $\xi = |\bra{\alpha}\ket{0}|^2=e^{-|\alpha|^2}$.

\uline{Config. II}, $\forall x \in \{0,1,2\}$
\begin{equation}
\begin{aligned}
& p(b=x|x)= (1-\xi+\xi\epsilon)^2(1-\epsilon) \,,
\\
& p(b=\varnothing_x|x)=  (1-\xi+\xi\epsilon)\xi(1-\epsilon)^2\,,
\\
& p(b=\varnothing''_x|x)=  \epsilon\xi^2(1-\epsilon)^2 \,,
\\
& p(b \neq x\wedge b<3|x)= (1-\xi+\xi\epsilon) \epsilon\xi(1-\epsilon) \,,
\\
& p(b=6|x)=  1-p(b\neq 6|x) \,.
\end{aligned}
\label{prob:congig 2}
\end{equation}
where $\varnothing' \in \{b=6\}$, $\varnothing_0 \in \{b=3,b=4\}$, $\varnothing_1 \in \{b=3,b=5\}$, $\varnothing_2 \in \{b=4,b=5\}$, $\varnothing''_0 \in \{b=5\}$, $\varnothing''_1 \in \{b=4\}$, and $\varnothing''_2 \in \{b=3\}$. Inserting these probabilities to the SDP (Eq. \ref{eq:SDP_primal}), we can compute the expected achievable min-entropy $H_{min}$ with our system. 

The advantage of this scheme 
compared with other solutions based on coherent detection is the simplicity 
of the experimental setup, which
does not require any 
complex phase-correction 
stabilization or further post-processing.
These advantages are particularly relevant for real-time implementations.
On the other hand, the possible drawback could be the random number generation rate, which, compared with similar continuous-variable systems \cite{avesani2020,Rusca2020}, is drastically lower, due to the high dead-time of the current SPDs~\cite{SPD}. 

\section{Experiment}

The experimental setup is depicted in Fig. \ref{fig:setup}. The realization is based on an all-in-fiber scheme with components that are commercially available off-the-shelf (COTS). The setup's core is a fast and self-stabilized optical switch based on Sagnac interferometer (SI)\cite{Roberts:18}, capable of operating up to GHz range. 
The switch is comprised of a ($50:50$) polarization-maintaining (PM) fiber-beamsplitter (BS), PM fiber delay line and a LiNbO\textsubscript{3} phase modulator (MPZ-LN-20 by iXblue). The ($50:50$) BS is used to split a pulse in two that travel in the Sagnac loop clockwise (CW) and counter-clockwise (CCW). The phase modulator applies a $0$ or $\pi$-phase shift to the CW pulse while leaving the CCW one intact. The two parts are then recombined again at the BS and according to the phase modulation value are either redirected to the trusted part and then measurement unit or send back toward the laser where it is blocked by the internal isolator.
\begin{figure*}
\caption{The conditional min-entropy as a function of the mean-photon number $\mu$ for Config. I (left-side), and Config. II (right-side). The dashed and solid-line curves show the theoretical prediction with and without the experimental loss, respectively. The green dots represent the experimental data.
An SNSPD with detection efficiency equal to $75\%$ is used for Config. II, while an SNSPD with higher detection efficiency, $90\%$, is used for the Cofing. I.}
\label{fig:entropy}
\end{figure*}
The main advantage of the self-compensating 
Sagnac implementation over other types of intensity 
modulators is its resilience against phase fluctuations, ensuring very high extinction ratio at the output as well as high speed and long-term stability.
Unlike other intensity modulator this device does not requires to be stabilized in temperature or bias voltage.

A pulsed laser emitting at 1550 nm with ~2 ns pulse-width and fixed repetition rate of 10 MHz generates the train of pulses, which is first sent to a polarization controller (PC) and then to the input port of the switch. The input power is controlled accurately by changing its polarization via the polarization controller, where the PM-fiber BS acts as a polarizer. The output port of the switch is connected to a ($90:10$) PM-fiber BS, where the $90\%$ output is used to monitor the power and the $10\%$ is further transmitted along the optical path for the randomness generation.

A field programmable gate array (FPGA) board (ZedBoard by Avnet) provides the electrical signals to trigger the laser driver (LD) as well as phase modulation and a clock signal to synchronize the events. The phase modulation signal is amplified with an RF amplifier and then is used to drive the phase modulator.
States $\rho_x$ are generated by properly switching the input pulse, removing two (one) from every three pulses of the pulse train in Config. I (II). A typical output of the optical switch for Config. I is depicted in Fig. \ref{fig:setup}. An arbitrary sequence can be fed into the FPGA to perform the switching.
Two sequences of randomly distributed states, according to Config. I and II, are created and used for the experiment.    

Finally, the mean photon number at the exit of the transmitter is regulated with extra attenuation (Att.) set properly at the beginning of the experiment and is left fixed to maintain the ratio of the output power and monitor.
Prior to each run, the power is monitored and the average mean photon number per pulse is registered for the SDP and post-processing stages. 

For the measurement, we exploited SNSPDs with different detection efficiencies to inspect matching of the results with the theoretical predictions for each configuration. Further analysis of the performances as a function of the detection efficiency is contained in Appendix~\ref{app:c}. The very low dark count and dead-time of SNSPDs allow for measurement and symbol detection at high repetition rates where, for example, $\mu$-second range hold-off time of single-photon avalanche diodes (SPAD) limits the detection rate to tens of kilo-symbols per second.
Detection events are tagged with a time-to-digital converter (TDC) and the data is sent to a computer for post-processing. 
From the set of detections $b$ and the string of input $x$, it was possible to obtain the experimental conditional probabilities $p(b|x)$ for both configurations shown in Fig. \ref{fig:conf1}. 
\section{Results}
This section presents the 
results obtained from the experimental data.
We compare this experimental results with the model given by Eq. \eqref{prob:congig 1} and Eq. \eqref{prob:congig 2}
After implementing the experimental setup, represented in Fig. \ref{fig:setup}, we performed several measurement-runs with various mean-photon numbers $\mu$. The mean-photon number is determined by a calibrated optical powermeter per operation run, represented in the green box in Fig. \ref{fig:setup}. 
Collecting the receiver's outcomes $b$, and given the input sequence $x$, we calculate the input-output correlation $p(b|x)$. The extractable amount of randomness is then estimated by inserting $p(b|x)$ and $\mu$'s experimental values into the SDP code.

Fig. \ref{fig:entropy} shows the conditional min-entropy 
per measurement, as a function of the mean-photon number for the two supported configurations.
The experimentally obtained error value for Config. I and II are $\epsilon=10^{-5}$, and $\epsilon=10^{-4}$ respectively.
The difference in the 
$\epsilon$ values is due to the switch performance, noise and dark count rate (DCR) of the detectors which are $\simeq70$cps and $\simeq1400$cps in free-running, respectively. 

This shows an excellent stability and performance of the switch as well as the detectors.
In both plots, the blue curve represents the theoretical prediction without considering detection loss (perfect detector), while in the dashed orange curve, the losses (e.g., detector's efficiency) are also considered.
The green dots correspond to the experimental data obtained with two SNSPDs with different efficiencies; $90\%$ (used for Config. I), and $75\%$ (used for Config. II). Comparing the experimental data and theoretical predictions, we see an excellent agreement between them. 

From the theoretical model,
the maximum conditional min-entropy with a lossless detector is 0.258, and 0.349 bits per measurement {for Config. I and II, respectively}. They occur when the mean-photon number $\mu$ is roughly around $0.18$, and $0.164$ for Config. I and II.

Nevertheless, taking the losses into consideration, the conditional min-entropy recedes from its optimum value. Indeed the output entropy is very sensitive to the detector efficiency and losses. A comprehensive study of the amount of extractable randomness versus detectors' efficiency for two different assumptions (energy and overlap) is presented in Appendix \ref{app:c}.
Taking into account the parameters $\eta$ and $\epsilon$ that model our experiment, the maximum min-entropy that can be achieved experimentally are  0.183 and 0.23 for Config. I and II, respectively. We point our that the two configurations were not tested experimentally at their optimal points, but we tested they systems for some $  \mu$ values as a proof-of-principle demonstration.

Exploiting an optical switch rather than modulating the pulses directly on the laser has the advantage of avoiding fluctuations in mean photon number per pulse at the source due to laser cavity relaxation time. 
Besides, implementing binary or ternary states and states with higher number of time bins, e.g., $4$, $5$, etc., and various configurations can be readily done with this experimental setup, provided that the input to the FPGA is modified accordingly. Appendix \ref{app:c} compares the conditional min-entropy for several time-bins strategies.

Finally, it should be noted that this is a proof-of-principle experiment, and it can be significantly improved and optimized in forthcoming works, particularly by utilizing integrated photonics.

\section{conclusion}
In conclusion, we have presented a practical 
semi-DI QRNG based on
{ternary input} and measurements with multiple outcomes. 
Furthermore, we showed that it is possible to
{realize} two different implementations with a
{simple} setup based on
time-bin encoding. In addition, we compared our results with a binary modulated system and showed that by increasing the number of inputs from two to three, the output randomness increases accordingly. 
The proposed protocol features an increased security with respect to common QRNG, since it only requires two simple assumptions and a measurable condition on the prepared pulses' energy. 
The latter condition is experimentally easier to verify respect to other semi-DI protocol, for example based on an overlap bound.
Simultaneously, the protocol is practical,
since it can be implemented with a simple all-fiber optical setup at telecom wavelength with only commercial off-the-shelf components.
The performances of this proof-of-principle implementation could be further increased using faster repetition rates, faster modulation or integrated optics.

The proposed setup can also be useful to test higher 
dimensional states from an experimental point of view. 
In fact, this implementation only requires binary electrical signals even for higher dimensional states, while coherent systems require multi-amplitude modulations, increasing the complexity of the driving electronics.
Compared to the security estimation presented in \cite{Himbeeck2019CorrelationsConstraints}, our security evaluation requires an additional assumption (I.I.D hypothesis). Nevertheless, our protocol can be readily generalized for more input-outcome cases, 
while it is not clear how the security estimation provided in \cite{Himbeeck2019CorrelationsConstraints} can be generalized for more input and outputs.
Indeed, one of the main objectives of semi-DI protocols is to facilitate the implementation and improve the generation rate while keeping the security relatively high, which is contemplated in our protocol.
To conclude, our work shows how the increased number of input and output can improve the secure generation rate of QRNG in the semi-DI framework for future devices with simple experimental setups and high-security levels.

\begin{acknowledgments}
This work was supported by: ``Fondazione Cassa di Risparmio di Padova e Rovigo'' with the project QUASAR funded within the call ``Ricerca Scientifica di Eccellenza 2018''; 
MIUR (Italian Minister for Education) under the initiative ``Departments of Excellence'' (Law 232/2016); EU-H2020 program under the Marie Sklodowska Curie action, project QCALL (Grant No. GA 675662).
\end{acknowledgments}

\appendix
\section{Generalized Semi-definite Programming for $n$-input $d$-outcome}
\label{app:a}
\subsection{Primal}
This appendix 
{presents a generalized expression }of 
the guessing probability optimization problem shown in Eq.\ref{eq:P_g}, in the form of a semidefinite program (SDP). This optimization is used to derive a bound on the min-entropy for a $n$-input $d$-outcome semi-DI QRNG protocol based on an energy bound,
generalizing the approach proposed in~\cite{Brask2017}.
The generalized form of guessing probability for $n$-input $d$-outcomes reads:

\begin{equation}
\begin{aligned}
P_{\rm guess} =
\frac{1}{n}  \max\limits_{\{\rho^{\boldsymbol\lambda}_x, p_{\boldsymbol\lambda} ,\Pi _b^{\boldsymbol\lambda}\}}
\left( 
\sum\limits_{x = 0}^{n-1} \sum\limits_{\boldsymbol\lambda} {p_{\boldsymbol\lambda}} \max_b  \bigg\{ \Tr[\rho^{\boldsymbol\lambda}_x \Pi^{\boldsymbol\lambda}_b] \bigg\} \right)\,,
\end{aligned}
\label{eq:P_g33}
\end{equation}
where $\Pi^{\boldsymbol\lambda}_b$ with $b=0,\cdots,d-1$ represent
positive-operator valued measurement (POVM) operators 
in a $n$ dimensional Hilbert space
and the states $\rho_x$ satisfy
the constraint
$p(b|x) = \sum\limits_{\boldsymbol\lambda}  {p_{\boldsymbol\lambda}} 
\text{Tr}[\hat\rho_x \hat\Pi_b^{\boldsymbol\lambda}]
$.
In the above equation, we assume the probability of transmitting $x \in \{0,\dots,n-1\}$ is identical and equal to $p_{x} = \frac{1}{n} $.
The variable $\boldsymbol\lambda$ labels a possible ``strategy''.
As discussed in \cite{Brask2017} and \cite{Bancal14}, all strategies 
in which the inner maximization over $b$ in equation (\ref{eq:P_g33}) occurs for the same value of $b$ at given $x$ can be grouped.
Consequently, it is sufficient to consider at most $d^{n}$ strategies when maximizing equation (\ref{eq:P_g33}) over all potential measurement strategies. Then, each strategy 
can be labeled as 
${\Lambda}=(\lambda_0,\cdots,\lambda_{n-1})$, where $\lambda_k=0,\cdots, d-1$, and $\sum_{\Lambda } := \sum_{\lambda_0 = 0}^{d-1}\cdots \sum_{\lambda_{n-1} = 0}^{d-1}$ is defined for simplicity. The value of $\lambda_x$ indicates that the $b=\lambda_x$ outcome maximizes  
$\Tr[\rho_x \Pi^{\Lambda}_b]$ when the state $\hat\rho_x$ is sent.
By absorbing the weight $p_{\Lambda}$ into the normalization of POVMs, 
$M _b^{\Lambda}=p_{\Lambda} \Pi _b^{\Lambda}$, Eq. (\ref{eq:P_g33}) can be rewritten as
\begin{equation}
{P_{\rm guess}} = \frac{1}{n}\mathop{\max }\limits_{\{M _b^{\Lambda}\}} \sum\limits_{x = 0}^{n-1}
{\sum\limits_{\Lambda} \Tr[\rho_x M _{\lambda_x}^{\Lambda} ]},
\label{eq:P_g3}
\end{equation}
As discussed in the main text, the states $\rho_x$ can
be chosen to be pure $\rho_x=\ket{\psi_x}\bra{\psi_x}$. If the energy constraint is imposed, then the states $\{\ket{\psi_0}, \ket{\psi_1}, \dots, \ket{\psi_{n-1}}\}$ can be 
{can be express as a linear combination of an orthonormal basis} $\{\ket{0},\ket{1}, \dots, \ket{n-1}\}$ 
with
fixed overlap $|\braket{\psi_x}{\psi_y}|=\delta$ for $x\neq y$.

The maximization of the guessing probability $P_{\rm guess}$ can be cast as an SDP,  
whose primal form can be written as follows
\begin{maxi}|l|
  {
  M_b^{\Lambda}
  }
  { P_{\rm g}=
  \frac{1}{n}\sum\limits_{x = 0}^{n-1} 
  \sum\limits_{\Lambda} \bra{\psi_x}
  M_{\lambda_x}^{\Lambda}\ket{\psi_x}
  }
  {}{}
  \addConstraint{M_b^{\Lambda} = (M_b^{\Lambda})^\dag }
  \addConstraint{M_b^{\Lambda} \ge 0}
  \addConstraint{\sum_{b=0}^{d-1} {M_b^{\Lambda}  = \frac1n \text{Tr}[\sum_{b=0}^{d-1} M_b^{\Lambda}}]\mathbb{I}}
  \addConstraint{\sum\limits_{\Lambda}
  \bra{\psi_x}
  M_{b}^{\Lambda}
  \ket{\psi_x}
  = p(b|x)\,,\quad \forall b,x}
  \label{eq:SDP_primal}
\end{maxi}
where $M_{b}^{\Lambda}$ are $n\times n$ Hermitian semi-positive matrices.
This maximization defines an SDP, converging to optimal bounds on $P_{\rm guess}$ 
given the constraints on the overlap or the energy and the observed data $p(b|x)$. 

The maximization is performed over all measurement strategies $M _b^{\Lambda}$ meaning that the computational cost increases with the number of outcomes. 
In this case, we can also derive the dual SDP, whose derivation is described in the next section.
\begin{figure}
\caption{The conditional min-entropy as a function of mean-photon number for a different number of inputs based on overlap assumption when the detector efficiency is $80\%$. 2-inputs describes two time-intervals; one is empty, the other has a weak-pulse (similar to \cite{Brask2017}
\label{fig:compar}
\end{figure}
\subsection{Dual}
The dual SDP has three critical benefits when compared with the primal version:
it gives an upper-bound on the guessing probability rather than a lower-bound. In this way, conservative bounds are obtained, which never overestimates the min-entropy.  Further, the dual form enables recomputing bounds without running a full optimization for real-time operation, reducing the entropy estimation resources. Lastly, the finite-size effects can be
easily taken into account with this formulation.
Here, we use Lagrangian duality~\cite{boyd2004convex}, with an approach a similar to the one used in \cite{Bancal14,Brask2017}. 
We define the Lagrangian associated with the problem (\ref{eq:SDP_primal}) as:
\begin{equation}
\begin{aligned}
 {\mathcal L} = &\frac{1}{n} \sum\limits_{x = 0}^{n-1} \sum\limits_{\Lambda} \text{Tr} [{\rho _x}(\sum\limits_{b = 0}^{d-1}\delta_{\lambda_x,b} M _{b}^{\Lambda})] + \sum\limits_{\Lambda,b} {\text{Tr}[G_b^{\Lambda}M_b^{\Lambda}]}+ \\
& +\sum\limits_{\Lambda} {\text{Tr}[H^{\Lambda}\sum\limits_b {\left(M_b^{\Lambda} - \frac{1}{n} \text{Tr}[M_b^{\Lambda}]\right)} ]} +
\\
&+\sum\limits_{x,b} {{\nu _{bx}}\{\sum\limits_{\Lambda} {\text{Tr}[{\rho _x}M_b^{\Lambda}] - p(b|x)\}
} } \,,
\end{aligned}
\end{equation}
where $n\times n$ Hermitian matrices $ H^{\Lambda}$, $ G_b^{\Lambda}$, and scalar coefficient $\nu _{bx}$ are introduced as the Lagrange multipliers to each constraint in the primal problem. $\lambda_0,\dots, \lambda_{n-1}$ and $b$ range from $0$ to $d-1$, and $x$ ranges from $0$ to $n-1$. 
The next step is finding the supremum of the Lagrangian over the primal variables $M_b^{\Lambda}$. Now we minimize ${\mathcal L}$ over the Lagrangian multipliers to get a tighter bound on the guessing probability, so we have
\begin{equation}
\overbrace {\mathop {\sup ({\mathcal L} )}  \limits_{M_b^{\Lambda}} }^\chi = \mathop {\sup }\limits_{M_b^{\Lambda}} \{ \sum\limits_{\Lambda,b} {\text{Tr}[M_b^{\Lambda}J_b^{\Lambda}]} - \sum\limits_{x,b} {{\nu _{bx}}p(b|x)\} },
\label{SUP}
\end{equation}
where 
\begin{equation}
J_b^{\Lambda} = \sum\limits_x \rho _x(\frac{1}{n}\sum\limits_{b = 0}^{d-1}\delta_{\lambda_x,b}  + \nu _{bx}) 
+ G_b^{\Lambda} + H^{\Lambda}
- \frac{1}{n} \text{Tr}[H^{\Lambda}].
\label{JJ}
\end{equation}
Considering there is no constraint on $M_b^{\Lambda}$ in the Lagrangian, the supremum in Eq. (\ref{SUP}) will be infinite, except $J_b^{\Lambda}$ is restricted to be zero; thus we require that $J_b^{\Lambda}=0$. 

However, given that the operators $G_b^{\Lambda}$ are positive semidefinite, due to the second constraint of the primal SDP ($\ref{eq:SDP_primal}$), this is equivalent to cut $G_b^{\Lambda}$ from Eq. (\ref{SUP}) and expecting the rest of the expression to be negative semidefinite.
Consequently, we have the dualized SDP as
\begin{equation}
 P^*_g = \mathop {\min}\limits_{{H^{\Lambda}, \nu _{bx}}}  [- \sum_{x=0}^{n-1}\sum_{b=0}^{d-1} {{\nu _{bx}}p(b|x)}] 
\label{objec}
\end{equation}
subjected to

\begin{align}
&{H^{\Lambda}} = {\rm{ }}{({H^{\Lambda}})^\dag }, \\
& \sum\limits_x  {{\rho _x}(\frac{1}{n}\sum\limits_{b = 0}^{d-1}\delta_{\lambda_x,b} + {\nu _{bx}})} + {H^{\Lambda}} - \frac{1}{n} \text{Tr}[{H^{\Lambda}}]\mathbb{I} \le 0,
\label{const}
\end{align}
\section{Overlap bound and many inputs}
\label{app:c}
\begin{figure}
\caption{The maximum achievable conditional min-entropy (with optimal mean-photon number) as a function of the detector's efficiency.}
\label{fig:efficiency}
\end{figure}
In this section we compare the energy bound considered so far 
$\langle \hat N\rangle_{\rho_x}\leq \mu$
with the
overlap bound assumption $\braket{\psi_x}{\psi_y}\geq\delta$ proposed in \cite{Brask2017}.
The advantage of the overlap bound assumption is that the QRNG could operate in a broader mean-photon number range and 
higher rates can be achieved.
However, from the experimental point of view, testing the energy bound is
easier than ensuring that the overlap bound is satisfied. 
We note that the bound on the energy imposes a bound on the overlap (see\cite{VanHimbeeck2017semidevice}), but not the other way around.
We will also compare the performances of the proposed implementation when the number of inputs are increased.

\subsection{Overlap bound}
To apply the overlap instead of the energy bound, we should change the assumption to 
\begin{equation}
|\braket{\psi_i}{\psi_j}|\geq e^{-\mu}, \;\;\;\;\;\; x,y \in \{0,1,2\}, \;\; x \neq y.
\label{Ovelap_bounddd}
\end{equation}
{For the estimation of the min-entropy with the overlap bound, we use the security framework described in the text (and in Appendix \ref{app:a}), with the only difference of the substitution of the overlap in Eq.\ref{state:ternary} with the one given by Eq. \ref{Ovelap_bounddd}. } 

In Fig. \ref{fig:compar}, the conditional min-entropy is plotted as a function of the mean-photon number for binary and ternary time-bin (Config. I) encoding schemes when the detector's efficiency is $80\%$. As shown, the maximum value of conditional min-entropy increases from $0.4$ to $0.7$, which is a significant improvement. 

We also show in the inset of Fig. \ref{fig:compar}
the numerical results obtained by
increasing the number of inputs to four, five, six and seven. It is worth to notice that, 
besides the extra experimental and computational complexity added by increasing the inputs, a negligible growth in the conditional min-entropy's maximum value is observed.  
Therefore, the ternary time-bin encoding scheme 
provides an excellent trade-off between the achievable conditional min-entropy and computational complexity.
It should be pointed out that when the number of inputs increases, the number of possible outcomes rise accordingly, and the guessing probability should be optimized over more measurement and preparation strategies. 
Thus, the optimization problem—either as a form of dual or primal SDP— would require more time to be determined, which reduces the system’s rate.
Notwithstanding, for a chosen number of input/output, the dual form can boost the generation rate compared to the primal form, 
since it allows to compute (sub-optimal) bounds without running a full optimization (the value of $P^*_g$ is linear in the experimental values $p(b|x)$.
We further show in Fig. \ref{fig:efficiency} the maximum achievable min-entropy (maximized of the possible $\mu$ values) in function of the detector's efficiency.
From the figure it is evident that increasing the number of outcomes from 2 to three increases the 
resistance to inefficiency.
As expected, the maximum achievable  min-entropy decreases by reducing the detector's efficiency, but only for 3 or more inputs it shows a quasi-linear behavior in function of the efficiency.

The gap between 2-inputs and 3-inputs cases grows when the detector efficiency decreases, while for the rest inputs, the gap is almost constant, see Fig. \ref{fig:efficiency}. This shows that the ternary encoding scheme is more robust to the detector efficiency than the binary one, which is an 
advantage as the typical single-photon detector's efficiency ranges from $0.5$ to $0.95$.
\begin{figure}
\caption{The maximal achievable conditional min-entropy (with optimal mean-photon number) as a function of the detector's efficiency when the energy bound is considered.}
\label{fig:energy_assump}
\end{figure}
\subsection{Energy bound with many inputs}
\begin{figure}
\caption{The maximum conditional min-entropy $H_{min}
\label{fig:optimal_mu}
\end{figure}
In this subsection, by employing the general SDP form given in the Appendix \ref{app:a}, 
we study the effect of changing the detector efficiency and the number of inputs when the energy bound is considered. 
Let's first consider the effect of detector efficiency, when no error are present ($\epsilon=0$). In Fig. \ref{fig:energy_assump} we show the maximum value of the min-entropy that can be achieved in function of the detection efficiency. 
Fig. \ref{fig:energy_assump} shows that increasing the number of inputs always improves the generation rate also when detection inefficiencies are taken into account. 
Consequently, it is possible to find the optimal trade-off between the computational complexity, entropy value, and robustness to the detector's efficiency.
Fig. \ref{fig:optimal_mu} shows the maximum min-entropy and the corresponding optimal value of $\mu$ as a function of the number of inputs in the
noiseless perfect-efficiency case ($\eta=1$, $\epsilon=0$). 
The data indicate that the optimal mean-photon number grows with the number of inputs and seemingly reaches a plateau of about $0.25$ for  high number of inputs ($>9$).
The 2-inputs results shown in Figs. (\ref{fig:efficiency}) and (\ref{fig:energy_assump}) illustrate that the binary inputs preparation scheme is less sensitive to the efficiency when  the energy bound is considered.

\end{document}