Por que o PGP criptografa de maneira diferente ao inserir um arquivo em vez de imprimir o resultado?

3

Vou usar a seguinte chave PGP armazenada em pub.pem:

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>
mQGiBDp1yy0RBADVlyDewVwltBs7HnHCG3bXlVUODFkn/00TdbM2SPnOAIkj4giB
ylOP7Mg+Hr5y7FIBvmPWx06In6JjNQiSbpshP5YHv57UfE79nEJdWuSTQt/7j7IJ
GkHYtBRHQMIAHMgT8IB5d3gFq52jSa8hw/ixMP09a0Rw8RP9+kOE4s9UrQCg/zVH
IHswdc/mb50PjdeXwnjxQbkD/3lJYEzz8eUlFHB4rVaC1yRi21Lypf0DIMfQg5j9
xBxY4odFJKyf22PeuAjp9roURRIbGIkIGH8eXF+Mav9OqEdD80JbEn1hZuaLk1RF
k1XJjmFRdKXz+Q7JmRdbs3zXXav2cYwalgzEXT5kuXuNlThLTnLoEFop8Hl3xM4/
PdqMBACkkHb07vPY5l429tdXqL00lE6LedlBW4FLjI534QgselsrUxq5U5y0Wg1Z
//a66l5QkyaMrpsHKfkLHdaPOVCs/WeG6eLwD/cUBEM1Y9Yb5DaB0njdZB3Yxcm8
W23hpKjDanb7SbaSA16gBIWRlvrB/qU+MZAj+EXRDJmwMJq2y7QjbmV0aXZhIGNh
ZnRvcmkgPG5ldGl2YWNAb25lYm94LmNvbT6JAE4EEBECAA4FAjp1yy0ECwMCAQIZ
AQAKCRDFpFclYzXzSwiRAJ0S3djCkJJPUalRyE+vWnfnhvJmDgCfTEBN2N6GlGWO
mrOg1tQlZoWbd5q5Ag0EOnXLLRAIAPZCV7cIfwgXcqK61qlC8wXo+VMROU+28W65
Szgg2gGnVqMU6Y9AVfPQB8bLQ6mUrfdMZIZJ+AyDvWXpF9Sh01D49Vlf3HZSTz09
jdvOmeFXklnN/biudE/F/Ha8g8VHMGHOfMlm/xX5u/2RXscBqtNbno2gpXI61Brw
v0YAWCvl9Ij9WE5J280gtJ3kkQc2azNsOA1FHQ98iLMcfFstjvbzySPAQ/ClWxiN
jrtVjLhdONM0/XwXV0OjHRhs3jMhLLUq/zzhsSlAGBGNfISnCnLWhsQDGcgHKXrK
lQzZlp+r0ApQmwJG0wg9ZqRdQZ+cfL2JSyIZJrqrol7DVekyCzsAAgIH+wVFKD3A
FEdEBHqDZuKjLdLJIKHk4gloKeQ60R9NLLFynfIgSvgsii5uWLY9+gZ2FIGnP3Yc
GxZH1HASv+pG1sw0MnhutxZui3E3Mt69Uv1KTlTGYkfS+mXBw4Qr7hXavCkF45we
f/9Qlj6hSKVjy4YcewdvpopM9S4gVcBq+EdTp1negsCyj3YhFiEo0JEL40mnoHX7
HudJBbiBmknmBZOjxzBBeDPcu7fWV/LDCWiFoGg9uWy2KOcIt7sNXVJbukbSGYg2
hzOB2JPaqCqI5+4YfUCumNLd0lktT7S1V3/6xszEnybQL7tMtmrZZFAFHFAwLNPA
bLxdF/b26GbrTT+JAEYEGBECAAYFAjp1yy0ACgkQxaRXJWM180ttbQCg98c40J41
iXkP9CuqGR0LBJ46VNAAnj+5dH9N226fBp5TN0rAyxwBveTK
=0VvA
-----END PGP PUBLIC KEY BLOCK-----

Importando a chave:

