# HG changeset patch
# User Minh Van Nguyen <mvngu.name@gmail.com>
# Date 1367910153 25200
# Node ID 58c5bacef9af4298568aafe8c7ba9b137b352c23
# Parent 592b5f7e633754aa343bf00012a6942597e084b4
trac #14478: reviewer patch
diff --git a/sage/crypto/lwe.py b/sage/crypto/lwe.py
a
|
b
|
|
231 | 231 | |
232 | 232 | INPUT: |
233 | 233 | |
234 | | - ``n`` - number of coeficients to be sampled |
| 234 | - ``n`` - number of coefficients to be sampled |
235 | 235 | - ``stddev`` - standard deviation |
236 | 236 | - ``precision`` - precision used for internal computations (default: ``53``) |
237 | 237 | - ``tailcut`` - cut the tail at ``tailcut`` standard deviations |
… |
… |
|
318 | 318 | UniformSampler(-2, 2) |
319 | 319 | """ |
320 | 320 | if lower_bound > upper_bound: |
321 | | raise TypeError("lower bound must be <= than upper bound.") |
| 321 | raise TypeError("lower bound must be <= upper bound.") |
322 | 322 | self.lower_bound = ZZ(lower_bound) |
323 | 323 | self.upper_bound = ZZ(upper_bound) |
324 | 324 | |
… |
… |
|
348 | 348 | |
349 | 349 | class UniformPolynomialSampler(SageObject): |
350 | 350 | """ |
351 | | uniform sampler for polynomials. |
| 351 | Uniform sampler for polynomials. |
352 | 352 | |
353 | 353 | EXAMPLE:: |
354 | 354 | |
… |
… |
|
367 | 367 | |
368 | 368 | INPUT: |
369 | 369 | |
370 | | - ``n`` - number of coeficients to be sampled |
| 370 | - ``n`` - number of coefficients to be sampled |
371 | 371 | - ``lower_bound`` - integer |
372 | 372 | - ``upper_bound`` - integer |
373 | 373 | |
… |
… |
|
380 | 380 | self.n = ZZ(n) |
381 | 381 | self.P = ZZ['x'] |
382 | 382 | if lower_bound > upper_bound: |
383 | | raise TypeError("lower bound must be <= than upper bound.") |
| 383 | raise TypeError("lower bound must be <= upper bound.") |
384 | 384 | self.lower_bound = ZZ(lower_bound) |
385 | 385 | self.upper_bound = ZZ(upper_bound) |
386 | 386 | self.D = UniformSampler(self.lower_bound, self.upper_bound) |
… |
… |
|
429 | 429 | - ``q`` - modulus typically > n (integer > 0) |
430 | 430 | - ``D`` - an error distribution such as an instance of |
431 | 431 | :class:`DiscreteGaussianSamplerRejection` or :class:`UniformSampler` |
432 | | - ``secret_dist`` - distribution of the secret; one of |
| 432 | - ``secret_dist`` - distribution of the secret (default: 'uniform'); one of |
433 | 433 | |
434 | 434 | - "uniform" - secret follows the uniform distribution in `\Zmod{q}` |
435 | | - "noise" - secret follows the noise distrbution |
| 435 | - "noise" - secret follows the noise distribution |
436 | 436 | - ``(lb,ub)`` - the secret is chosen uniformly from ``[lb,...,ub]`` including both endpoints |
437 | 437 | |
438 | 438 | - ``m`` - number of allowed samples or ``None`` if no such limit exists |
… |
… |
|
539 | 539 | """ |
540 | 540 | def __init__(self, n, secret_dist='uniform', m=None): |
541 | 541 | """ |
542 | | Construct LWE instance parameterised by security paramter ``n`` where |
| 542 | Construct LWE instance parameterised by security parameter ``n`` where |
543 | 543 | the modulus ``q`` and the ``stddev`` of the noise are chosen as in |
544 | 544 | [Reg09]_. |
545 | 545 | |
546 | 546 | INPUT: |
547 | 547 | |
548 | | - ``n`` - security paramter (integer > 0) |
| 548 | - ``n`` - security parameter (integer > 0) |
549 | 549 | - ``secret_dist`` - distribution of the secret. See documentation of :class:`LWE` |
550 | 550 | for details (default='uniform') |
551 | 551 | - ``m`` - number of allowed samples or ``None`` if no such limit exists |
… |
… |
|
570 | 570 | """ |
571 | 571 | def __init__(self, n, delta=0.01, m=None): |
572 | 572 | """ |
573 | | Construct LWE instance parameterised by security paramter ``n`` where |
| 573 | Construct LWE instance parameterised by security parameter ``n`` where |
574 | 574 | the modulus ``q`` and the ``stddev`` of the noise is chosen as in |
575 | 575 | [LP11]_. |
576 | 576 | |
577 | 577 | INPUT: |
578 | 578 | |
579 | | - ``n`` - security paramter (integer > 0) |
| 579 | - ``n`` - security parameter (integer > 0) |
580 | 580 | - ``delta`` - error probability per symbol (default: 0.01) |
581 | 581 | - ``m`` - number of allowed samples or ``None`` in which case ``m=2*n + |
582 | 582 | 128`` as in [LP11]_ (default: ``None``) |
… |
… |
|
613 | 613 | |
614 | 614 | class UniformNoiseLWE(LWE): |
615 | 615 | """ |
616 | | LWE oracle with uniform sectet with parameters as in [CGW13]_. |
| 616 | LWE oracle with uniform secret with parameters as in [CGW13]_. |
617 | 617 | |
618 | 618 | .. automethod:: __init__ |
619 | 619 | """ |
620 | 620 | def __init__(self, n, instance='key', m=None): |
621 | 621 | """ |
622 | | Construct LWE instance parameterised by security paramter ``n`` where |
| 622 | Construct LWE instance parameterised by security parameter ``n`` where |
623 | 623 | all other parameters are chosen as in [CGW13]_. |
624 | 624 | |
625 | 625 | INPUT: |
626 | 626 | |
627 | | - ``n`` - security paramter (integer >= 80) |
| 627 | - ``n`` - security parameter (integer >= 89) |
628 | 628 | - ``instance`` - one of |
629 | 629 | |
630 | 630 | - "key" - the LWE-instance that hides the secret key is generated |
… |
… |
|
929 | 929 | |
930 | 930 | def balance_sample(s, q=None): |
931 | 931 | r""" |
932 | | Given ``(a,c) = s`` return a tuple ``(a',c')`` where ``a'`` is a integer |
| 932 | Given ``(a,c) = s`` return a tuple ``(a',c')`` where ``a'`` is an integer |
933 | 933 | vector with entries between -q//2 and q//2 and ``c`` is also within these |
934 | 934 | bounds. |
935 | 935 | |