1 00:00:00,000 --> 00:00:06,380 We have Matt with prototyping cryptographic protocols in Python with charm. Thank you 2 00:00:10,220 --> 00:00:10,820 So 3 00:00:14,440 --> 00:00:16,960 What is charm why they use that word? 4 00:00:16,980 --> 00:00:24,600 So charm is actually the name of a Python framework that came out of jhu it uses a mix of Python and C and 5 00:00:25,200 --> 00:00:27,900 It's used for prototyping cryptographic protocols 6 00:00:27,900 --> 00:00:35,640 so in this talk, I'm gonna go over a number of cryptographic primitives and I 7 00:00:37,420 --> 00:00:43,720 Intend to demo how some of them work in charm just so you can get idea of how you could play with some of this 8 00:00:43,720 --> 00:00:45,200 yourself and 9 00:00:45,200 --> 00:00:50,400 Some of these will be ones you're familiar with perhaps some not so much. So 10 00:00:52,400 --> 00:00:55,620 Let's start get started with that. All right, so 11 00:00:56,420 --> 00:00:57,440 some of the 12 00:00:57,440 --> 00:01:02,740 Basic primitives in charm are block ciphers and math 13 00:01:03,620 --> 00:01:04,260 so 14 00:01:05,840 --> 00:01:08,260 So as far as block ciphers are concerned 15 00:01:09,000 --> 00:01:12,880 They include DS triple des and a yes 16 00:01:13,540 --> 00:01:18,500 It does also have stream ciphers. I just didn't really look too much into them, but 17 00:01:19,800 --> 00:01:21,860 It's gonna be a lot of back-and-forth the microphone 18 00:01:23,520 --> 00:01:26,120 Okay, so I 19 00:01:26,120 --> 00:01:28,300 I just put basically as a a 20 00:01:30,240 --> 00:01:37,260 Stretch pad here a bunch of Python code that we can use to demo some of this. So I'm gonna 21 00:01:39,040 --> 00:01:44,700 Explain a little bit about what this is. So first I'm just going to just convince you that 22 00:01:44,700 --> 00:01:48,860 We it does support a yes encryption and decryption 23 00:01:49,700 --> 00:01:52,580 Here I'm just doing an example of CBC mode 24 00:01:53,700 --> 00:01:55,900 and when you create a new 25 00:01:56,120 --> 00:01:57,400 AES object 26 00:01:57,400 --> 00:02:05,960 The first argument is the key. The second is the mode and the third is the IV as applicable 27 00:02:07,000 --> 00:02:07,560 so 28 00:02:08,200 --> 00:02:11,540 You know submarine was it's a bit of a shout out to the medicine challenges 29 00:02:12,080 --> 00:02:18,680 They like to have a lot of music references and their challenges and that was their favorite AES key apparently, so 30 00:02:19,380 --> 00:02:21,060 It's kind of my favorite AES key 31 00:02:22,040 --> 00:02:23,640 not in production, but 32 00:02:25,440 --> 00:02:25,720 just 33 00:02:25,720 --> 00:02:31,220 Like it's a convenient one. For examples. It's happens to work out to be 16 characters. So that's nice 34 00:02:31,220 --> 00:02:35,380 All right, so I'm gonna jump into the console 35 00:02:49,420 --> 00:02:51,780 And I'm just going to restart it real quick 36 00:02:51,780 --> 00:02:52,580 and 37 00:02:57,200 --> 00:03:01,500 Okay, so, hold on one moment. 38 00:03:21,240 --> 00:03:23,420 Well, I guess that would be nice. 39 00:03:23,420 --> 00:03:25,440 It's intended for questions. 40 00:03:25,760 --> 00:03:28,040 I'm not sure if, yeah. 41 00:03:28,940 --> 00:03:30,060 Fred, what do you think about this? 42 00:03:31,280 --> 00:03:31,880 Yeah, okay. 43 00:03:32,160 --> 00:03:33,620 Yeah, it makes your life easier. 44 00:03:33,780 --> 00:03:34,000 Yeah. 45 00:03:34,080 --> 00:03:34,720 This whole story. 46 00:03:35,880 --> 00:03:38,160 I was, when I first saw the setup here, 47 00:03:38,220 --> 00:03:39,660 I was like, no, I don't understand. 48 00:03:39,960 --> 00:03:42,040 Somebody's like, do you know how to turn these off? 49 00:03:42,100 --> 00:03:43,160 I don't know how to turn these off. 50 00:03:43,300 --> 00:03:44,420 You do that one on, I'll grab it. 51 00:03:46,760 --> 00:03:47,080 Excellent. 52 00:03:47,260 --> 00:03:48,360 That's that hacker right there. 53 00:03:48,520 --> 00:03:48,840 Yep. 54 00:03:51,920 --> 00:03:52,380 Thank you. 55 00:03:53,420 --> 00:03:54,260 All right. 56 00:03:56,600 --> 00:03:57,580 That's a lot better. 57 00:03:58,040 --> 00:03:58,720 All right. 58 00:04:03,040 --> 00:04:08,120 Okay, so, first I'm just gonna copy some imports. 59 00:04:08,380 --> 00:04:09,060 Or you know what? 60 00:04:09,380 --> 00:04:10,980 It might be just faster for me to type. 61 00:04:12,060 --> 00:04:13,100 So, from, 62 00:04:14,720 --> 00:04:19,060 so the structure of Charm is that as a, 63 00:04:19,880 --> 00:04:22,000 some of the core stuff is under core. 64 00:04:24,120 --> 00:04:29,080 And then Crypto, AES, and we'll import the AES class. 65 00:04:31,840 --> 00:04:32,800 Oh, oopsies. 66 00:04:32,820 --> 00:04:33,320 What did I miss? 67 00:04:36,060 --> 00:04:37,200 Oh, Crypto, ha. 68 00:04:38,520 --> 00:04:39,100 Thank you. 69 00:04:43,700 --> 00:04:44,180 Hmm. 70 00:04:45,440 --> 00:04:46,300 Maybe it's a, 71 00:05:02,280 --> 00:05:03,280 it should be. 72 00:05:05,540 --> 00:05:07,160 I swear this was just working. 73 00:05:09,480 --> 00:05:09,880 Hmm. 74 00:05:11,520 --> 00:05:12,040 Let's see. 75 00:05:12,320 --> 00:05:12,720 So. 76 00:05:17,100 --> 00:05:17,900 Well, actually. 77 00:05:19,500 --> 00:05:20,500 Let me just make sure that, 78 00:05:20,900 --> 00:05:22,120 oh, no, wait, it's not the one. 79 00:05:22,400 --> 00:05:22,800 Okay. 80 00:05:23,000 --> 00:05:23,400 I know this is the first time I've done this. 81 00:05:28,660 --> 00:05:32,140 Let me just make sure that we can do some of the other ones, too, so it would be a real 82 00:05:32,140 --> 00:05:52,820 shame if the other demos don't work, okay, so, I'll do it, all right, there we go, okay, 83 00:05:52,820 --> 00:05:59,560 so, at least that one works, all right, so, perhaps, you'll take my word for it that AES works 84 00:05:59,560 --> 00:06:08,900 properly, as you can see, also, we have to import padding, so, it's not going to just assume what 85 00:06:08,900 --> 00:06:17,180 padding you want, it has PKCS7 padding included, so, if you just look at the code, we'll create a 86 00:06:17,180 --> 00:06:22,800 new AES object, we create a PKCS7 padding object, and then we can encrypt, you know, 87 00:06:22,820 --> 00:06:30,960 sample messages, and one thing to know, also, this is fairly common, I've noticed, with most 88 00:06:30,960 --> 00:06:39,860 implementations in software is that any time you want to decrypt, if you're doing both encryption 89 00:06:39,860 --> 00:06:46,500 and decryption in the same process, you need to create a separate instance of the object, so, 90 00:06:46,580 --> 00:06:52,420 you notice that before we decrypt, I create a new one with the same key and IV, 91 00:06:54,880 --> 00:07:07,500 and, yeah, trust me, it works, all right, so, move back to the slides a little bit, okay, 92 00:07:07,600 --> 00:07:14,160 so, as far as math is concerned, some core mathematical objects are integer groups, 93 00:07:14,400 --> 00:07:21,400 elliptic curve groups, and pairing groups, so, for integer groups, there are Schnorr groups and 94 00:07:21,400 --> 00:07:22,480 RSA groups. 95 00:07:22,820 --> 00:07:29,840 Schnorr groups are groups that are used for discrete log-based cryptosystems, they have the 96 00:07:29,840 --> 00:07:37,740 property of being a multiplicative group with a large, of a large prime order, so, it's a large 97 00:07:37,740 --> 00:07:48,060 prime order subgroup of a prime field, and RSA groups are the groups that use their RSA, and 98 00:07:48,060 --> 00:07:52,600 not just RSA, there are other cryptosystems that we'll see that use this same group. 99 00:07:55,060 --> 00:08:10,080 So, we already got RSA group here, and so, you can create an instance just by calling RSA group, 100 00:08:12,580 --> 00:08:21,900 and then it will allow you to just generate a new one, so, there's a pram gen method, and say, 1024, 101 00:08:28,100 --> 00:08:33,100 And that's just outputting the prime factors that make up the 102 00:08:33,100 --> 00:08:37,260 modulus. And the 1024 in this case is the size of the primes, 103 00:08:37,280 --> 00:08:43,680 not the final modulus. So this will be a 2048 modulus. And all 104 00:08:43,680 --> 00:08:46,940 the groups support getting random values. So you can do 105 00:08:47,920 --> 00:09:03,000 group.random. And you can multiply. Oh, I think it's the other side. 106 00:09:09,460 --> 00:09:13,360 No, maybe not. The other groups do. Okay. Anyway. 107 00:09:18,100 --> 00:09:27,180 Oops. Okay. So the elliptic curves, so both elliptic curves and pairing groups 108 00:09:27,180 --> 00:09:33,300 are, well, pairing groups are elliptic curves. But these elliptic curves 109 00:09:33,300 --> 00:09:39,060 are more the standard curves that, I think they include the standard NIST 110 00:09:39,060 --> 00:09:46,600 curves. I don't recall which ones they, other ones they include. These two 111 00:09:46,940 --> 00:09:52,260 files that I just mentioned are just put out, pointed out here is because this is how they 112 00:09:52,260 --> 00:10:01,140 split up their elliptic curve implementation. So the EC curve dot pi just specifies which curve 113 00:10:01,140 --> 00:10:09,640 it is. So it has just a huge list of variables or, so, for example, prime 256 V1 is, I believe, 114 00:10:09,680 --> 00:10:16,920 the NIST 256 bit prime P256. And EC group will implement all the group operations. So this is a 115 00:10:16,940 --> 00:10:19,660 very simple way to do this. So if you want to do this, if you want to do the group operations, or at least provide the 116 00:10:19,660 --> 00:10:33,420 interface to the group operations, everything should be implemented in C. So. We'll get the 117 00:10:39,680 --> 00:10:46,920 toolbox. And then we'll get the interface. And then we'll get the interface. And then we'll get the interface. And then we'll get the 118 00:10:46,940 --> 00:10:48,000 interface. And then we'll get the interface. And then we'll get the interface. And then we'll get the interface. And then we'll get the 119 00:10:48,000 --> 00:11:05,900 where we are going. So first import from EC curves, a prime 256 V1. And from EC group 120 00:11:07,420 --> 00:11:16,920 we'll get the EC group class. And then we'll have our group equals. And then we'll also 121 00:11:18,900 --> 00:11:33,400 group of prime 256 V1. And we can check things like group order. 122 00:11:34,770 --> 00:11:39,380 So that's how big the curve is. And we can get a random point P. 123 00:11:46,920 --> 00:11:57,400 And this one I know we can't multiply. So we can do point multiplication. We can add points. 124 00:11:57,600 --> 00:12:16,900 So if we make another random point Q. Then we can compute P plus Q. So we can 125 00:12:16,920 --> 00:12:25,820 do that. So I'm talking mostly about these math basics. Just because, so the whole idea here is 126 00:12:26,660 --> 00:12:31,440 if at any point you find out about some cryptosystem that you don't know of an existing 127 00:12:31,440 --> 00:12:36,140 implementation, you want to start working with it. So if you're, this is a more lower level one 128 00:12:36,140 --> 00:12:43,520 where you want to implement maybe some new scheme that uses elliptic curves. You can, and I 129 00:12:43,520 --> 00:12:46,900 misspelled pairing. I'm sorry. It's a good idea. So I'm going to go back to the 130 00:12:46,920 --> 00:12:53,480 elliptic curves. You can use elliptic curves or pairing curves. Was anybody here for the 131 00:12:54,060 --> 00:13:03,280 Pythia talk yesterday by any chance? Yeah. So I suspect that, I haven't actually tested this, 132 00:13:03,420 --> 00:13:09,940 but I suspect that it would be possible to implement that scheme using charm. Because you 133 00:13:09,940 --> 00:13:16,900 have access to pairings and from what little I could see all you need are hashes and elliptic 134 00:13:16,900 --> 00:13:25,540 curve pairings. But I could be wrong about that. Okay. So that's, that's all like basic, all the 135 00:13:25,540 --> 00:13:31,960 basics. Now we're going to get into what they call schemes. So we'll talk about a few of these. 136 00:13:32,440 --> 00:13:39,820 The first being public key cryptography. So we've got RSA and PyA. How many of you are familiar with 137 00:13:39,820 --> 00:13:46,880 PyA? Anybody? Okay. So PyA is used as an RSA group, but it's not a public key cryptography. It's a 138 00:13:46,900 --> 00:13:53,900 private key cryptography. But it has a neat property that the private key trapdoors discrete log. 139 00:13:54,180 --> 00:14:05,280 So you can have an additively homomorphic scheme and actually get back what the exponent is. So 140 00:14:05,280 --> 00:14:16,880 when you use the PyA class, PyA class, you can encrypt values of numbers and add them together. 141 00:14:16,900 --> 00:14:29,020 Or multiply them by scalars. So let's take a look at that. Okay. So. We'll get an import from 142 00:14:29,020 --> 00:14:45,060 charm.schemes. It's under public key encryption and then PKinc.py.99. It'll import pi99. And if we 143 00:14:45,060 --> 00:14:58,920 we call, we'll call lower case pi, pi 99. Oh, right. I forgot. So we need the RSA group 144 00:14:58,920 --> 00:15:07,620 object. So we'll just create a new one here. And then we can do key generation. It'll give 145 00:15:07,620 --> 00:15:20,880 us both a public key and a private key. And we'll specify our security parameter, which is 146 00:15:20,880 --> 00:15:36,000 just bit size. And so we have our public key, which you can see, so it's a generator G and 147 00:15:36,000 --> 00:15:37,600 modules N and then all of the other stuff. So we can see that it's a generator G and modules N and 148 00:15:37,600 --> 00:15:47,940 that also has N squared. That's what the N2 is. And private key is this lambda in U value, 149 00:15:48,600 --> 00:15:54,780 which allows us for doing the trap door of discrete log. And so if we want to encrypt the 150 00:15:54,780 --> 00:16:02,080 value, we'll, let's see, we'll do M1 equals, so I just, I have, those are just random 151 00:16:02,080 --> 00:16:07,500 digits in the little scratch file up there, so I'm just going to do a few more random 152 00:16:07,500 --> 00:16:07,580 digits. So I'm just going to do a few more random digits. So I'm going to do a few more 153 00:16:07,580 --> 00:16:26,920 digits. Like that. M2 be other random digits. M3 is M1 plus M2. And now we'll encrypt each 154 00:16:26,920 --> 00:16:37,560 one. The encrypt method requires the public key and the message you want to encrypt. And 155 00:16:47,920 --> 00:17:01,160 now I'll show you so we can do C3 equals C1 plus C2. So it lets you add cipher text. So 156 00:17:01,160 --> 00:17:07,320 cipher text structure is just a dictionary with the key being C and the value is just a long 157 00:17:07,320 --> 00:17:20,320 integer. And if we then decrypt it, yeah. So pi.decrypt, give it the public key, private 158 00:17:20,320 --> 00:17:31,760 key, and C3, I'll show that that's equal to M3. So you can see how this operation really is 159 00:17:31,760 --> 00:17:37,260 preserved through the encryption. And this can be 160 00:17:37,320 --> 00:17:43,400 quite useful in a number of schemes. So I think yesterday there were multiple talks that talked 161 00:17:43,400 --> 00:17:50,100 about homomorphic encryption. I plan on at the end of this one talking about a protocol that I 162 00:17:50,100 --> 00:17:56,660 worked on with another team that did secure text pattern matching using additively homomorphic 163 00:17:56,660 --> 00:18:07,300 encryption. And one of the cryptosystems they used was PiA. Okay. Oh, right. So this is a 164 00:18:07,320 --> 00:18:12,060 micro tymography, right. And I'll also demonstrate that in addition to adding you can also multiply 165 00:18:12,060 --> 00:18:25,220 by plain numbers. So it will let you, you know, do whatever times C3. Oh. Right. This is the one 166 00:18:25,720 --> 00:18:35,140 where I remember you have to put the number on the right side. There you go. So I mean all this really 167 00:18:35,140 --> 00:18:39,820 means is that you can do linear algebra, you can do matrix multiplication or 168 00:18:40,320 --> 00:18:54,480 vector math using encrypted values and unencrypted values. Okay so the next thing 169 00:18:54,480 --> 00:18:59,360 I'm just going to mention are commitment schemes. So commitment schemes allow for 170 00:18:59,360 --> 00:19:07,800 zero-knowledge proof. So this allows you to say I'm going to commit to this value but I'm not 171 00:19:07,800 --> 00:19:13,480 going to show you what it is first. So it has first binding property and hiding. So binding 172 00:19:13,480 --> 00:19:21,840 just means that I can't take back that that value was from me and hiding means that you won't 173 00:19:21,840 --> 00:19:29,340 know what the value was until I open the commitment. And they have, you know, they have 174 00:19:29,360 --> 00:19:36,680 support in here for Pedersen commitments. So this is just a quick overview of how Pedersen 175 00:19:36,680 --> 00:19:43,280 commitments work. Basically the way that Pedersen commitment works is that you're going to do 176 00:19:43,280 --> 00:19:52,380 algorithm encryption and then when you open the commitment, you just give them the private 177 00:19:52,380 --> 00:19:59,240 key and that allows them to decrypt it and verify that you give them the key and the 178 00:19:59,240 --> 00:19:59,340 encryption. So when you're doing this you give them the key and the encryption. And to 179 00:19:59,360 --> 00:20:05,360 message and you can show that they're the same thing. Okay. 180 00:20:08,320 --> 00:20:13,220 All right. So I'll talk a little bit about the protocol class. 181 00:20:13,400 --> 00:20:16,200 I'm going to go back and actually just show a little bit 182 00:20:16,200 --> 00:20:20,000 how it's structured. So one of the nice things about charm is 183 00:20:20,000 --> 00:20:24,000 that if you have a protocol that involves communication between 184 00:20:24,000 --> 00:20:30,020 two parties, then you can just write this in terms of methods 185 00:20:30,020 --> 00:20:33,580 that call, just return back values that would get sent back 186 00:20:33,580 --> 00:20:38,860 and forth. And it maintains the state machine of where you are 187 00:20:38,860 --> 00:20:44,500 in the protocol and handles for you the transport portion. So 188 00:20:45,180 --> 00:20:50,760 sending and receiving of data. And this also can be used as a 189 00:20:50,760 --> 00:20:53,980 sub-protocol. So you can, if you have a protocol that's 190 00:20:54,000 --> 00:20:58,500 contained in the protocol, you can have other protocols within 191 00:20:58,500 --> 00:21:02,380 your main protocol and refer back to what you already have 192 00:21:02,380 --> 00:21:16,260 contained in the bigger protocol. So let's, I'll show the, I'm just 193 00:21:16,260 --> 00:21:20,100 going to, actually, I'm going to get out of the presentation 194 00:21:20,100 --> 00:21:21,420 real quick for just a second. 195 00:21:36,300 --> 00:21:51,340 Okay. So the first, the init method just sets up all the sort 196 00:21:51,340 --> 00:21:53,880 of the common parameters that both sides of the protocol are 197 00:21:53,880 --> 00:22:00,100 going to have. And then in particular, it has what kind of, 198 00:22:00,480 --> 00:22:03,960 what are the party types. So are you going to refer to it as a 199 00:22:03,960 --> 00:22:10,200 sender, a receiver, or client and server. And the, there's a 200 00:22:10,780 --> 00:22:17,540 state machine that you set up in your init method. And this self.db 201 00:22:17,540 --> 00:22:21,320 just allows you to store data between different parts of the 202 00:22:21,320 --> 00:22:35,080 different method calls. The setup is all the information that tells it which instance it is, 203 00:22:35,120 --> 00:22:44,880 whether it's the server or the client. And this add instance is just used in the initialization 204 00:22:44,880 --> 00:23:14,860 method. And, yeah, it just has a variety of different useful methods that you can call to keep track of state, get state, and different points. Send messages and receive messages. So this is one thing that is, was not entirely clear to me when I was first using it. And it takes a bit of work. This is probably the hardest part of actually using this protocol class is that it's not 205 00:23:16,260 --> 00:23:44,860 necessarily the easiest thing to do. So when you initialize the class, you can pass it a socket, either a server socket or a client socket, and then it will transmit the data. But, you know, Python objects aren't just raw binary. You need to serialize and deserialize it. And it turns out that oftentimes it isn't smart enough to just serialize and deserialize all the objects it knows about. So you have to implement some serialization and deserialization in the 206 00:23:44,880 --> 00:23:52,000 protocol to get data back and forth. But once you have the appropriate methods and it just looks 207 00:23:52,000 --> 00:24:04,320 like passing data back and forth, one stage in the protocol will just be, will give you a return value and that will end up being the input to the next step in the protocol on the other 208 00:24:04,320 --> 00:24:14,860 side, just transparently. All right. So one of the first things that we did was we took a lot of data and we took a lot of data from the 209 00:24:14,880 --> 00:24:17,820 first types of protocols I'm going to talk about that is used 210 00:24:17,820 --> 00:24:23,560 is called sigma protocols. And so sigma protocols, they're 211 00:24:23,560 --> 00:24:26,300 called sigma protocols because of this three part structure 212 00:24:26,300 --> 00:24:31,660 that looks like the, in cryptographers' minds I guess, 213 00:24:31,740 --> 00:24:35,740 looks like the lines of a sigma, a great capital sigma. 214 00:24:36,540 --> 00:24:40,240 And so there are a number of these proofs where you want to 215 00:24:40,240 --> 00:24:44,180 show that you know something about a public value without 216 00:24:44,180 --> 00:24:48,660 revealing that information. And it follows this general 217 00:24:48,660 --> 00:24:53,360 structure of the prover sends some message A, the verifier 218 00:24:53,360 --> 00:24:59,360 sends back some string E, and then the prover sends a Z value 219 00:24:59,360 --> 00:25:03,180 and the verifier will either accept or reject the proof based 220 00:25:03,180 --> 00:25:10,120 on the values of X, A, E, and Z. And so I'll give you a little 221 00:25:10,120 --> 00:25:13,440 bit of an example here. So the first one is, you know, 222 00:25:14,180 --> 00:25:18,520 this is a discrete log based sigma protocol. So how can I 223 00:25:18,520 --> 00:25:23,340 prove to you that I know discrete log of a given group 224 00:25:23,340 --> 00:25:29,260 element and a given base without revealing that discrete log. And 225 00:25:31,820 --> 00:25:37,520 so here what we do is we start with a random exponentiation of 226 00:25:37,520 --> 00:25:43,180 our generator G and that's our A value. We send that back. The 227 00:25:44,180 --> 00:25:50,260 sends back an E value. So this 2 to the T less than size of G, 228 00:25:50,360 --> 00:25:54,200 that just means it's just some random value in the size of the 229 00:25:54,200 --> 00:25:57,160 group that we're working with. And then the prover sends back 230 00:25:57,960 --> 00:26:06,380 Z equals R plus EW. And if you look, since A is G to the R and 231 00:26:07,200 --> 00:26:13,280 H was originally G to the W, and the verifier is going to compute 232 00:26:13,280 --> 00:26:16,040 H to the E power, when you multiply all of this together, 233 00:26:16,160 --> 00:26:18,720 that should be the same thing as what's on the left side, that G 234 00:26:18,720 --> 00:26:24,820 to the Z value. So this allows you to hide the information 235 00:26:24,820 --> 00:26:35,380 about the original exponent in the new exponent. So I'm not 236 00:26:35,380 --> 00:26:39,340 going to quite show that because the sigma protocols aren't in 237 00:26:39,340 --> 00:26:43,260 charm already, aren't really, weren't implemented in the 238 00:26:43,260 --> 00:26:44,320 past. They were implemented with the intention of being 239 00:26:44,320 --> 00:26:50,160 independent protocols. It turns out that they use those for a 240 00:26:51,120 --> 00:26:56,640 different protocol called oblivious transfer. And so we'll 241 00:26:56,640 --> 00:27:00,400 talk a little bit about oblivious transfer. So the idea 242 00:27:00,400 --> 00:27:06,100 here is that you have, say a server has multiple messages and 243 00:27:06,100 --> 00:27:09,840 a client might want to know what one of those messages is, but 244 00:27:09,840 --> 00:27:12,760 they don't want to tell you what that message is and the server 245 00:27:13,260 --> 00:27:18,320 doesn't want to reveal the, all the, any other message besides 246 00:27:18,320 --> 00:27:24,160 the one the client's asking for. And this I think is a very 247 00:27:24,160 --> 00:27:28,320 interesting privacy preserving protocol. You can imagine a 248 00:27:28,320 --> 00:27:31,980 number of situations where you want to verify some information 249 00:27:31,980 --> 00:27:35,060 about, say, some domain, but you don't want to tell everybody 250 00:27:35,060 --> 00:27:37,640 that you want to check out this domain. It might be one that, 251 00:27:37,660 --> 00:27:43,180 you know, people are like, why are you looking there? So using a 252 00:27:43,180 --> 00:27:46,180 oblivious transfer is at least one way that I thought of that 253 00:27:46,180 --> 00:27:51,940 you could keep the privacy of this inquiry while still being 254 00:27:51,940 --> 00:27:56,720 able to satisfy these security considerations of doing 255 00:27:56,720 --> 00:28:02,880 validation on a domain. So this text just basically says what I 256 00:28:02,880 --> 00:28:05,760 was trying to say that, you know, in the original 257 00:28:06,920 --> 00:28:09,900 definition, it was just two messages. It's since been 258 00:28:09,900 --> 00:28:13,160 expanded to, you can have N messages and allow for, you know, 259 00:28:13,180 --> 00:28:25,640 up to K requests. And so I'll show you that they implemented 260 00:28:25,640 --> 00:28:31,520 what was called an adaptive oblivious transfer protocol in 261 00:28:32,490 --> 00:28:36,400 here. And it will demonstrate a little bit of how the protocol 262 00:28:36,400 --> 00:28:43,160 class is used, how it's subclassed in Python. So this 263 00:28:45,880 --> 00:29:01,380 is the protocol class. Okay. So you can see the first couple of 264 00:29:01,380 --> 00:29:06,480 lines under the protocol.net are talking about what I was saying 265 00:29:06,480 --> 00:29:11,020 before about how the protocol class maintains a state machine. 266 00:29:11,300 --> 00:29:13,160 So the way this works is it's a state machine. So it's a state 267 00:29:13,180 --> 00:29:15,080 machine. So the way this works is just by having a dictionary 268 00:29:15,080 --> 00:29:19,240 that maps which state you are, which is just a number, to the 269 00:29:19,820 --> 00:29:24,220 method that you have to call for the next part of the protocol. 270 00:29:26,280 --> 00:29:30,240 And, you know, typically it just goes in order one, two, three, 271 00:29:30,260 --> 00:29:36,820 four. But as you can see, I guess, like, the sender has the 272 00:29:36,820 --> 00:29:40,580 option of going from three to back to three or three to five. 273 00:29:40,580 --> 00:29:46,560 So the dictionary below, these are the transitions. So these 274 00:29:46,560 --> 00:29:49,000 basically are the nodes in your state machine. These are the 275 00:29:49,000 --> 00:29:54,860 transitions between them. And here's where we add the 276 00:29:54,860 --> 00:29:59,060 different types of parties, the receiver and sender. You'll 277 00:29:59,060 --> 00:30:03,240 notice a lot in charm a lot of these protocols use pairing 278 00:30:03,240 --> 00:30:10,560 groups. So we use a pairing group here. And then we have a 279 00:30:10,580 --> 00:30:19,760 set of methods. And then most of the, so these methods right 280 00:30:19,760 --> 00:30:24,100 here are actually ones I added because they didn't exist at the 281 00:30:24,100 --> 00:30:28,900 time. So when I tried first running this, I found that it 282 00:30:28,900 --> 00:30:32,320 would just crash. I was like, why, it was saying key. So what 283 00:30:32,320 --> 00:30:37,680 would happen is that when, because the serialization 284 00:30:37,680 --> 00:30:40,560 methods were not actually occurring, it was not actually 285 00:30:40,580 --> 00:30:44,360 sending and receiving data and then it would move on and try to 286 00:30:44,360 --> 00:30:50,580 access data that it didn't actually have. So, I had to go 287 00:30:50,580 --> 00:30:57,000 through and serialize the data. So more or less, what should work 288 00:30:57,000 --> 00:31:01,680 is you can pick up the data so you can use loads and dumps. 289 00:31:02,580 --> 00:31:06,280 However, there are a number of the classes that they have in 290 00:31:06,280 --> 00:31:09,200 here, pickle can't serialize. 291 00:31:09,200 --> 00:31:12,540 one of them being parent groups, the integer groups are also ones 292 00:31:12,540 --> 00:31:16,360 that just can't pickle. But those objects have their own 293 00:31:16,360 --> 00:31:20,100 serialization methods. So you can just call the serialized 294 00:31:20,100 --> 00:31:23,800 method on those and then it's just a byte string and you can 295 00:31:23,800 --> 00:31:30,480 pickle that. And then you can see that so in this case the 296 00:31:30,480 --> 00:31:33,720 first step in the protocol for the sender, that's the one that 297 00:31:33,720 --> 00:31:41,440 has all the messages is to set up these values and when a 298 00:31:41,440 --> 00:31:46,460 receiver first initiates contact, it's going to say, okay 299 00:31:47,000 --> 00:31:55,660 let's run sigma protocol 1. They structure all the sender 300 00:31:55,660 --> 00:31:58,500 methods together. So you'll see there's another one that 301 00:31:58,500 --> 00:32:01,400 involves where it's going to do the proving for sigma protocol 302 00:32:01,400 --> 00:32:03,700 one, do sigma protocol two, all the sender methods together. So 303 00:32:03,700 --> 00:32:08,980 three, so on and so forth. And then down here are the receiver 304 00:32:08,980 --> 00:32:16,560 methods and it will create the sigma protocol class and 305 00:32:16,560 --> 00:32:26,600 initialize it. And I had to extract out the necessary 306 00:32:26,600 --> 00:32:30,020 information for me to actually construct the values that need 307 00:32:30,020 --> 00:32:34,680 to go into the sigma protocol. In this case, the public key. And 308 00:32:36,000 --> 00:32:44,000 more or less works that way. At the bottom, they did allow this 309 00:32:44,000 --> 00:32:46,180 to be a script, although I couldn't actually get this to 310 00:32:46,180 --> 00:32:50,660 run properly here. So, I actually, what I did end up 311 00:32:50,660 --> 00:32:54,280 doing was, mostly because in PyCharm, I haven't found a way 312 00:32:54,280 --> 00:32:58,300 to run the same file with different parameters at the same 313 00:32:58,300 --> 00:33:00,000 time. So, I just, I don't know. If anybody has any questions, 314 00:33:00,000 --> 00:33:03,660 does anybody know how to do that? No? Okay. So, I just 315 00:33:03,660 --> 00:33:08,700 basically create two files that have the same functionality and 316 00:33:08,700 --> 00:33:11,720 just one gets the one parameter, the other gets the other, and it 317 00:33:11,720 --> 00:33:25,280 implements the protocol. And so. Locks? Oh, okay. So, 318 00:33:30,000 --> 00:33:34,180 yeah. So, I mean, I'm not exactly sure. So, I didn't end up 319 00:33:34,180 --> 00:33:38,740 doing that. So, what I did was I created two separate files. So, 320 00:33:39,740 --> 00:33:43,340 there's, this one's called oblivious transfer receiver and 321 00:33:43,340 --> 00:33:47,800 oblivious transfer sender. And in this case, the receiver acts 322 00:33:47,800 --> 00:33:53,080 as a server. So, let's hope this one actually works. Did work 323 00:33:53,080 --> 00:33:57,120 earlier today. So, it's operating a receiver and then, 324 00:34:00,400 --> 00:34:08,320 we'll do the sender. And, wow, that went fast. So, it appears 325 00:34:08,320 --> 00:34:13,360 to have gone through all the steps and, oh, that's the 326 00:34:13,360 --> 00:34:19,900 sender. The receiver said, yep, it looks like the protocol 327 00:34:19,900 --> 00:34:25,940 completed. So, this is, with a little bit of work of implementing 328 00:34:25,940 --> 00:34:28,280 the serialization and deserialization methods, this 329 00:34:28,280 --> 00:34:29,980 protocol is basically working. So, I'm going to go ahead and 330 00:34:30,000 --> 00:34:40,060 get ready out of the box in charm. All right. So, I'm going 331 00:34:40,060 --> 00:34:42,540 to now actually talk about that protocol I mentioned earlier. 332 00:34:43,560 --> 00:34:49,480 Also, I think it's pretty neat. And I think it would lend itself 333 00:34:49,480 --> 00:34:54,760 well to prototyping in charm here. So, when I actually did 334 00:34:54,760 --> 00:34:58,740 this, this was a while ago, about 7 years ago. We did the entire 335 00:35:00,000 --> 00:35:11,540 plus plus. But we looked into a Python based, a Python derivative called tasty L. And tasty 336 00:35:11,540 --> 00:35:17,820 stood for something about multi-party computation I think. I mentioned it in my talk last 337 00:35:17,820 --> 00:35:23,380 year. So I forgot what it stands for off the top of my head. But I think we always had 338 00:35:23,380 --> 00:35:29,460 problems getting it to actually work and compile. This should actually work. I haven't 339 00:35:29,460 --> 00:35:33,860 fully finished getting it to work. But I'm going to just quickly explain how the protocol 340 00:35:33,860 --> 00:35:45,720 works. So this, what we're trying to do here is we have a server that has some body of text. And 341 00:35:45,720 --> 00:35:55,520 you want to run a query on some sort of wild card based expression. So you can think of like 342 00:35:57,160 --> 00:35:59,440 grep with, without, you know, you can think of it as a, you know, you can think of it as a 343 00:35:59,440 --> 00:36:04,160 regular expression without allowing for multiple characters. Like you need to know exactly how 344 00:36:04,160 --> 00:36:10,960 many characters you're looking for. But you can, you can in principle ask for, say I want a 345 00:36:10,960 --> 00:36:20,140 pattern where like the first character is A through F and the second character is, you know, B 346 00:36:20,140 --> 00:36:29,420 through G or something like that. And then maybe the rest of them are all fixed characters. And or maybe, you know, you'll have just a like, it can be a little bit of a 347 00:36:29,440 --> 00:36:45,040 wild card star character. And this protocol should work. So the idea here is that what you're going to do is for each letter in your 348 00:36:45,040 --> 00:36:59,020 pattern, you're going to construct what we call, so this is CDV, a character delay vector. The idea is that let's assume that if we find that letter in the 349 00:36:59,500 --> 00:37:09,420 text we're searching, that it's part of our pattern, then how far away would we have to go until we reach the end of the pattern. So then we're 350 00:37:09,420 --> 00:37:28,720 going to say, we're going to go that much further and put a one there. And in the end, we should end up with a total of, like say for this pattern of TACT, we'll get a four in the location where the pattern is found. 351 00:37:30,000 --> 00:37:41,000 So I'll just go through real quick explaining this. So when you construct the CDV, you'll see, you first have a T here. That 352 00:37:41,000 --> 00:37:49,820 corresponds with this one here. The one at the end. Because that's saying that if this is that T, then we have to wait three more 353 00:37:49,820 --> 00:37:59,420 characters before we get to our pattern. And then if you get to see an A, that means, okay, if that was part of the pattern, then we're going to weight 3 more 354 00:37:59,440 --> 00:38:01,700 We have to wait two more characters. 355 00:38:01,860 --> 00:38:02,460 I'll be over here. 356 00:38:02,680 --> 00:38:05,360 The C corresponds to this one, 357 00:38:05,500 --> 00:38:08,760 and this T corresponds to this one right here. 358 00:38:08,820 --> 00:38:11,220 That's saying we're there, right? 359 00:38:11,320 --> 00:38:14,640 If the T we're on is that one, we're done. 360 00:38:15,460 --> 00:38:21,580 And then what you do is you start off with what we call an activation vector, 361 00:38:22,160 --> 00:38:25,700 and we go through each letter in the text 362 00:38:25,700 --> 00:38:29,460 and look at the corresponding character delay vector 363 00:38:29,460 --> 00:38:35,780 and add that chunk to the vector and keep moving forward. 364 00:38:35,860 --> 00:38:37,160 And then shift one over. 365 00:38:37,500 --> 00:38:42,480 So G had an all zero vector, so nothing happens here. 366 00:38:43,000 --> 00:38:47,300 The A has a 0, 0, 1, 0, so we get a one over here. 367 00:38:48,080 --> 00:38:52,080 There's this T, another T here, A, C, T. 368 00:38:52,580 --> 00:38:55,680 And what happens is... 369 00:38:55,700 --> 00:39:01,160 See, this one, as I said, corresponded to the end of the pattern, 370 00:39:01,280 --> 00:39:04,760 and it landed right here where that's the length of the pattern you want. 371 00:39:06,320 --> 00:39:08,220 If you want a wildcard situation, 372 00:39:08,620 --> 00:39:13,240 then you actually do that by saying, 373 00:39:13,340 --> 00:39:14,380 I'm going to look for one less. 374 00:39:14,520 --> 00:39:18,340 So say instead of looking for tact, 375 00:39:18,480 --> 00:39:22,960 I just wanted T, A, and then it could be anything, A, C, G, and T. 376 00:39:23,360 --> 00:39:25,680 Then instead of looking for... 377 00:39:25,700 --> 00:39:26,940 If I were looking for a four, I'd look for a three. 378 00:39:29,660 --> 00:39:36,320 And this actually comes from what I think are called time-delayed neural networks. 379 00:39:36,540 --> 00:39:39,120 That's where this terminology comes from, of activation vectors. 380 00:39:39,380 --> 00:39:45,900 So the whole idea being that the activation vector is how much time is delayed 381 00:39:45,900 --> 00:39:49,640 between when it sees it and when this neuron fires. 382 00:39:49,840 --> 00:39:54,920 But my colleagues realized, well, we could sort of borrow that concept 383 00:39:54,920 --> 00:39:55,680 and apply that. 384 00:39:55,680 --> 00:39:57,000 We could apply it here in this way. 385 00:40:01,200 --> 00:40:04,200 So in this protocol, 386 00:40:04,460 --> 00:40:07,320 what we do is we use an additively homomorphic encryption scheme. 387 00:40:07,920 --> 00:40:09,120 It can be pi A. 388 00:40:09,300 --> 00:40:12,660 There's an additive elgamol or an elliptic curve elgamol. 389 00:40:14,020 --> 00:40:17,340 And one of the things that's nice about this protocol 390 00:40:17,340 --> 00:40:23,180 is we make a few tweaks to allow us to use those bottom two. 391 00:40:24,780 --> 00:40:25,660 And that is... 392 00:40:25,680 --> 00:40:28,540 Instead of actually looking for four, 393 00:40:28,760 --> 00:40:35,040 what we do is we subtract by the four that we're looking for in every single spot. 394 00:40:35,640 --> 00:40:38,380 And that means we're really looking for zero. 395 00:40:40,500 --> 00:40:44,420 So what happens in our secure version is we do all this homomorphically. 396 00:40:44,640 --> 00:40:50,320 So what the server will do is it will generate this initial activation vector 397 00:40:50,320 --> 00:40:53,560 by creating an encryption of all zeros. 398 00:40:54,440 --> 00:40:55,660 And they'll all look the same. 399 00:40:55,680 --> 00:41:00,080 They'll all be different, because it's a probabilistic encryption scheme. 400 00:41:00,600 --> 00:41:07,220 And then the query that you send is going to be encryptions of all these values. 401 00:41:07,420 --> 00:41:09,480 So these are all going to be encrypted values. 402 00:41:09,860 --> 00:41:12,780 And the server won't be able to tell whether this is a zero or one. 403 00:41:13,020 --> 00:41:19,780 But because of the homomorphic nature of it, you can add and effectively subtract. 404 00:41:20,600 --> 00:41:25,040 And so we'll get back down here where this one will be zero. 405 00:41:25,680 --> 00:41:30,880 And then this protocol, the secure text pattern matching, 406 00:41:31,060 --> 00:41:35,600 adds a few extra steps to make sure that we don't leak any additional information. 407 00:41:36,020 --> 00:41:39,820 So what we also do is we multiply by random values. 408 00:41:40,160 --> 00:41:46,160 So anything else will become random except for the zeros, 409 00:41:46,300 --> 00:41:48,160 because anything times zero is zero. 410 00:41:48,920 --> 00:41:52,400 And then you can also shuffle around the values. 411 00:41:52,800 --> 00:41:55,180 So ultimately what you get is... 412 00:41:55,680 --> 00:41:59,560 So you can find out how many times that pattern showed up in the text, but not where. 413 00:41:59,860 --> 00:42:02,380 And you don't learn anything about... 414 00:42:03,100 --> 00:42:07,200 So in this protocol right here, you can learn that... 415 00:42:07,200 --> 00:42:13,080 You could get some information about how far off the text was at each location from your pattern. 416 00:42:13,560 --> 00:42:15,280 But by doing this... 417 00:42:18,620 --> 00:42:24,040 Subtracting by four is just to allow us to do a blinding step of just multiplying. 418 00:42:24,220 --> 00:42:25,660 That destroys a lot of the data. 419 00:42:25,660 --> 00:42:26,880 It destroys the information of the other ones. 420 00:42:27,040 --> 00:42:30,800 And then the shuffling just eliminates the information about where you found it. 421 00:42:33,320 --> 00:42:38,080 So I was hoping to actually demo this in Charm, 422 00:42:38,140 --> 00:42:43,200 but those serialization issues have been dogging me. 423 00:42:43,320 --> 00:42:45,980 So I don't quite have it working right now. 424 00:42:46,180 --> 00:42:52,060 But I can show you basically the structure of it. 425 00:42:52,200 --> 00:42:52,600 So... 426 00:42:58,160 --> 00:42:58,720 Okay. 427 00:42:58,980 --> 00:42:59,540 So... 428 00:43:04,500 --> 00:43:09,260 I wasn't sure if there was any way for me to just have one step on the server. 429 00:43:09,400 --> 00:43:11,000 Because really there's only one step. 430 00:43:11,420 --> 00:43:13,220 Each step is a... 431 00:43:15,860 --> 00:43:16,980 Between communications. 432 00:43:17,320 --> 00:43:23,900 So we'll either receive information and then send or do everything inside that. 433 00:43:24,040 --> 00:43:24,320 So... 434 00:43:24,320 --> 00:43:25,420 Since... 435 00:43:25,420 --> 00:43:25,640 Okay. 436 00:43:25,660 --> 00:43:31,320 All that happens is the server receives an encrypted request and then returns back a 437 00:43:31,320 --> 00:43:33,240 encrypted reply. 438 00:43:36,120 --> 00:43:38,260 There's really only one step here. 439 00:43:38,360 --> 00:43:42,100 But I put basically a dummy step here that just returns none. 440 00:43:43,180 --> 00:43:43,740 There. 441 00:43:44,440 --> 00:43:45,000 But... 442 00:43:47,900 --> 00:43:48,460 Okay. 443 00:43:48,660 --> 00:43:49,220 So... 444 00:43:52,200 --> 00:43:53,520 Go back up to the... 445 00:43:55,080 --> 00:43:55,640 Okay. 446 00:43:56,960 --> 00:43:57,480 And we'll see what happens. 447 00:43:57,480 --> 00:43:57,500 So... 448 00:43:57,500 --> 00:43:58,820 So here, you know, I... 449 00:43:58,820 --> 00:44:05,480 Again, have my states, my transitions, add parties, do all that kind of stuff. 450 00:44:06,560 --> 00:44:07,820 If you notice the... 451 00:44:07,820 --> 00:44:12,780 In the diagram I had before, it was using an alphabet of A, C, G, and T. 452 00:44:13,280 --> 00:44:19,580 And that was because one of the original applications of this protocol was for privacy preserving 453 00:44:19,580 --> 00:44:22,160 searches of DNA. 454 00:44:22,480 --> 00:44:25,580 So I think one of the applications they were saying is... 455 00:44:25,580 --> 00:44:25,620 Okay. 456 00:44:25,640 --> 00:44:31,780 One of the things that they suggested was you might have some researchers who know some 457 00:44:31,780 --> 00:44:35,080 gene mutations that make you more prone to cancer. 458 00:44:36,260 --> 00:44:38,280 You'd like to know, hey, am I more likely to have cancer? 459 00:44:38,380 --> 00:44:41,380 But you don't want other people to know what the answer is, right? 460 00:44:41,440 --> 00:44:45,120 Because that could mess with your insurance or anything like that. 461 00:44:45,240 --> 00:44:47,600 So you get your genes sequenced. 462 00:44:47,660 --> 00:44:49,140 You encrypt the... 463 00:44:49,840 --> 00:44:54,040 You encrypt your DNA in this special way, send the response back, and then you can see 464 00:44:54,040 --> 00:44:54,480 if... 465 00:44:55,700 --> 00:44:59,220 If the appropriate genes match any of the patterns they have. 466 00:45:01,660 --> 00:45:08,800 So, in this case, I just tried to keep it to a relatively small alphabet of just ASCII 467 00:45:08,800 --> 00:45:15,780 letters, digits, some white space and punctuation, but also allow you to specify the alphabet 468 00:45:15,780 --> 00:45:16,440 if you want. 469 00:45:16,920 --> 00:45:24,460 And the NIP method, you know, has two other parameters in it. 470 00:45:24,480 --> 00:45:29,640 One is a text file, so that's the text that's on the server side and the query. 471 00:45:29,840 --> 00:45:31,020 So only one... 472 00:45:31,020 --> 00:45:34,920 Only the server is going to fill in that one and only the client is going to fill in 473 00:45:34,920 --> 00:45:36,300 the query parameter there. 474 00:45:38,260 --> 00:45:44,940 And then I just have a few helper methods here. 475 00:45:45,060 --> 00:45:48,340 This one constructs the character delay vectors. 476 00:45:49,660 --> 00:45:51,380 This one does the encryption. 477 00:45:52,780 --> 00:45:55,700 This does the searching on the server side. 478 00:45:55,980 --> 00:45:59,800 So this does all the homomorphic encryption or homomorphic operations. 479 00:46:02,140 --> 00:46:05,880 And it does, you know, the blinding and the shuffling. 480 00:46:06,820 --> 00:46:11,920 And then in the actual... 481 00:46:11,920 --> 00:46:16,460 For the actual steps of the protocol, the client, you know, just first generates a key. 482 00:46:17,560 --> 00:46:21,360 It constructs the character delay vector and sends the... 483 00:46:21,360 --> 00:46:23,040 Both the character... 484 00:46:23,040 --> 00:46:24,860 All of the... 485 00:46:24,860 --> 00:46:32,960 The character delay vector, the pattern length and the public key. 486 00:46:35,100 --> 00:46:42,620 And then what it expects back is an encrypted activation vector and it just does a search 487 00:46:42,620 --> 00:46:44,460 through that to see are any of those... 488 00:46:44,460 --> 00:46:46,200 Do any of those values decrypt to zero? 489 00:46:46,400 --> 00:46:48,400 And if it does, it'll print pattern found. 490 00:46:48,780 --> 00:46:51,180 Otherwise, pattern not found. 491 00:46:51,360 --> 00:46:55,500 So, unfortunately, my demo's not quite working. 492 00:46:56,360 --> 00:46:58,040 So I'll basically leave it there. 493 00:46:58,420 --> 00:47:01,200 I think we have a few minutes for questions if anybody has any. 494 00:47:02,040 --> 00:47:04,320 But other than that, I think that's all I've got. 495 00:47:04,740 --> 00:47:06,640 So, thank you.