>>> gpg < pub.pem
pub  1024D/6335F34B 2001-01-29 netiva caftori <[email protected]>
sub  2048g/97F431A1 2001-01-29

>>> gpg --import < pub.pem 
gpg: key 6335F34B: "netiva caftori <[email protected]>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1

Criptografando e imprimindo o resultado:

>>> echo "encrypt this." | gpg --armor --recipient 18A489A6 --encrypt
gpg: 9BD7D221: There is no assurance this key belongs to the named user

pub  4096R/9BD7D221 2014-11-06 Apotheke2
 Primary key fingerprint: CAAF 8F36 3B87 E945 25D9  8AF8 9B73 8EE5 18A4 89A6
      Subkey fingerprint: 6817 E44B E8CF B4A8 4D88  BED4 B74B 3DAC 9BD7 D221

It is NOT certain that the key belongs to the person named
in the user ID.  If you *really* know what you are doing,
you may answer the next question with yes.

Use this key anyway? (y/N) y
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1

hQIMA7dLPayb19IhAQ/+PQSNWVgAKWjeQsotCvFeV95RFqNHFj7EDeLrbgdhWQAu
0MgCg7MrCrT8Hr6kKVXG1FmPX8ql9/CZfQf5iqSNL6v0k8zQCpet7RRhL2TuUwmm
3qLkEcbTzieoukKYqhVqascBSYUFpnpTKocywDScuiB4tRbRSgbca9YJvF3IgAtv
fcdoyspGef4QaEcgJ/mAFhun0AtQSZgPErxl87HBbgAV6VnC9L/0jpev3lZDn4CF
YN5jtOogSiZCVNQEm8uWUNN7j2S1HD0yfAdTU6ngB9g4gXQq3UEIN1hxHUzBSguD
N2C4/dGnKGDkvy9UFiV9rjYhwaEwyYqbChrwilxfhirZh1OY/pLJmTyy4BPgX3hP
EemUNW8TfjkXnciSdv0/nb/Ll+29dK/wW0nI1/4yU6lmAkAxC+ZLcT+GAK9kIQk1
RkuMk4DS5cRDRvTno5zPWKdYKlzcxeZczDvBBJLzBhiwOYAoHR7moFHm1n2QFR78
LKm/nyHvm34YDkjSloEGygfLo9oSzi+L/BeX9IHOYO3O8p5p+sisqzoti7JFsdZp
1iRdCu7wKyVI74bYHU6CzoB7awyI3QTmcgy83IgB6Ntlwjwt/J2OObT9K9WBOiJC
L3UqUrlTfjpSVdfZeqpAdR9AISU7rLd7LH2XWezs2YRDlg74ey8ruz+kYnVSi0DS
SQHfqlwyqpb+r5kW/GBdOdxVFSVZMpz0qyNcUFeNdAfCrCdWDmyqPc47+2tY8xsn
y/ZitDx9ram0Nc99GddxkmxGsz15vQFE/Ak=
=uHqF
-----END PGP MESSAGE-----

Criptografando e canalizando o resultado para um arquivo:

>>> echo "encrypt this." | gpg --armor --recipient 18A489A6 --encrypt > text.enc
gpg: 9BD7D221: There is no assurance this key belongs to the named user

pub  4096R/9BD7D221 2014-11-06 Apotheke2
 Primary key fingerprint: CAAF 8F36 3B87 E945 25D9  8AF8 9B73 8EE5 18A4 89A6
      Subkey fingerprint: 6817 E44B E8CF B4A8 4D88  BED4 B74B 3DAC 9BD7 D221

It is NOT certain that the key belongs to the person named
in the user ID.  If you *really* know what you are doing,
you may answer the next question with yes.

Use this key anyway? (y/N) y

>>> cat text.enc 
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1

