That fuck shit the fascists are using
at master 120 lines 3.3 kB view raw
1/** 2 * Copyright (C) 2011 Whisper Systems 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17package org.tm.archive.crypto; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21 22import java.util.Arrays; 23 24import javax.crypto.spec.SecretKeySpec; 25 26/** 27 * When a user first initializes TextSecure, a few secrets 28 * are generated. These are: 29 * 30 * 1) A 128bit symmetric encryption key. 31 * 2) A 160bit symmetric MAC key. 32 * 3) An ECC keypair. 33 * 34 * The first two, along with the ECC keypair's private key, are 35 * then encrypted on disk using PBE. 36 * 37 * This class represents 1 and 2. 38 * 39 * @author Moxie Marlinspike 40 */ 41 42public class MasterSecret implements Parcelable { 43 44 private final SecretKeySpec encryptionKey; 45 private final SecretKeySpec macKey; 46 47 public static final Parcelable.Creator<MasterSecret> CREATOR = new Parcelable.Creator<MasterSecret>() { 48 @Override 49 public MasterSecret createFromParcel(Parcel in) { 50 return new MasterSecret(in); 51 } 52 53 @Override 54 public MasterSecret[] newArray(int size) { 55 return new MasterSecret[size]; 56 } 57 }; 58 59 public MasterSecret(SecretKeySpec encryptionKey, SecretKeySpec macKey) { 60 this.encryptionKey = encryptionKey; 61 this.macKey = macKey; 62 } 63 64 private MasterSecret(Parcel in) { 65 byte[] encryptionKeyBytes = new byte[in.readInt()]; 66 in.readByteArray(encryptionKeyBytes); 67 68 byte[] macKeyBytes = new byte[in.readInt()]; 69 in.readByteArray(macKeyBytes); 70 71 this.encryptionKey = new SecretKeySpec(encryptionKeyBytes, "AES"); 72 this.macKey = new SecretKeySpec(macKeyBytes, "HmacSHA1"); 73 74 // SecretKeySpec does an internal copy in its constructor. 75 Arrays.fill(encryptionKeyBytes, (byte) 0x00); 76 Arrays.fill(macKeyBytes, (byte)0x00); 77 } 78 79 80 public SecretKeySpec getEncryptionKey() { 81 return this.encryptionKey; 82 } 83 84 public SecretKeySpec getMacKey() { 85 return this.macKey; 86 } 87 88 @Override 89 public void writeToParcel(Parcel out, int flags) { 90 out.writeInt(encryptionKey.getEncoded().length); 91 out.writeByteArray(encryptionKey.getEncoded()); 92 out.writeInt(macKey.getEncoded().length); 93 out.writeByteArray(macKey.getEncoded()); 94 } 95 96 @Override 97 public int describeContents() { 98 return 0; 99 } 100 101 public MasterSecret parcelClone() { 102 Parcel thisParcel = Parcel.obtain(); 103 Parcel thatParcel = Parcel.obtain(); 104 byte[] bytes = null; 105 106 thisParcel.writeValue(this); 107 bytes = thisParcel.marshall(); 108 109 thatParcel.unmarshall(bytes, 0, bytes.length); 110 thatParcel.setDataPosition(0); 111 112 MasterSecret that = (MasterSecret)thatParcel.readValue(MasterSecret.class.getClassLoader()); 113 114 thisParcel.recycle(); 115 thatParcel.recycle(); 116 117 return that; 118 } 119 120}