├── .travis.yml
├── doc
├── cachesize.png
└── auditpathgen.png
├── .gitignore
├── util.go
├── gosmt_test.go
├── README.md
├── cmd
├── benchht
│ └── main.go
└── benchsmt
│ └── main.go
├── cache.go
├── gosmt.go
└── LICENSE
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | go:
4 | - tip
5 |
--------------------------------------------------------------------------------
/doc/cachesize.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pylls/gosmt/HEAD/doc/cachesize.png
--------------------------------------------------------------------------------
/doc/auditpathgen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pylls/gosmt/HEAD/doc/auditpathgen.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files, Static and Dynamic libs (Shared Objects)
2 | *.o
3 | *.a
4 | *.so
5 |
6 | # Folders
7 | _obj
8 | _test
9 |
10 | # Architecture specific extensions/prefixes
11 | *.[568vq]
12 | [568vq].out
13 |
14 | *.cgo1.go
15 | *.cgo2.c
16 | _cgo_defun.c
17 | _cgo_gotypes.go
18 | _cgo_export.*
19 |
20 | _testmain.go
21 |
22 | *.exe
23 | *.test
24 | *.prof
25 | *.out
26 |
--------------------------------------------------------------------------------
/util.go:
--------------------------------------------------------------------------------
1 | package gosmt
2 |
3 | import "crypto/sha512"
4 |
5 | // thank you https://play.golang.org/p/sycUxCZyxf.
6 |
7 | // bitIsSet checks whether bit of a bit string (stored as a byte string)
8 | // at position i (range:[1, N] and big-endian) is set to 1 .
9 | func bitIsSet(bits []byte, i uint64) bool { return bits[i/8]&(1<
41 |
42 |
43 |
44 | There is no such thing as a free lunch though. Below is the average time it
45 | takes to generate an (Merkle) audit path. We include a number of B- caches with
46 | different caching probabilities (note that the B cache is identical to B-1.0).
47 | While B-0.5 behaves erratic, B-0.6 and above needs less then 4ms. For many
48 | applications this is practical and saves a significant amount of space compared
49 | to explicity stored authenticated data structures.
50 |
51 |
52 |
53 |
54 |
55 | You can reproduce these benchmarks with the
56 | [cmd/benchht](https://github.com/pylls/gosmt/tree/master/cmd/benchht) and
57 | [cmd/benchsmt](https://github.com/pylls/gosmt/tree/master/cmd/benchsmt)
58 | executables.
59 |
60 | #### Paper
61 | [https://eprint.iacr.org/2016/683](https://eprint.iacr.org/2016/683)
62 |
63 | #### License
64 | Apache 2.0
65 |
--------------------------------------------------------------------------------
/cmd/benchht/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "crypto/sha512"
5 | "fmt"
6 | "log"
7 | "math/rand"
8 | "testing"
9 |
10 | "github.com/pylls/balloon/hashtreap"
11 | )
12 |
13 | type run struct {
14 | f func(b *testing.B)
15 | cache string
16 | size int
17 | }
18 |
19 | var (
20 | maxSize = 20
21 | hashOutputLen = 32
22 | updateSize = 256
23 | keyUpdateDSsize = 15
24 | )
25 |
26 | func main() {
27 | log.Printf("update time (ms) for keys in 2^%d HT:", keyUpdateDSsize)
28 | for i := uint(1); i <= uint(maxSize); i++ {
29 | result := testing.Benchmark(makeUpdateKeysBench(1<= s
36 | i := sort.Search(d.Len(), func(i int) bool {
37 | return bytes.Compare(d[i], s) >= 0
38 | })
39 | return d[:i], d[i:]
40 | }
41 |
42 | // Key also implements Trie interface, splitable on split index.
43 | type Key [][]byte
44 |
45 | func (k Key) Len() int { return len(k) }
46 | func (k Key) Swap(i, j int) { k[i], k[j] = k[j], k[i] }
47 | func (k Key) Less(i, j int) bool { return bytes.Compare(k[i], k[j]) == -1 }
48 | func (k Key) Split(s []byte) (l, r Key) {
49 | // make sure k is stable-sorted first
50 | sort.Stable(k)
51 | // the smallest index i where d[i] >= s
52 | i := sort.Search(k.Len(), func(i int) bool {
53 | return bytes.Compare(k[i], s) >= 0
54 | })
55 | return k[:i], k[i:]
56 | }
57 |
58 | // SMT is a sparse Merkle tree.
59 | type SMT struct {
60 | c []byte // tree-wide constant, an empty leaf will have a default value of hash(c)
61 | cache Cache // Cache interface could be implemented by different caching strategies
62 | Base []byte // key of left-most leaf of a subtree, fixed in size.
63 | hash func(data ...[]byte) []byte
64 | N uint64 // output length, in bits, of hash
65 | defaultHashes [][]byte // [height][]byte, one default byte string per height (range:[0, N]), leaf node has height of 0, root node has height of N.
66 | }
67 |
68 | // NewSMT creates a new SMT. SMT instantiation requires a default empty leaf constant c, a caching strategy cache (e.g. CacheBranch, CacheBranchPlus), and a particular hash function (e.g. SHA256)
69 | func NewSMT(c []byte, cache Cache, hash func(data ...[]byte) []byte) *SMT {
70 | s := new(SMT)
71 | s.cache = cache
72 | s.hash = hash
73 | s.c = c
74 | s.N = uint64(len(hash([]byte("smt"))) * 8) // hash any string to get output length
75 | s.Base = make([]byte, s.N/8)
76 |
77 | s.defaultHashes = make([][]byte, s.N+1)
78 | s.defaultHashes[0] = s.leafHash(Empty, nil)
79 | for i := 1; i <= int(s.N); i++ {
80 | s.defaultHashes[i] = hash(s.defaultHashes[i-1], s.defaultHashes[i-1])
81 | }
82 | return s
83 | }
84 |
85 | // Update updates keys to the value. Note: d and keys should be sorted as param.
86 | func (s *SMT) Update(d D, keys Key, height uint64, base, value []byte) []byte {
87 | if height == 0 {
88 | return s.leafHash(value, base)
89 | }
90 | split := bitSplit(base, s.N-height)
91 | ld, rd := d.Split(split)
92 | lkeys, rkeys := keys.Split(split)
93 |
94 | // When there's a key falling within the range of left/right subtree, meaning
95 | // a leaf node in left/right branch should be updated to a new value, then update
96 | // the root hash of left/right subtree recursively;
97 | // When no leaf node in left/right subtree shall be updated, then directly return
98 | // its root hash and update upwards recursively.
99 | switch {
100 | case lkeys.Len() == 0 && rkeys.Len() > 0:
101 | return s.cache.HashCache(s.RootHash(ld, height-1, base),
102 | s.Update(rd, keys, height-1, split, value),
103 | height, base, split, s.interiorHash, s.defaultHashes)
104 | case lkeys.Len() > 0 && rkeys.Len() == 0:
105 | return s.cache.HashCache(s.Update(ld, keys, height-1, base, value),
106 | s.RootHash(rd, height-1, split),
107 | height, base, split, s.interiorHash, s.defaultHashes)
108 | default:
109 | return s.cache.HashCache(s.Update(ld, lkeys, height-1, base, value),
110 | s.Update(rd, rkeys, height-1, split, value),
111 | height, base, split, s.interiorHash, s.defaultHashes)
112 | }
113 | }
114 |
115 | // AuditPath generates an audit path.
116 | func (s *SMT) AuditPath(d D, height uint64, base, key []byte) [][]byte {
117 | if height == 0 {
118 | return nil
119 | }
120 | split := bitSplit(base, s.N-height)
121 | l, r := d.Split(split)
122 |
123 | if !bitIsSet(key, s.N-height) { // if k_j == 0
124 | return append(s.AuditPath(l, height-1, base, key),
125 | s.RootHash(r, height-1, split))
126 | }
127 | return append(s.AuditPath(r, height-1, split, key),
128 | s.RootHash(l, height-1, base))
129 | }
130 |
131 | // VerifyAuditPath verifies an audit path.
132 | func (s *SMT) VerifyAuditPath(ap [][]byte, key, value, root []byte) bool {
133 | return bytes.Equal(root,
134 | s.auditPathCalc(ap, s.N, make([]byte, s.N/8), key, value))
135 | }
136 |
137 | func (s *SMT) auditPathCalc(ap [][]byte, height uint64,
138 | base, key, value []byte) []byte {
139 | if height == 0 {
140 | return s.leafHash(value, base)
141 | }
142 | split := bitSplit(base, s.N-height)
143 | if !bitIsSet(key, s.N-height) { // if k_j == 0
144 | return s.interiorHash(s.auditPathCalc(ap, height-1, base, key, value),
145 | ap[height-1], height, base)
146 | }
147 | return s.interiorHash(ap[height-1],
148 | s.auditPathCalc(ap, height-1, split, key, value), height, base)
149 | }
150 |
151 | // RootHash returns the root hash of a subtree with certain height.
152 | func (s *SMT) RootHash(d D, height uint64, base []byte) []byte {
153 | switch {
154 | case s.cache.Exists(height, base):
155 | return s.cache.Get(height, base)
156 | case d.Len() == 0:
157 | return s.defaultHash(height)
158 | case d.Len() == 1 && height == 0:
159 | return s.leafHash(Set, base)
160 | case d.Len() > 0 && height == 0:
161 | panic("this should never happen (unsorted D or broken split?)")
162 | default:
163 | split := bitSplit(base, s.N-height)
164 | l, r := d.Split(split)
165 | return s.interiorHash(s.RootHash(l, height-1, base),
166 | s.RootHash(r, height-1, split), height, base)
167 | }
168 | }
169 |
170 | func (s *SMT) defaultHash(height uint64) []byte {
171 | return s.defaultHashes[height]
172 | }
173 |
174 | // leafHash returns the leaf value of SMT.
175 | func (s *SMT) leafHash(a, base []byte) []byte {
176 | if bytes.Equal(a, Empty) {
177 | return s.hash(s.c)
178 | }
179 | return s.hash(s.c, base)
180 | }
181 |
182 | // interiorHash returns the non-leaf node value of SMT.
183 | func (s *SMT) interiorHash(left, right []byte,
184 | height uint64, base []byte) []byte {
185 | if bytes.Equal(left, right) {
186 | return s.hash(left, right)
187 | }
188 | buf := new(bytes.Buffer)
189 | if binary.Write(buf, binary.BigEndian, height) != nil {
190 | panic("failed to encode height")
191 | }
192 | return s.hash(left, right, base, buf.Bytes())
193 | }
194 |
195 | // CacheEntries returns the number of cache entries.
196 | func (s *SMT) CacheEntries() int {
197 | return s.cache.Entries()
198 | }
199 |
--------------------------------------------------------------------------------
/cmd/benchsmt/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "crypto/sha512"
5 | "flag"
6 | "fmt"
7 | "log"
8 | "math/rand"
9 | "os"
10 | "sort"
11 | "strconv"
12 | "testing"
13 | "time"
14 |
15 | "github.com/montanaflynn/stats"
16 | "github.com/pylls/gosmt"
17 | )
18 |
19 | type run struct {
20 | f func(b *testing.B)
21 | s func() string
22 | cache string
23 | }
24 |
25 | var (
26 | maxSMT = 20
27 | keyUpdateDSsize = 15
28 | bMin = 0.5
29 | bMax = 0.9
30 | bDelta = 0.1
31 | updateSize = 256
32 | filename = "benchsmt." + time.Now().String()
33 | data []gosmt.D
34 | repeat = 4
35 | )
36 |
37 | type res struct {
38 | index int
39 | ms float64
40 | }
41 |
42 | func main() {
43 | flag.Parse()
44 | if len(flag.Args()) == 0 {
45 | log.Fatal("need to specify maximum size of SMT")
46 | }
47 | m, err := strconv.Atoi(flag.Arg(0))
48 | if err != nil {
49 | log.Fatal("the first argument has to be an int")
50 | }
51 | maxSMT = m
52 | file, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
53 | if err != nil {
54 | panic(err)
55 | }
56 | defer file.Close()
57 |
58 | // generate testdata only once
59 | for i := uint(1); i <= uint(maxSMT); i++ {
60 | var d gosmt.D
61 | size := 1 << i
62 | for j := 0; j < size; j++ {
63 | d = append(d, hash(randKey(make([]byte, 32))))
64 | }
65 | sort.Sort(gosmt.D(d))
66 | data = append(data, d)
67 | }
68 |
69 | var benchAP []run
70 | for i := 0; i < maxSMT; i++ {
71 | for j := bMin; j <= bMax; j += bDelta {
72 | benchAP = append(benchAP, run{
73 | f: makeAuditPathBench(data[i],
74 | gosmt.NewCacheBranchMinus(j)),
75 | cache: fmt.Sprintf("B-%.1f", j),
76 | })
77 | }
78 | benchAP = append(benchAP, run{
79 | f: makeAuditPathBench(data[i],
80 | gosmt.CacheBranch(make(map[string][]byte))),
81 | cache: "B",
82 | })
83 | benchAP = append(benchAP, run{
84 | f: makeAuditPathBench(data[i],
85 | gosmt.CacheBranchPlus(make(map[string][]byte))),
86 | cache: "B+",
87 | })
88 | }
89 |
90 | var benchUpdate []run
91 | for i := 0; i < maxSMT; i++ {
92 | for j := bMin; j <= bMax; j += bDelta {
93 | benchUpdate = append(benchUpdate, run{
94 | f: makeUpdateBench(data[i], gosmt.NewCacheBranchMinus(j)),
95 | cache: fmt.Sprintf("B-%.1f", j),
96 | })
97 | }
98 | benchUpdate = append(benchUpdate, run{
99 | f: makeUpdateBench(data[i],
100 | gosmt.CacheBranch(make(map[string][]byte))),
101 | cache: "B",
102 | })
103 | benchUpdate = append(benchUpdate, run{
104 | f: makeUpdateBench(data[i],
105 | gosmt.CacheBranchPlus(make(map[string][]byte))),
106 | cache: "B+",
107 | })
108 | }
109 |
110 | var benchUpdateKey []run
111 | for i := 0; i < maxSMT; i++ {
112 | size := 1 << uint(i+1)
113 | for j := bMin; j <= bMax; j += bDelta {
114 | benchUpdateKey = append(benchUpdateKey, run{
115 | f: makeUpdateKeyBench(size, data[keyUpdateDSsize-1],
116 | gosmt.NewCacheBranchMinus(j)),
117 | cache: fmt.Sprintf("B-%.1f", j),
118 | })
119 | }
120 | benchUpdateKey = append(benchUpdateKey, run{
121 | f: makeUpdateKeyBench(size, data[keyUpdateDSsize-1],
122 | gosmt.CacheBranch(make(map[string][]byte))),
123 | cache: "B",
124 | })
125 | benchUpdateKey = append(benchUpdateKey, run{
126 | f: makeUpdateKeyBench(size, data[keyUpdateDSsize-1],
127 | gosmt.CacheBranchPlus(make(map[string][]byte))),
128 | cache: "B+",
129 | })
130 | }
131 |
132 | var benchCacheSize []run
133 | for i := 0; i < maxSMT; i++ {
134 | for j := bMin; j <= bMax; j += bDelta {
135 | benchCacheSize = append(benchCacheSize, run{
136 | s: makeCacheSizeBench(data[i],
137 | gosmt.NewCacheBranchMinus(j)),
138 | cache: fmt.Sprintf("B-%.1f", j),
139 | })
140 | }
141 | benchCacheSize = append(benchCacheSize, run{
142 | s: makeCacheSizeBench(data[i],
143 | gosmt.CacheBranch(make(map[string][]byte))),
144 | cache: "B",
145 | })
146 | benchCacheSize = append(benchCacheSize, run{
147 | s: makeCacheSizeBench(data[i],
148 | gosmt.CacheBranchPlus(make(map[string][]byte))),
149 | cache: "B+",
150 | })
151 | }
152 |
153 | do(fmt.Sprintf("update time (ms) for 2^i keys in 2^%d SMT", keyUpdateDSsize),
154 | benchUpdateKey, file)
155 | do(fmt.Sprintf("update time (ms) for %d keys", updateSize), benchUpdate, file)
156 | do("cache size (MiB)", benchCacheSize, file)
157 | do("audit path generation time (ms)", benchAP, file)
158 |
159 | }
160 |
161 | func do(exp string, bench []run, file *os.File) {
162 | flog(fmt.Sprintf("####### experiment: %s #######", exp), file)
163 | expCount := len(bench) / maxSMT
164 | header := "SMT size 2^x"
165 | for i := 0; i < expCount; i++ {
166 | header += fmt.Sprintf(", %s", bench[i].cache)
167 | }
168 | flog(header, file)
169 |
170 | for i := 0; i < maxSMT; i++ {
171 | r := fmt.Sprintf("%d", i+1)
172 | for j := 0; j < expCount; j++ {
173 | if bench[i].s != nil {
174 | r += fmt.Sprintf(", %s", bench[i*expCount+j].s())
175 | } else {
176 | results := make([]float64, repeat)
177 | for round := 0; round < repeat; round++ {
178 | results[round] = float64(testing.Benchmark(bench[i*expCount+j].f).NsPerOp()) / float64(1000*1000) // ns to ms
179 | }
180 | avg, err := stats.LoadRawData(results).Mean()
181 | if err != nil {
182 | panic(err)
183 | }
184 | r += fmt.Sprintf(", %.4f", avg)
185 | }
186 | }
187 | flog(r, file)
188 | }
189 | }
190 |
191 | func flog(str string, f *os.File) {
192 | _, err := f.WriteString(str + "\n")
193 | if err != nil {
194 | panic(err)
195 | }
196 | log.Println(str)
197 | }
198 |
199 | func makeAuditPathBench(data gosmt.D,
200 | cache gosmt.Cache) func(b *testing.B) {
201 | return func(b *testing.B) {
202 | s := gosmt.NewSMT([]byte{0x42}, cache, hash)
203 | s.Update(data, gosmt.Key(data), s.N, s.Base, gosmt.Set)
204 |
205 | // create N keys
206 | keys := make([][]byte, b.N)
207 | for i := 0; i < b.N; i++ {
208 | keys[i] = randKey(make([]byte, s.N/8))
209 | }
210 |
211 | b.ResetTimer()
212 | for i := 0; i < b.N; i++ {
213 | s.AuditPath(data, s.N, s.Base, keys[i])
214 | }
215 | }
216 | }
217 |
218 | func makeUpdateBench(data gosmt.D,
219 | cache gosmt.Cache) func(b *testing.B) {
220 | return func(b *testing.B) {
221 | s := gosmt.NewSMT([]byte{0x42}, cache, hash)
222 | s.Update(data, gosmt.Key(data), s.N, s.Base, gosmt.Set)
223 |
224 | // create updateSize keys
225 | keys := make([][]byte, updateSize)
226 | for i := 0; i < updateSize; i++ {
227 | keys[i] = randKey(make([]byte, s.N/8))
228 | }
229 | newdata := make([][]byte, len(data), len(data)+len(keys))
230 | copy(newdata, data)
231 | newdata = append(newdata, keys...)
232 | sort.Sort(gosmt.D(newdata))
233 |
234 | b.ResetTimer()
235 | for i := 0; i < b.N; i++ {
236 | s.Update(newdata, keys, s.N, s.Base, gosmt.Set)
237 | b.StopTimer()
238 | s.Update(data, keys, s.N, s.Base, gosmt.Empty)
239 | b.StartTimer()
240 | }
241 | }
242 | }
243 |
244 | func makeUpdateKeyBench(size int, data gosmt.D,
245 | cache gosmt.Cache) func(b *testing.B) {
246 | return func(b *testing.B) {
247 | s := gosmt.NewSMT([]byte{0x42}, cache, hash)
248 | s.Update(data, gosmt.Key(data), s.N, s.Base, gosmt.Set)
249 |
250 | b.ResetTimer()
251 | for i := 0; i < b.N; i++ {
252 | b.StopTimer()
253 |
254 | keys := make([][]byte, size)
255 | for i := 0; i < size; i++ {
256 | keys[i] = randKey(make([]byte, s.N/8))
257 | }
258 | newdata := make([][]byte, len(data), len(data)+len(keys))
259 | copy(newdata, data)
260 | newdata = append(newdata, keys...)
261 | sort.Sort(gosmt.D(newdata))
262 |
263 | b.StartTimer()
264 | s.Update(newdata, keys, s.N, s.Base, gosmt.Set)
265 |
266 | b.StopTimer()
267 | // cleanup, remove the keys we just inserted
268 | s.Update(data, keys, s.N, s.Base, gosmt.Empty)
269 | b.StartTimer()
270 | }
271 | }
272 | }
273 |
274 | func makeCacheSizeBench(data gosmt.D,
275 | cache gosmt.Cache) func() string {
276 | return func() string {
277 | s := gosmt.NewSMT([]byte{0x42}, cache, hash)
278 | s.Update(data, gosmt.Key(data), s.N, s.Base, gosmt.Set)
279 |
280 | return fmt.Sprintf("%.4f",
281 | float64(s.CacheEntries()*int(s.N))/float64(1024*1024))
282 | }
283 | }
284 |
285 | func randKey(key []byte) []byte {
286 | _, err := rand.Read(key)
287 | if err != nil {
288 | panic(err)
289 | }
290 | return key
291 | }
292 |
293 | func hash(data ...[]byte) []byte {
294 | hasher := sha512.New512_256()
295 | for i := 0; i < len(data); i++ {
296 | hasher.Write(data[i])
297 | }
298 | return hasher.Sum(nil)
299 | }
300 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------