hQIMA7dLPayb19IhARAAq5Sgcqr+reXH8V35ZvFCL3l/Auqq/EkNwIICHW9LfflB
exst6WHaF2t/wMKSCw0kkyCoqbw6typD4Hida4jg5QJytWjezWPA6qLcpf9LtMxg
hO4vPVOyP9sK1140LhqTK4lkTHEYrcS9HC1uy4KUVhEoYll43xwn8ofO7VfKuMzj
KmskwNiehSfye3KuCvbpqsHW14vK193GgGylaDwKRqvwkeXIzDN1Wv8Xq6wspocP
Q96fo5gTn5RxtlLZ5UJgdVQgjUgKs1V+LnUABQgAloEJdmFKCMRvIuE680doaJzF
A2ny+rfoDJYFSkfnWHebd2v21vKruSWFrseVLRadKlejgzjUmND7oflAjaX0hYt2
uFIjRhLshrMTPmgMXai+vSx3LgtMa5fJvkZ/5k9svm/e7PUoagEaD1y3dM81f99j
vvmcRVsVsABMwa7YvQz/C4i4PgD/LTeIZMuVU7ynbP9IpVUlP8XRvkOu1XBzxVFa
ggD4O8TTKgcfoy2D+dbnuSEH4ftQOpE4oC7Q9JaBEsUE3bAi8DC8OdkidJpGYVx/
rdfz6n2XW4W3siU4teGkmpnJacGrNCHpYbdesxYwj/9P/gvrumX7Xt6kbiCJVpte
r5wI7YSZcVLYvnWOcqFZ2vU6aTgK2enB6n9OChdYnkgZoQZ3PkQzYC2hw+ZOksnS
SQHlNBYasLhYqNDH8oYN5UKcZfip+R67r0kv8pYshFLoDIdFaDeRRWMovDfO9vRE
jaPHU2PgUB2JkqNHcWcUsLYy4nVbm8QKD8M=
=r7ho
-----END PGP MESSAGE-----

Por que a criptografia resultante não é idêntica?

    
por Raffael 03.12.2015 / 22:22

2 respostas

2

Existem várias razões para diferenças aqui.

  1. O OpenPGP é um criptosistema híbrido , combinando uma criptografia de chave pública / privada simétrica. Uma chave de sessão gerada aleatoriamente é usada para criptografar a mensagem real, e a própria chave de sessão é criptografada usando a chave pública. Como a chave de sessão é selecionada aleatoriamente cada vez que uma nova mensagem é criptografada, você receberá um novo texto criptografado cada vez que criptografar algo, não importando de STDIN ou de um arquivo.
  2. O "pacote de dados literais", a camada mais interna que contém a mensagem real (antes de ser compactada e criptografada) contém o nome do arquivo - ou a seqüência vazia se você criptografou a partir de STDIN.
  3. O pacote de dados literal mencionado acima também inclui um carimbo de data / hora, geralmente o carimbo de data / hora do arquivo criptografado ou a hora atual ao criptografar a partir de STDIN.

Todos esses pontos resultarão em criptografias muito diferentes para pequenas diferenças na entrada. Então, criptografar um segundo antes produzirá um criptografo completamente não relacionado!

  1. Finalmente, também os pacotes de criptografia (e, se usados, de assinatura) têm carimbos de data e hora, mas eles só alteram o timestamp individual, não o criptograma completo.
por 03.12.2015 / 23:53
2

Parece ser um número aleatório em vez de timestamp.

How PGP works PGP combines some of the best features of both conventional and public key cryptography. PGP is a hybrid cryptosystem. When a user encrypts plaintext with PGP, PGP first compresses the plaintext. Data compression saves modem transmission time and disk space and, more importantly, strengthens cryptographic security. Most cryptanalysis techniques exploit patterns found in the plaintext to crack the cipher. Compression reduces these patterns in the plaintext, thereby greatly enhancing resistance to cryptanalysis. (Files that are too short to compress or which don't compress well aren't compressed.)

PGP then creates a session key, which is a one-time-only secret key. This key is a random number generated from the random movements of your mouse and the keystrokes you type. This session key works with a very secure, fast conventional encryption algorithm to encrypt the plaintext; the result is ciphertext. Once the data is encrypted, the session key is then encrypted to the recipient's public key. This public key-encrypted session key is transmitted along with the ciphertext to the recipient.

Veja insira a descrição do link aqui

    
por 03.12.2015 / 22:52