├── Notes ├── .gitignore ├── notes.pdf ├── notes.png ├── cover.tex └── main.tex ├── Wonderland ├── source │ ├── chapters │ │ ├── chapter01.tex │ │ └── chapter02.tex │ ├── macros.tex │ └── book.tex └── book.pdf ├── .gitignore ├── Exams ├── 20200505.pdf └── source │ ├── exam.tex │ ├── lelu.sty │ └── 20200505.tex ├── Homework ├── hw1.pdf ├── hw1.png ├── hw2.pdf ├── hw2.png └── source │ ├── hw2 │ ├── hw2.tex │ ├── template.tex │ ├── macros.tex │ ├── exercises │ │ ├── ex4.tex │ │ ├── ex2.tex │ │ ├── ex1.tex │ │ ├── ex3.tex │ │ └── ex5.tex │ └── notation.sty │ └── hw1 │ ├── hw1.tex │ ├── template.tex │ ├── exercises │ ├── ex4.tex │ ├── ex1.tex │ ├── ex5.tex │ ├── ex3.tex │ ├── ex2.tex │ ├── ex6.tex │ └── ex7.tex │ ├── macros.tex │ └── notation.sty ├── .gitmodules ├── README.md └── LICENSE /Notes/.gitignore: -------------------------------------------------------------------------------- 1 | *.tuc -------------------------------------------------------------------------------- /Wonderland/source/chapters/chapter01.tex: -------------------------------------------------------------------------------- 1 | \chapter{Introduzione} -------------------------------------------------------------------------------- /Wonderland/source/macros.tex: -------------------------------------------------------------------------------- 1 | \newcommand{\mod}{\mbox{ mod }} 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.fdb_latexmk 3 | *.fls 4 | *.log 5 | *.gz 6 | *.out 7 | *.toc 8 | -------------------------------------------------------------------------------- /Notes/notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrusso96/Cryptography/HEAD/Notes/notes.pdf -------------------------------------------------------------------------------- /Notes/notes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrusso96/Cryptography/HEAD/Notes/notes.png -------------------------------------------------------------------------------- /Exams/20200505.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrusso96/Cryptography/HEAD/Exams/20200505.pdf -------------------------------------------------------------------------------- /Homework/hw1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrusso96/Cryptography/HEAD/Homework/hw1.pdf -------------------------------------------------------------------------------- /Homework/hw1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrusso96/Cryptography/HEAD/Homework/hw1.png -------------------------------------------------------------------------------- /Homework/hw2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrusso96/Cryptography/HEAD/Homework/hw2.pdf -------------------------------------------------------------------------------- /Homework/hw2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrusso96/Cryptography/HEAD/Homework/hw2.png -------------------------------------------------------------------------------- /Wonderland/book.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrusso96/Cryptography/HEAD/Wonderland/book.pdf -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Notes/source"] 2 | path = Notes/source 3 | url = https://github.com/Project2100/Cryptography-2018_19.git 4 | -------------------------------------------------------------------------------- /Homework/source/hw2/hw2.tex: -------------------------------------------------------------------------------- 1 | \input{template} 2 | \input{macros} 3 | 4 | \begin{document} 5 | \homework{2}{December 9, 2019} 6 | \input{exercises/ex1} 7 | \input{exercises/ex2} 8 | \input{exercises/ex3} 9 | \input{exercises/ex4} 10 | \input{exercises/ex5} 11 | \end{document} -------------------------------------------------------------------------------- /Homework/source/hw1/hw1.tex: -------------------------------------------------------------------------------- 1 | \input{template} 2 | \input{macros} 3 | 4 | \begin{document} 5 | \homework{1}{November 4, 2019} 6 | \input{exercises/ex1} 7 | \input{exercises/ex2} 8 | \input{exercises/ex3} 9 | \input{exercises/ex4} 10 | \input{exercises/ex5} 11 | \input{exercises/ex6} 12 | \input{exercises/ex7} 13 | \end{document} 14 | 15 | 16 | -------------------------------------------------------------------------------- /Wonderland/source/book.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper,12pt]{memoir} 2 | \usepackage[utf8]{inputenc} 3 | \usepackage[italian]{babel} 4 | \usepackage{graphicx} 5 | \input{macros} 6 | 7 | \begin{document} 8 | 9 | \author{Luigi Russo} 10 | \title{Crittografia nel Paese delle Meraviglie} 11 | \date{(Soluzioni v0.1 - \today)} 12 | 13 | \frontmatter 14 | \maketitle 15 | \tableofcontents 16 | 17 | \mainmatter 18 | \include{./chapters/chapter01} 19 | 20 | \part{Crittografia di Base} 21 | \include{./chapters/chapter02} 22 | 23 | \part{Protocolli} 24 | 25 | \backmatter 26 | \end{document} -------------------------------------------------------------------------------- /Homework/source/hw1/template.tex: -------------------------------------------------------------------------------- 1 | \documentclass[twoside]{article} 2 | \usepackage 3 | [pdftex,pagebackref,letterpaper=true,colorlinks=true,pdfpagemode=none,urlcolor=blue,linkcolor=blue,citecolor=blue,pdfstartview=FitH]{hyperref} 4 | 5 | \usepackage{amsmath,amsfonts} 6 | \usepackage{graphicx} 7 | \usepackage{enumerate} 8 | \usepackage{notation} 9 | \usepackage{algorithm2e} 10 | 11 | \bibliographystyle{alpha} 12 | 13 | \setlength{\oddsidemargin}{0pt} 14 | \setlength{\evensidemargin}{0pt} 15 | \setlength{\textwidth}{6.0in} 16 | \setlength{\topmargin}{0in} 17 | \setlength{\textheight}{8.5in} 18 | 19 | \setlength{\parindent}{0in} 20 | \setlength{\parskip}{5px} 21 | -------------------------------------------------------------------------------- /Homework/source/hw2/template.tex: -------------------------------------------------------------------------------- 1 | \documentclass[twoside]{article} 2 | \usepackage 3 | [pdftex,pagebackref,letterpaper=true,colorlinks=true,pdfpagemode=none,urlcolor=blue,linkcolor=blue,citecolor=blue,pdfstartview=FitH]{hyperref} 4 | 5 | \usepackage{amsmath,amsfonts} 6 | \usepackage{graphicx} 7 | \usepackage{enumerate} 8 | \usepackage{notation} 9 | \usepackage{algorithm2e} 10 | 11 | \bibliographystyle{alpha} 12 | 13 | \setlength{\oddsidemargin}{0pt} 14 | \setlength{\evensidemargin}{0pt} 15 | \setlength{\textwidth}{6.0in} 16 | \setlength{\topmargin}{0in} 17 | \setlength{\textheight}{8.5in} 18 | 19 | \setlength{\parindent}{0in} 20 | \setlength{\parskip}{5px} 21 | -------------------------------------------------------------------------------- /Notes/cover.tex: -------------------------------------------------------------------------------- 1 | \startcomponent cover 2 | 3 | \setvariables[document][ 4 | title=Cryptography, 5 | subtitle=Notes by students, 6 | ] 7 | 8 | \startpagemakeup 9 | 10 | \startMPcode 11 | 12 | StartPage; 13 | 14 | fill Page enlarged 5mm withcolor \MPcolor{black}; 15 | 16 | draw anchored.lrt(image(draw textext("\getvariable{document}{title}") xsized(.800PaperWidth) withcolor white), (lrcorner Page) shifted (-PaperWidth/20, PaperWidth/ 5)); 17 | draw anchored.lrt(image(draw textext("\getvariable{document}{subtitle}") xsized(.700PaperWidth) withcolor white),(lrcorner Page) shifted (-PaperWidth/20, PaperWidth/10)); 18 | 19 | setbounds currentpicture to Page; 20 | 21 | StopPage; 22 | 23 | \stopMPcode 24 | 25 | \stoppagemakeup 26 | 27 | \stopcomponent -------------------------------------------------------------------------------- /Notes/main.tex: -------------------------------------------------------------------------------- 1 | \setuppagenumbering[state=stop] 2 | 3 | \starttext 4 | \component cover 5 | 6 | This document is a collection of notes taken by some students for the course of Cryptography held by prof. Daniele Venturi, Sapienza University of Rome. 7 | 8 | Currently, the document is split as the cryptography lessons themselves, to preserve the original course timeline; most lesson files do keep a comment with the date. 9 | \blank[2*big] 10 | \startquotation 11 | Please note that these notes were our personal interpretation of what the professor said / what we were able to write during lectures , so they could be full of potential errors. 12 | \stopquotation 13 | 14 | \blank[2*big] 15 | I am one of the contributors too; also, I have added the cover and this reminder, and I have compiled the document again with \ConTeXt. 16 | \blank[6*big] 17 | \startlines 18 | Luigi Russo 19 | Roma (IT) 20 | \blank 21 | Date: \currentdate \; \currenttime 22 | \stoplines 23 | 24 | \stopchapter 25 | 26 | \copypages[notes.pdf][n=118] 27 | \stoptext -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cryptography 2 | 3 | [![made-with-latex](https://img.shields.io/badge/Made%20with-LaTeX-008080.svg)](https://www.latex-project.org/) 4 | [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 5 | 6 | This repo contains utils for class [1047622](http://danieleventuri.altervista.org/crypto.shtml) (prof. D. Venturi). 7 | 8 | |[Course Notes](/Notes/notes.pdf)|[Homework 1](/Homework/hw1.pdf)|[Homework 2](/Homework/hw2.pdf)| 9 | |----------------------------|----------------------------|----------------------------| 10 | | [![Course Notes](/Notes/notes.png)](/Notes/notes.pdf)| [![HW1](/Homework/hw1.png)](/Homework/hw1.pdf)| [![HW2](/Homework/hw2.png)](/Homework/hw2.pdf)| 11 | 12 | ## What do I find here? 13 | 14 | This repository includes my solutions to 15 | 16 | * homework 1 & 2 17 | * some previous exams 18 | * some exercises of *Cryptography in Wonderland* 19 | 20 | I have also included course notes taken by some students. 21 | 22 | ## Contributing 23 | 24 | [See the page of discussions](https://github.com/lrusso96/Cryptography/discussions) to discover suggested study material, discuss about issues or errors and ask questions. 25 | 26 | Feel free to open PR as well! 27 | -------------------------------------------------------------------------------- /Exams/source/exam.tex: -------------------------------------------------------------------------------- 1 | \documentclass[twoside]{article} 2 | \usepackage 3 | [pdftex,pagebackref,letterpaper=true,colorlinks=true,pdfpagemode=none,urlcolor=blue,linkcolor=blue,citecolor=blue,pdfstartview=FitH]{hyperref} 4 | 5 | \usepackage{amsmath,amsfonts} 6 | \usepackage{graphicx} 7 | \usepackage{enumerate} 8 | \usepackage{amsmath} 9 | \usepackage{amssymb} 10 | \usepackage{mathtools} 11 | \usepackage{todonotes} 12 | \usepackage[secpar = \lambda]{lelu} 13 | 14 | \bibliographystyle{alpha} 15 | 16 | \setlength{\oddsidemargin}{0pt} 17 | \setlength{\evensidemargin}{0pt} 18 | \setlength{\textwidth}{6.0in} 19 | \setlength{\topmargin}{0in} 20 | \setlength{\textheight}{8.5in} 21 | 22 | \setlength{\parindent}{0in} 23 | \setlength{\parskip}{5px} 24 | 25 | 26 | % Typesetting shortcuts 27 | \def\xor{\oplus} 28 | \def\and{\wedge} 29 | \def\MsgSpace{\mathcal{M}} 30 | \def\cSpace{\mathcal{C}} 31 | \def\Prover{\mathcal{P}} 32 | \def\Verifier{\mathcal{V}} 33 | \def\Simulator{\mathcal{S}} 34 | 35 | \newenvironment{solution}{\noindent {\sc \underline{\textbf{SOLUTION}}}}{$\Box$ \medskip} 36 | 37 | % To typeset the header 38 | 39 | \def\courseprof{Daniele Venturi} 40 | \def\coursenum{1047622} 41 | \def\coursename{Cryptography} 42 | \def\author{Luigi Russo, 1699981} 43 | 44 | \newlength{\tpush} 45 | \setlength{\tpush}{2\headheight} 46 | \addtolength{\tpush}{\headsep} 47 | 48 | \newcommand{\handout}[2]{ 49 | \noindent\vspace*{-\tpush}\newline\parbox{\textwidth}{ 50 | \textbf{\coursenum : \coursename} \hfill #1 \newline 51 | by prof. \courseprof \newline 52 | \mbox{}\hrulefill\mbox{}} 53 | \vspace*{1ex}\mbox{}\newline 54 | \bigskip 55 | 56 | \begin{center}{\Large\bf #2}\end{center} 57 | \begin{center} 58 | solutions by \author 59 | \end{center} 60 | \bigskip 61 | } 62 | 63 | \newcommand{\exam}[1]{ 64 | \handout{#1}{Exam #1} 65 | \pagestyle{myheadings} 66 | \thispagestyle{plain} 67 | \markboth{#1}{\coursename} 68 | } 69 | 70 | \setlength{\marginparwidth}{3cm} -------------------------------------------------------------------------------- /Wonderland/source/chapters/chapter02.tex: -------------------------------------------------------------------------------- 1 | \chapter{Sicurezza incondizionata} 2 | \paragraph*{Esercizio 2.1} 3 | In questo caso è possibile usare un attacco a forza bruta e testare, quindi, tutte e 26 le chiavi per scoprire il messaggio originale. 4 | Se, però, si osserva che le lettere \emph{R}, \emph{X} e \emph{N} compaiono alla fine di alcune parole, e si ipotizza che esse siano delle vocali nel messaggio originale, il numero di tentativi si restringe ulteriormente. 5 | Per k = \textbf{17}, si ha la soluzione: 6 | \begin{quote} 7 | Combatti solo le guerre che puoi vincere\dots preparati per le guerre che devi combattere --- Della guerra, Carl Von Clausewitz 8 | \end{quote} 9 | 10 | \paragraph*{Esercizio 2.2} 11 | \begin{quote} 12 | L'arte della guerra ci insegna a confidare non soltanto nella probabilità\footnote{le vocali accentate e gli apostrofi sono stati aggiunti per completezza.} che il nemico non si presenti, ma sulla nostra preparazione a riceverlo; non soltanto sulla possibilità che non attacchi, ma piuttosto sull'avere reso le nostre posizioni imprendibili --- L'arte della guerra, Sun Tzu 13 | \end{quote} 14 | 15 | \paragraph*{Esercizio 2.3} 16 | Osservando le sequenze di caratteri ripetuti (come \emph{PJ} e \emph{KAN I}) si determina che la chiave ha lunghezza 6. 17 | In un secondo momento, si procede l'analisi e si può ricavare che la chiave è \textbf{Scozia}, da cui: 18 | \begin{quote} 19 | Non essere il primo a provare le cose nuove e tantomeno l’ultimo a mettere da parte quelle vecchie --- Antico proverbio scozzese 20 | \end{quote} 21 | 22 | \paragraph*{Esercizio 2.4} 23 | \subparagraph*{.1} 24 | A deve essere una matrice quadrata invertibile: quindi $A \in Z^{2 \times 2}_{4}$ e $\det(A) \neq 0$. 25 | 26 | \subparagraph*{.2} 27 | Si divide il messaggio in 6 blocchi $m_i$ da 2 elementi e si applica il prodotto $c_i = A^T \cdot m_i (\mod 4)$ da cui $c = (c_1, \dots, c_6) = (013301303301)^T$. 28 | Per ottenere $m$ da $c$ si calcolano i blocchi $m_i = (A^{-1})^T \cdot c_i (\mod 4)$, da cui $m = (m_1, \dots, m_6) = (100110110110)^T$. 29 | -------------------------------------------------------------------------------- /Exams/source/lelu.sty: -------------------------------------------------------------------------------- 1 | \NeedsTeXFormat{LaTeX2e}[1994/06/01] 2 | \ProvidesPackage{lelu}[2020/03/19 Lelu Package] 3 | 4 | \RequirePackage{amsfonts} 5 | \RequirePackage{amstext} 6 | \RequirePackage{kvoptions} 7 | 8 | \DeclareStringOption[\lambda]{secpar} 9 | 10 | \ProcessKeyvalOptions* 11 | 12 | \newcommand{\secpar}{\lelu@secpar} 13 | 14 | % styles 15 | \newcommand{\neglstyle}[1]{\mathrm{#1}} 16 | \newcommand{\polystyle}[1]{\mathrm{#1}} 17 | \newcommand{\advstyle}[1]{\mathcal{#1}} 18 | \newcommand{\notionstyle}[1]{\ensuremath{\mathrm{#1}}} 19 | \newcommand{\algstyle}[1]{\ensuremath{\mathsf{#1}}} 20 | \newcommand{\keystyle}[1]{\ensuremath{\mathsf{#1}}} 21 | 22 | % security parameter 1^n 23 | \newcommand{\secparam}{1^\secpar} 24 | 25 | % computational and statistical distance 26 | \newcommand{\xclose}[1]{\approx_{#1}} 27 | \newcommand{\cclose}{\xclose c} 28 | \newcommand{\sclose}{\xclose s} 29 | 30 | % sample at random 31 | \newcommand{\samples}{\leftarrow_\$} 32 | 33 | % negligible 34 | \newcommand{\negl}[1][\secpar]{ 35 | \neglstyle{negl}({#1})} 36 | 37 | % poly 38 | \newcommand{\poly}[1][\secpar]{ 39 | \polystyle{poly}({#1})} 40 | 41 | % set and bits 42 | \newcommand{\set}[3][\secpar]{{\{#2, #3\}^{#1}}} 43 | \newcommand{\bits}[1][\secpar]{\set[#1]{0}{1}} 44 | 45 | % numerical sets 46 | \newcommand{\numset}[1]{\mathbb #1} 47 | \newcommand{\Nset}{\numset N} 48 | \newcommand{\Zset}{\numset Z} 49 | 50 | % adversaries 51 | \newcommand{\adv}[1][A]{\advstyle{#1}} 52 | 53 | % Landau 54 | \newcommand{\bigO}[1]{\mathcal{O}(#1)} 55 | \newcommand{\bigTheta}[1]{\Theta(#1)} 56 | \newcommand{\bigOmega}[1]{\Omega(#1)} 57 | 58 | % Basic crypto notions 59 | \newcommand{\notion}[2]{\notionstyle{#1 {\text -}#2}} 60 | \newcommand{\indNotion}[1]{\notion{IND}{#1}} 61 | \newcommand{\indCPA}{\indNotion{CPA}} 62 | \newcommand{\indCCA}{\indNotion{CCA}} 63 | 64 | % Algorithms 65 | \newcommand{\algX}[1]{\algstyle{#1}} 66 | \newcommand{\KGen}{\algX{KGen}} 67 | \newcommand{\Enc}{\algX{Enc}} 68 | \newcommand{\Dec}{\algX{Dec}} 69 | \newcommand{\Sign}{\algX{Sign}} 70 | \newcommand{\Vrfy}{\algX{Vrfy}} 71 | 72 | % Keys 73 | \newcommand{\keyX}[1]{\keystyle{#1}} 74 | \newcommand{\pk}{\keyX{pk}} 75 | \newcommand{\sk}{\keyX{sk}} 76 | \newcommand{\vk}{\keyX{vk}} 77 | \endinput -------------------------------------------------------------------------------- /Homework/source/hw1/exercises/ex4.tex: -------------------------------------------------------------------------------- 1 | \section{Pseudo-random Generators} 2 | \begin{enumerate}[(a)] 3 | \item Let $G_1, G_2: \bits^\lambda \to \bits^{\lambda + l}$ be two deterministic functions mapping $\lambda$ bits into $\lambda + l$ bits (for $l \ge 1$). You know that at least one of $G_1, G_2$ is a secure PRG, but you don't know which one. Show how to design a secure PRG $G^*:\bits^{2\lambda} \to \bits^{\lambda + l}$ by combining $G_1$ and $G_2$. 4 | 5 | \begin{solution} 6 | I claim that $G^*\deq G_1(s_1) \xor G_2(s_2), s_1, s_2 \ud \bits^\lambda$ is a PRG. Indeed, assume without loss of generality that $G_1$ is a PRG and assume that there exists a PPT attacker $\mathcal{A}$ able to distinguish, with non negligible probability, between $G^*(U_\lambda||U_\lambda)$ and $U_{\lambda + l}$. Then we can build an attacker $\mathcal{A}^*$ that breaks $G_1$ (see figure \ref{cryptoredux:4.a}). 7 | \begin{cryptoredux} 8 | {4.a} 9 | {Base an attack to PRG $G_1$, assuming the existence of a PPT attacker $\mathcal{A}$, able to break the security of $G^*$ with non-negligible probability. $\mathcal{A}^*$ returns a bit $b$ to the challenger $\mathcal{C}$, in order to distinguish.} 10 | {} 11 | {} 12 | {} 13 | \receive{\shortstack[l]{ 14 | $z \casesnew{-stealth}{ G_1(s_1), s_1 \ud \bits^\lambda}{\ud \bits^\lambda}$ 15 | }} 16 | {$z$}{} 17 | \cseqdelay 18 | \invoke{\shortstack[l]{ 19 | $s_2 \ud \bits^\lambda$ \\ 20 | $z^* = z \xor G_2(s_2)$ 21 | }}{$z^*$}{} 22 | \cseqdelay 23 | \return{}{$b$}{} 24 | \send{}{$b$}{} 25 | \end{cryptoredux} 26 | 27 | Note that is crucial that $s_1, s_2$ are both uniformly chosen at random, otherwise $G^*$ is not guaranteed to be a secure PRG. 28 | \end{solution} 29 | 30 | \item Can you prove that your construction works when using the same seed $s^* \in \bits^\lambda$ for both $G_1$ and $G_2$? Motivate your answer. 31 | 32 | \begin{solution} 33 | A simple counterexample is for $G_2\deq G_1 \xor a$, for some $a \in \bits^{\lambda + l}$. Then $G^*(s^*, s^*) = a, \forall s^*$. Note, however, that if the two seeds are both chosen at random, this happens only with negligible probability, so we can tolerate the existence of such a bad case. 34 | \end{solution} 35 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw1/macros.tex: -------------------------------------------------------------------------------- 1 | \usepackage{amsmath} 2 | \usepackage{amssymb} 3 | \usepackage{tikz} 4 | \usepackage{mathtools} 5 | \usepackage{xcolor} 6 | \usepackage{framed} 7 | \usetikzlibrary{tikzmark,decorations.pathreplacing,positioning,shapes,fit,arrows} 8 | 9 | 10 | % Typesetting shortcuts 11 | \def\xor{\oplus} 12 | \def\and{\wedge} 13 | 14 | \def\enc{\texttt{Enc}} 15 | \def\dec{\texttt{Dec}} 16 | \def\tag{\texttt{Tag}} 17 | \def\vrfy{\texttt{Vrfy}} 18 | 19 | \def\P{\mathop{\mathbb P}} 20 | 21 | \def\N{{\mathbb N}} 22 | \def\Z{{\mathbb Z}} 23 | 24 | \def\ud{{\leftarrow_\$}} % <--$ uniform distribution 25 | \def\deq{{\coloneqq}} % := def symbol 26 | \def\bits{{\{0, 1\}}} % {0, 1} set 27 | 28 | \newenvironment{solution}{\noindent {\sc \underline{\textbf{SOL}}}}{$\Box$ \medskip} 29 | 30 | 31 | % To typeset the header 32 | 33 | \def\courseprof{Daniele Venturi} 34 | \def\coursenum{1047622} 35 | \def\coursename{Cryptography} 36 | \def\author{Luigi Russo, 1699981} 37 | 38 | \newlength{\tpush} 39 | \setlength{\tpush}{2\headheight} 40 | \addtolength{\tpush}{\headsep} 41 | 42 | \newcommand{\handout}[2]{ 43 | \noindent\vspace*{-\tpush}\newline\parbox{\textwidth}{ 44 | \textbf{\coursenum : \coursename} \hfill #1 \newline 45 | by prof. \courseprof \newline 46 | \mbox{}\hrulefill\mbox{}} 47 | \vspace*{1ex}\mbox{}\newline 48 | \bigskip 49 | 50 | \begin{center}{\Large\bf #2}\end{center} 51 | \begin{center} 52 | solutions by \author 53 | \end{center} 54 | \bigskip 55 | } 56 | 57 | \newcommand{\homework}[2]{ 58 | \handout{#2}{Homework #1} 59 | \pagestyle{myheadings} 60 | \thispagestyle{plain} 61 | \markboth{#2}{\coursename\space -- homework #1} 62 | } 63 | 64 | 65 | % To_do shortcut 66 | 67 | \newcounter{todo_counter} 68 | \newcommand{\notodo}[1]{ 69 | } 70 | \newcommand{\todo}[1]{ 71 | \stepcounter{todo_counter} 72 | \definecolor{shadecolor}{rgb}{1,0,0} % this is yellow 73 | \begin{shaded} 74 | TODO \arabic{todo_counter}: #1 75 | \end{shaded} 76 | } 77 | 78 | %TikZ code "illustrating" the new "brace" 79 | \newcommand{\newbrace}[1][]{ 80 | \begin{tikzpicture}[baseline=-0.5ex] 81 | \draw[#1] (0.35,0.25) -- (0,0); 82 | \draw[#1] (0.35, -0.25) -- (0,0); 83 | \end{tikzpicture} 84 | } 85 | 86 | % the optional argument allows you to select the type of arrow 87 | % you can also customize the "new brace" 88 | \newcommand{\casesnew}[3]% 89 | {\;\newbrace[#1] 90 | \begin{array}{lcr} 91 | #2 \\ 92 | #3 93 | \end{array} 94 | } -------------------------------------------------------------------------------- /Homework/source/hw2/macros.tex: -------------------------------------------------------------------------------- 1 | \usepackage{amsmath} 2 | \usepackage{amssymb} 3 | \usepackage{tikz} 4 | \usepackage{mathtools} 5 | \usepackage{xcolor} 6 | \usepackage{framed} 7 | \usetikzlibrary{tikzmark,decorations.pathreplacing,positioning,shapes,fit,arrows} 8 | 9 | 10 | % Typesetting shortcuts 11 | \def\xor{\oplus} 12 | \def\and{\wedge} 13 | 14 | \def\enc{\texttt{Enc}} 15 | \def\dec{\texttt{Dec}} 16 | \def\kgen{\texttt{KGen}} 17 | \def\tag{\texttt{Tag}} 18 | \def\sign{\texttt{Sign}} 19 | \def\vrfy{\texttt{Vrfy}} 20 | \def\hyb{\texttt{Hyb}} 21 | \def\game{\texttt{Game}} 22 | \def\prover{\texttt{P}} 23 | \def\verifier{\texttt{V}} 24 | \def\transcript{\texttt{Trans}} 25 | 26 | \def\P{\mathop{\mathbb P}} 27 | 28 | \def\N{{\mathbb N}} 29 | \def\Z{{\mathbb Z}} 30 | \def\G{{\mathbb G}} 31 | \def\QR{{\mathbb{QR}}} 32 | 33 | \def\ud{{\leftarrow_\$}} % <--$ uniform distribution 34 | \def\deq{{\coloneqq}} % := def symbol 35 | \def\bits{{\{0, 1\}}} % {0, 1} set 36 | \def\modop{\mbox{ mod }} % mod operation 37 | \def\attacker{\mathcal{A}} % A 38 | \def\newattacker{\mathcal{A}^*} % A* 39 | \def\challenger{\mathcal{C}} % C 40 | 41 | \newenvironment{solution}{\noindent {\sc \underline{\textbf{SOL}}}}{$\Box$ \medskip} 42 | 43 | 44 | % To typeset the header 45 | 46 | \def\courseprof{Daniele Venturi} 47 | \def\coursenum{1047622} 48 | \def\coursename{Cryptography} 49 | \def\author{Luigi Russo, 1699981} 50 | 51 | \newlength{\tpush} 52 | \setlength{\tpush}{2\headheight} 53 | \addtolength{\tpush}{\headsep} 54 | 55 | \newcommand{\handout}[2]{ 56 | \noindent\vspace*{-\tpush}\newline\parbox{\textwidth}{ 57 | \textbf{\coursenum : \coursename} \hfill #1 \newline 58 | by prof. \courseprof \newline 59 | \mbox{}\hrulefill\mbox{}} 60 | \vspace*{1ex}\mbox{}\newline 61 | \bigskip 62 | 63 | \begin{center}{\Large\bf #2}\end{center} 64 | \begin{center} 65 | solutions by \author 66 | \end{center} 67 | \bigskip 68 | } 69 | 70 | \newcommand{\homework}[2]{ 71 | \handout{#2}{Homework #1} 72 | \pagestyle{myheadings} 73 | \thispagestyle{plain} 74 | \markboth{#2}{\coursename\space -- homework #1} 75 | } 76 | 77 | 78 | % To_do shortcut 79 | 80 | \newcounter{todo_counter} 81 | \newcommand{\notodo}[1]{ 82 | } 83 | \newcommand{\todo}[1]{ 84 | \stepcounter{todo_counter} 85 | \definecolor{shadecolor}{rgb}{1,0,0} % this is yellow 86 | \begin{shaded} 87 | TODO \arabic{todo_counter}: #1 88 | \end{shaded} 89 | } 90 | 91 | %TikZ code "illustrating" the new "brace" 92 | \newcommand{\newbrace}[1][]{ 93 | \begin{tikzpicture}[baseline=-0.5ex] 94 | \draw[#1] (0.35,0.25) -- (0,0); 95 | \draw[#1] (0.35, -0.25) -- (0,0); 96 | \end{tikzpicture} 97 | } 98 | 99 | % the optional argument allows you to select the type of arrow 100 | % you can also customize the "new brace" 101 | \newcommand{\casesnew}[3]% 102 | {\;\newbrace[#1] 103 | \begin{array}{lcr} 104 | #2 \\ 105 | #3 106 | \end{array} 107 | } -------------------------------------------------------------------------------- /Homework/source/hw1/exercises/ex1.tex: -------------------------------------------------------------------------------- 1 | \section{Perfect Secrecy} 2 | \begin{enumerate}[(a)] 3 | \item Prove or refute. An encryption scheme $(\enc, \dec)$ with key space $\mathcal{K}$, message space $\mathcal{M}$, and ciphertext space $\mathcal{C}$ is perfectly secret if and only if the following holds: for every probability distribution $M$ over $\mathcal{M}$, and every $c_0, c_1 \in \mathcal{C}$, we have $\P[C = c_0] = \P[C = c_1]$, where $C\deq \enc(K, M)$ with $K$ uniform over $\mathcal{K}$. 4 | 5 | \begin{solution} 6 | I am going to refute the previous claim. Indeed, it is easy to show that it is possible to have a non-uniform ciphertext distribution, still preserving the perfect secrecy property. Consider the following scheme $\Pi$: 7 | \begin{align*} 8 | \enc(m) & = (m \xor r) || b = c' || b \\ 9 | \dec(c) & = \dec(c' || b) = c' \xor r 10 | \end{align*} 11 | with $r \ud \bits^\lambda$ and $b \in \bits$, such that $\P[b = 0] > \P[b = 1]\footnote{it's crucial that this probability is nonzero, otherwise $\mathcal{C}$ does not contain messages ending in 1.} > 0$. 12 | 13 | Note that this is a simple variant of OTP, except that we append a bit $b$ to the ciphertext: this scheme is clearly correct since $\dec$ algorithm simply ignores the last bit of the ciphertext and then applies the xor with the secret key. Note that the choice of $b$ is completely independent of the message. So we can claim this scheme is perfectly secure because: 14 | 15 | \begin{align*} 16 | \P[M = m|C = c] & = \\ 17 | \mbox{(b is chosen independently of m)} \rightarrow & = \P[M = m|C = c'||\cdot] \\ 18 | \mbox{(OTP)} \rightarrow & = \P[M = m] \\ 19 | \end{align*} 20 | 21 | However, the distribution over $\mathcal{C}$ is not uniform: indeed, let's consider the case for $\P[b = 0] = \frac{2}{3}$. The ciphertexts ending with a 0 bit are two times as likely as ciphertexts ending with bit 1. 22 | 23 | \end{solution} 24 | 25 | \item Let $(\enc, \dec)$ be a perfectly secret encryption scheme over message space $\mathcal{M}$ and key space $\mathcal{K}$, satisfying the following relaxed correctness requirement: there exists $t \in \N$ such that, $\forall m \in \mathcal{M}$, it holds that $\P[\dec(k, \enc(k, m)) = m] \ge 2^{-t}$ (where the probability is over the choice of $k \ud \mathcal{K}$). Prove that $|\mathcal{K}| \ge |\mathcal{M}| \cdot 2^{-t}$. 26 | 27 | \begin{solution} 28 | Assume not: so $|\mathcal{K}| < 2^{-t}|\mathcal{M}|$. 29 | Let $M$ be uniform over $\mathcal{M}, c \in \mathcal{C}: \P[C=c] > 0$ and define $\mathcal{M}' = \{ m \in \mathcal{M}: \P[m = \dec(k,c)] \ge 2^{-t}\}_{k \in \mathcal{K}}$. 30 | 31 | We have that, $\forall k \in \mathcal{K}$: 32 | \begin{align} 33 | & \sum_{m \in \mathcal{M}'} \P[m=\dec(k, c)] \le 1 \\ 34 | & \sum_{m \in \mathcal{M}'} \P[m=\dec(k, c)] \ge 2^{-t} \cdot |\{m: \dec(k, c) = m\}| 35 | \end{align} 36 | 37 | This implies that: 38 | \[ 2^{-t} \cdot |\{m: \dec(k, c) = m\}| \le 1 \] 39 | 40 | If we now sum over the key-space $\mathcal{K}$ we have that: 41 | \[2^{-t}\cdot |\mathcal{M}'| \le 2^{-t}\cdot \sum_{k \in \mathcal{K}} |\{m: \dec(k, c) = m\}| \le |\mathcal{K}| < 2^{-t}\cdot |\mathcal{M}| \] 42 | 43 | from which we derive that $|\mathcal{M}| < |\mathcal{M}'|$, i.e. $\exists m^* \in \mathcal{M} \backslash \mathcal{M}'$. 44 | Note that $\forall k \in \mathcal{K}, \enc(k, m^*)\ne c$, otherwise we would have that 45 | \begin{align} 46 | & \P[\dec(k, c) = m^*] < 2^{-t} & (m^* \in \mathcal{M} \backslash \mathcal{M}') \\ 47 | & \P[\dec(k, c) = m^*] \ge 2^{-t} & (\mbox{relaxed correctness}) 48 | \end{align} 49 | that is clearly an absurd. But now we have that $\P[M=m^*] = \frac{1}{|\mathcal{M}|}$ (it is uniform by assumption). However, $\P[M=m^*|C=c] = 0 \ne \frac{1}{|\mathcal{M}|}$ and this violates the perfect secrecy of the scheme. 50 | \end{solution} 51 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw2/exercises/ex4.tex: -------------------------------------------------------------------------------- 1 | \section{Signature Schemes} 2 | \begin{enumerate}[(a)] 3 | \item Consider a weaker variant of UF-CMA in which the attacker receives $(pk, m^*)$ at the beginning of the experiment, where the message $m^*$ is uniformly random over $\Z^*_\N$, and thus it has to forge on $m^*$ after possibly seeing polynomially-many signatures $\sigma_i$ on uniformly random messages $m_i \ud \Z^*_N$ chosen by the challenger. Call this notion random-message unforgeability under random-message attacks (RUF-RMA). 4 | 5 | Formalize the above security notion, and prove that UF-CMA implies RUF-RMA but not vice-versa. 6 | 7 | \begin{solution} 8 | Given a signature scheme $\Pi \deq (\kgen, \sign, \vrfy)$, let consider the following game $\game_{\Pi, \mathcal{A}}^{\texttt{RUF-RMA}}(\lambda)$: 9 | \begin{enumerate} 10 | \item the challenger $\challenger$ generates $(pk, sk) \ud \kgen(1^\lambda)$ 11 | \item the challenger $\challenger$ fixes a message $m^* \ud \Z^*_\N$ and forwards to $\attacker$ both the public key $pk$ and the message $m^*$ 12 | \item $\attacker$ has access to oracle $O_1(sk)$: this oracle samples a message $m_i \ud \Z_\N^*$ and returns $(m_i, \sigma_i)$ such that $\vrfy(pk, (m_i, \sigma_i)) = 1$ 13 | \item $\attacker$ forges the signature $\sigma^*$ 14 | \item the output of the game is $\vrfy(pk, (m^*, \sigma^*))$ (i.e. 1 in case of win, 0 otherwise) 15 | \end{enumerate} 16 | We say that a scheme $\Pi$ is RUF-RMA-secure if $\forall$ PPT attackers $\mathcal{A}, \exists \epsilon(\lambda) \in negl(\lambda)$: 17 | \[\P[\game_{\Pi, \mathcal{A}}^{\texttt{RUF-RMA}}(\lambda) = 1] \le \epsilon(\lambda) \] 18 | 19 | \bigskip 20 | \textbf{(UF-CMA $\Rightarrow$ RUF-RMA)} Assume that a scheme $\Pi \deq (\kgen, \sign, \vrfy)$ is not RUF-RMA: then there exists a PPT attacker $\attacker$ able to forge, with non negligible probability, a valid signature $\sigma^*$ for the message $m^*$ fixed by the challenger. If this is true, we can build on top of $\attacker$ an attacker $\newattacker$ able to forge a valid pair and break UF-CMA-security too. 21 | 22 | First of all, in this reduction, $\newattacker$ forwards to $\attacker$ all the public parameters. Moreover, it randomly selects a message $m^*$ and relays this to $\attacker$: $m^*$ simulates the random challenge. At this point, the attacker $\attacker$ can start querying the oracle $O_1$; but $\newattacker$ can simulate very easily these queries, simply picking a message at random $m_i \ud \Z_\N^*$ and asking the challenger $\challenger$ to forge a valid signature $\sigma_i$: the pair $(m_i, \sigma_i)$ is then forwarded to $\attacker$. After potentially a polynomial number of these oracle calls, $\attacker$ is ready to forge a signature $\sigma^*$ and $\newattacker$ forwards to $\challenger$ the pair $(m^*, \sigma^*)$, retaining the same non-negligible advantage. 23 | 24 | \bigskip 25 | \textbf{(RUF-RMA $\not\Rightarrow$ UF-CMA)} 26 | The textbook version of RSA signatures is RUF-RMA (see next exercise), however it is not UF-CMA as proved in class. 27 | \end{solution} 28 | 29 | \item Recall the textbook-version of RSA signatures. 30 | 31 | $\kgen(1^\lambda)$: Run $(N, e, d) \ud \texttt{GenModulus}(1^\lambda)$, and let $pk = (e, N)$ and $sk = (N, d)$. 32 | 33 | $\texttt{Sign}(sk, m)$: Output $\sigma = m^d \modop N$. 34 | 35 | $\vrfy(pk, m, \sigma)$: Output 1 if and only if $\sigma^e \equiv m \modop N$. 36 | 37 | Prove that the above signature scheme $\Pi = (\kgen, \texttt{Sign}, \vrfy)$ satisfies RUF-RMA under the RSA assumption. 38 | 39 | \begin{solution} 40 | Assume not: then there exists a PPT attacker $\attacker$ (against RUF-RMA of $\Pi$), on top of which we can break RSA assumption. In particular, the challenger generates RSA params $(N, e, d)$ and fixes, at random, a value $x \ud \Z_\N^*$ and computes $y = x^e$. The attacker $\newattacker$ forwards the public key $(N, e)$ to $\attacker$; moreover it fixes $m^* = y$. In order to simulate the calls to oracle $O_1$ it can do the following: generates a signature $\sigma_i \ud \Z_N^*$ and then computes the message $m_i = \sigma_i^e$ and returns the pair $(m_i, \sigma_i)$. Note that such a pair is valid (because $\sigma_i^e = m_i$ by definition, and since $\sigma_i$ is chosen at random, also $m_i$ looks random\footnote{this is crucial, otherwise it would not be a valid simulation.}). We know that $\attacker$ forges a valid pair $(y, \sigma^*)$ with non negligible probability, such that $\sigma^*: {\sigma^*}^e = y \Rightarrow \sigma^* = x$. This concludes the proof. 41 | \end{solution} 42 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw1/exercises/ex5.tex: -------------------------------------------------------------------------------- 1 | \section{Pseudo-random Functions} 2 | \begin{enumerate}[(a)] 3 | \item Show that no PRF family can be secure against computationally unbounded distinguishers. 4 | 5 | \begin{solution} 6 | Let us consider any PRF family $F_k: \bits^n \to \bits^l, k \in \bits^\lambda, n, l \in poly(\lambda)$. An unbounded attacker could "simply" brute-force\footnote{in the sense that computes $F_k(x) \forall k,x$.} $F_k(\cdot), \forall k$. At this point he queries the challenger, with all possible inputs $x_i$, receiving back $y_i$ and returns 1 iff $\exists k^*: \forall i, F_{k^*}(x_i) = y_i$. Of course, if the challenger returns values computed with the PRF, the distinguisher will return 1 with probability 1. Moreover, we know that the number of possible distinct functions associated with $F$ is at most $2^\lambda$ (since they depend on the key $k$); on the contrary, the number of possible functions from $2^n \to 2^l$ is $(2^l)^{2^n}$. The probability that the challenger, selecting at random a function R, picks a function that is equivalent to one of the functions $F_k$ is $\le \frac{|K|}{|\mathcal{R}(n,l)|} = \frac{2^\lambda}{(2^l)^{2^n}}$. 7 | 8 | This means that 9 | \[\P[\mathcal{A}(y) = 1: y = F_k(x); k \ud \bits^l] - \P[\mathcal{A}(y) = 1: y = R(x); R \ud \mathcal{R}(n, l)] \ge 1 - \frac{2^\lambda}{(2^l)^{2^n}}\] 10 | that is non negligible, since I assume that $(2^l)^{2^n} >> 2^\lambda$. 11 | \end{solution} 12 | 13 | \item Analyze the following candidate PRFs. For each of them, specify whether you think the derived construction is secure or not; in the first case prove your answer, in the second case exhibit a concrete counterexample. 14 | 15 | \begin{enumerate}[(i)] 16 | \item $F_k(x) = G'(k) \xor x$, where $G: \bits^\lambda \to \bits^{\lambda + l}$ is a PRG, and $G'$ denotes the output of $G$ truncated to $\lambda$ bits. 17 | 18 | \begin{solution} 19 | This solution does not work, since we have that, for two inputs $x_1, x_2$: 20 | \[x_1 \xor x_2 = F_k(x_1) \xor F_k(x_2), \forall k\] 21 | Observed that, we can build an efficient distinguisher that makes two distinct queries and outputs 1 if and only if the xor of the inputs is equal to the xor of the outputs. Clearly, if the values are the outputs of $F_k$, the attacker returns 1 with probability 1; if the values are taken from a truly random function $R$, then the attacker outputs 1 with probability equal to $2^{-\lambda}$. 22 | Then it follows: 23 | \begin{align*} 24 | & \P[A(y_1, y_2): y_1 = F_k(x_1); y_2 = F_k(x_2), k \ud \bits^\lambda] + \\ 25 | - & \P[A(y_1, y_2): y_1 = R(x_1); y_2 = R(x_2), R \ud \mathcal{R}(\lambda, \lambda + l)] \ge 1 - 2^{-\lambda} 26 | \end{align*} 27 | that is non-negligible. 28 | \end{solution} 29 | 30 | \item $F_k(x) \deq F_x(k)$, where $F: \bits^\lambda \times \bits^\lambda \to \bits^{\lambda + l}$ is a PRF. 31 | 32 | \begin{solution} 33 | This solution does not work. Assume the existence of a very bad key $k_b$ that transforms F into a constant function (e.g. always 0): this subtle property does not alter the security of $F_k(\cdot)$ for a random key, since this bad key is only chosen with negligible probability. However, the proposed construction allows the attacker to fix the key (it is the input $x$ passed by the attacker!), so in order to distinguish, he simply queries the challenger with input $k_b$: then it is easy to distinguish with non-negligible probability since the attacker returns 1 if and only if he obtains 0. In the case of PRF, the attacker returns 1 with probability 1; otherwise it returns 1 with probability $2^{-\lambda}$. 34 | \end{solution} 35 | 36 | \item $F_k'(x) = F_k(k||0) || F_k(k||1)$, where $x \in \bits^{n - 1}$. 37 | 38 | \begin{solution} 39 | This solution works instead. Assume not: then there exists a PPT attacker $\mathcal{A}$ able to break $F_k'(\cdot)$. I show how to build on top of $\mathcal{A}$ an attacker $\mathcal{A}^*$ able to break the security of $F$. In particular $\mathcal{A}$ can distinguish $F_k'(\cdot)$ from a truly random function $R \ud \mathcal{R}(n-1, n)$. Whenever $\mathcal{A}$ queries some input $x$, $\mathcal{A}^*$ forwards two queries $x_b\deq x || b$, for $b \in \bits$, after receiving the values $y_1, y_2$, sends back to $\mathcal{A}$ the value $y\deq y_1 || y_2$. 40 | Finally, $\mathcal{A}^*$ returns the same bit $b'$ of $\mathcal{A}$ and distinguishes as well as $\mathcal{A}$ does. Note that the number of queries to the challenger is double of the queries needed by $\mathcal{A}$: however, this is perfectly legitimate (it is still polynomial!). 41 | \end{solution} 42 | 43 | \end{enumerate} 44 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw2/exercises/ex2.tex: -------------------------------------------------------------------------------- 1 | \section{Number Theory} 2 | \begin{enumerate}[(a)] 3 | \item Recall that the CDH problem asks to compute $g^{ab}$ given $(g, g^a, g^b)$ for $(G, g, q) \ud \texttt{GroupGen}(1^\lambda)$ and $a, b \ud \Z_q$. Prove that the CDH problem is equivalent to the following problem: given $(g, g^a)$ compute $g^{a^2}$, where $(G, g, q) \ud \texttt{GroupGen}(1^\lambda)$ and $a \ud \Z_q$. 4 | 5 | \begin{solution} 6 | For sake of simplicity, let us call SCDH the problem defined above (i.e. compute $g^{a^2}$, given a tuple $(\G, g, q, g^a)$). We have to prove that both CDH $\Rightarrow$ SCDH and SCDH $\Rightarrow$ CDH. 7 | 8 | \bigskip 9 | \textbf{(CDH $\Rightarrow$ SCDH)} given some $g^a$ it is easy to see that this is equivalent to solve $\frac{\mbox{CDH}(g, g^a, g^{a+r})}{g^{ar}} = \frac{g^{aa + ar}}{g^{ar}} = g^{a^2}$, for a random choiche of $r \ud \Z_q$. 10 | 11 | \bigskip 12 | \textbf{(SCDH $\Rightarrow$ CDH)} given $(g^a, g^b)$, we can compute $\frac{\mbox{SCDH}(g^{a+b})}{\mbox{SCDH}(g^a) \cdot \mbox{SCDH}(g^b)} = \frac{g^{a^2+2ab + b^2}}{g^{a^2} \cdot g^{b^2}} = g^{2ab}$: at this point we need to compute the square root of such a value: generally speaking this operation cannot be done efficiently; however, there are some groups where computing the square root can be done very easily (e.g. cyclic groups or when the order $q$ is odd). For example, consider the case for $q$ odd: it holds that $(g^{2ab})^{\frac{q + 1}{2}} = 1 \cdot (g^{2ab})^{\frac{1}{2}} = g^{ab}$. 13 | 14 | \end{solution} 15 | 16 | \item Let $f_{g,p}: \Z_{p-1} \to \Z^*_p$ be the function defined by $f_{g,p}(x) \deq g^x \modop p$. Under what assumption is $f_{g,p}$ one-way? Prove that the predicate $h(x)$ that returns the least significant bit of $x$ is not hard-core for $f_{g,p}$. 17 | 18 | \begin{solution} 19 | The function $f_{g,p}(\cdot)$ is one-way if $g$ is a generator of $Z_p^*$, $p$ is prime and under the DL assumption. First of all we know that this function is efficiently computable: this is a requirement for all OWF. On the contrary it is hard to "invert", i.e. to find a value $x': f(x) = f(x')$. Indeed, given $y = g^x \modop p$, a PPT attacker should find a value $x': g^x \modop p = g^{x'} \modop p$. But this is possible if an only if $x - x' \equiv 0 \modop (p-1)$. 20 | 21 | Note that an element $g^x \in \QR_p$ if and only if the least significant bit of the exponent $x$ is $0$. Without loss of generality, indeed, we assume $x \in \bits^t$: this means that $x$ can be written as $\sum_{i=0}^{t} x_i \cdot 2^i$. Given $f_{g,p}(x) = g^x \modop p = g^{\sum_{i=0}^{t} x_i \cdot 2^i} \modop p$, we can check whether $f_{g,p}(x) \in \QR_p$ or not, in order to leak the least significant bit of $x$. 22 | 23 | The last step is to find a necessary and sufficient condition to check whether an element $y$ is a quadratic residue modulo $p$ or not. 24 | 25 | We can compute $s = y^{\frac{p-1}{2}}$; if $s \equiv 1 \modop p$, then $y$ is a quadratic residue; otherwise it is not. 26 | 27 | \bigskip 28 | \textbf{($\Rightarrow$)} 29 | If y is a quadratic residue, then it holds that $y = (g^\alpha)^2 = g^{2\alpha}$, for some $\alpha$. But then: $y^{\frac{p-1}{2}} = g^{\alpha (p-1)} = (g^{p-1})^\alpha = 1^\alpha = 1 \modop p$. 30 | 31 | \bigskip 32 | \textbf{($\Leftarrow$)} 33 | If it holds that $y^{\frac{p-1}{2}} \equiv 1 \modop p$, then $g^{\frac{x(p-1)}{2}} \equiv 1 \modop p$. This implies that $\frac{x(p-1)}{2} = 0 \modop (p-1)$ that can be satisfied if and only if $x$ is even. Finally, we conclude that $y = g^x = (g^{\frac{x}{2}})^2$, proving that $y$ is a quadratic residue. 34 | 35 | \end{solution} 36 | 37 | \item Let $N$ be the product of 5 distinct odd primes. If $y \in Z^*_N$ is a quadratic residue, how many solutions are there to the equation $x^2 = y \modop N$? 38 | 39 | \begin{solution} 40 | $x^2 \equiv y \modop N$ means that $x^2 \equiv y \modop p_1\cdot p_2\cdot p_3\cdot p_4\cdot p_5$. This implies that there exists a $k \in \Z$ such that $y = x^2 + k\prod_{i=1}^{5}p_i$. If we define $y_i\deq y \modop p_i$, we can rewrite the equation as $y_i \equiv x^2 \modop p_i, i \in \{1, \dots, 5\}$. This system of equation can be safely rewritten as $x^2 \equiv y_i \modop p_i$, but now, for the Chinese remainder theorem, we know that once we fix the values $y_i$ for all $i$, there exists a unique solution satisfying the system\footnote{with a simple substitution, we put $T\deq x^2$ and can apply the theorem.}. Note that each $y_i$ is such that it is equivalent (modulo $p_i$) to $x_i^2$, where $x_i \deq x \modop y_i$. Each of the 5 equations has two distinct solutions $\pm \alpha_i$, since $\alpha_i \not\equiv -\alpha_i \modop p_i$, because $p_i \ne 2, \forall i$. And this proves that there are $2^5$ distinct systems, each of these with a unique solution (for CR theorem). This implies that the number of solutions to the original equation is $2^5 = 32$. 41 | \end{solution} 42 | \end{enumerate} -------------------------------------------------------------------------------- /Exams/source/20200505.tex: -------------------------------------------------------------------------------- 1 | \input{exam} 2 | 3 | \begin{document} 4 | \exam{May 5, 2020} 5 | 6 | \section{A PRG Candidate} 7 | 8 | Let $f: \bits \to \bits$ be a one-way permutation, and $G: \bits \to \bits[\secpar + l]$ be a pseudorandom generator with positive stretch (i.e., $l \ge 1$). Analyze the following derived construction of a pseudorandom generator $G'_f : \bits \to \bits[2\secpar + l]$, where $G'(s) := (f(s), G(s))$. 9 | 10 | In case you think the derived construction is not secure, exhibit a concrete attack; otherwise, provide a proof of security. 11 | 12 | \solution{ 13 | 14 | $G'$ is not secure for any possible instantiation. Indeed, assume $G$ be constructed from the OWP $f$, by using as hardcore predicate Goldreich-Levin $l$ times. 15 | 16 | Namely, let $G(s) = h(f(s)) || h(f(f(s))) || \dots || h(f(\dots(f(s)))) || f(\dots(f(s)))$, where $h$ is the Goldreich-Levin hard-core predicate for $f$. In this case we can easily break the security of $G'$, since we are given both $G(s)$ and $f(s)$. 17 | } 18 | 19 | \section{PKE Combiners} 20 | 21 | Let $\Pi_1 = (\KGen_1, \Enc_1, \Dec_1)$ and $\Pi_2 = (\KGen_2, \Enc_2, \Dec_2)$ be two PKE schemes with the same message space $\MsgSpace = \bits[n]$. You know that at least one of the two PKE schemes is secure, but you don't know which one. Show how to combine $\Pi_1$ and $\Pi_2$ into a PKE scheme $\Pi = (\KGen, \Enc, \Dec)$, with message space $\MsgSpace$, such that $\Pi$ satisfies $\indCPA$ security as long as at least one of $\Pi$ and $\Pi_2$ satisfies $\indCPA$ security. 22 | 23 | \solution{ 24 | 25 | Let $\Pi = (\KGen, \Enc, \Dec)$ be the following: 26 | \begin{itemize} 27 | \item $\KGen$: it returns $(pk, sk)$, with $\pk = (\pk_1, \pk_2)$, $sk = (\sk_1, \sk_2)$, where $(\pk_i, sk_i) \samples \KGen_i$ 28 | \item $\Enc(pk, m)$: returns $(c_1, c_2)$, where $c_1= \Enc_1(pk_1, (m \xor r))$ and $c_2 = \Enc_2(pk_2, r)$ for $r \samples \MsgSpace$. 29 | \item $\Dec(sk, (c_1, c_2))$: it returns $\Dec_1(sk_1, c_1) \xor \Dec_2(sk_2, c_2)$ 30 | \end{itemize} 31 | 32 | Let assume $\Pi_i$ is $\indCPA$ secure. If $\Pi$ is not, then there exists a valid PPT adversary $\adv$ that we can use as follows to build a PPT attacker $\adv_i$ to $\Pi_i$: 33 | 34 | \begin{itemize} 35 | \item $\adv_i$ generates $(\pk_{3-i}, \sk_{3-i}) \samples \KGen_{3-i}(\secparam)$ 36 | \item $\adv_i$ receives $(\pk_i)$ from the challenger and forwards to $\adv$ the new public key $\pk = (\pk_1, \pk_2)$ 37 | \item $\adv$ produces the challenge $(m_0, m_1)$. $\adv_i$ samples $r \samples \MsgSpace$ and forwards to the challenger the new pair $(m_0 \xor r, m_1 \xor r)$ 38 | \item the challenger chooses at random a bit $b$ and encrypts $m_b$, thus producing the ciphertext $c_b^*$ 39 | \item $\adv_i$ gives $\adv$ the new ciphertext $(c_1, c_2)$, where $c_i = c_b^*$ and $c_{3-i} \samples \Enc_{3-i}(pk_{3-i}, r)$ 40 | \item $\adv$ returns a bit $b'$, which is passed to the challenger 41 | \end{itemize} 42 | } 43 | 44 | \section{ID scheme based on RSA} 45 | 46 | Consider the following ID scheme $\Pi = (\KGen, \Prover, \Verifier)$. 47 | 48 | \begin{itemize} 49 | \item The key generation algorithm first computes parameters $(N, e, d)$ as in the RSA cryptosystem. In particular, $N = p \cdot q$ for sufficiently large primes $p, q$, and $e \cdot d \equiv 1 \mod (p - 1)(q - 1)$ with $e$ a prime number. Hence, it picks $x \samples \Zset_N^*$, computes $y = x^e \mod N$, and it returns $\pk = (N, e, y)$ and $\sk = x$. 50 | \item One execution of the ID scheme goes as follows: 51 | \begin{description} 52 | \item[(1)] The prover $\Prover$ picks $a \samples \Zset_N^*$, and sends $\alpha = a^e \mod N$ to $\Verifier$; 53 | \item[(2)] The verifier $\Verifier$ forwards a random challenge $\beta \samples \Zset_e$ to $\Prover$; 54 | \item[(3)] The prover $\Prover$ replies with $\gamma = x^\beta \cdot a \mod N$, where $x$ is taken from the secret key and $a$ is the same value sampled in the first round. 55 | \end{description} 56 | \item The verifier $\Verifier$ accepts a transcript $\tau = (\alpha, \beta, \gamma)$ if and only if \[\gamma^e \cdot y^{-\beta} = \alpha \mod N.\] 57 | \end{itemize} 58 | 59 | Prove that $\Pi$ is a canonical ID scheme satisfying completeness, special soundness and honest-verifier zero knowledge under the RSA assumption. 60 | 61 | (\textbf{Hint:} To prove special soundness you can use the following fact: Given $N$, elements $u, v \in \Zset_N^*$ and integers $e, e'$ for which it holds that $gcd(|e|, |e'|) = 1$ and $u^e = v^{e'} \mod N$, an $e$-th root of $v$ 62 | (modulo $N$) can be computed in polynomial time.) 63 | 64 | \solution{ 65 | 66 | \begin{description} 67 | \item[(completeness)] $\forall x, \tau$ we have that $\gamma^e \cdot y^{-\beta} = (x^\beta \cdot a)^e \cdot y^{-\beta} = a^e = \alpha$ 68 | \item[(special soundness)] Assume there exists $\adv$ able to produce two transcripts $\tau_1 = (\alpha, \beta_1, \gamma_1)$, $\tau_2 = (\alpha, \beta_2, \gamma_2)$. Then we have that $\gamma_1^e \cdot y^{-\beta_1} = \gamma_2^e \cdot y^{-\beta_2}$. We derive that $(\frac{\gamma_1}{\gamma_2})^e = y^{\beta_1 - \beta_2} \mod N$. We can compute\footnote{we use the hint} the $e$-th root of $y^{\beta_1 - \beta_2}$ that is equal to $x^{e\cdot(\beta_1 - \beta_2)} = x^{\beta_1 - \beta_2}$. 69 | \item[honest-verifier zero knowledge] The simulator $\Simulator(pk)$ produces the transcript $\tau = (\alpha, \beta, \gamma)$ in the following way: 70 | \begin{itemize} 71 | \item samples $\beta \samples \Zset_e$ 72 | \item samples $\gamma \samples \Zset_N^*$ 73 | \item computes $\alpha = \gamma^e \cdot y^{-\beta}$ 74 | \end{itemize} 75 | \end{description} 76 | } 77 | 78 | \end{document} -------------------------------------------------------------------------------- /Homework/source/hw1/exercises/ex3.tex: -------------------------------------------------------------------------------- 1 | \section{One-way Functions} 2 | \begin{enumerate}[(a)] 3 | \item Let $G: \bits^\lambda \to \bits^{2\lambda}$ be a PRG with $\lambda$-bit stretch. Prove that $G$ is by itself a one-way function. 4 | 5 | \begin{solution} 6 | \begin{cryptoredux} 7 | {3.a} 8 | {Base an attack to PRG $G$, assuming the existence of a PPT attacker $\mathcal{A}$, able to find pre-images of $G$ with non-negligible probability. $\mathcal{A}^*$ returns a bit $b$ to the challenger $\mathcal{C}$, in order to distinguish.} 9 | {} 10 | {} 11 | {} 12 | \receive{\shortstack[l]{ 13 | $y \casesnew{-stealth}{\ud \bits^{2\lambda}}{G(x), x \ud \bits^\lambda}$ 14 | }} 15 | {$y$}{} 16 | \invoke{}{$y$}{} 17 | \return{}{$x'$}{} 18 | \cseqdelay 19 | \send{$b = \begin{cases} 20 | 1 & \textsc{iff } G(x') = y \\ 21 | 0 & \textsc{else} 22 | \end{cases}$ 23 | }{$b$}{} 24 | \end{cryptoredux} 25 | Assume G is not a OWF: then there exists some PPT attacker $\mathcal{A}$ able to find a pre-image $x'$ of input values $y$ (see figure \ref{cryptoredux:3.a}). 26 | Let us define \underline{valid}\footnote{just a shortcut to indicate that $y \in G(\cdot)$.} an input $y$ if $\exists x: G(x) = y$. 27 | 28 | We have that $\P[\mathcal{A}(y) = 1: x \ud \bits^\lambda; y = G(x)] \ge \frac{1}{p(\lambda)}$, for some $p(\lambda) \in poly(\lambda)$ for hypothesis. 29 | Moreover, the probability that a random $2\lambda$ bits string is valid is at most equal to the ratio between the number of valid inputs and the number of possible inputs: this ratio is equal to $\frac{2^\lambda}{2^{2\lambda}} = 2^{-\lambda}$. 30 | From which we derive that $\P[\mathcal{A}(y) = 1: y \ud \bits^{2\lambda}] \le 2^{-\lambda}$. 31 | So we have: 32 | \[\P[\mathcal{A}(y) = 1: x \ud \bits^\lambda; y = G(x)] - \P[\mathcal{A}(y) = 1: y \ud \bits^{2\lambda}] \ge \frac{1}{p(\lambda)} - 2^{-\lambda} \notin negl(\lambda) \] 33 | \end{solution} 34 | 35 | \item Let $f: \bits^n \to \bits^n$ be a OWF. Consider the function $g: \bits^{n + \log{n}} \to \bits^{n + \log{n} + 1}$ defined by $g(x||j) \deq (f(x), j, x_j)$, where $x \deq (x_1, \dots, x_n)$, and $j$ is interpreted as an integer in $[n]$ (i.e. $|j| = \log n$). 36 | 37 | \begin{enumerate}[(i)] 38 | \item Show that $g$ is an OWF if $f$ is. 39 | 40 | \begin{solution} 41 | Assume not. Then there exists a PPT attacker $\mathcal{A}$ able to invert $g$ with non negligible probability: if so, we show that we can break $f$ too (see figure \ref{cryptoredux:3.b.1}). 42 | \begin{cryptoredux} 43 | {3.b.1} 44 | {Base an attack to OWF $f$, assuming the existence of a PPT attacker $\mathcal{A}$, able to invert $g$ with non negligible probability. $\mathcal{A}^*$ wins the game if it finds a value $x'$ such that $f(x') = y$ provided by the challenger $\mathcal{C}$.} 45 | {} 46 | {} 47 | {} 48 | \receive{\shortstack[l]{ 49 | $x \ud \bits^n$ \\ 50 | $y = f(x) $ 51 | }} 52 | {$y$}{} 53 | \cseqdelay 54 | \invoke{\shortstack[l]{ 55 | $j \ud [n]$ \\ 56 | $x'_j \ud \bits $ 57 | }}{$y || j || x'_j$}{} 58 | \cseqdelay 59 | \return{}{$x'$}{} 60 | \send{}{$x'$ \textsc{iff } f(x') = y}{} 61 | \invoke{}{$y || j || (x'_j \xor 1)$}{} 62 | \return{}{$x'$}{} 63 | \send{}{$x'$}{} 64 | \end{cryptoredux} 65 | Our attacker tries to guess the value for the $j$-th bit and queries $\mathcal{A}$ to find the pre-image of $y||j|x_j$. However, it could be that the guess is wrong: but we can try again, flipping the $j$-th bit, if we realize that $f(x') \ne y$. Then, it is obvious that the probability to win the game, i.e. to find some valid pre-image of $y$ is exactly equal to the probability of finding a pre-image of a valid $y^*$ for attacker $\mathcal{A}$: and this is non-negligible by assumption. 66 | \end{solution} 67 | 68 | \item Show that for every $i \in [n']$ there is a PPT algorithm $A_i$ for which 69 | \[ \P[A_i(g(x')) = x_i' : x' \ud \bits^{n + \log{n}}] \ge \frac{1}{2} + \frac{1}{2n}\] 70 | where $x' = (x_1, \dots, x_{n'})$ 71 | 72 | \begin{solution} 73 | Let $y \in \bits^{n + \log{n}}, y' \in \bits^n, j \in \bits^{\log n}$. 74 | 75 | We define $A_i(y) = A_i(y'||j||\cdot) = \begin{cases} 76 | y_i & \textsc{if } i > n \vee i = j \\ 77 | 0 & \textsc{else} 78 | \end{cases}$ 79 | 80 | Then we can prove that $\P[A_i(g(x')) = x_i' : x' \ud \bits^{n + \log{n}}] \ge \frac{1}{2} + \frac{1}{2n}$ 81 | 82 | First of all, $A_i$ is a PPT $\forall i$, since it only parses the input string, whose length is $n + \log{n} + 1$. 83 | As for the bound, for all indexes $i > n$ (i.e. the last $\log{n}$ bits) $A_i$ finds the correct value, because it is embedded in the input. 84 | For all other indexes, there are two cases: if $i = j$ (this happens with probability = $1/n$) $A_i$ returns the correct value with probability 1 (again, the value is visible to the attacker); if $i \ne j$ (with probability $\frac{n-1}{n}$) $A_i$ can at least guess (returning 0) and win with probability $\frac{1}{2}$. If we take the weighted average we prove the bound also for $i \le n$, since: 85 | \[\forall i \le n,\; \P[A_i(g(x')) = x_i' : x' \ud \bits^{n + \log{n}}] \ge \frac{1}{n} + \frac{n-1}{2n} = \frac{1}{2} + \frac{1}{2n} \] 86 | \end{solution} 87 | \end{enumerate} 88 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw2/exercises/ex1.tex: -------------------------------------------------------------------------------- 1 | \section{Hashing} 2 | \begin{enumerate}[(a)] 3 | \item Let $\mathcal{H} = \{H_s : \bits^{2n} \to \bits^n\}_{s\in\bits^\lambda}$ be a family of collision-resistant hash 4 | functions compressing $2n$ bits into $n$ bits. Answer the following questions. 5 | \begin{enumerate}[(i)] 6 | \item Show that $\mathcal{H}$ is a seeded one-way function in the following sense: for all PPT adversaries $\texttt{A}$ there exists a negligible function $\nu: \N \to [0, 1]$ such that 7 | \[\P[H_s(x') = y: s \leftarrow \bits^\lambda; x \leftarrow \bits^{2n}; y \leftarrow H_s(x); x' \leftarrow \texttt{A}(s,y)] \le \nu(n) \] 8 | 9 | \begin{solution} 10 | \begin{cryptoredux} 11 | {1.a} 12 | {Base an attack to CR $\mathcal{H}$ family, assuming the existence of a PPT attacker $\attacker$, able to win the seeded one-way function Game with non-negligible probability.} 13 | {} 14 | {} 15 | {} 16 | \receive{\shortstack[l]{ 17 | $s \ud \bits^\lambda$ 18 | }}{$s$}{} 19 | \cseqdelay 20 | \invoke{\shortstack[l]{ 21 | $x \ud \bits^{2n}$ \\ 22 | $y = H_s(x)$ 23 | }}{$(s, y)$}{} 24 | \cseqdelay 25 | \return{}{$x'$}{} 26 | \send{}{$(x, x')$}{} 27 | \end{cryptoredux} 28 | Assume there exists a PPT attacker $\attacker$ that given a value $y = H_s(x)$, with $s\ud \bits^\lambda$ and $x\ud\bits^{2n}$, finds a pre-image $x': H_s(x) = H_s(x')$ with non negligible probability $\ge \frac{1}{p(n)}$ for some $p(n) \in poly(n)$. Then we can build on top of $\attacker$ an attacker $\newattacker$ able to break the collision resistance of $\mathcal{H}$. 29 | 30 | In particular, the challenger selects and fixes a seed $s$; $\newattacker$ fixes a value $x$ and forwards to $\attacker$ the value $y = H_s(x)$; $\attacker$ returns a value $x'$ and the tuple $(x, x')$ is forwarded to the challenger: the game is won if $x \ne x'$ and $H_s(x) = H_s(x')$. Now, by construction, we know that $\attacker$ "inverts"\footnote{with some abuse, we mean that it finds a valid preimage of y.} $y$ with probability $\ge \frac{1}{p(n)}$. We also know that the domain of $\mathcal{H}$ is the set of $2n-$bit strings, while its co-domain is the set of $n-$bit strings: this implies that the expected value of elements $x: H_s(x) = y$, once we fix $y$ and $s$, is $2^n$, thus implying that the probability for the attacker $\attacker$ to output a value $x'$ equal to $x$ is only negligible ($= 2^{-n}$). These two considerations allow to conclude that $\newattacker$ outputs a valid and colliding pair $(x, x')$ with probability $\ge \frac{1}{p(n)} (1 - 2^{-n}) \in poly(n)$. 31 | \end{solution} 32 | 33 | \item What happens in case the set of functions $\mathcal{H}$ is not compressing (i.e., the domain of each function $H_s$ is also $\bits^n$? Does collision-resistance imply one-way in this case? 34 | 35 | \begin{solution} 36 | Consider $H_s(x) \deq x \xor \texttt{pad}(s)$, where $\texttt{pad}: \bits^\lambda \to \bits^n$ is public padding function\footnote{e.g. $\texttt{pad}(s) \deq s||0^{n-\lambda}$.}. Then it is easy to see that $\mathcal{H}$ is collision resistant, since there is no collision at all (for each $s$, $H_s(\cdot)$ defines a permutation). By the way, this family of functions is definitely not one way; it is easily invertible, since the seed $s$ is public in the game, i.e. it is known to the adversary too: indeed, given $y = H_s(x) = \texttt{pad}(s) \xor x$, the attacker outputs $\mathcal{A}(s, y) = y \xor \texttt{pad}(s) = \texttt{pad}(s) \xor \texttt{pad}(s) \xor x = x$. 37 | \end{solution} 38 | \end{enumerate} 39 | 40 | \item Let $\mathcal{H} = \{H_s: \bits^{4n} \to \bits^{2n}\}_{s \in \bits^\lambda}$ and $\mathcal{H}' = \{H'_s: \bits^{2n} \to \bits^{n}\}_{s \in \bits^\lambda}$ be families of collision-resistant hash functions. Analyse the following candidate hash function family compressing $4n$ bits into $n$ bits: $\mathcal{H}^* \deq \{H^*_{s_1,s_2}: \bits^{4n} \to \bits^n\}_{s_1, s_2 \in \bits^\lambda}$ such that $H^*_{s_1, s_2}(x) = H'_{s_2}(H_{s_1}(x))$ for $s_1, s_2 \ud \bits^\lambda$. 41 | 42 | \begin{solution} 43 | \begin{cryptoredux} 44 | {1.b} 45 | {Base an attack to CR $\mathcal{H}'$ family on top of an attacker $\attacker$ to the collision resistance of $\mathcal{H}^*$.} 46 | {} 47 | {} 48 | {} 49 | \receive{\shortstack[l]{ 50 | $s_2 \ud \bits^\lambda$ 51 | }}{$s_2$}{} 52 | \cseqdelay 53 | \invoke{\shortstack[l]{ 54 | $s_1 \ud \bits^\lambda$ 55 | }}{$(s_1, s_2)$}{} 56 | \cseqdelay 57 | \return{}{$(x, x')$}{} 58 | \send{}{$(H_{s_1}(x), (H_{s_1}(x'))$}{} 59 | \end{cryptoredux} 60 | Let assume that $\mathcal{H}^*$ is not collision resistant: this means that, by definition, there exists some PPT attacker $\attacker$ that, given two values as seed $s_1, s_2$, is able to find, with non negligible probability, a valid pair $(x, x')$ such that $H_{s_1, s_2}^*(x) = H_{s_1, s_2}^*(x')$, with $x \ne x', x, x' \in \bits^{4n}$. If this is the case we can try to build an attacker $\newattacker$ to break the collision resistance of $\mathcal{H}'$. Note that the challenger fixes a seed $s_2$ and waits for the attacker to find a collision; $\newattacker$ randomly selects and fixes a seed $s_1 \in \bits^\lambda$ and uses $\attacker$ in order to find a pair $(x, x')$. By assumption, this pair is such that $H^*_{s_1, s_2}(x) = H^*_{s_1, s_2}(x')$ with non negligible probability $\ge \frac{1}{p(n)}$, for some $p(n) \in poly(n)$. 61 | 62 | But if $\mathcal{A}$ is successful (i.e. $H^*_{s_1, s_2}(x) = H^*_{s_1, s_2}(x')$), either (i) $H_{s_1}(x) = H_{s_1}(x')$ or (ii) $H_{s_1}(x) \ne H_{s_1}(x')$. Case (i) can happen only with negligible probability $\epsilon(n)$, otherwise we could use $\attacker$ to build a PPT attacker to break the collision resistance of $\mathcal{H}$. Instead case (ii) guarantees that the pair is valid to build a successful attack to $\mathcal{H}'$: in both situations we come to an absurd given our initial assumptions. 63 | \end{solution} 64 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw2/exercises/ex3.tex: -------------------------------------------------------------------------------- 1 | \section{ Public-Key Encryption} 2 | \begin{enumerate}[(a)] 3 | \item Show that for any CPA-secure public-key encryption scheme for single-bit messages, the length of the ciphertext must be super-logarithmic in the security parameter. 4 | 5 | \begin{solution} 6 | If the length of the ciphertext is not super-logarithmic, we know that the number of possible ciphertexts is at most $\lambda^c$ for some constant $c$. The attacker can compute a ciphertext $c_0$ associated to bit 0, then waits for the challenge $c_b^*$ and compares the two values: if they are equal it returns 0, otherwise returns 1. Now, if the challenger selects $b = 0$, the attacker wins with probability at least $\lambda^{-c}$, otherwise wins with probability 1. Taking the weighted average we have a winning probability $w \ge \frac{1}{2} + \frac{1}{2\lambda^c}$. 7 | 8 | But then $|w - \frac{1}{2}| \ge \frac{1}{2\lambda^c},$ where $2\lambda^c \in poly(\lambda)$. 9 | \end{solution} 10 | 11 | \item Let $\Pi = (\kgen, \enc, \dec)$ be a PKE scheme with message space $\bits$ (i.e., for encrypting a single bit). Consider the following natural construction of a multi-bit PKE scheme $\Pi' = (\kgen', \enc', \dec')$ with message space $\bits^t$, for some polynomial 12 | $t = t(\lambda)$: (i) The key generation stays the same, i.e. $\kgen'(1^\lambda) = \kgen(1^\lambda)$; (ii) Upon input $m = (m[1], \dots,m[t]) \in \bits^t$ the encryption algorithm $\enc'(pk, m)$ outputs a ciphertext $c = (c_1, \dots, c_t)$ where $c_i \ud \enc(pk, m[i])$ for all $i \in [t]$; (iii) Upon input a ciphertext $c = (c_1,\dots, c_t)$ the decryption algorithm $\dec'(sk, c)$ outputs the same as $(\dec(sk, c_1), \dots, \dec(sk, c_t))$. 13 | 14 | \begin{enumerate}[(i)] 15 | \item Show that if $\Pi$ is CCA1 secure, so is $\Pi'$. 16 | 17 | \begin{solution} 18 | In order to prove the above claim, it is convenient to use the hybrid argument: note that the goal is to prove that for all PPT adversaries $\attacker$, it holds that $\game_{\Pi, \attacker}^\texttt{CCA-1}(\lambda, 0) \approx_c \game_{\Pi, \attacker}^\texttt{CCA-1}(\lambda, 1)$. 19 | 20 | In particular let us define a set of intermediate hybrid games $\hyb_i$, where the adversary is given access to the decryption oracle (together with all the public parameters to make encryptions too, of course) exactly as each of the two games above: the difference is that, when the adversary commits the challenge tuple $(m_0, m_1)$, the challenge ciphertext $c^*$ is such that its $j$-th component is sampled from $\enc(pk, m_0[j])$ if $i \le j$, otherwise comes from $\ud \enc(pk, m_1[j])$. 21 | 22 | Note that once we fix the pair $(m_0, m_1)$, the only difference between two hybrids $\hyb_i$ and $\hyb_{i+1}$ is in the distribution of the $i$-th component of the challenge $c^*$. It is easy to see that $\hyb_1 \equiv \game_{\Pi, \attacker}^\texttt{CCA-1}(\lambda, 0)$ and $\game_{\Pi, \attacker}^\texttt{CCA-1}(\lambda, 1) \equiv \hyb_t$. 23 | 24 | Here for simplicity we give the distribution of the challenge ciphertext $c^*$ for each hybrid game: 25 | \begin{itemize} 26 | \item $\hyb_1 \rightarrow (\enc(pk, m_0[1]), \enc(pk, m_0[2]), \dots, \enc(pk, m_0[t])) \equiv \enc'(m_0)$ 27 | \item $\hyb_2 \rightarrow (\enc(pk, m_1[1]), \enc(pk, m_0[2]), \dots, \enc(pk, m_0[t]))$ 28 | \item \dots 29 | \item $\hyb_{t-1} \rightarrow (\enc(pk, m_1[1]), \dots, \enc(pk, m_1[t-1]), \enc(pk, m_0[t]))$ 30 | \item $\hyb_t \rightarrow (\enc(pk, m_1[1]), \dots, \enc(pk, m_1[t-1]), \enc(pk, m_1[t])) \equiv \enc'(m_1)$ 31 | \end{itemize} 32 | 33 | Imagine there exists a PPT distinguisher between two hybrids $\hyb_i$ and $\hyb_{i+1}$ (for some $i$). If this is the case, we can build a PPT attacker $\attacker$ to break the CCA1-security of $\Pi$. Indeed, we can ask the challenger to give us an encryption $c_b^*$ of a bit $b$. Then we pass to the distinguisher a value $c$ such that the first $i$ components are $\ud \enc(pk, m_0[j]), \forall j < i$, its $i$-th component is equal to $c_b^*$ and then the last $t-i-1$ components are $\ud \enc(pk, m_1[j])$. We then forward to the challenger the same bit returned by the distinguisher and we retain the same non negligible advantage\footnote{this proof is not valid if $m_0[i] = m_1[i]$: but in such a scenario a distinguisher between $\hyb_i$ and $\hyb_{i+1}$ cannot even exist, since the $i$-th component is sampled from the same distribution and then the two distributions are equivalent.}. This proves that $\forall i, \hyb_i \approx_c \hyb_{i+1}$ which implies that also $\game_{\Pi, \attacker}^\texttt{CCA-1}(\lambda, 0) \approx_c \game_{\Pi, \attacker}^\texttt{CCA-1}(\lambda, 1)$. 34 | \end{solution} 35 | 36 | \item Show that, even if $\Pi$ is CCA2 secure, $\Pi'$ is not CCA2 secure. 37 | 38 | \begin{solution} 39 | Even if the original scheme is CCA2, it is very simple to break the CCA2-security of $\Pi'$: the attacker obtains a ciphertext $c_b^*$ where the first bit of $m_0^*$ is 0 as well as the first bit of $m_1^*$. Now it produces another ciphertext for the bit 0: $x \deq \enc(0)$ such that $x$ is different from the encryption of the first bit of $m_b^*$, and then asks for the decryption of $c' = (x || c_b^{**}$\footnote{it is $c_b^*$ without the first block, the one corresponding to the encryption of the first bit of $m_b^*$}), and finally returns the decision bit $b': m_{b'}^* = \dec(c')$, winning with probability 1. 40 | \end{solution} 41 | \end{enumerate} 42 | 43 | \item Consider the following variant of El Gamal encryption. Let $p = 2q + 1$, let $\G$ be the group of squares modulo $p$ (so $\G$ is a subgroup of $\Z^*_p$ of order $q$), and let $g$ be a generator of $\G$. The private key is $(\G, g, q, x)$ and the public key is $(\G, g, q, h)$, where $h = g^x$ and $x \in \Z_q$ is chosen uniformly. To encrypt a message $m \in \Z_q$, choose a uniform $r \in \Z_q$, compute $c_1 \deq g^r \modop p$ and $c_2 \deq h^r + m \modop p$, and let the ciphertext be $(c_1, c_2)$. Is this scheme CPA-secure? Prove your answer. 44 | 45 | \begin{solution} 46 | This scheme is not CPA-secure. Indeed, note that in order to compute $c_1$ we add an element $ h^r \in \G$ to the message $m \in \Z_q$. This means that $c_2 \in \Z_p^*$ but not necessarily it is an element of $\G$: in particular, an attacker could exploit the fact that choosing uniformly a message $m \ud \Z_q$, $\P[c_2 \in \G : c_2 = h^r + m \modop p; h^r \in \G] = \frac{q}{2q+1}$, because among all the $2q + 1$ elements of the group, only $q$ of them are squares (and then belong to $\G$). 47 | 48 | Note also that when $m = 0$, $c_2 = h^r + m = h^r \Rightarrow c_2 \in \G$. 49 | 50 | So our attacker can use these two messages $m_0^* = 0$ and $m_1^* \ud \Z_q$ and can receive the challenge $c_b^* (c_1^*, c_2^*)$: if $c_2^* \in \G$ it outputs 0, otherwise outputs 1. Note that if $b=1$, the attacker wins with probability 1; otherwise it wins with probability $\frac{q + 1}{2q+1}$. But this is enough to retain a non negligible advantage (the winning probability is $w = \frac{1}{2} + \frac{q + 1}{2(2q + 1)} \Rightarrow |w - \frac{1}{2}| $ is non negligible in $\lambda$). 51 | \end{solution} 52 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw2/exercises/ex5.tex: -------------------------------------------------------------------------------- 1 | \section{Actively Secure ID Schemes} 2 | Let $\Pi = (\kgen, \prover, \verifier)$ be an ID scheme. Informally, an ID scheme is actively secure if no efficient adversary $\attacker$ (given just the public key $pk$) can make $\verifier$ accept, even after $\attacker$ participates maliciously in poly-many interactions with $\prover$ (where the prover is given both the public key $pk$ and the secret key $sk$). More formally, we say that $\Pi$ satisfies active security if for all PPT adversaries $\attacker$ there is a negligible function $\nu: \N \in \bits$ such that: 3 | \[\P[\game_{\Pi, \attacker}^\texttt{mal-id}(\lambda) = 1] \le \nu(\lambda),\] 4 | where the game $\game_{\Pi, \attacker}^\texttt{mal-id}(\lambda)$ is defined as follows: 5 | \begin{itemize} 6 | \item The challenger runs $(pk, sk) \ud \kgen(1^\lambda)$, and returns $pk$ to $\attacker$. 7 | \item Let $q(\lambda) \in poly(\lambda)$ be a polynomial. For each $i \in [q]$, the adversary can run the protocol $\Pi$ with the challenger (where the challenger plays the prover and the adversary plays the malicious verifier), obtaining transcripts $\tau_i \ud (\prover(pk, sk) \rightleftarrows \attacker(pk))$. 8 | \item Finally, the adversary tries to impersonate the prover in an execution of the protocol with the challenger (where now the challenger plays the honest verifier), yielding a transcript $\tau^* \ud (\attacker(pk) \rightleftarrows \verifier(pk))$. 9 | \item The game outputs $1$ if and only if the transcript $\tau^*$ is accepting, i.e. $\verifier(pk, \tau^*) = 1$. 10 | \end{itemize} 11 | Answer the following questions. 12 | \begin{enumerate}[(a)] 13 | \item Prove that passive security is strictly weaker than active security. Namely, show that every ID scheme $\Pi$ that is actively secure is also passively secure, whereas there exists a (possibly contrived) ID scheme $\Pi_{bad}$ that is passively secure but not actively secure. 14 | 15 | \begin{solution} 16 | \textbf{(active $\Rightarrow$ passive)} Assume not, then there exists some PPT attacker $\attacker$ that breaks the passive security of an actively secure scheme $\Pi$. If this is true, we can build a new PPT attacker $\newattacker$ that breaks the active security of $\Pi$. Indeed, when $\attacker$ asks to see some valid transcript $\tau_i$, prompting the empty string, $\newattacker$ will simply start a session of the protocol as an \textbf{honest}\footnote{must behave honestly, for each transcript requested by $\attacker$, in order to perfectly simulate the oracle.} verifier with the challenger acting as the (honest) prover. The final transcript $\tau_i$ is then forwarded to the original attacker: and this can be done up to a polynomial number of times of course. At this point, $\attacker$ impersonates a malicious prover (because it has not the secret key sk), directly interacting with the verifier ($\newattacker$, of course, forwards the messages of $\attacker$ to the challenger and then sends its replies back to $\attacker$). This allows $\newattacker$ to retain the same non-negligible advantage of $\attacker$ since the reduction is tight. 17 | 18 | \bigskip 19 | \textbf{(passive $\not\Rightarrow$ active)} Consider a canonical $\Sigma$ protocol $\Pi$: we define a variant $\Pi'$ such that the verifier appends a bit $b$ to its (unique) message $\beta$ where $\P[b=0] = 2^{-\lambda}$; if $b = 0$ (this happens only with negligible probability in $\lambda$) the prover has to send the secret key $sk$; otherwise it follows the original protocol to compute $\gamma$\footnote{of course $\verifier'$ will check the last bit of $\beta$ and if it is equal to $1$, it will run $\verifier(\cdot)$.}. This clearly does not compromise the passive security of $\Pi'$, because the attacker should hope to see a transcript where the secret key is leaked, but this happens only with negligible probability since the verifier is honest (it is simulated by the challenger itself); on the contrary, this scheme is not actively secure, because the adversary is allowed to impersonate the verifier in the first part of its attack: then it can easily find out the secret key (needs only one query where it appends $b = 0$ to some $\beta$) and then it can act as a malicious prover and forge a valid transcript thanks to the leaked key. 20 | \end{solution} 21 | 22 | \item Let $\Pi' = (\kgen, \sign, \vrfy)$ be a signature scheme, with message space $\mathcal{M}$. Prove that if $\Pi'$ is UF-CMA, the following ID scheme $\Pi = (\kgen, \prover, \verifier)$ (based on $\Pi'$) achieves active security: 23 | 24 | $\prover(pk, sk) \rightleftarrows \verifier(pk)$: The verifier picks random $m \ud \mathcal{M}$, and forwards $m$ to the prover. The prover replies with $\sigma \ud \sign(sk, m)$, and finally the verifier accepts if and only if $\vrfy(pk, m, \sigma) = 1$. 25 | 26 | \begin{solution} 27 | As always, assume not: then if there exists a PPT $\attacker$ able to break the active security of $\Pi$, we can build on top of it a new attacker $\newattacker$ to break the UF-CMA-security of $\Pi'$. In our reduction, we first forward to the original attacker the public key $pk$ (and, of course, all the public parameters generated by $\challenger$). 28 | 29 | The attacker $\attacker$ is allowed in the first phase to interact as a (possibly malicious) verifier: it will start sending some message $m_i$, waiting for the prover to reply; $\newattacker$ will forward $m_i$ to the challenger in order to produce a valid $\sigma_i$ and then is ready to reply; this allows the attacker $\attacker$ to collect some transcript $\tau_i$. After polynomially many such queries, it tries to impersonate the prover: so $\newattacker$ will pick a random message $m^*$ and passes it to $\attacker$; then, a $\sigma^*$ is forged (valid with probability $\ge \frac{1}{p(\lambda)}, p(\lambda) \in poly(\lambda)$); the pair $(m^*, \sigma^*)$ is forwarded to the challenger and the winning condition is that $\sigma^*$ is a valid signature of $m^*$ and $m^*$ is fresh, i.e. $m^* \ne m_i, \forall i$ queried\footnote{The probability to pick $m^*$ equal to some message already queried is negligible, since the total number of queries must be polynomial.}. But this directly implies that $\newattacker$ has non-negligible advantage of the original $\attacker$. 30 | \end{solution} 31 | 32 | \item Is the above protocol honest-verifier zero-knowledge? Prove your answer. 33 | 34 | \begin{solution} 35 | In order to be HVZK, it should exist a simulator $S$ such that $\{pk, sk, \transcript(pk, sk)\} \approx_c \{pk, sk, S(pk)\}$. Note that this simulator is given in input only the public key $pk$. But if such $S$ exists, the underlying signature scheme $\Pi$ cannot be UF-CMA: this because $S$ is able to produce valid pairs $(m_i, \sigma_i)$ in a way that is (computationally) indistinguishable from $\transcript(pk, sk)$ and in particular it can forge a valid pair in $\game_{\Pi'}^\texttt{UF-CMA}(\lambda)$ too. 36 | 37 | If, instead, we remove the UF-CMA assumption of $\Pi'$, it could be that for some schemes it is possible to compute pairs $(m_i, \sigma_i)$ given only $pk$: e.g. a possible strategy could be to pick a random $\sigma_i$ and then find some message $m_i$ such that $\vrfy(pk, (m_i, \sigma_i)) = 1$. If this is the case, then we can build such a simulator $S$ and the above protocol is HVZK. 38 | \end{solution} 39 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw1/exercises/ex2.tex: -------------------------------------------------------------------------------- 1 | \section{Universal Hashing} 2 | \begin{enumerate}[(a)] 3 | \item A family $\mathcal{H} \deq \{h_s: X \to Y\}_{s \in \mathcal{S}}$ of hash functions is called $t$-wise independent if for all sequences of distinct inputs $x_1, \dots, x_t \in \mathcal{X}$, and for any output sequence $y_1, \dots, y_t \in \mathcal{Y}$ (not necessarily distinct), we have that: 4 | \[ \P[h_s(x_1) = y_1 \and \dots \and h_s(x_t) = y_t, s \ud S] = \frac{1}{|\mathcal{Y}|^t} \] 5 | \begin{enumerate}[(i)] 6 | \item For any $t \ge 2$, show that if $\mathcal{H}$ is $t$-wise independent, then it is also $(t-1)$-wise independent. 7 | 8 | \begin{solution} 9 | In order to be $(t-1)$-wise independent, we have to prove that: 10 | \[ \P[h_s(x_1) = y_1 \and \dots \and h_s(x_{t-1}) = y_{t-1}, s \ud S] = \frac{1}{|\mathcal{Y}|^{t-1}} \] 11 | 12 | We can easily see that: 13 | \begin{align*} 14 | \P[\and_{i=1}^{t-1} (h_s(x_i) = y_i), s \ud S ] & = \\ 15 | \mbox{(law of total probability)} \rightarrow & = \sum_{y_t \in \mathcal{Y}} \P[\and_{i=1}^{t} (h_s(x_i) = y_i), s \ud S] \\ 16 | \mbox{(by definition of $\mathcal{H}$)} \rightarrow & = \sum_{y_t \in \mathcal{Y}} \frac{1}{|\mathcal{Y}|^t} \\ 17 | & = \frac{1}{|\mathcal{Y}|^{t-1}} 18 | \end{align*} 19 | that concludes the proof. 20 | \end{solution} 21 | 22 | \item Let $q$ be a prime. Show that the family $\mathcal{H} = \{h_s:\Z_q \to \Z_q \}_{s \in \Z_q^3}$ defined by 23 | \[ h_s(x) \deq h_{s_0,s_1,s_2}(x) \deq s_0 + s_1 \cdot x + s_2 \cdot x^2 \mbox{ mod } q \] 24 | is 3-wise independent. 25 | 26 | \begin{solution} 27 | By applying the definition, we should prove that, for a uniformly random choice of $s$: 28 | \[ \P[h_s(x_1) = y_1 \and h_s(x_2) = y_2 \and h_s(x_3) = y_3] = \frac{1}{q^3} \] 29 | We have that: 30 | \begin{align*} 31 | \P[\and_{i=1}^3 (h_s(x_i) = y_i)] & = \\ 32 | & =\P\begin{bmatrix} 33 | \begin{cases} 34 | s_2\cdot x_1^2 + s_1\cdot x_1 + s_0 = y_1 \\ 35 | s_2\cdot x_2^2 + s_1\cdot x_2 + s_0 = y_2 \\ 36 | s_2\cdot x_3^2 + s_1\cdot x_3 + s_0 = y_3 37 | \end{cases} 38 | \end{bmatrix} \\ 39 | & = \P\begin{bmatrix} 40 | \begin{pmatrix} 41 | x_1^2 & x_1 & 1 \\ 42 | x_2^2 & x_2 & 1 \\ 43 | x_3^2 & x_3 & 1 44 | \end{pmatrix} 45 | \begin{pmatrix} 46 | s_2 \\ 47 | s_1 \\ 48 | s_0 49 | \end{pmatrix} 50 | = 51 | \begin{pmatrix} 52 | y_1 \\ 53 | y_2 \\ 54 | y_3 55 | \end{pmatrix} 56 | \end{bmatrix} \\ 57 | & = \P\begin{bmatrix} 58 | \begin{pmatrix} 59 | s_2 \\ 60 | s_1 \\ 61 | s_0 62 | \end{pmatrix} 63 | = 64 | \begin{pmatrix} 65 | x_1^2 & x_1 & 1 \\ 66 | x_2^2 & x_2 & 1 \\ 67 | x_3^2 & x_3 & 1 68 | \end{pmatrix}^{-1} 69 | \begin{pmatrix} 70 | y_1 \\ 71 | y_2 \\ 72 | y_3 73 | \end{pmatrix} 74 | \end{bmatrix} \\ 75 | \mbox{(for some constant k)} \rightarrow & = \P\begin{bmatrix} 76 | \begin{pmatrix} 77 | s_2 \\ 78 | s_1 \\ 79 | s_0 80 | \end{pmatrix} 81 | = 82 | \begin{pmatrix} 83 | k_1 \\ 84 | k_2 \\ 85 | k_3 86 | \end{pmatrix} 87 | \end{bmatrix} \\ 88 | \mbox{($s$ is uniformly random)} \rightarrow & = \frac{1}{q^3} 89 | \end{align*} 90 | Note that this is valid if and only if we can invert that matrix, i.e. its determinant has to be nonzero. 91 | \begin{align*} 92 | \det\begin{pmatrix} 93 | x_1^2 & x_1 & 1 \\ 94 | x_2^2 & x_2 & 1 \\ 95 | x_3^2 & x_3 & 1 96 | \end{pmatrix} & = 97 | x_1^2x_2 + x_1x_3^2 + x_2^2x_3 - x_2x_3^2 -x_1^2x_3 - x_1x_2^2 \\ 98 | & = (x_1 - x_2)(x_1-x_3)(x_2-x_3) \\ 99 | \mbox{(inputs are distinct by hypothesis)} \rightarrow & \ne 0 100 | \end{align*} 101 | \end{solution} 102 | \end{enumerate} 103 | 104 | \item Say that $X$ is a $(k, n)$-source if $X \in \bits^n$, and the min-entropy of $X$ is at least $k$. 105 | Answer the following questions: 106 | 107 | \begin{enumerate}[(i)] 108 | \item Suppose that $l = 128$; what is the minimal amount of min-entropy needed in order to obtain statistical error $\epsilon = 2^{-80}$ when applying the leftover hash lemma? What is the entropy loss? 109 | 110 | \begin{solution} 111 | Leftover hash lemma states that, given pairwise independent $\mathcal{H} = \{h_s: \bits^n \to \bits^l\}_{s \in \bits^d}, h_S(X)$ is a $(k, \epsilon)$-extractor for a value of min-entropy $k \geq l + \delta$, where $\delta = 2 \log(1/\epsilon) - 2$ is the entropy loss. 112 | 113 | In this case we want to compute $k^*$, i.e. the minimum $k$ satisfying the inequality. So we have: 114 | \begin{align*} 115 | & \delta = 2 \log(1/2^{-80}) - 2 = 2 \log(2^{80}) - 2 = 2\cdot 80 - 2 = 158 \\ 116 | & \Rightarrow k \ge 128 + 158 = 286 = k^* 117 | \end{align*} 118 | \end{solution} 119 | 120 | \item Suppose that $k = 238$; what is the maximal amount of uniform randomness that you can obtain with statistical error $\epsilon = 2^{-80}$ when applying the leftover hash lemma? Explain how to obtain $l = 320$ using computational assumptions. 121 | 122 | \begin{solution} 123 | We follow a similar approach, this time we are interested in $l^*$, i.e. the maximum $l$ satisfying the inequality: 124 | \begin{align*} 125 | & \delta = 158 \leftarrow \mbox{(same as before)} \\ 126 | & 238 \ge l + 158 \Rightarrow l \le 238 - 158 = 80 = l^* 127 | \end{align*} 128 | Now, in order to obtain 320 bits of output, we can make use of a PRG $G: \bits^{\lambda} \to \bits^{4\lambda}$, for $\lambda = 80$. 129 | There is a well-known theorem that guarantees us the existence of such $G$ (since the stretch is polynomial in $\lambda$) under the assumption that OWFs exist. In this way, however, it should be noticed that we are moving from the statistical equivalence between distributions (thanks to random extraction) to computational equivalence (we have deeply discussed the differences and the practical implications of this hypothesis). 130 | \end{solution} 131 | \end{enumerate} 132 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw1/exercises/ex6.tex: -------------------------------------------------------------------------------- 1 | \section{Secret-Key Encryption} 2 | \begin{enumerate}[(a)] 3 | \item Prove that no secret-key encryption scheme $\Pi = (\enc, \dec)$ can achieve chosen-plaintext attack security in the presence of a computationally unbounded adversary 4 | (which thus can make an exponential number of encryption queries before/after being given the challenge ciphertext). 5 | 6 | \begin{solution} 7 | Without loss of generality we can say that any SKE scheme $\Pi = (\enc, \dec)$, is such that: 8 | \begin{align*} 9 | & c \ud \enc(k, m) \\ 10 | & m = \dec(k, c) 11 | \end{align*} 12 | for $k \in \bits^\lambda$. 13 | Note that here I assume that the algorithm $\enc$ uses the secret key $k$ in addition to some source of random (e.g. nonces) in order to produce the ciphertext $c$: without loss of generality I assume that, once we fix the secret key and the message m, the maximum number of valid ciphertexts associated with m is some $p(\lambda) \in poly(\lambda)$ (clearly this quantity depends on the randomness injected by $\enc$); instead, as discussed in class, I assume that $\dec$ is a deterministic algorithm. 14 | 15 | 16 | \begin{cryptogame} 17 | {6.a.1} 18 | {Simulation of $Game_{\Pi, \mathcal{A}}^{\texttt{SKE-CPA}}(\lambda, b)$ for an unbounded $\mathcal{A}$ adversary that asks exponentially many times to encrypt the same message $m_0^*$ trying to get a collision.} 19 | {} 20 | {} 21 | {} 22 | \cseqchallenger{$k \ud \bits^\lambda$} 23 | \send{}{$m_0^*, m_1^*$}{} 24 | \receive{\shortstack[l]{ 25 | $c^* \ud \enc(k, m_b^*)$ 26 | }}{$c^*$}{} 27 | \cseqdelay 28 | \cseqbeginloop 29 | \send{}{$m_0^*$}{} 30 | \receive{$c \ud \enc(k, m_0^*)$}{$c$}{} 31 | \send{}{$0 \textsc{ iff } c = c^*$}{} 32 | \cseqendloop 33 | \cseqdelay 34 | \send{}{$1$}{} 35 | \end{cryptogame} 36 | 37 | I claim that the following unbounded attacker (see figure \ref{cryptogame:6.a.1}) $\mathcal{A}$ is able to distinguish with non negligible probability the CPA games\footnote{as defined in class} $G_{\Pi, \mathcal{A}}^{CPA}(\lambda, b), b \in \bits$: $\mathcal{A}$ sends two messages $m_0^*$ and $m_1^*$, and receives a ciphertext $c_b^*$ (remind that the goal for the attacker is to guess $b$). Then it asks for exponentially many encryptions of $m_0^*$: if it gets back $c_b^*$, then returns $b' = 0$; otherwise, if at the end of all these queries, it never observes the desired ciphertext, returns $b'=1$. Note that if the challenger selects $b = 1$, the attacker wins with probability 1 (because it will never\footnote{$\dec$ is deterministic: it uses the secret key and (part of) the ciphertext to extract the message.} observe $c_1^*$ asking for the encryption of $m_0$); instead, if $b = 0$, it loses the game with negligible probability. Indeed, let assume that the number of queries is $Q = 2^{p(\lambda)}$: then, the probability that after $Q$ runs, the challenger never encrypts the message in the same way\footnote{clearly the secret key $k$ is fixed: what continuously changes is the random information used by $\enc$.} he did the first time is $ \le (1 - \frac{1}{2^{p(\lambda)}})^{2^{p(\lambda)}} \le \frac{1}{e}$. But then: 38 | \[ \P[G_{\Pi, \mathcal{A}}^{CPA}(\lambda, 1) = 1] - \P[G_{\Pi, \mathcal{A}}^{CPA}(\lambda, 0) = 1] \ge 1 - \frac{1}{e} \] 39 | i.e. non-negligible. 40 | \end{solution} 41 | 42 | \item Let $\mathcal{F} = \{ F_k: \bits^n \to \bits^n \}_{k \in \bits^\lambda}$ be a family of pseudorandom permutations, and define a fixed-length encryption scheme $(\enc, \dec)$ as follows: upon input message $m \in \bits^{n/2}$ and key $k \in \bits^\lambda$ , algorithm $\enc$ chooses a random string $r \ud \bits^{n/2}$ and computes $c \deq F_k(r||m)$. Show how to decrypt, and prove that this scheme is CPA-secure for messages of length $n/2$. 43 | 44 | \begin{solution} 45 | \begin{cryptoredux} 46 | {6.b.1} 47 | {Simulation of $Game_{\mathcal{A}^*}^{\texttt{PRF}}(\lambda)$. Base an attack to PRF $F_k$, assuming the existence of a PPT attacker $\mathcal{A}$, able to break the CPA-security of $F$ with non-negligible probability. $\mathcal{A}^*$ returns a bit $b$ to the challenger $\mathcal{C}$, in order to distinguish.} 48 | {} 49 | {} 50 | {} 51 | \cseqchallenger{$k \ud \bits^\lambda$} 52 | \cseqadversary{$r \ud \bits^{n/2}$} 53 | \cseqdelay 54 | \cseqbeginloop 55 | \return{}{$m$}{} 56 | \send{}{$r||m$}{} 57 | \receive{$c \ud F_k(r||m)$}{$c$}{} 58 | \invoke{}{$c$}{} 59 | \cseqendloop 60 | \cseqdelay 61 | \return{}{$m_0^*, m_1^*$}{} 62 | \cseqadversary{$b \ud \bits$} 63 | \send{}{$r||m_b^*$}{} 64 | \receive{\shortstack[l]{ 65 | $c^* \ud F_k(r||m_b^*)$ 66 | }}{$c^*$}{} 67 | \invoke{}{$c*$}{} 68 | \cseqdelay 69 | \cseqbeginloop 70 | \return{}{$m$}{} 71 | \send{}{$r||m$}{} 72 | \receive{$c \ud F_k(m)$}{$c$}{} 73 | \invoke{}{$c$}{} 74 | \cseqendloop 75 | \cseqdelay 76 | \return{}{$b'$}{} 77 | \send{}{$b \xor b'$}{} 78 | \end{cryptoredux} 79 | 80 | \begin{cryptoredux} 81 | {6.b.2} 82 | {Simulation of $Game_{\mathcal{A}^*}^{\texttt{random}}(\lambda)$. Same approach of \ref{cryptoredux:6.b.1}, but in this case the challenger uses random values from a randomly chosen permutation P.} 83 | {} 84 | {} 85 | {} 86 | \cseqchallenger{$P \ud \mathcal{P}(n)$} 87 | \cseqadversary{$r \ud \bits^{n/2}$} 88 | \cseqdelay 89 | \cseqbeginloop 90 | \return{}{$m$}{} 91 | \send{}{$r||m$}{} 92 | \receive{$c \ud P(r||m)$}{$c$}{} 93 | \invoke{}{$c$}{} 94 | \cseqendloop 95 | \cseqdelay 96 | \return{}{$m_0^*, m_1^*$}{} 97 | \cseqadversary{$b \ud \bits$} 98 | \send{}{$r||m_b^*$}{} 99 | \receive{\shortstack[l]{ 100 | $c^* \ud P(r||m_b^*)$ 101 | }}{$c^*$}{} 102 | \invoke{}{$c*$}{} 103 | \cseqdelay 104 | \cseqbeginloop 105 | \return{}{$m$}{} 106 | \send{}{$r||m$}{} 107 | \receive{$c \ud P(m)$}{$c$}{} 108 | \invoke{}{$c$}{} 109 | \cseqendloop 110 | \cseqdelay 111 | \return{}{$b'$}{} 112 | \send{}{$b \xor b'$}{} 113 | \end{cryptoredux} 114 | Since $F$ is a PRP it is efficiently invertible; so in order to decrypt, we do: $F_k^{-1}(c) = r || m$ and then we only take the last $n/2$ bits. 115 | 116 | Assume the scheme is not CPA-secure: then there exists an efficient attacker $\mathcal{A}$ able to break our scheme (win the CPA game with non-negligible probability); but then we can break $F$ too, i.e. we can build on top of it an attacker $\mathcal{A}^*$ able to distinguish with a non-negligible probability between a random distribution (figure \ref{cryptoredux:6.b.2}) and the output of $F_k$ (figure \ref{cryptoredux:6.b.1}). Indeed, $A^*$ whenever $\mathcal{A}$ asks for some message $m$ to be encrypted, appends this to some random $r \in \bits^{n/2}$, and forwards this new message $m'\deq r||m$ to the challenger $\mathcal{C}$; finally, it forwards the ciphertext $c$, provided by $\mathcal{C}$ to the attacker. This is done for all the messages queried by $\mathcal{A}$ (this is allowed, of course, up to a polynomial number of queries since both $\mathcal{A}$ and $\mathcal{A}^*$ are PPT) both before and after the messages $m_0^*, m_1^*$: when these two messages are sent by $\mathcal{A}$, $\mathcal{A}^*$ selects at random a bit $b$, simulating the CPA game, modifies and forwards $m_b^*$ in the very same way as before. When the attacker outputs a bit $b'$, $\mathcal{A}^*$ forwards to the challenger 0 if and only if $b = b'$. Note that, if the challenger takes the value at random, we expect to win only in half of the cases; otherwise, by assumption, $\mathcal{A}^*$ returns 0 with a non negligible probability $\ge \frac{1}{2} + \frac{1}{p(\lambda)}$. This means that $\mathcal{A}^*$ can distinguish between the two scenarios (i.e. the two games) since: 117 | 118 | \[\P[Game_{\mathcal{A}^*}^{\texttt{PRF}}(\lambda) = 0] - \P[Game_{\mathcal{A}^*}^{\texttt{random}}(\lambda) = 0] \ge \frac{1}{p(\lambda)}\] 119 | that is non-negligible. 120 | \end{solution} 121 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw1/exercises/ex7.tex: -------------------------------------------------------------------------------- 1 | \section{Message Authentication} 2 | \begin{enumerate}[(a)] 3 | \item Assume UF-CMA MACs exist. Prove that there exists a MAC that is UF-CMA but is not strongly UF-CMA. (Recall that strong unforgeability allows the attacker to 4 | produce a forgery $(m^*, \tau^*)$ such that $(m^*, \tau^*) \ne (m, \tau)$ for all messages m queried. 5 | 6 | \begin{solution} 7 | Under this assumption, we can always build $M'$ such that $\tag'(m)\deq (\tag(m) || b), b \ud \bits$ and $\vrfy'(m, \tau)\deq \vrfy(m, \tau')$, where $\tau'$ is $\tau$ without the last bit: with this scheme, for each message $m$, we can produce $2k$ valid tags, for some $k \in \N \backslash \{0\}$ 8 | 9 | It easy to prove that $M'$ is not strongly UF-CMA, because if we know a valid pair $(m^*, \tau_1)$, obtained querying the oracle, we can produce a new valid pair $(m^*, \tau_2)$, flipping the last bit of $\tau_1$. 10 | But this scheme is still UF-CMA: assume not; then there exists some efficient attacker $\mathcal{A}$ able to produce, with non-negligible probability, a valid pair $(m, \tau)$: this pair is still valid for $M$ if we remove the last bit of $\tau$. 11 | \end{solution} 12 | 13 | \item Assume a generalization of MACs where a MAC $\Pi$ consists of a pair of algorithms $(\tag, \vrfy)$, such that $\tag$ is as defined in class (except that it could be randomized), whereas $\vrfy$ is a deterministic algorithm that takes as input a candidate pair $(m, \tau )$ and returns a decision bit $d \in \bits$ (indicating whether $\tau$ is a valid tag of $m$). Consider a variant of the game defining UF-CMA security of a MAC $\Pi$ = $(\tag, \vrfy)$, with key space $K = \bits^\lambda$, where the adversary is additionally granted access to a verification oracle $\vrfy(k, \cdot, \cdot)$. 14 | 15 | \begin{enumerate}[(i)] 16 | \item Make the above definition precise, using the formalism we used in class. Call the new notion "unforgeability under chosen-message and verification attacks" (UF-CMVA). 17 | 18 | \begin{solution} 19 | Let consider the following game $Game_{\Pi, \mathcal{A}}^{\texttt{UF-CMVA}}(\lambda)$: 20 | \begin{enumerate} 21 | \item the challenger $\mathcal{C}$ choses a key $k \ud \bits^\lambda$ 22 | \item $\mathcal{A}$ can query (up to a polynomial number of times) $\mathcal{C}$ with some message $m$ and receive back $\tag(k, m)$ 23 | \item $\mathcal{A}$ can query (up to a polynomial number of times) $\mathcal{C}$ with some pair $(m, \tau)$ and receive back the output of $\vrfy(k, m, \tau)$ 24 | \item $\mathcal{A}$ forges a pair $(m^*, \tau^*)$ such that $m^* \ne m, \forall m$ queried ($m^*$ has to be "fresh") 25 | \item the output of the game is $\vrfy(k, m^*, \tau^*)$ (i.e. 1 in case of winning, 0 otherwise) 26 | \end{enumerate} 27 | We say that a MAC $\Pi$ is UF-CMVA-secure if $\forall$ PPT attackers $\mathcal{A}, \exists \epsilon(\lambda) \in negl(\lambda)$: 28 | \[\P[Game_{\Pi, \mathcal{A}}^{\texttt{UF-CMVA}}(\lambda) = 1] \le \epsilon(\lambda) \] 29 | \end{solution} 30 | 31 | \item Show that whenever a MAC has unique tags (i.e., for every key $k$ there is only one valid tag $\tau$ for each message $m$) then UF-CMA implies UF-CMVA. 32 | 33 | \begin{solution} 34 | First of all, note that the only difference between the two games (i.e. the two definitions of security UF-CMA and UF-CMVA) is that in $Game_{\Pi, \mathcal{A}}^{\texttt{UF-CMVA}}(\lambda)$ the attacker can verify the validity of pairs $(m, \tau)$ before submitting its proposal $(m^*, \tau^*)$. 35 | It is easy to see that if for every key $k$, there is only one valid tag $\tau$ for each message $m$, the above situation can be simulated in a very simple way. 36 | 37 | Whenever $\mathcal{A}$ asks for some pair $(m, \tau)$ to be verified, we can simply forward to the challenger $m$ and receive back some $\tau_m$: if $\tau_m = \tau$, then we know that $\vrfy(m, \tau) = \vrfy(m, \tau_m) = 1$; otherwise, we know\footnote{we know it with probability 1: here it is crucial the assumption of unique tags, once the key is fixed.} that the pair $(m, \tau)$ is not valid (i.e. $\vrfy(m, \tau) = 0$). 38 | Of course, this trick does not alter the number of queries (because $\mathcal{A}$ is a PPT making a polynomial number of queries) and does not modify the correctness. 39 | \end{solution} 40 | 41 | \item Show that if tags are not unique there exists a MAC that satisfies UF-CMA but not UF-CMVA. 42 | 43 | \begin{solution} 44 | From the previous exercise, we know that if tags are unique (once the key is fixed), then UF-CMA implies UF-CMVA. Instead, if this condition does not hold, we can build some UF-CMA scheme that is not UF-CMVA. Assume to have some UF-CMA-secure scheme $\Pi\deq(\tag, \vrfy)$, that produces tags of $n$ bits for secret keys $\in \bits^\lambda$. 45 | 46 | Let $\Pi'\deq(\tag', \vrfy')$ such that $\tag'(k, m)$ computes $\tag(k,m)$ and appends some $x \in \bits^{\log \lambda}$ to it: this x is equal to $0^{\log \lambda}$, unless with some negligible probability, $2^{-\lambda}$, the algorithm $\tag'$ decides to chose as $x$ the binary representation of an index $i$ such that the i-th bit of the secret key $k_i = 1$\footnote{if such an index exists. The case for $k = 0^\lambda$ is also handled by the algorithm.}. The definition of algorithm $\vrfy'$ is straightforward, since it has to check the correctness of the first $n$ bits of the tag, i.e. it uses $\vrfy$ on that part of the tag. Then it has also to check that the bit $k_x$ is 1 (this is done if and only if $x \ne 0$). 47 | 48 | Here I also provide the pseudocodes of such algorithms. 49 | 50 | \subsubsection*{Pseudocode of $\tag'(k,m)$} 51 | \begin{algorithm}[H] 52 | \KwIn{secret key $k$, message $m$} 53 | \KwOut{a valid tag $\tau' \in \bits^{n + \log{\lambda}}$} 54 | $\tau \ud Tag(k, m)$ \\ 55 | luck $\ud \bits^\lambda$ \\ 56 | $x \leftarrow 0$ \\ 57 | \uIf{luck $= 0^\lambda \and k \ne 0^\lambda$}{$x \ud \{i : k_i = 1\}$} 58 | \Return $\tau || \langle x \rangle\footnote{the binary ($\log \lambda$ bits) representation of x}$ 59 | %\caption{} 60 | \end{algorithm} 61 | 62 | \subsubsection*{Pseudocode of $\vrfy'(k,m, (\tau || x))$} 63 | \begin{algorithm}[H] 64 | \KwIn{secret key $k$, message $m$, tag $(\tau || x), x\in \bits^{log \lambda}$} 65 | \KwOut{a decision bit $d \in \bits$} 66 | $d \leftarrow \vrfy(k, m, \tau)$ \\ 67 | $d' \leftarrow 1$ \\ 68 | \uIf{$x \ne 0^{\log \lambda}$}{\tcc{the $\in$ operator returns a bit (1 for true, 0 else)} 69 | $d' = x \in \{\langle i\rangle: k_i = 1\}$} 70 | \Return $d \and d'$ 71 | \end{algorithm} 72 | 73 | It is clear that such a scheme cannot be UF-CMVA-secure, because an attacker $\mathcal{A}$, after receiving some valid pair $(m, (\tau || x))$ can start querying the challenger (up to $\lambda - 1$ times, this is clearly polynomial) in order to leak bits of the secret keys: it tests all possible $x \in \bits^{\log \lambda}$, without varying $m$ and $\tau$; depending on the output of $\vrfy'$ on its inputs, it can understand whether a certain bit of $k$ is 1 or 0. Once it knows $\lambda - 1$ bits of the secret key $k$, it is very simple to guess the last one (i.e. the first bit $k_0$): e.g. it can compute a tag (valid with probability $1/2$) for a fresh message and ask the challenger to verify it; at this point it knows the full key, so it is really easy to always win the UF-CMVA game! 74 | 75 | On the contrary, this scheme preserves the UF-CMA security property. Indeed, an attacker can only ask the challenger to tag messages, but has no control over the choice of the last $\log \lambda$ bits of the tag. Since the probability to \textbf{not} use $0^{\log \lambda}$ as "padding" is negligible ($2^{-\lambda}$ by definition of $\enc'$), we can assume that the attacker can observe one single\footnote{the average number of bits of the secret key we expect to be leaked after $2^\lambda$ queries is 1: this is clearly not enough to retain a non-negligible advantage, so the number of queries should be even higher to leak enough bits! But this is for sure out the possibilities of a PPT attacker.} bit of the key only after exponentially (in $\lambda$) many queries. 76 | \end{solution} 77 | \end{enumerate} 78 | \end{enumerate} -------------------------------------------------------------------------------- /Homework/source/hw1/notation.sty: -------------------------------------------------------------------------------- 1 | \ProvidesPackage{notation}[Crypto Notation] 2 | 3 | % Required for crypto games 4 | \RequirePackage{tikz} 5 | \usetikzlibrary{arrows,shadows} % shadows for the entities, arrows for the messages 6 | \RequirePackage{xparse} % Improved macro/environment definition commands 7 | 8 | % Cryptography 9 | % 10 | % Evaluate UAR [math mode] 11 | \newcommand{\pickUAR}{\mathrel{{\leftarrow}\vcenter{\hbox{\scriptsize\rmfamily\upshape\!\!\textsf{\$}}}}} 12 | % Default challenger 13 | \newcommand{\challenger}{\textsf{C}} 14 | % Default adversary 15 | \newcommand{\adversary}{\textsf{A}} 16 | % Default distinguisher 17 | \newcommand{\distinguisher}{\textsf{D}} 18 | % Cryptogame [math mode] 19 | \NewDocumentCommand{\cryptog}{m O{\Pi} O{\adversary}}{\textsc{Game}^{\textsc{#1}}_{#2, #3}} 20 | % Hybrid game [math mode] 21 | \NewDocumentCommand{\hybridg}{m O{\Pi} O{\adversary}}{\textsc{Hyb}^{\textsc{#1}}_{#2, #3}} 22 | 23 | % Acronyms 24 | % 25 | % Independent and Identically Distributed 26 | \newcommand{\iid}{\textsc{iid}} 27 | % Uniformly At Random 28 | \newcommand{\uar}{\textsc{uar}} 29 | % Probabilistic Polynomial Time 30 | \newcommand{\ppt}{\textsc{ppt}} 31 | 32 | % Secret Key Encryption 33 | \newcommand{\ske}{\textsc{ske}} 34 | % Public Key Encryption 35 | \newcommand{\pke}{\textsc{pke}} 36 | % Message Authentication Code 37 | \newcommand{\mac}{\textsc{mac}} 38 | 39 | % One-Way Function 40 | \newcommand{\owf}{\textsc{owf}} 41 | % One-Way Permutation 42 | \newcommand{\owp}{\textsc{owp}} 43 | % PseudoRandom Generator 44 | \newcommand{\prg}{\textsc{prg}} 45 | % PseudoRandom Function 46 | \newcommand{\prf}{\textsc{prf}} 47 | % PseudoRandom Permutation 48 | \newcommand{\prp}{\textsc{prp}} 49 | % TrapDoor Permutation 50 | \newcommand{\tdp}{\textsc{tdp}} 51 | 52 | % Chosen Plaintext Attack 53 | \newcommand{\cpa}{\textsc{cpa}} 54 | % Chosen Ciphertext Attack 55 | \newcommand{\cca}{\textsc{cca}} 56 | % Universally unForgeable from Chosen Message Attack 57 | \newcommand{\ufcma}{\textsc{ufcma}} 58 | 59 | % Discrete Logarithm assumption 60 | \newcommand{\dl}{\textsc{dl}} 61 | % Decisional Diffie-Hellman assumption 62 | \newcommand{\ddh}{\textsc{ddh}} 63 | % Computational Diffie-Hellman assumption 64 | \newcommand{\cdh}{\textsc{cdh}} 65 | 66 | % Goldreich-Goldwasser-Micali construct 67 | \newcommand{\ggm}{\textsc{ggm}} 68 | 69 | % Function classes and relations 70 | % 71 | % Computational indistinguishability 72 | \newcommand{\compindist}{\approx_\textsc{c}} 73 | % Statistical indistinguishability 74 | \newcommand{\statindist}{\approx_\textsc{s}} 75 | 76 | %%%%%%%%%%%%%%%%%%%%%%%% 77 | % Cryptosequences 78 | %%%%%%%%%%%%%%%%%%%%%%%% 79 | 80 | % Define counters 81 | \newcounter{preinstance} 82 | \newcounter{instancecount} 83 | \newcounter{sequencecursor} 84 | \newcounter{intransientfigure} 85 | \setcounter{intransientfigure}{0} 86 | \newcounter{looplabel} 87 | 88 | \newcommand{\cseqcraftfloat}{ 89 | \ifnum\@floatpenalty<0\relax 90 | \else 91 | \setcounter{intransientfigure}{1} 92 | \begin{figure}[htbp] 93 | \centering 94 | \fi 95 | } 96 | 97 | % Styles 98 | \tikzstyle{msgstyle}=[->, >=angle 60] 99 | \tikzstyle{inststyle}=[rectangle, draw, anchor=west, minimum height=0.8cm, minimum width=1.6cm, fill=white, drop shadow={opacity=1,fill=black}] 100 | 101 | % Internal commands 102 | % 103 | % Diagram spacing 104 | \newcommand{\cseqdelay}{\stepcounter{sequencecursor}} 105 | 106 | % Message: from, fromtext, msgtext, to, totext 107 | \newcommand{\cseqmessager}[5]{ 108 | \stepcounter{sequencecursor} 109 | \path (#1)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor) 110 | node (tail) {} node [anchor = east] {#2}; 111 | \path (#4)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor) 112 | node (head) {} node [anchor = west] {#5}; 113 | \draw [msgstyle] (tail) -- (head) 114 | node [midway, above] {#3}; 115 | } 116 | 117 | % Message: from, fromtext, msgtext, to, totext 118 | \newcommand{\cseqmessagel}[5]{ 119 | \stepcounter{sequencecursor} 120 | \path (#1)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor) 121 | node (tail) {} node [anchor = west] {#2}; 122 | \path (#4)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor) 123 | node (head) {} node [anchor = east] {#5}; 124 | \draw [msgstyle] (tail) -- (head) 125 | node [midway, above] {#3}; 126 | } 127 | 128 | % New participant 129 | % \cseqentity[edge distance]{var}{name:class} 130 | \newcommand{\cseqentity}[3][0]{ 131 | \stepcounter{instancecount} 132 | \path (inst\thepreinstance.east)+(#1,0) 133 | node[inststyle] (inst\theinstancecount) {#3}; 134 | \path (inst\theinstancecount)+(0,-0.5*\unitfactor) 135 | node (#2) {}; 136 | \tikzstyle{instcolor#2}=[] 137 | \stepcounter{preinstance} 138 | } 139 | 140 | % Entity computation 141 | \newcommand{\cseqcompute}[3]{ 142 | \stepcounter{sequencecursor} 143 | \path (#1)+(0,-\thesequencecursor*\unitfactor-0.7*\unitfactor) 144 | node [anchor = #3] {#2}; 145 | } 146 | 147 | 148 | % API Commands 149 | % 150 | % Challenger computation 151 | \newcommand{\cseqchallenger}[1]{ 152 | \cseqcompute{C}{#1}{west}; 153 | } 154 | % Adversary computation - optional orientation as first argument: [east|west] 155 | \newcommand{\cseqadversary}[2][east]{ 156 | \cseqcompute{A}{#2}{#1}; 157 | } 158 | % Distinguisher computation 159 | \newcommand{\cseqdistinguisher}[1]{ 160 | \cseqcompute{D}{#1}{east}; 161 | } 162 | 163 | 164 | % Message from adversary to challenger 165 | \newcommand{\send}[3]{ 166 | \cseqmessager{A}{#1}{#2}{C}{#3} 167 | } 168 | % Message from challenger to adversary 169 | \newcommand{\receive}[3]{ 170 | \cseqmessagel{C}{#1}{#2}{A}{#3} 171 | } 172 | % Message from adversary to distinguisher - cryptoredux only 173 | \newcommand{\invoke}[3]{ 174 | \cseqmessagel{A}{#1}{#2}{D}{#3} 175 | } 176 | % Message from distinguisher to adversary - cryptoredux only 177 | \newcommand{\return}[3]{ 178 | \cseqmessager{D}{#1}{#2}{A}{#3} 179 | } 180 | 181 | 182 | % Arguments: Identifier (used as label) | description | challengername 183 | \NewDocumentEnvironment{cryptogame}{m m O{$\mathcal{A}$} O{$\mathcal{C}$} O{2.2}} 184 | { % Crypto-game BEGIN 185 | 186 | \cseqcraftfloat 187 | 188 | \begin{tikzpicture} 189 | 190 | % Set unit measurements 191 | \setlength{\unitlength}{1cm} 192 | \def\unitfactor{0.6} 193 | 194 | % Set counters 195 | \setcounter{preinstance}{0} 196 | \setcounter{instancecount}{0} 197 | \setcounter{sequencecursor}{0} 198 | \node[coordinate] (inst0) {}; 199 | 200 | % Loop macros 201 | \newcommand{\cseqbeginloop}{ 202 | \ifnum\thelooplabel=0 203 | \setcounter{looplabel}{\thesequencecursor} 204 | \stepcounter{looplabel} 205 | \else \PackageError{notation}{Attempting to nest loops in a cryptosequence. Close the former loop first} 206 | \fi 207 | } 208 | 209 | \newcommand{\cseqendloop}{ 210 | \ifnum\thelooplabel=0 211 | \PackageError{notation}{No loop to close here} 212 | \fi 213 | \ifnum\thelooplabel>\thesequencecursor\relax 214 | \PackageError{notation}{Closing an empty loop} 215 | \fi 216 | \draw[->](A)+(-0.2, -0.15-\thesequencecursor*\unitfactor-0.7*\unitfactor) 217 | .. controls +(-0.6, -1.3) 218 | and +(-0.6, +1.3) 219 | .. +(-0.2, 0.15-\thelooplabel*\unitfactor-0.7*\unitfactor); 220 | \setcounter{looplabel}{0} 221 | } 222 | 223 | % Add the game's participants 224 | \cseqentity{A}{#3} 225 | \cseqentity[#5]{C}{#4} 226 | 227 | } 228 | { % Crypto-game END 229 | 230 | \ifnum\value{instancecount}>0 231 | \foreach \t [evaluate=\t] in {1,...,\theinstancecount}{ 232 | \draw[dotted] (inst\t) -- ++(0,-\thesequencecursor*\unitfactor-2.2*\unitfactor); 233 | } 234 | \fi 235 | \end{tikzpicture} 236 | 237 | \ifnum\value{intransientfigure}=1 238 | \caption{#2} 239 | \label{cryptogame:#1} 240 | \end{figure} 241 | \setcounter{intransientfigure}{0} 242 | \fi 243 | } 244 | 245 | 246 | 247 | % Arguments: Identifier (used as label) | description | hp attacker | custom attacker | challengername 248 | \NewDocumentEnvironment{cryptoredux}{m m O{$\mathcal{A}$} O{$\mathcal{A}^*$} O{$\mathcal{C}$} O{2.2}} 249 | { % Crypto-game BEGIN 250 | 251 | \cseqcraftfloat 252 | 253 | \begin{tikzpicture} 254 | 255 | % Set unit measurements 256 | \setlength{\unitlength}{1cm} 257 | \def\unitfactor{0.6} 258 | 259 | % Set counters 260 | \setcounter{preinstance}{0} 261 | \setcounter{instancecount}{0} 262 | \setcounter{sequencecursor}{0} 263 | \node[coordinate] (inst0) {}; 264 | 265 | % Loop macros 266 | \newcommand{\cseqbeginloop}{ 267 | \ifnum\thelooplabel=0 268 | \setcounter{looplabel}{\thesequencecursor} 269 | \stepcounter{looplabel} 270 | \else \PackageError{notation}{Attempting to nest loops in a cryptosequence. Close the former loop first} 271 | \fi 272 | } 273 | 274 | \newcommand{\cseqendloop}{ 275 | \ifnum\thelooplabel=0 276 | \PackageError{notation}{No loop to close here} 277 | \fi 278 | \ifnum\thelooplabel>\thesequencecursor\relax 279 | \PackageError{notation}{Closing an empty loop} 280 | \fi 281 | \draw[->](D)+(-0.2, -0.15-\thesequencecursor*\unitfactor-0.7*\unitfactor) 282 | .. controls +(-0.6, -1.3) 283 | and +(-0.6, +1.3) 284 | .. +(-0.2, 0.15-\thelooplabel*\unitfactor-0.7*\unitfactor); 285 | \setcounter{looplabel}{0} 286 | } 287 | 288 | % Add the reduction's participants 289 | \cseqentity{D}{#3} 290 | \cseqentity[#6]{A}{#4} 291 | \cseqentity[#6]{C}{#5} 292 | 293 | } 294 | { % Crypto-game END 295 | 296 | \ifnum\value{instancecount}>0 297 | \foreach \t [evaluate=\t] in {1,...,\theinstancecount}{ 298 | \draw[dotted] (inst\t) -- ++(0,-\thesequencecursor*\unitfactor-2.2*\unitfactor); 299 | } 300 | \fi 301 | \end{tikzpicture} 302 | 303 | \ifnum\value{intransientfigure}=1 304 | \caption{#2} 305 | \label{cryptoredux:#1} 306 | \end{figure} 307 | \setcounter{intransientfigure}{0} 308 | \fi 309 | } -------------------------------------------------------------------------------- /Homework/source/hw2/notation.sty: -------------------------------------------------------------------------------- 1 | \ProvidesPackage{notation}[Crypto Notation] 2 | 3 | % Required for crypto games 4 | \RequirePackage{tikz} 5 | \usetikzlibrary{arrows,shadows} % shadows for the entities, arrows for the messages 6 | \RequirePackage{xparse} % Improved macro/environment definition commands 7 | 8 | % Cryptography 9 | % 10 | % Evaluate UAR [math mode] 11 | \newcommand{\pickUAR}{\mathrel{{\leftarrow}\vcenter{\hbox{\scriptsize\rmfamily\upshape\!\!\textsf{\$}}}}} 12 | % Default challenger 13 | \newcommand{\challenger}{\textsf{C}} 14 | % Default adversary 15 | \newcommand{\adversary}{\textsf{A}} 16 | % Default distinguisher 17 | \newcommand{\distinguisher}{\textsf{D}} 18 | % Cryptogame [math mode] 19 | \NewDocumentCommand{\cryptog}{m O{\Pi} O{\adversary}}{\textsc{Game}^{\textsc{#1}}_{#2, #3}} 20 | % Hybrid game [math mode] 21 | \NewDocumentCommand{\hybridg}{m O{\Pi} O{\adversary}}{\textsc{Hyb}^{\textsc{#1}}_{#2, #3}} 22 | 23 | % Acronyms 24 | % 25 | % Independent and Identically Distributed 26 | \newcommand{\iid}{\textsc{iid}} 27 | % Uniformly At Random 28 | \newcommand{\uar}{\textsc{uar}} 29 | % Probabilistic Polynomial Time 30 | \newcommand{\ppt}{\textsc{ppt}} 31 | 32 | % Secret Key Encryption 33 | \newcommand{\ske}{\textsc{ske}} 34 | % Public Key Encryption 35 | \newcommand{\pke}{\textsc{pke}} 36 | % Message Authentication Code 37 | \newcommand{\mac}{\textsc{mac}} 38 | 39 | % One-Way Function 40 | \newcommand{\owf}{\textsc{owf}} 41 | % One-Way Permutation 42 | \newcommand{\owp}{\textsc{owp}} 43 | % PseudoRandom Generator 44 | \newcommand{\prg}{\textsc{prg}} 45 | % PseudoRandom Function 46 | \newcommand{\prf}{\textsc{prf}} 47 | % PseudoRandom Permutation 48 | \newcommand{\prp}{\textsc{prp}} 49 | % TrapDoor Permutation 50 | \newcommand{\tdp}{\textsc{tdp}} 51 | 52 | % Chosen Plaintext Attack 53 | \newcommand{\cpa}{\textsc{cpa}} 54 | % Chosen Ciphertext Attack 55 | \newcommand{\cca}{\textsc{cca}} 56 | % Universally unForgeable from Chosen Message Attack 57 | \newcommand{\ufcma}{\textsc{ufcma}} 58 | 59 | % Discrete Logarithm assumption 60 | \newcommand{\dl}{\textsc{dl}} 61 | % Decisional Diffie-Hellman assumption 62 | \newcommand{\ddh}{\textsc{ddh}} 63 | % Computational Diffie-Hellman assumption 64 | \newcommand{\cdh}{\textsc{cdh}} 65 | 66 | % Goldreich-Goldwasser-Micali construct 67 | \newcommand{\ggm}{\textsc{ggm}} 68 | 69 | % Function classes and relations 70 | % 71 | % Computational indistinguishability 72 | \newcommand{\compindist}{\approx_\textsc{c}} 73 | % Statistical indistinguishability 74 | \newcommand{\statindist}{\approx_\textsc{s}} 75 | 76 | %%%%%%%%%%%%%%%%%%%%%%%% 77 | % Cryptosequences 78 | %%%%%%%%%%%%%%%%%%%%%%%% 79 | 80 | % Define counters 81 | \newcounter{preinstance} 82 | \newcounter{instancecount} 83 | \newcounter{sequencecursor} 84 | \newcounter{intransientfigure} 85 | \setcounter{intransientfigure}{0} 86 | \newcounter{looplabel} 87 | 88 | \newcommand{\cseqcraftfloat}{ 89 | \ifnum\@floatpenalty<0\relax 90 | \else 91 | \setcounter{intransientfigure}{1} 92 | \begin{figure}[htbp] 93 | \centering 94 | \fi 95 | } 96 | 97 | % Styles 98 | \tikzstyle{msgstyle}=[->, >=angle 60] 99 | \tikzstyle{inststyle}=[rectangle, draw, anchor=west, minimum height=0.8cm, minimum width=1.6cm, fill=white, drop shadow={opacity=1,fill=black}] 100 | 101 | % Internal commands 102 | % 103 | % Diagram spacing 104 | \newcommand{\cseqdelay}{\stepcounter{sequencecursor}} 105 | 106 | % Message: from, fromtext, msgtext, to, totext 107 | \newcommand{\cseqmessager}[5]{ 108 | \stepcounter{sequencecursor} 109 | \path (#1)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor) 110 | node (tail) {} node [anchor = east] {#2}; 111 | \path (#4)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor) 112 | node (head) {} node [anchor = west] {#5}; 113 | \draw [msgstyle] (tail) -- (head) 114 | node [midway, above] {#3}; 115 | } 116 | 117 | % Message: from, fromtext, msgtext, to, totext 118 | \newcommand{\cseqmessagel}[5]{ 119 | \stepcounter{sequencecursor} 120 | \path (#1)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor) 121 | node (tail) {} node [anchor = west] {#2}; 122 | \path (#4)+(0, -\thesequencecursor*\unitfactor-0.7*\unitfactor) 123 | node (head) {} node [anchor = east] {#5}; 124 | \draw [msgstyle] (tail) -- (head) 125 | node [midway, above] {#3}; 126 | } 127 | 128 | % New participant 129 | % \cseqentity[edge distance]{var}{name:class} 130 | \newcommand{\cseqentity}[3][0]{ 131 | \stepcounter{instancecount} 132 | \path (inst\thepreinstance.east)+(#1,0) 133 | node[inststyle] (inst\theinstancecount) {#3}; 134 | \path (inst\theinstancecount)+(0,-0.5*\unitfactor) 135 | node (#2) {}; 136 | \tikzstyle{instcolor#2}=[] 137 | \stepcounter{preinstance} 138 | } 139 | 140 | % Entity computation 141 | \newcommand{\cseqcompute}[3]{ 142 | \stepcounter{sequencecursor} 143 | \path (#1)+(0,-\thesequencecursor*\unitfactor-0.7*\unitfactor) 144 | node [anchor = #3] {#2}; 145 | } 146 | 147 | 148 | % API Commands 149 | % 150 | % Challenger computation 151 | \newcommand{\cseqchallenger}[1]{ 152 | \cseqcompute{C}{#1}{west}; 153 | } 154 | % Adversary computation - optional orientation as first argument: [east|west] 155 | \newcommand{\cseqadversary}[2][east]{ 156 | \cseqcompute{A}{#2}{#1}; 157 | } 158 | % Distinguisher computation 159 | \newcommand{\cseqdistinguisher}[1]{ 160 | \cseqcompute{D}{#1}{east}; 161 | } 162 | 163 | 164 | % Message from adversary to challenger 165 | \newcommand{\send}[3]{ 166 | \cseqmessager{A}{#1}{#2}{C}{#3} 167 | } 168 | % Message from challenger to adversary 169 | \newcommand{\receive}[3]{ 170 | \cseqmessagel{C}{#1}{#2}{A}{#3} 171 | } 172 | % Message from adversary to distinguisher - cryptoredux only 173 | \newcommand{\invoke}[3]{ 174 | \cseqmessagel{A}{#1}{#2}{D}{#3} 175 | } 176 | % Message from distinguisher to adversary - cryptoredux only 177 | \newcommand{\return}[3]{ 178 | \cseqmessager{D}{#1}{#2}{A}{#3} 179 | } 180 | 181 | 182 | % Arguments: Identifier (used as label) | description | challengername 183 | \NewDocumentEnvironment{cryptogame}{m m O{$\mathcal{A}$} O{$\mathcal{C}$} O{2.2}} 184 | { % Crypto-game BEGIN 185 | 186 | \cseqcraftfloat 187 | 188 | \begin{tikzpicture} 189 | 190 | % Set unit measurements 191 | \setlength{\unitlength}{1cm} 192 | \def\unitfactor{0.6} 193 | 194 | % Set counters 195 | \setcounter{preinstance}{0} 196 | \setcounter{instancecount}{0} 197 | \setcounter{sequencecursor}{0} 198 | \node[coordinate] (inst0) {}; 199 | 200 | % Loop macros 201 | \newcommand{\cseqbeginloop}{ 202 | \ifnum\thelooplabel=0 203 | \setcounter{looplabel}{\thesequencecursor} 204 | \stepcounter{looplabel} 205 | \else \PackageError{notation}{Attempting to nest loops in a cryptosequence. Close the former loop first} 206 | \fi 207 | } 208 | 209 | \newcommand{\cseqendloop}{ 210 | \ifnum\thelooplabel=0 211 | \PackageError{notation}{No loop to close here} 212 | \fi 213 | \ifnum\thelooplabel>\thesequencecursor\relax 214 | \PackageError{notation}{Closing an empty loop} 215 | \fi 216 | \draw[->](A)+(-0.2, -0.15-\thesequencecursor*\unitfactor-0.7*\unitfactor) 217 | .. controls +(-0.6, -1.3) 218 | and +(-0.6, +1.3) 219 | .. +(-0.2, 0.15-\thelooplabel*\unitfactor-0.7*\unitfactor); 220 | \setcounter{looplabel}{0} 221 | } 222 | 223 | % Add the game's participants 224 | \cseqentity{A}{#3} 225 | \cseqentity[#5]{C}{#4} 226 | 227 | } 228 | { % Crypto-game END 229 | 230 | \ifnum\value{instancecount}>0 231 | \foreach \t [evaluate=\t] in {1,...,\theinstancecount}{ 232 | \draw[dotted] (inst\t) -- ++(0,-\thesequencecursor*\unitfactor-2.2*\unitfactor); 233 | } 234 | \fi 235 | \end{tikzpicture} 236 | 237 | \ifnum\value{intransientfigure}=1 238 | \caption{#2} 239 | \label{cryptogame:#1} 240 | \end{figure} 241 | \setcounter{intransientfigure}{0} 242 | \fi 243 | } 244 | 245 | 246 | 247 | % Arguments: Identifier (used as label) | description | hp attacker | custom attacker | challengername 248 | \NewDocumentEnvironment{cryptoredux}{m m O{$\mathcal{A}$} O{$\mathcal{A}^*$} O{$\mathcal{C}$} O{2.2}} 249 | { % Crypto-game BEGIN 250 | 251 | \cseqcraftfloat 252 | 253 | \begin{tikzpicture} 254 | 255 | % Set unit measurements 256 | \setlength{\unitlength}{1cm} 257 | \def\unitfactor{0.6} 258 | 259 | % Set counters 260 | \setcounter{preinstance}{0} 261 | \setcounter{instancecount}{0} 262 | \setcounter{sequencecursor}{0} 263 | \node[coordinate] (inst0) {}; 264 | 265 | % Loop macros 266 | \newcommand{\cseqbeginloop}{ 267 | \ifnum\thelooplabel=0 268 | \setcounter{looplabel}{\thesequencecursor} 269 | \stepcounter{looplabel} 270 | \else \PackageError{notation}{Attempting to nest loops in a cryptosequence. Close the former loop first} 271 | \fi 272 | } 273 | 274 | \newcommand{\cseqendloop}{ 275 | \ifnum\thelooplabel=0 276 | \PackageError{notation}{No loop to close here} 277 | \fi 278 | \ifnum\thelooplabel>\thesequencecursor\relax 279 | \PackageError{notation}{Closing an empty loop} 280 | \fi 281 | \draw[->](D)+(-0.2, -0.15-\thesequencecursor*\unitfactor-0.7*\unitfactor) 282 | .. controls +(-0.6, -1.3) 283 | and +(-0.6, +1.3) 284 | .. +(-0.2, 0.15-\thelooplabel*\unitfactor-0.7*\unitfactor); 285 | \setcounter{looplabel}{0} 286 | } 287 | 288 | % Add the reduction's participants 289 | \cseqentity{D}{#3} 290 | \cseqentity[#6]{A}{#4} 291 | \cseqentity[#6]{C}{#5} 292 | 293 | } 294 | { % Crypto-game END 295 | 296 | \ifnum\value{instancecount}>0 297 | \foreach \t [evaluate=\t] in {1,...,\theinstancecount}{ 298 | \draw[dotted] (inst\t) -- ++(0,-\thesequencecursor*\unitfactor-2.2*\unitfactor); 299 | } 300 | \fi 301 | \end{tikzpicture} 302 | 303 | \ifnum\value{intransientfigure}=1 304 | \caption{#2} 305 | \label{cryptoredux:#1} 306 | \end{figure} 307 | \setcounter{intransientfigure}{0} 308 | \fi 309 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------